Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

breaking up long path names

I am having trouble breaking the path into two lines in my python compiler. It is simply a long path on the compiler screen and i have to stretch the window too wide. I know how to break a print("string") into two lines of code that will compile correctly, but not an open(path). As I write this I notice the text box can not even hold it all on one line. print()

`raw_StringFile = open(r'C:\Users\Public\Documents\year 2013\testfiles\test          code\rawstringfiles.txt', 'a')`
like image 774
Adreamer82 Avatar asked Oct 01 '13 20:10

Adreamer82


1 Answers

That is what the \ is for.

>>> mystr = "long" \
... "str"
>>> mystr
'longstr'

Or in your case:

longStr = r"C:\Users\Public\Documents\year 2013\testfiles" \
           r"\testcode\rawstringfiles.txt"
raw_StringFile = open(longStr, 'a')

EDIT

Well, you don't even need the \ if you use parenthesis, i.e.:

longStr = (r"C:\Users\Public\Documents\year 2013\testfiles"
               r"\testcode\rawstringfiles.txt")
raw_StringFile = open(longStr, 'a')
like image 163
George Mitchell Avatar answered Oct 31 '22 03:10

George Mitchell