Python Forum
invalid syantx - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: invalid syantx (/thread-17842.html)



invalid syantx - metro779966 - Apr-25-2019

I am new in programing , I use python 3.7.2- when I write any code in python file and make RUN I have invalid syntax message
forexample:
I have file with name new file.py I write this :
f=open('bbb.txt', 'w')
file.Write('hello')
file.close()
make RUN then I receive invalid syantax

Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.

>>> f=open('new.txt','w')
>>> f.write(h'hello')
>>> f.close()

>>> import os
>>> if os.path.exists('newfolder'):
print('yes')
else:
print('no')

>>> if not os.path.exists('folderst'):
os.mkdir('folderst')


RE: invalid syantx - keames - Apr-26-2019

There is an h in front of the string literal 'hello' where you write to the file.
Output:
>>> h"This string literal is syntactically invalid" SyntaxError: invalid syntax >>> r"This is a syntactically valid raw string." 'This is a syntactically valid raw string.' >>> b"This is a syntactically valid bytes literal." b'This is a syntactically valid bytes literal.' >>> "This is a syntactically valid string literal." 'This is a syntactically valid string literal.'



RE: invalid syantx - perfringo - Apr-26-2019

I also observe that in file you have file.Write('hello'). Shouldn't it be .write?


RE: invalid syantx - keames - Apr-26-2019

I noticed that too, perfringo. I assumed that in his actual code he typed it correctly because it is a lowercase w in his copy paste of the python console. Also, he isn't talking about getting a NameError, he's getting a syntax error.