I was running the 2to3 tool on various scripts I'd written to get an idea of what I will need to change to port these to Python 3 (though I will be doing it by hand in the end).
While doing so, I ran into an odd change 2to3 made in one of my scripts:
-def open_pipe(pipe, perms=0644):
+def open_pipe(pipe, perms=0o644):
Um... Why did 2to3 add a "o" in the middle of my "perms" integer?
That's line 41 from the original source found here: https://github.com/ksoviero/Public/blob/master/tempus.py
Try typing 0644
in your python2 shell. It will give you a different number because it is octal
. In python3, the 0o
signifies an octal
number.
python2
:
>>> 0644
420
>>>
python3
:
>>> 0644
File "<stdin>", line 1
0644
^
SyntaxError: invalid token
>>> 0o644
420
>>>
New in python3
:
Octal literals are no longer of the form 0720; use 0o720 instead.
According to What's New In Python 3.0 - Integers:
Octal literals are no longer of the form
0720
; use0o720
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With