I wonder if anyone can tell me why the following happens:
If I run the code
If I run the code
path = r'C:\Users\New\Andys Docs\Python\Datafiles' textfile = 'shortmusic' fullfilename = path+'\\'+textfile+'.txt' try: infile = open(fullfilename, 'r') except IOError: print('MDB: Cannot open {} for input'.format(fullfilename)) sys.exit()it works fine - the file is found and opened. You will note that I have included the raw string operator
'r'
before the string in path
so that the backslashes don't have to be escaped (with another backslash) but use the string '\\'
when building the fullfilename
string. That is because if I change that line to readfullfilename = path+r'\'+textfile+'.txt'I get the compiler error 'EOL while scanning string literal' which tends to suggest that one of the quotes isn't recognised. Please, why should this be? Can I not use a raw string here?