【发布时间】:2018-10-08 12:29:18
【问题描述】:
这是我的测试代码,但我有一个更详细的代码 - 但它们都不起作用。在 python 3.x 中。
import sys
def main():
inputfile = 'hi'
print(inputfile)
if __name__ == '__main__':
main()
编辑:这是我想使用终端的(和语法错误 - 同样的问题):
import csv
import sys
import json
inputfile = sys.argv[1]
outputfile = sys.argv[2]
# reading the csv
with open(inputfile, 'r') as inhandle: # r is reading while w is writing
reader = csv.DictReader(inhandle)
data = []
for row in reader:
data.append(row)
print(data)
# writing the json
with open(outputfile, "W") as outhandle:
json.dump(data, outhandle, indent=2)
【问题讨论】:
-
请发布您遇到的错误。对于第一个代码 sn-p,
hi没有在任何地方定义。我想你可能打算做'hi',一个字符串。 -
啊抱歉,我现在明白了。我会做那个编辑。但即使纠正它,我也没有收到错误,每当我在 PyCharm 的终端中调用程序时,都没有输出,它只是再次提示我。
-
如何你如何调用程序?你提到
Terminal让我觉得你实际上使用了内置的 OS shell。或者你使用Ctrl+Shift+F10描述here 吗? -
是的,我使用内置的 shell。我也刚刚使用了 Windows 的命令行,但它会将我路由回 PyChram 的终端以在那里运行它(很可能是因为它保存为 JetBrains PyChram 文件)。