Hi, I want to split a very long string, it will look like this:
"numerodecaracter1"
&_
"numerodecaracter2"
.. etc..
Try this
import re
s = "This is a long string that is holding more than 80 characters and thus should be split into several lines. That is if everything is working properly and nicely and all that. No misshaps no typos. No bugs. But I want the code too look good too. That's the problem!"
print '\n'.join(line.strip() for line in re.findall(r'.{1,80}(?:\s+|$)', s))
But I'm left as follows:
de 1 a 80 caracteres salto de linea
de 1 a 80 caracteres salto de linea
How could I make it look like the way I said:
"numerodecaracter1"
&_
"numerodecaracter2"
&_
.. etc..
So my chain will splite but as the way it indicates. And as last I wrote in a file the result instead of a print
but I get the error:
TypeError: 'encoding' is an invalid keyword argument for this function
Code:
s = "lalalalala"
#print '\n'.join(line.strip() for line in re.findall(r'.{1,80}(?:\s+|$)', s))
with open('filename.txt', mode='wt', encoding='utf-8') as myfile:
myfile.write('\n'.join(line.strip() for line in re.findall(r'.{1,80}(?:\s+|$)', s)))
I removed the enconding and it resolved the writing but when I use a long string and with symbols I break the whole chain so it is important that I can use the encoding.