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')`
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With