python-3.5

Why does pip freeze list “pkg-resources==0.0.0”?

女生的网名这么多〃 提交于 2019-11-27 10:47:34
问题 On Ubuntu 16.04 with virtualenv 15.0.1 and Python 3.5.2 (both installed with apt ) when I create and activate new Python virtual environment with virtualenv .virtualenvs/wtf -p $(which python3) --no-site-packages source .virtualenvs/wtf/bin/activate I get the following output: Already using interpreter /usr/bin/python3 Using base prefix '/usr' New python executable in /home/das-g/.virtualenvs/wtf/bin/python3 Also creating executable in /home/das-g/.virtualenvs/wtf/bin/python Installing

asyncio.ensure_future vs. BaseEventLoop.create_task vs. simple coroutine?

瘦欲@ 提交于 2019-11-27 10:08:27
I've seen several basic Python 3.5 tutorials on asyncio doing the same operation in various flavours. In this code: import asyncio async def doit(i): print("Start %d" % i) await asyncio.sleep(3) print("End %d" % i) return i if __name__ == '__main__': loop = asyncio.get_event_loop() #futures = [asyncio.ensure_future(doit(i), loop=loop) for i in range(10)] #futures = [loop.create_task(doit(i)) for i in range(10)] futures = [doit(i) for i in range(10)] result = loop.run_until_complete(asyncio.gather(*futures)) print(result) All the three variants above that define the futures variable achieve the

Self-reference or forward-reference of type annotations in Python [duplicate]

早过忘川 提交于 2019-11-27 09:27:10
This question already has an answer here: Type hints: solve circular dependency 2 answers I'm trying to figure out how self-reference of types work with python3's type annotations - the docs don't specify anything regarding this. As an example: from typing import TypeVar, Optional, Generic T = TypeVar('T') class Node(Generic[T]): left = None right = None value = None def __init__( self, value: Optional[T], left: Optional[Node[T]]=None, right: Optional[Node[T]]=None, ) -> None: self.value = value self.left = left self.right = right This code generates the error: Traceback (most recent call last

Tensorflow install on Windows Error

China☆狼群 提交于 2019-11-27 08:32:45
问题 Tensorflow is now available on Windows: https://developers.googleblog.com/2016/11/tensorflow-0-12-adds-support-for-windows.html I used pip install tensorflow. I try running the intro code: https://www.tensorflow.org/versions/r0.12/get_started/index.html I get this error: C:\Python\Python35-32\python.exe "C:/tensorflow_tutorial.py" Traceback (most recent call last): File "C:\Python\Python35-32\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper return

Python NameError, variable 'not defined'

五迷三道 提交于 2019-11-27 08:30:47
问题 the error it returns is: NameError: name 'lives' is not defined I know the code isn't as efficient as possible, this is one of my first projects, however whatever i try to do this error pops up, I've tried making a global for it but that didn't help. I would really appreciate some help with this, thanks! import random import time def main(): global guess,rand_num win = False rand_num = 45 lives = 10 while lives > 0 and win == False: guess = int(input("Guess a number!")) compare() print("Well

How to read pdf file using pdfminer3k?

南笙酒味 提交于 2019-11-27 06:05:03
问题 I am using python 3.5 and I want to read the text, line by line from pdf files. Was trying to use pdfminer3k but not getting proper syntax anywhere. How to use it correctly? 回答1: I have corrected Lisa's code. It works now! fp = open(path, 'rb') from pdfminer.pdfparser import PDFParser, PDFDocument from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter from pdfminer.converter import PDFPageAggregator from pdfminer.layout import LAParams, LTTextBox, LTTextLine parser = PDFParser

installing cPickle with python 3.5

匆匆过客 提交于 2019-11-27 05:39:39
问题 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

__metaclass__ in Python3.5

安稳与你 提交于 2019-11-27 04:52:13
In Python2.7 this code can work very well, __getattr__ in MetaTable will run. But in Python 3.5 it doesn't work. class MetaTable(type): def __getattr__(cls, key): temp = key.split("__") name = temp[0] alias = None if len(temp) > 1: alias = temp[1] return cls(name, alias) class Table(object): __metaclass__ = MetaTable def __init__(self, name, alias=None): self._name = name self._alias = alias d = Table d.student__s But in Python 3.5 I get an attribute error instead: Traceback (most recent call last): File "/Users/wyx/project/python3/sql/dd.py", line 31, in <module> d.student__s AttributeError:

How to annotate types of multiple return values?

风格不统一 提交于 2019-11-27 04:25:27
问题 How do I use type hints to annotate a function that returns an Iterable that always yields two values: a bool and a str ? The hint Tuple[bool, str] is close, except that it limits the return value type to a tuple, not a generator or other type of iterable. I'm mostly curious because I would like to annotate a function foo() that is used to return multiple values like this: always_a_bool, always_a_str = foo() Usually functions like foo() do something like return a, b (which returns a tuple),

Does asyncio supports asynchronous I/O for file operations?

℡╲_俬逩灬. 提交于 2019-11-27 02:38:07
问题 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? 回答1: 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. 回答2: 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