six-python

Python Error: “ImportError: No module named six”

心已入冬 提交于 2019-12-29 08:33:17
问题 I am running Python 2.7 on a Windows 7 OS Here is what I run: >>> import matplotlib.pyplot as plt Then I get this: Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> import matplotlib.pyplot as plt File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 29, in <module> from matplotlib.figure import Figure, figaspect File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 36, in <module> from matplotlib.axes import Axes, SubplotBase, subplot_class

How can I call super() so it's compatible in 2 and 3?

☆樱花仙子☆ 提交于 2019-12-10 12:32:16
问题 I'm trying to write 2/3 compatible code using six , but I don't see how I can call super() in a cross-compatible manner. Is there some better way besides, for example: class MyClass(MyBase): def __init__(): if six.PY3: super().__init__() else: super(MyClass, self).__init__() ... 回答1: Using super() with arguments is backwards compatible, so you should just be able to use super(MyClass, self) without needing to check the version. 来源: https://stackoverflow.com/questions/21768391/how-can-i-call

unicode_literals and type()

前提是你 提交于 2019-12-05 13:54:56
问题 I'm having problems supporting python2 and python3 on a type() call. This demonstrates the problem: from __future__ import unicode_literals name='FooClass' type(name, (dict,), {}) No problem on python3, but on python2: Traceback (most recent call last): File "test.py", line 6, in <module> type(name, (dict,), {}) TypeError: type() argument 1 must be string, not unicode This is related to Any gotchas using unicode_literals in Python 2.6?. In that question, someone recommends typecasting to a

unicode_literals and type()

前提是你 提交于 2019-12-04 00:50:54
I'm having problems supporting python2 and python3 on a type() call. This demonstrates the problem: from __future__ import unicode_literals name='FooClass' type(name, (dict,), {}) No problem on python3, but on python2: Traceback (most recent call last): File "test.py", line 6, in <module> type(name, (dict,), {}) TypeError: type() argument 1 must be string, not unicode This is related to Any gotchas using unicode_literals in Python 2.6? . In that question, someone recommends typecasting to a bytestring, so naively I thought about using six.b() : A “fake” bytes literal. data should always be a

No module named six

岁酱吖の 提交于 2019-12-03 20:48:22
问题 After installing transifex and ./manage.py the following error shows up: Error: No modules named six. Python Six is installed in the virtualenv (from https://pypi.python.org/pypi/six) Django Version is 1.4 Any help would be great! thx & best regards Michael 回答1: django.utils.six is added in Django 1.4.2, see https://docs.djangoproject.com/en/1.5/topics/python3/#philosophy 回答2: I've just had the same problem. Seems like the dependencies in the transifex package are not listed correctly (it

No module named six

半腔热情 提交于 2019-11-30 18:33:19
After installing transifex and ./manage.py the following error shows up: Error: No modules named six. Python Six is installed in the virtualenv (from https://pypi.python.org/pypi/six ) Django Version is 1.4 Any help would be great! thx & best regards Michael django.utils.six is added in Django 1.4.2, see https://docs.djangoproject.com/en/1.5/topics/python3/#philosophy I've just had the same problem. Seems like the dependencies in the transifex package are not listed correctly (it depends on Django == 1.3.1 and django-filter >= 0.1, but django-filter 0.6 depends on Django >= 1.4.5). I solved by

Python Metaclass : Understanding the 'with_metaclass()'

心已入冬 提交于 2019-11-29 22:49:47
I want to ask what the with_metaclass() call means in the definition of a class. E.g.: class Foo(with_metaclass(Cls1, Cls2)): Is it a special case where a class inherits from a metaclass? Is the new class a metaclass, too? with_metaclass() is a utility class factory function provided by the six library to make it easier to develop code for both Python 2 and 3. It uses a little slight of hand (see below) with a temporary metaclass, to attach a metaclass to a regular class in a way that's cross-compatible with both Python 2 and Python 3. Quoting from the documentation: Create a new class with

Python Error: “ImportError: No module named six”

倾然丶 夕夏残阳落幕 提交于 2019-11-29 13:22:24
I am running Python 2.7 on a Windows 7 OS Here is what I run: >>> import matplotlib.pyplot as plt Then I get this: Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> import matplotlib.pyplot as plt File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 29, in <module> from matplotlib.figure import Figure, figaspect File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 36, in <module> from matplotlib.axes import Axes, SubplotBase, subplot_class_factory File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 20, in <module> import matplotlib.dates

Python Metaclass : Understanding the 'with_metaclass()'

╄→尐↘猪︶ㄣ 提交于 2019-11-28 19:33:22
问题 I want to ask what the with_metaclass() call means in the definition of a class. E.g.: class Foo(with_metaclass(Cls1, Cls2)): Is it a special case where a class inherits from a metaclass? Is the new class a metaclass, too? 回答1: with_metaclass() is a utility class factory function provided by the six library to make it easier to develop code for both Python 2 and 3. It uses a little slight of hand (see below) with a temporary metaclass, to attach a metaclass to a regular class in a way that's