I have an old file written using python2, which contains things like 148191387849281587952L
. When I try to read it (using ast.literal_eval
) in python3, I, naturally, get SyntaxError: invalid syntax
.
Is there anything I could do to read the file into python3?
PS. The only solutions I see at this time require modifying the file:
Convert to JSON: read the file into python2, write it using json, then read into python3 using json.
Remove the offending L
using sed -i 's/([0-9]+)L/\\1/g'
.
Convert the file using 2to3
(suggested by @user3080953).
Is there anything better?
After your clarification, there is a simple answer:
No, you cannot modify ast.leteral_eval()
or the python interpreter to be "backwards compatible" with the L
syntax.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.