Python 2to3 tool adds vowel to my whole

I ran the 2to3 tool on various scripts that I wrote to get an idea of ​​what I would need to change in order to port them to Python 3 (although I will do it manually at the end).

In doing so, I came across an odd 2to3 change made in one of my scripts:

-def open_pipe(pipe, perms=0644):
+def open_pipe(pipe, perms=0o644):

Um ... Why did 2to3 add an "o" in the middle of my "perms" integer?

This line 41 from the original source is found here: https://github.com/ksoviero/Public/blob/master/tempus.py

+4
source share
3 answers

0644 python2. , octal. python3 0o octal.

python2:

>>> 0644
420
>>> 

python3:

>>> 0644
  File "<stdin>", line 1
    0644
       ^
SyntaxError: invalid token
>>> 0o644
420
>>> 

python3:

0720; 0o720.

+4

Python 3.0 - :

0720; 0o720.

+3

0 Python 3. , 0o:

$ python
Python 2.7.3 (default, Dec 18 2012, 13:50:09)
>>> 0644
420
>>>

$ python3
Python 3.2.3 (default, Jul 23 2012, 16:48:24)
>>> 0644
  File "<stdin>", line 1
    0644
       ^
SyntaxError: invalid token
>>> 0o644
420

, :

0720; 0o720.

+2

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


All Articles