[英]How can I save this file txt?
I am trying to save a .txt file, previously cleaning from the previous .txt, but it is not saved and gives me an error in the final print [0]. 我正在尝试保存一个.txt文件,该文件先前是从以前的.txt文件中清除的,但是没有保存,最终打印时出现错误[0]。 I have been watching video and they do it.
我一直在观看视频,他们正在这样做。
I am using jupyter notebook. 我正在使用jupyter笔记本。 I'm sorry for my English it is low.
对不起,我的英语太差了。
archivo = open ("salida_tweets.txt")
linea = archivo.readline()
tweet=linea.split(',"text":"')
s = len(tweet)
for i in range(1,s):
final = tweet[i].split('","truncated"')
print final [0]
File "<ipython-input-6-acef6c26b974>", line 9
print final [0]
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean
print(final [0])?
Your error is syntax error its because in the video you were watching they were using python2.7 but your current version is 3 so use 您的错误是语法错误,因为您在观看视频的过程中使用的是python2.7,但当前版本为3,请使用
print(final[0])
In python3 print has been used as a function so this throws an error 在python3中,print已用作函数,因此会引发错误
Python has different access specifiers that specify the modes the file is open in Python具有不同的访问说明符,用于指定文件打开的模式
file=open("file_address.txt","w")
This will open file in write mode to write an string in a file you can simply use 这将以写入模式打开文件,以在您可以简单使用的文件中写入字符串
file.write("anything")
"anything" will be written in the file If you want to append the new information just open file in append mode 文件中将写入“任何内容”。如果要附加新信息,只需以附加模式打开文件
file=open("file_address.txt","a")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.