[英]Get input from file in integer form
我想从python中int类型的文件中获取数据,但发生错误:
ValueError: invalid literal for int() with base 10: 'from sys import argv\n'
Try:尝试:
file_descriptor = open('file.name')
bytes = file_descriptor.read()
try:
newint=int(bytes)
except Exception as e:
print(str(e))
print(newint)
this retrieves data from the file, and tries to parse it into an integer format.这将从文件中检索数据,并尝试将其解析为整数格式。 (and then prints it back out.) (然后打印出来。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.