如何从命令行将Set(或网络)作为参数传递给Python

时间:2019-03-25 20:13:02

标签: c# python ipc

IronPython在获得批准并被告知这可能需要相当长的时间后才能使用,因此我试图从命令行使用一些网络算法,以便可以在C#代码中使用它们。我正在尝试通过命令行将网络作为参数传递。我遇到的问题是,当我定义图

template_name = 'properties/property_list.html'
template_name = 'properties/property_new.html'

在Python代码中,它很好用,我得到了想要的答案。当我尝试将其作为参数发送时:

 graph = {'s': {'a': 2, 'b': 1}, 'a': {'s': 3, 'b': 4, 'c':8}, 'b': {'s': 4, 'a': 2, 'd': 2}, 'c': {'a': 2, 'd': 7, 't': 4}, 'd': {'b': 1, 'c': 11, 't': 5}, 't': {'c': 3, 'd': 5}}

我收到以下错误:

C:\\Python27\\Python.exe C:\\PythonFiles\\DijkstraAlgorithm3.py  "{'s': {'a': 2, 'b': 1}, 'a': {'s': 3, 'b': 4, 'c':8}, 'b': {'s': 4, 'a': 2, 'd': 2}, 'c': {'a': 2, 'd': 7, 't': 4}, 'd': {'b': 1, 'c': 11, 't': 5}, 't': {'c': 3, 'd': 5}}"

我还注意到,虽然我以相同的方式传递代码,但在代码中定义的网络顺序与通过命令行发送的网络顺序似乎有所不同。这是完整的代码:

Traceback (most recent call last):
File "C:\\PythonFiles\\DijkstraAlgorithm3.py", line 60, in <module>
dijkstra(args.g,'s','t')
File "C:\\PythonFiles\\DijkstraAlgorithm3.py", line 27, in dijkstra
for neighbor in graph[src] :
TypeError: string indices must be integers, not str

0 个答案:

没有答案
相关问题