python-future | Easy , clean , reliable Python 2/3 compatibility
kandi X-RAY | python-future Summary
kandi X-RAY | python-future Summary
Easy, clean, reliable Python 2/3 compatibility
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Load a module
- Return True if source is a Python 2 code
- Setup the RTs library
- Transform source
- Transform metaclasses
- Fix indentation
- Find metaclass
- Cleans up simple statement node
- Check if a domain is allowed
- Combine a piece of Text
- Retrieve a file from a URL
- Transform a print
- Performs the fold folding
- Decode a list of parameters
- Parse a Content - Type header
- Open a file using ftp
- Implementation of Set - Cookie3
- Encode a query
- Encode the header
- Decode a header
- Install aliases
- Transform an AST node into a string
- Parse a MIME version number
- Actually load a cookie file
- Retrieve a file
- Handle the RPC request
python-future Key Features
python-future Examples and Code Snippets
f(a=2, b=3)
from pyodide import create_once_callable
from js import setTimeout
def my_callback():
print("hi")
setTimeout(create_once_callable(my_callback), 1000)
from pyodide import create_proxy
from js import document
def my_callback():
pr
>>> from pyswedbank import Swedank
>>> swe = Swedbank(username, password='password')
>>> print(swe.list_accounts())
{'account1 name': 1500000.4, 'account2 name': 1200000.4} # Money!!!
>>> acc = swe.get_account('ac
cd
git clone -b v0.7.1-dev https://github.com/justagist/franka_ros_interface src/franka_ros_interface
catkin build # or catkin_make (catkin build is recommended)
source devel/setup.bash
Community Discussions
Trending Discussions on python-future
QUESTION
Since there is some behavior difference in map
(especially with three arguments between Python 2 and Python - Python 2 vs Python 3 - Difference in map behavior with three arguments?), I was trying to be "safe" by using from past.builtins import map
so that my functionality is intact. But it doesn't seem to be so?
Here is a Python 2 code:
...ANSWER
Answered 2020-Mar-12 at 13:21This is an error in their implementation of map
. Here is their code for it:
QUESTION
On Python 2.7 os.makedirs()
is missing exist_ok
. This is available in Python 3 only.
I know that this is the a working work around:
...ANSWER
Answered 2017-Aug-07 at 09:51What you are doing is probably fine, but if you want to detect and adapt, you can monkeypatch at runtime. I wouldn't say this is the best idea, it can result in some odd eventualities, but depending on your situation maybe it's fine. At a minimum, put some documentation in and around this code so the next guy or gal knows what's happening.
Here's an example of this - you can run this script with either "true" or something else as an argument and see the difference.
Detect the version of python by using sys.version_info: https://docs.python.org/2/library/sys.html#sys.version_info https://docs.python.org/3/library/sys.html#sys.version_info
QUESTION
This question looks strikingly similar to this one, however the suggestion in the comments there doesn't work (anymore?) as demonstrated below.
I'm trying to write a python2-3 compatible package, and one of my methods has a class generator in it, and type()
is giving me problems in the python-2.7 tests:
ANSWER
Answered 2020-Jan-30 at 18:09Don't use builtins.str()
, use the plain str
that comes with your Python version:
QUESTION
Since we use with_metaclass() PyCharm does not detect the super-class any more.
New code (autocomplete does not work):
...ANSWER
Answered 2019-Nov-18 at 08:10Using with_metaclass()
from six module is working for Python2 and 3.
QUESTION
For some projects, I'd like to stop supporting Python 2.7 (see http://python3statement.org/) to use only Python > 3.6 (or rather 3.5 + f-string, like Pypy v6.0).
A first step could be to modify the setup.py file to get an explicit error if one try to use the package with a Python version without f-string.
But then there is a lot of work to switch to pure Python 3.6 syntax and remove all the
and to replace in many places
class MyClass(object)
->class MyClass:
super(MyClass, self)
->super()
"{}".format(foo)
->f"{foo}"
I did this work for a code basically manually (actually I also automate some steps by processing the code with a Python script) and I really see the difference. The code is much less verbose now and globally much nicer.
I'm sure that I forget many other nice simplifications that could be done, for example I now use a lot from pathlib import Path
but these changes are much less direct.
How would you transform a Python 2.7/3.6 compatible code to a clean Python 3.6 code? How can you avoid to do this boring work manually?
Edit after the first answerI think a hypothetical internalization (which in many cases won't append) should not stop us from using f-strings, which are just cleaner (and slightly faster).
I still think the modifications that I mentioned are reasonable.
...ANSWER
Answered 2018-Sep-20 at 23:15If your goal is to stop your code from running on pre-Python-3.6, then explicitly check for that:
QUESTION
I have a python-3 code that I would like to be compatible for both python-2 and python-3 keeping the code as is as much as possible. I would like to use the iteration behavior of range (to iterate over many items).
In order to get an iterator:
- python-2 uses xrange(N)
- python-3 uses range(N)
what is the best way to make it an iterator for python2 with minimal changes as possible?
looking at this link, it suggests a few ways for range and xrange but couldn't make it work
...ANSWER
Answered 2018-Dec-26 at 15:30try:
n_range = xrange
except NameError:
n_range = range
QUESTION
I am unable to start a Jupyter notebook server on a linux machine. When I type jupyter notebook
, I get the following errors:
ANSWER
Answered 2018-Nov-01 at 12:00This part is wrong:
QUESTION
As part of an effort to write code that works consistently on both Python 2 and 3, I would like to test for any unadorned string literals (any opening " or ' not preceded by a b or u).
I'm fine with writing test cases, so I just need a function that returns all unadorned string literals across my .py files.
As an example, say I have Python code containing the following:
example_byte_string = b'This is a string of ASCII text or bytes'
example_unicode_string = u"This is a Unicode string"
example_unadorned_string = 'This string was not marked either way and would be treated as bytes in Python 2, but Unicode in Python 3'
example_unadorned_string2 = "This is what they call a 'string'!"
example_unadorned_string3 = 'John said "Is it really?" very loudly'
I want to find all of the strings that are not explicitly marked, like example_unadorned_string, so that I can mark them properly and therefore make them behave the same way when run in Python 2 and 3. It would also be good to accommodate quotes within strings, like example_unadorned_string2 and 3, as these shouldn't have u/b added to the internal quotes. Obviously long term we will drop Python 2 support and only Bytes will need explicit marking. This aligns with the approach recommended by python-future.org: http://python-future.org/automatic_conversion.html#separating-text-from-bytes
I can think of ways to do this with grep that are pretty nasty. AST looks potentially helpful, too. But I feel like somebody must have already solved this problem before, so thought I'd ask.
...ANSWER
Answered 2018-Jun-02 at 13:17QUESTION
Problem
I'm trying to develop a basic Google App Engine app. I do a lot of data science and so I use Anaconda to manage my python distributions.
Recently I've been trying to set-up the Google Cloud SDK + Google Cloud Client Libraries to develop on GAE (in the standard environment) and can't get the two to function together.
I have activated a Python 2.7 env (py27) and when I try to run a basic app I get the following error:
...ANSWER
Answered 2018-Feb-08 at 14:41The google-cloud-bigquery
library is not a GAE-supplied one for the standards env, so you need to vendor it into your application (GAE doesn't care if it's installed into your local python installation). Your traceback indicates it's coming from the local installation, note the py27\lib\site-packages\google\cloud\bigquery
string in it.
Also to be noted here is that the standard env only supports apps designed for GAE, executed through the sandbox, not generic, standalone apps. It's unclear if the basic app you tried is of one type or the other. See import cloudstorage, ImportError: No module named google.appengine.api.
As for flask
or other GAE-provided libraries you need to request them in your app.yaml
file (personally I'd use an explicit version in there instead of latest
, I think I saw some issues reported possibly related to latest
). To be noted here that some of these libraries/versions aren't installed by default in the cloud SDK, the additional app-engine-python-extras
component may need to be installed, see PyCharm - Can't create App Engine Application using DJango.
As for your last attempt:
- just in case it's not clear, note that the standard env only supports python 2.7, python 3 won't work. The
This package should not be accessible on Python 3
string could indicate the attempt may have been done using python 3. You'll need to explicitly use python 2.7 executables since your primary version is python 3. matplotlib
is one of the few GAE-provided libs which needs extra care for the local development using the SDK, see Using built-in bundled libraries with the local development server
QUESTION
I recently discovered that the round
function available in future
does not support negative digit rounding, which is incompatible with builtin round
:
ANSWER
Answered 2018-Jan-20 at 20:39There is no such list.
The Python-Future project is entirely separate from the Python project, so you indeed won't find any implementation gaps in the Python-Future project listed in the official Python documentation.
It is unfortunate that the reference documentation for round()
fails to mention this gap in the implementation. An oblique reference to the newround
module docstring isn't helpful either, as it too is very scant on details.
You'll have to ask the Python-Future project for such a list, you could try to file an issue to ask them to make such a list.
In the intervening time, you could search for NotImplementedError
references in the source code. This will yield an incomplete list, as there may be short-comings in the implementation not covered by raising that exception.
On a personal note, I would recommend against using Python-Future; the project's philosophy of backporting everything without regard for suitability or performance is ill-suited for production code; for example, their super()
implementation has to rely on full scans of all attributes on the class MRO to locate the relevant class to use as the first argumant, making it slow and cumbersome. Just because you can make it work somehow doesn't mean you should.
That their implementations are incomplete without clear indication where the gaps are only makes it harder to change my view on the project.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install python-future
You can use python-future like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page