Porting a Python 2.X based project to Python 3 [closed]

拈花ヽ惹草 提交于 2020-01-04 15:25:12
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I want to port a web application scanning framework from Python 2.6.5-2.7.3 to Python 3 without causing much harm to the compatibility with Python 2.6+ . I have read briefly about six: Python 2 and 3 Compatibility Library and python-modernize . The framework I am intending to port

Attempted relative import in non-package (after 2to3)

回眸只為那壹抹淺笑 提交于 2019-12-30 05:55:09
问题 After converting to Python 3.x using 2to3 (see my previous question), I get this error during the build: File "", line 28, in <module> from . import mof_compiler ValueError: Attempted relative import in non-package The code: from . import mof_compiler mof_compiler._build() But I don’t know why this is wrong, since mof_compiler is in the same dir as . Please help! 回答1: Since there is no , the working directory is a non-package. You don't need a relative import. Or.

eval(input()) in python 2to3

耗尽温柔 提交于 2019-12-23 21:05:02
问题 From the Python 2to3 doc: input : Converts input(prompt) to eval(input(prompt)) I am currently trying to learn Python 3 after a few years working with Python 2. Can anybody please explain why the tool inserts eval before the call to input , and whether I should do so in all my Python 3 code? 回答1: python 2's old input behavior has been removed, python 3's current input was what was previously named raw_input. raw_input and python 3 input always returns a string, unlike input which tries to

How to launch own 2to3 fixer?

梦想的初衷 提交于 2019-12-22 10:34:23
问题 I wrote own fixer, how can i run it? I don't find obvious way to do this. Only this: > cd /usr/lib/python2.7/lib2to3/fixes/ > ln -s path/to/ And then run it: > cd path/to/project > 2to3 -f my_fixer . 回答1: I got it! (file: my2to3) #!/usr/bin/env python2.7 import sys from lib2to3.main import main sys.path.append('path/to/my_own_package') sys.exit(main('my_own_package.contained_fixers')) And then run it: > ./my2to3 -f my_fixer -w project 回答2: Create a directory /mypath/custom_fixers

Using Z3Py With Python 3.3

筅森魡賤 提交于 2019-12-20 04:11:47
问题 My Situation I've installed Microsoft Z3 ( Z3 [version 4.3.0 - 64 bit]. (C) 2006 ) and it's pyc binaries for Python2. I've written an Python3 package which needs access to z3 functionality. In order to be able to use the pyc binaries with my Python3 package, I decompyle the z3 binaries and applied 2to3 . My Problem Int('string') doesn't work because Z3Py isn't able to handle the new <class 'str'> used as 'string' argument: >>> import z3; z3.Int('abc') Traceback (most recent call last): File "

How to use 2to3 tool in windows?

三世轮回 提交于 2019-12-17 23:47:13
问题 I tried to modify the sintax using 2to3 tool by running command python C:\Python32\Tools\scripts\ and got the output When opening however I noticed there hasn't been anything changed. Below is the block of code where changes (accoridng to output) should be made: try: import json except ImportError: import simplejson as json try: from urllib.parse import quote except ImportError: from urllib import quote try: from . import rest, batch, cypher except ImportError: import

Should we use pandas.compat.StringIO or Python 2/3 StringIO?

回眸只為那壹抹淺笑 提交于 2019-12-17 20:40:35
问题 StringIO is the file-like string buffer object we use when reading pandas dataframe from text, e.g. "How to create a Pandas DataFrame from a string?" Which of these two imports should we use for StringIO (within pandas)? This is a long-running question that has never been resolved over four years. StringIO.StringIO (Python 2) / io.StringIO (Python 3) Advantages: more stable for futureproofing code, but forces us to version-fork, e.g. see code at bottom from EmilH. pandas.compat.StringIO

TypeError: a bytes-like object is required, not 'str' - python 2 to 3 [duplicate]

佐手、 提交于 2019-12-17 18:49:27
问题 This question already has answers here : Why do I need 'b' to encode a string with Base64? (6 answers) Closed 2 years ago . Hi I am having trouble with this error message. I am new to Python and this Python2 and Python3 is a hassle. I'm not sure what to do here, the error message is as shown below. Using Ticker: AAPL Traceback (most recent call last): File "", line 18, in <module> r=requests.get(auth_url, headers={"Authorization": "Basic %s" % base64.b64encode(os.environ['INTRINIO

How to use 2to3 properly for python?

我怕爱的太早我们不能终老 提交于 2019-12-17 17:47:15
问题 I have some code in python 2.7 and I want to convert it all into python 3.3 code. I know 2to3 can be used but I am not sure exactly how to use it. Thanks for any help 回答1: As it is written on 2to3 docs, to translate an entire project from one directory tree to another, use: $ 2to3 --output-dir=python3-version/mycode -W -n python2-version/mycode 回答2: If you don't have 2to3 on your path, you can directly invoke lib2to3 : python -m lib2to3 directory\ And as the docs (and other answers)

Python 2 and Python 3 dual development

让人想犯罪 __ 提交于 2019-12-17 05:02:26
问题 I'm just starting a new Python project, and ideally I'd like to offer Python 2 and 3 support from the start, with minimal developmental overhead. My question is, what is the best way of doing this for brand new projects? I have come across projects that run 2to3, or even 3to2, as part of their installation script. This seems to be a very common way. However, there seems to be several different ways of doing this. I also came across Distribute. There is also the option of trying to write