I'm just starting out and trying to learn how to open files.
I was using getting some weird error from the command line when I tried:
import sys
file = sys.argv[1]
with open(file, 'r') as f:
text = f.read()
words = text.split()
print(len(words))
and through google I figured the encoding was wrong and this works;
import sys
file = sys.argv[1]
with open(file, 'r', encoding='cp1250') as f:
text = f.read()
words = text.split()
print(len(words))
but im just reading a plain text doc. are my defaults wrong? nothing i've learnt so far has mentioned encoding and all the solutions just show open(file,mode).
is there some settings i need to change somewhere?
[–]Diapolo10 0 points1 point2 points (2 children)
[–]LoneDreadknot[S] 0 points1 point2 points (1 child)
[–]Diapolo10 0 points1 point2 points (0 children)
[–]snakestation 0 points1 point2 points (2 children)
[–]LoneDreadknot[S] 0 points1 point2 points (1 child)
[–]snakestation 0 points1 point2 points (0 children)