Ammar Askar added the comment:
Please read this excerpt from the documentation Ronald linked for open:
newline controls how universal newlines mode works (it only applies to text
mode). It can be None, '', '\n', '\r', and '\r\n'. It works as follows:
When reading input from the stream, if ne
pashkasan added the comment:
str2 = open('sample.txt', 'rU').read()
if "\n" in str2:
print ("\\n found")
else:
print ("\\n not found")
if "\r" in str2:
print ("\\r found")
else:
print ("\\r not found")
if "\r\n" in str2:
print ("\\r\\n found")
else:
Ronald Oussoren added the comment:
@pahskazan: It is correct that '\r\n' is not found in those strings, Python
source code is always parsed after conversion to "Unix" line endings with "\n"
between lines. This is basicly the same as the "universal newlines" feature of
the open function
pashkasan added the comment:
>I suspect that there may also be confusion about the line ending in multiline
>strings. Is there any documentation on the fact that this is always "\n" and
>not "\r\n" (even on Windows)?
the problem is that "\r\n" not found in source multiline strings str, str
Ronald Oussoren added the comment:
I suspect that there may also be confusion about the line ending in multiline
strings. Is there any documentation on the fact that this is always "\n" and
not "\r\n" (even on Windows)?
The closest I've found is the Lexical Analysis part of the language re
Raymond Hettinger added the comment:
The test code for the third case looks incorrect in two places:
Given: if str.find("\n\r"):
^-- should compare to -1
- these are reversed
Corrected: if str.fin
Ronald Oussoren added the comment:
What do you think the problem is? The output of the script is what I'd expect
it to be.
Note that str.find() returns -1 when the needle is not present (and the first
offset where the needle is found when it is present).
--
nosy: +ronaldoussoren
__
New submission from pashkasan :
find substring in string
its correct behavior?
sample code
str = """
Content-Length: 3192
Connection: close
Cookie: _secure_admin_session_id=2a5dc26329de17ca4eafe;
-1477319126846
Content-Disposition: form-data; name="utf8