0

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]. I have been watching video and they do it.

I am using jupyter notebook. 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])?
  • 2
    I think you are using python 3.x so you need parenthesis for the print statement. Also you have space between ```final``` and ```[0]```. There shouldn't be any. It should be like ```print(final[0])``` – Kartikeya Sharma Jul 31 '19 at 19:51
  • Which version of Python are you using? `print x` is used in Python 2 while `print(x)` is used in Python 3. Also are you trying to print the first element in the list `final`? if so then remove the space between `final` and `[0]`: `print(final[0])`. – Philip Ciunkiewicz Jul 31 '19 at 19:52
  • 1
    Possible duplicate of [What does "SyntaxError: Missing parentheses in call to 'print'" mean in Python?](https://stackoverflow.com/questions/25445439/what-does-syntaxerror-missing-parentheses-in-call-to-print-mean-in-python) – Alessandro Da Rugna Jul 31 '19 at 20:10

1 Answers1

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

print(final[0])

In python3 print has been used as a function so this throws an error

Python has different access specifiers that specify the modes the file is open in

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")
  • but the file was not saved –  Jul 31 '19 at 20:02
  • Access modes govern the type of operations possible in the opened file.I will update the answer – Abhishek Dalakoti Jul 31 '19 at 20:06
  • Let me know if there are more queries @Tom – Abhishek Dalakoti Jul 31 '19 at 20:13
  • sorry to insist but I am new to python. I want to take several phrases that start at ', "text": "' and end at '", "truncated"' to save to a file called file.txt. I wanted to add it as file = open ("file_address.txt", "w") and I could not and I wanted to print it on the screen and neither. –  Aug 01 '19 at 15:25