python-3.4

Python3: ImportError: No module named '_ctypes' when using Value from module multiprocessing

僤鯓⒐⒋嵵緔 提交于 2019-11-26 08:47:03
问题 I am using Ubuntu and have installed Python 2.7.5 and 3.4.0. In Python 2.7.5 I am able to successfully assign a variable x = Value(\'i\', 2) , but not in 3.4.0. I am getting: Traceback (most recent call last): File \"<stdin>\", line 1, in <module> File \"/usr/local/lib/python3.4/multiprocessing/context.py\", line 132, in Value from .sharedctypes import Value File \"/usr/local/lib/python3.4/multiprocessing/sharedctypes.py\", line 10, in < module> import ctypes File \"/usr/local/lib/python3.4

How to install PyGame on Python 3.4?

房东的猫 提交于 2019-11-26 08:35:18
问题 So I have this little problem. When I try to install PyGame for Python 3.4 I download a .whl (wheel?) file and don\'t know how to use it. Some guys told me something about pip but don\'t know how to use/install it. 回答1: You can install the wheel file for Python 3.4 here: First you have to install the wheel package from pip then install Pygame. pip install wheel pip install pygame‑1.9.2a0‑cp34‑none‑win_amd64.whl Here's a video to help you install pip on Youtube. 回答2: Here is a great VIDEO

How can I use functools.singledispatch with instance methods?

白昼怎懂夜的黑 提交于 2019-11-26 08:07:06
问题 Python 3.4 added the ability to define function overloading with static methods. This is essentially the example from the documentation: from functools import singledispatch class TestClass(object): @singledispatch def test_method(arg, verbose=False): if verbose: print(\"Let me just say,\", end=\" \") print(arg) @test_method.register(int) def _(arg): print(\"Strength in numbers, eh?\", end=\" \") print(arg) @test_method.register(list) def _(arg): print(\"Enumerate this:\") for i, elem in

Why is one class variable not defined in list comprehension but another is?

◇◆丶佛笑我妖孽 提交于 2019-11-26 07:48:08
问题 I just read the answer to this question: Accessing class variables from a list comprehension in the class definition It helps me to understand why the following code results in NameError: name \'x\' is not defined : class A: x = 1 data = [0, 1, 2, 3] new_data = [i + x for i in data] print(new_data) The NameError occurs because x is not defined in the special scope for list comprehension. But I am unable to understand why the following code works without any error. class A: x = 1 data = [0, 1,

Python 3.4.0 with MySQL database

喜欢而已 提交于 2019-11-26 07:28:58
问题 I have installed Python version 3.4.0 and I would like to do a project with MySQL database. I downloaded and tried installing MySQLdb , but it wasn\'t successful for this version of Python. Any suggestions how could I fix this problem and install it properly? 回答1: MySQLdb does not support Python 3 but it is not the only MySQL driver for Python. mysqlclient is essentially just a fork of MySQLdb with Python 3 support merged in (and a few other improvements). PyMySQL is a pure python MySQL

Python enum, when and where to use?

左心房为你撑大大i 提交于 2019-11-26 06:07:11
问题 Python 3.4.0 introduced enum , I\'ve read the doc but still don\'t know the usage of it. From my perspective, enum is an extended namedtuple type, which may not be true. So these are what I want to know about enum: When and where to use enum? Why do we need enum? what are the advatages? What exactly is enum? 回答1: 1. When and where to use enums? When you have a variable that takes one of a limited set of possible values. For example, the days of the week: class Weekday(Enum): MONDAY = 1

How could I use requests in asyncio?

安稳与你 提交于 2019-11-26 03:47:29
问题 I want to do parallel http request tasks in asyncio , but I find that python-requests would block the event loop of asyncio . I\'ve found aiohttp but it couldn\'t provide the service of http request using a http proxy. So I want to know if there\'s a way to do asynchronous http requests with the help of asyncio . 回答1: To use requests (or any other blocking libraries) with asyncio, you can use BaseEventLoop.run_in_executor to run a function in another thread and yield from it to get the result