在Windows 7中找不到的文件,但在Windows 10中起作用
我写了一个在Windows 10上使用的Python脚本,但是当我在Windows 7上运行相同的Python版本(3.8)时,它找不到我的输入文件:
这是代码:
# Get list of command line arguments, remove first argument
argumentList = sys.argv[1:]
# Options
options = "hai:s:"
# Long options
longOptions = ["Help", "project", "Input", "Sqo"]
try:
# Parsing argument
arguments, values = getopt.getopt(argumentList, options, longOptions)
print("The arguments are : ", arguments)
print("The values are", values)
# checking each argument
for currentArgument, currentValue in arguments:
if currentArgument in ("-h", "--Help"):
print("Convert Polyspace findings from JSON file to console in Visual Studio ccompliant format")
print("Options:")
print(" -i, --Input: JSON input file")
print(" -s, --Sqo: SQO definition file")
print(" -a, --project: Show results for all rules, even the ones not mandatory to fix")
print(" -h, --Help : This help")
elif currentArgument in ("-i", "--Input"):
inputFile = currentValue
print(inputFile)
elif currentArgument in ("-s", "--Sqo"):
sqoFile = currentValue
print(sqoFile)
elif currentArgument in ("-a", "--All"):
product = currentValue
print(product)
except getopt.error as err:
# output error, and return with an error code
print(str(err))
# read JSON data generated by Polyspace
try:
with open(inputFile, "r") as readFile:
data = json.load(readFile)
sqoLevel = int(sqoRoot.get('level'))
...
except FileNotFoundError:
print("Error: File not found " + inputFile)
sys.exit(1)
I在CMD行中运行:
python PolyspaceReportGenerator.py -s polyspaceSqo.xml -i polyspaceResults.json -a XXX
在Windows 10中,一切都很好。 在Windows 7中,我会收到以下错误:
Error: File not found .\polyspaceResults.json
我什至尝试创建一个绝对路径:
elif currentArgument in ("-i", "--Input"):
inputFile = os.path.join("D:\\","Polyspace",currentValue)
#inputFile = os.path.abspath(inputFile)
print("The absolute path : ", inputFile)
但是仍然有相同的错误:
The absolute path : D:\Polyspace\polyspaceResults.json
Error: File not found D:\Polyspace\polyspaceResults.json
I have written a Python script which is working on my Windows 10, but when I run the same code on Windows 7 with the same Python version (3.8), it doesn't find my input file:
Here is the piece of code:
# Get list of command line arguments, remove first argument
argumentList = sys.argv[1:]
# Options
options = "hai:s:"
# Long options
longOptions = ["Help", "project", "Input", "Sqo"]
try:
# Parsing argument
arguments, values = getopt.getopt(argumentList, options, longOptions)
print("The arguments are : ", arguments)
print("The values are", values)
# checking each argument
for currentArgument, currentValue in arguments:
if currentArgument in ("-h", "--Help"):
print("Convert Polyspace findings from JSON file to console in Visual Studio ccompliant format")
print("Options:")
print(" -i, --Input: JSON input file")
print(" -s, --Sqo: SQO definition file")
print(" -a, --project: Show results for all rules, even the ones not mandatory to fix")
print(" -h, --Help : This help")
elif currentArgument in ("-i", "--Input"):
inputFile = currentValue
print(inputFile)
elif currentArgument in ("-s", "--Sqo"):
sqoFile = currentValue
print(sqoFile)
elif currentArgument in ("-a", "--All"):
product = currentValue
print(product)
except getopt.error as err:
# output error, and return with an error code
print(str(err))
# read JSON data generated by Polyspace
try:
with open(inputFile, "r") as readFile:
data = json.load(readFile)
sqoLevel = int(sqoRoot.get('level'))
...
except FileNotFoundError:
print("Error: File not found " + inputFile)
sys.exit(1)
I run in cmd line:
python PolyspaceReportGenerator.py -s polyspaceSqo.xml -i polyspaceResults.json -a XXX
in windows 10, everything is fine.
in windows 7, I get the following error:
Error: File not found .\polyspaceResults.json
I even tried to create an absolute path:
elif currentArgument in ("-i", "--Input"):
inputFile = os.path.join("D:\\","Polyspace",currentValue)
#inputFile = os.path.abspath(inputFile)
print("The absolute path : ", inputFile)
But is still get the same error:
The absolute path : D:\Polyspace\polyspaceResults.json
Error: File not found D:\Polyspace\polyspaceResults.json
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论