1
我想从脚本而不是命令行运行此函数。例如,功能是:如何从脚本中调用Python函数来运行命令行
def main():
parser = argparse.ArgumentParser(description='Caffe prototxt to mxnet model parameter converter.\
Note that only basic functions are implemented. You are welcomed to contribute to this file.')
parser.add_argument('caffe_prototxt', help='The prototxt file in Caffe format')
parser.add_argument('caffe_model', help='The binary model parameter file in Caffe format')
parser.add_argument('save_model_name', help='The name of the output model prefix')
args = parser.parse_args()
...
我该如何运行它?
file.main('file_1.csv', 'file_2.csv', 'name')
为什么有人会写一个函数,我只能从命令行运行?感觉不方便。
写这个函数是因为在'if name =='__main __''下编写代码通常是不好的。 – wRAR
嗨@wRAR,你有没有什么参考资料可以帮我阅读为什么会这样?非常感谢。 – user2014905
很简单,当你需要从不同的地方调用代码时,你不能像在单独的函数中编写的代码一样容易地调用写在'if name =='__main __'下的代码。 – wRAR