python-3.5

Does asyncio supports asynchronous I/O for file operations?

妖精的绣舞 提交于 2019-11-28 08:57:09
Does asyncio supports asynchronous I/O for file operations? If yes, how I can use this in Python 3.5 with async/await syntax code? Andrew Svetlov Most operating systems don't support asynchronous file operations. That's why asyncio doesn't support them either. See the asyncio wiki for further explanation. That depends what library you use. curio offers this functionality, https://curio.readthedocs.io/en/latest/reference.html#module-curio.file plain asyncio doesn't, but there are 3rd party libraries, e.g. https://github.com/Tinche/aiofiles (which is really synchronous file access isolated in

ImportError: cannot import name 'HTMLAwareEntitySubstitution'

蓝咒 提交于 2019-11-28 07:42:37
问题 I just setup beautifulsoup4-4.1.0 and upgrade pip to version 9.0.1. When I write this : from bs4 import BeautifulSoup error occurs: Traceback (most recent call last): File "<pyshell#4>", line 1, in <module> from bs4 import BeautifulSoup File "D:\Program Files (x86)\Python35-32\lib\site-packages\bs4\__init__.py", line 35, in <module> from .builder import builder_registry, ParserRejectedMarkup File "D:\Program Files (x86)\Python35-32\lib\site-packages\bs4\builder\__init__.py", line 7, in

installing cPickle with python 3.5

心不动则不痛 提交于 2019-11-28 07:14:59
This might be silly but I am unable to install cPickle with python 3.5 docker image Dockerfile FROM python:3.5-onbuild requirements.txt cpickle When I try to build the image $ docker build -t sample . Sending build context to Docker daemon 3.072 kB Step 1 : FROM python:3.5-onbuild # Executing 3 build triggers... Step 1 : COPY requirements.txt /usr/src/app/ Step 1 : RUN pip install --no-cache-dir -r requirements.txt ---> Running in 016c35a032ee Collecting cpickle (from -r requirements.txt (line 1)) Could not find a version that satisfies the requirement cpickle (from -r requirements.txt (line 1

Correct way to write type hints for keys and items

泄露秘密 提交于 2019-11-28 06:54:54
问题 I have some Python code (running for Python 3.5, 3.6 and 3.7) and added some type hints for static type checks using mypy. Please take a look at the following snippet: class MyParams(Singleton, metaclass=MyParamsMeta): @classmethod def keys(cls): # TODO -> type? return cls._params.keys() @classmethod def items(cls): # TODO -> type? return cls._params.items() _params = _load_from_csv() # returns Dict[str, MyParam] What are the correct type hint statements for def keys(cls) and def items(cls) ?

Is there a py2exe version that's compatible with python 3.5?

ぐ巨炮叔叔 提交于 2019-11-28 06:48:23
I am trying to compile my python 3.5 file with the latest py2exe version 0.9.2.2 with the following command: py -3.5 -m py2exe.build_exe myscript.py But it reports this: "run-py3.5-win-amd64.exe" file is not found in the ...lib\site-packages\py2exe\ folder. Does this mean that py2exe 0.9.2.2 is only compatible up to python 3.4? Unfortunately as of November 2016 there is still no Python 3.5 support in sight for py2exe. However, I've had great success using cx_Freeze 5.0 with Python 3.5 and since both projects use a very similar configuration I've migrated away from py2exe to cx_Freeze without

pip3 error - '_NamespacePath' object has no attribute 'sort'

社会主义新天地 提交于 2019-11-28 04:39:39
I tried to install a package through pip3, and I got this error. Every pip/pip3 command that I run gives me this error- alexg@hitbox:~$ pip3 -V Traceback (most recent call last): File "/usr/local/bin/pip3", line 7, in <module> from pip import main File "/home/alexg/.local/lib/python3.5/site-packages/pip/__init__.py", line 26, in <module> from pip.utils import get_installed_distributions, get_prog File "/home/alexg/.local/lib/python3.5/site-packages/pip/utils/__init__.py", line 27, in <module> from pip._vendor import pkg_resources File "/home/alexg/.local/lib/python3.5/site-packages/pip/_vendor

Python 3.5 typed NamedTuple syntax produces SyntaxError

依然范特西╮ 提交于 2019-11-28 03:17:51
问题 I get a SyntaxError: invalid syntax error when I try the new typed namedtuple syntax: class Employee(NamedTuple): name: str id: int in Python 3.5.2 even though according to the documentation it should be valid from 3.5+ onwards. Am I missing something? I've imported NamedTuple from typing in the code. 回答1: The syntax to declare the types for the name and id fields you are using requires Python 3.6 or up. Python 3.5 does not support the variable-level type hints required. From the typing

Importing bs4 in Python 3.5

烂漫一生 提交于 2019-11-28 02:42:10
问题 I have installed both Python 3.5 and Beautifulsoup4. When I try to import bs4, I get the error below. Is there any fix for that? Or should I just install Python 3.4 instead? Please be very explicit - I am new to programming. Many thanks! Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python 3.5\lib\sit-packages\bs4\__init__.py", line 30, in <module> from .builder import builder_registry, ParserRejectionMarkup File "C:\Python 3.5\lib\sit-packages\bs4\__init__

Python asyncio.semaphore in async-await function

冷暖自知 提交于 2019-11-28 02:04:35
I am trying to teach myself Python's async functionality. To do so I have built an async web scraper. I would like to limit the total number of connections I have open at once to be a good citizen on servers. I know that semaphore's are a good solution, and the asyncio library has a semaphore class built in. My issue is that Python complains when using yield from in an async function as you are combining yield and await syntax. Below is the exact syntax I am using... import asyncio import aiohttp sema = asyncio.BoundedSemaphore(5) async def get_page_text(url): with (yield from sema): try: resp

How do I encode a string to bytes in the send method of a socket connection in one line?

限于喜欢 提交于 2019-11-27 23:22:58
In Python 3.5, using sockets, I have: message = 'HTTP/1.1 200 OK\nContent-Type: text/html\n\n' s.send(message.encode()) How can I do that in one line? I ask because I had: s.send('HTTP/1.1 200 OK\nContent-Type: text/html\n\n') but in Python 3.5 bytes are required, not a string, so this gives the error: builtins.TypeError: a bytes-like object is required, not 'str' Should I not be using send? str , the type of text , is not the same as bytes , the type of sequences of eight-bit words . To concisely convert from one to the other, you could inline the call to encode (just as you could with any