import sys print("open_file.py") content=dir(sys) print(content) rep = 'y' while (rep != 'n'): name = input('Enter the name of the file:') print('You entered: ', name) name = '\Documents\Py2\' + name print('name is: ', name) try: fh = open(name, "r+") except IOError: print("Cannot find file ") else: str = fh.read(10); print("Read String is : ", str) # Check current position position = fh.tell(); print("Current file position : ", position) # Reposition pointer at the beginning once again position = fh.seek(0, 0); str = fh.read(140); print("Again read String is : ", str) fh.close() rep = input('Try for another file ? y/n ? ') if rep == 'n': print("Finished with this file") else: rep = 'y' print('READING THE WHOLE FILE') name=input('Enter the name of the file: ') name='/home/sylvain/'+name f=open(name) text=f.read() print(text) f.close()
Error:E:\Documents\Py2>python open_file.py
File "open_file.py", line 11
name = '\Documents\Py2\' + name
^
SyntaxError: EOL while scanning string literal
[/python]