Reputation: 98
This is the first question I'm posting so please pardon my ignorance. I am using python to write into files and then read them. Using the usual suspects (file.read()
, file.write()
)
The code is being run on both windows and Linux.
A particular string I'm reading, say str
is giving a length of 6 on Windows, while it is giving a length of 7 on Linux.
I tried exploring what this magic character is but it turns out I cant print it!
If i try printing str
, it gives the same results on Windows and Linux.
If i try printing str[6]
on Linux, it prints blank!
I have verified that it is not a whitespace or newline(\n) character. I am even unable to print the ascii value of this character. Are there characters out there without ascii values?
I have found that strip()
function eliminates this magic character but I am still curious as to what it is.
Upvotes: 0
Views: 163
Reputation: 201497
In Windows, newline is "\r\n", while on Linux it is "\n". This is why there is a character count discrepancy.
Upvotes: 1