【发布时间】:2021-02-15 17:03:00
【问题描述】:
我对 python 完全陌生,所以我不知道我应该通过使用用户输入到文本文件中来制作数据。我所能做的就是在 input() 中使用数据变量。我尝试使用输入将数据转换为文本文件,但之后,文本文件中没有任何内容。还有什么办法可以解决吗?
import sys
def write(nameOfFile):
name = nameOfFile+'.txt';
file = open(name, 'w+');
upper_code = input();
lower_code = input();
name_code = input();
first_code = input();
day = input();
date_start = input();
date_end = input();
hours = input();
num_code = input();
print(name);
print(upper_code, lower_name);
print(name_code, first_code);
print(day, date_start, date_end);
print(hours);
print(num_code);
return name;
if len(sys.argv)<2:
print('usage: makefile <filename.txt>');
print('Enter a file name: ');
inputFi = input();
write(inputFi);
这些是我在 python 中使用的变量:
upper_code lower_code
name_code first_code
day date_start date_end
hours
num_code
这是一个 file.txt,应该看起来像这样:
ABC abc
Rider I
TH 10/30/20 10/31/20
4
16
【问题讨论】:
标签: python-3.x file user-input store