python-3.5

Why does python behave this way with variables?

余生长醉 提交于 2019-12-18 04:54:13
问题 I have been trying to understand why python behaves this way, in the block of code below. I have done my research but couldn't find a good answer so I came here to see if anyone can point me in the right direction or provide a good clarification. I understand that it has to do with some old ALGOL principle, but I don't fully understand it. var = 5 def func1(): print(var) func1() def func2(): var = 8 print(var) func2() def func3(): print(var) var = 8 func3() The output of this code is as

TensorFlow on Windows: “pip install tensorflow” fails

我只是一个虾纸丫 提交于 2019-12-17 21:36:32
问题 I am using Visual Studio 2015, Python 3.5.2, Windows 10, and have recently upgraded pip to 9.0.1. I am trying to install Tensorflow 0.12 on my system. I tried to use VS's built in "Install Python Package" function, as well as command prompting pip install python Both ways I get the same error: Installing 'tensorflow' Collecting tensorflow Could not find a version that satisfies the requirement tensorflow (from versions: ) No matching distribution found for tensorflow 'tensorflow' failed to

What are list comprehension scoping rules within a Python class? [duplicate]

淺唱寂寞╮ 提交于 2019-12-17 20:34:53
问题 This question already has answers here : Accessing class variables from a list comprehension in the class definition (5 answers) Closed last year . In the following code, the mc assigment works fine in Python 2 and 3. The cc assignment, which uses the same list comprehension within a class, works in Python 2 but fails with Python 3. What explains this behavior? ml1 = "a b c".split() ml2 = "1 2 3".split() mc = [ i1 + i2 for i1 in ml1 for i2 in ml2 ] class Foo(object): cl1 = ml1 cl2 = ml2 cc1 =

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

ぐ巨炮叔叔 提交于 2019-12-17 19:12:02
问题 I'm trying to execute a Python script, but I am getting the following error: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV) I'm using python 3.5.2 on a Linux Mint 18.1 Serena OS Can someone tell me why this happens, and how can I solve? 回答1: The SIGSEGV signal indicates a "segmentation violation" or a "segfault". More or less, this equates to a read or write of a memory address that's not mapped in the process. This indicates a bug in your program. In a Python program

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

筅森魡賤 提交于 2019-12-17 18:23:05
问题 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? 回答1: 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

sift = cv2.xfeatures2d.SIFT_create() not working even though have contrib installed

南楼画角 提交于 2019-12-17 17:39:38
问题 So I am trying to use: sift = cv2.xfeatures2d.SIFT_create() and it is coming up with this error: cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv_contrib\modules\xfeatures2d\src\sift.cpp:1207: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'cv::xfeatures2d::SIFT::create' I am using Python 3.5.0 and opencv(3.4.3) and I am just using idle.

Python asyncio.semaphore in async-await function

那年仲夏 提交于 2019-12-17 16:58:14
问题 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

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

落爺英雄遲暮 提交于 2019-12-17 16:31:42
问题 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? 回答1: str , the type of text , is not the same as bytes , the type of sequences of eight-bit words . To

How to run multiple commands synchronously from one subprocess.Popen command?

和自甴很熟 提交于 2019-12-17 15:58:28
问题 Is it possible to execute an arbitrary number of commands in sequence using the same subprocess command? I need each command to wait for the previous one to complete before executing and I need them all to be executed in the same session/shell. I also need this to work in Python 2.6, Python 3.5. I also need the subprocess command to work in Linux, Windows and macOS (which is why I'm just using echo commands as examples here). See non-working code below: import sys import subprocess cmds = [

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

浪尽此生 提交于 2019-12-17 10:14:28
问题 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