Difference between python readline () and Java Scanner nextLine () class

What is the difference between Python readline () and the Java Scanner nextLine () class method?

nextLine () looks for the next line separator, which may be something other than "\ n", as written here:

http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#nextLine ()

Does the Python readline () method do the same? This is important because my file may have other line separators, but I need to look specifically for a new line character.

Any ideas?

+4
source share
2 answers

You must check it yourself.

f.readline(), \n, \r .

>>> f.readline()
'This is a test\n'
>>> f.readline()
'Second line\rwith char\n'
>>> f.readline()
'Third line' 

. , python script. repr(str), \n \r.

+1

, . Scanner Java python. BufferedReader , , nextLine BufferedReader:

. ('\n'), ('\r') .

Python this :

, : Unix '\n', Windows '\r\n' Macintosh '\r'. . PEP 278 PEP 3116, str.splitlines() .


AFAIK python Java Scanner. () re.Scanner, , . "" , scan.

, , , - re.split.

+1

Source: https://habr.com/ru/post/1535202/


All Articles