# Copy the data to a .bin file:
import shutil
shutil.copyfile("input.txt", "input.bin")
# Read the data as a string:
with open("input.bin") as data_file:
data = data_file.read()
# Now, to convert the string to useful data,
# parse it any way you want. For example, to take
# the first number in each line and store it into
# an array called "numbers":
data = [[field.strip() for field in line.split(",")]
for line in data.splitlines()]
numbers = [int(data[0]) for data in data]
print numbers
数据已经是您想要的格式。如果要将输入文件复制到另一个名为
input.bin
的文件,请使用shutil.copyfile
:相关问题 更多 >
编程相关推荐