0

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.

2
  • 5
    Try repr() on it. You will maybe see \r in Linux, but not in Windows. Commented Aug 17, 2014 at 7:03
  • What error do you have at print(ord(char))? (I hope you take care of bytes/unicode/string problem, right?) Commented Aug 17, 2014 at 9:54

1 Answer 1

1

In Windows, newline is "\r\n", while on Linux it is "\n". This is why there is a character count discrepancy.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.