Special National Characters Won't .split() In Python
I have trouble in Python, when reading special national characters from a text file. with open('../Data/DKsnak.txt') as f: content = f.readlines() str1 = content[0] print 'st
Solution 1:
Your code is fine. python
simply stores its special characters like that. If you print out your text, you will still get the original strings:
s = 'Udtræk fra observatør på årstal'
s = s.split()
for i in s:
print i
[OUTPUT] #all fine
Udtræk
fra
observatør
på
årstal
Solution 2:
Using the for loop as mentioned before, if you want them on the same line:
for i in len(list1):
string += list1[i] + ' 'print(string)
Solution 3:
from https://docs.python.org/2.7/howto/unicode.html:
importcodecsf= codecs.open('unicode.rst', encoding='utf-8')
so You get unicode and can split.
Post a Comment for "Special National Characters Won't .split() In Python"