【问题标题】:Terminal in PyChram not showing me an outputPyCharm 中的终端没有显示输出
【发布时间】: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 文件)。

标签: python terminal


【解决方案1】:

据我了解您所附的代码,您好必须写为'hi'。在您的原始代码中,hi 被视为分配给inputfile 的另一个变量,但尚未定义。

【讨论】:

  • 我只是看到了这个,但忽略了 import sys,将它用于 sys.argv,但我只是想在我的终端中获取 inputfile 的输出。到目前为止,无论何时调用程序都没有发生任何事情
  • 你能上传你所有的代码吗?很难说这些。
猜你喜欢
  • 2018-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-17
  • 2023-03-03
  • 2018-07-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多