我想要做什么:
我想要打印一个文件名。我可以看到输出文件是可用的。但我无法仅打印文件名。
Python代码:
today=datetime.datetime.today().strftime("%Y%m%d-%H%M%S")
string_file="string_"+today+".csv"
outputFile = open(string_file_rdkb, "w")
#....some code here...
my_df=pd.DataFrame(datalist2)
my_df.to_csv(outputFile, index=False, header=False)
print(outputFile + " is generated") #Here is the issue
输出结果如下:
print(outputFile + " is generated")
TypeError: unsupported operand type(s) for +: '_io.TextIOWrapper' and 'str'
我尝试解决的问题:
这与IT技术有关。print(str(outputFile) + " is generated")
输出结果如下:
<_io.TextIOWrapper name='string_20181213-160004.csv' mode='w' encoding='cp1252'> is generated
期望输出:
string_20181213-160004.csv is generated
string_file
,而不是打开文件对象outputFile
。 - Vikrant Sharmastring_file
而不是文件对象怎么样? - Serge Ballesta