Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将字典作为参数传递给另一个python脚本_Python_Dictionary_Arguments - Fatal编程技术网

将字典作为参数传递给另一个python脚本

将字典作为参数传递给另一个python脚本,python,dictionary,arguments,Python,Dictionary,Arguments,我想将字典作为参数传递给单独的python脚本,如下所示: dict1= {'appid':'facebook'} subprocess.call('python mypython.py -o' + dict1, shell=True) (Also tried with os.system) mypython.py的内容: parser = argparse.ArgumentParser(fromfile_prefix_chars='@') parser.add_argument("-o",

我想将字典作为参数传递给单独的python脚本,如下所示:

dict1= {'appid':'facebook'}
subprocess.call('python mypython.py -o' + dict1, shell=True) (Also tried with os.system)
mypython.py的内容:

parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
parser.add_argument("-o", dest="dict1")
args = parser.parse_args()
if args.dict1:
    op1 = args.dict1
    print op1
回溯详细信息:

python parent.py
Traceback (most recent call last):
  File "parent.py", line 52, in <module>
    sys.exit(main())
  File "mypython.py", line 30, in main
    subprocess.call('python mypython.py -o' + dict1, shell=True)
TypeError: cannot concatenate 'str' and 'dict' objects
它在:之后11之前添加了一个额外的空格,因此失败。唯一的解决方法是我的输入是字符串:

dict1="{2:11}"
os.system('python mypython.py -o '+dict1)
在上述情况下,它可以正常工作


有人能建议我如何将字典作为参数传递给另一个脚本吗?

您可以将dict转换为字符串strdict1,然后在另一个类中使用进行解析。

为什么要通过子进程进行此操作?看起来您正试图找到一种解决方法,解决如何从文件B调用文件a中的函数的问题。请。这是解决你假定问题的更好办法。
dict1="{2:11}"
os.system('python mypython.py -o '+dict1)