python-3.6

uWSGI and Python > 3.4

女生的网名这么多〃 提交于 2019-12-12 10:57:16
问题 I have a django project currently running with the following configuration: Debian 8 Python 3.4 uWSGI in emperor mode I installed Python 3.6.1 from source and created a new virtual environment with python 3.6 (I use virtualenvwrapper), but I seem to have some trouble getting the project to start up with uwsgi. Config file is as follows: [uwsgi] plugins = python3 project = %n module = myapp.wsgi:application home = path_to_new_env socket = /var/run/uwsgi-%n.sock chdir = path_to_new_env/myapp

Bad lock optimization in asyncio

99封情书 提交于 2019-12-12 09:52:34
问题 Update: Edited title to focus on the main problem. See my answer for full update. In the following code, a() and b() are identical. Each of them counts from 0 to 9 concurrently while acquiring and yielding a lock every 2 counts. import asyncio lock = asyncio.Lock() def a (): yield from lock.acquire() for i in range(10): print('a: ' + str(i)) if i % 2 == 0: lock.release() yield from lock.acquire() lock.release() def b (): yield from lock.acquire() for i in range(10): print('b: ' + str(i)) if i

python regular expression to split string and get all words is not working

北慕城南 提交于 2019-12-12 04:40:00
问题 I'm trying to split string using regular expression with python and get all the matched literals. RE: \w+(\.?\w+)* this need to capture [a-zA-Z0-9_] like stuff only. Here is example but when I try to match and get all the contents from string, it doesn't return proper results. Code snippet: >>> import re >>> from pprint import pprint >>> pattern = r"\w+(\.?\w+)*" >>> string = """this is some test string and there are some digits as well that need to be captured as well like 1234567890 and 321

Formatted string literals in Python 3.6 with tuples

旧城冷巷雨未停 提交于 2019-12-12 01:46:47
问题 With str.format() I can use tuples for accesing arguments: >>> '{0}, {1}, {2}'.format('a', 'b', 'c') 'a, b, c' or >>> t = ('a', 'b', 'c') >>> '{0}, {1}, {2}'.format(*t) 'a, b, c' But with the new formatted string literals prefixed with 'f' how can use tuples? 回答1: Your first str.format() call is a regular method call with 3 arguments, there is no tuple involved there . Your second call uses the * splat call syntax; the str.format() call receives 3 separate individual arguments, it doesn't

Webscraping with urllib

我的未来我决定 提交于 2019-12-11 17:51:59
问题 I am looking to get some information off the CME website Namely I want to get the Futures Yield and the Futures DV01 for the 10y Treasury Note Future. Found this little snippet on an old thread: import urllib.request class AppURLopener(urllib.request.FancyURLopener): version = "Mozilla/5.0" opener = AppURLopener() fh = opener.open('http://www.cmegroup.com/tools-information/quikstrike/treasury-analytics.html') It throws a deprecation warning and I am not quite sure how I get the info from the

Exporting / Importing trees created with python anytree 2.4.3 library

杀马特。学长 韩版系。学妹 提交于 2019-12-11 17:42:35
问题 I create a tree with anytree library. I want to be able to modify it, then export - save it to disk, and import it back with the modifications. For instance, the example tree: udo = Node("Udo") marc = Node("Marc", parent=udo) lian = Node("Lian", parent=marc) dan = Node("Dan", parent=udo) jet = Node("Jet", parent=dan) jan = Node("Jan", parent=dan) joe = Node("Joe", parent=dan) Udo ├── Marc │ └── Lian └── Dan ├── Jet ├── Jan └── Joe I can modify it, for instance cutting Dan off and adding a

Python Subprocess - filter out logging

橙三吉。 提交于 2019-12-11 17:31:28
问题 Python 3.6 I want to take all input from a subprocess which I run with the subprocess module. I can easily pipe this output to a log file, and it works great. But, I want to filter out a lot of the lines (lots of noisy output from modules I do not control). Attempt 1 def run_command(command, log_file): process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True) while True: output = process.stdout.readline() if output == '' and

Background process and tkinter

霸气de小男生 提交于 2019-12-11 17:13:20
问题 Looking for help on where to start with this, not too good with Python. What I trying to do is use tkinter for a gui interface but i need to be able to process recieved data and update labels widgets as information changes. I all ready have the communication portion of my program working fine in the shell but when I try to tie it to tkinter it will stop processing as soon as the interface is generated. Anyone have a simple code for me to modify to my needs or point me to a reference example

sys.path in virtualenv python

狂风中的少年 提交于 2019-12-11 16:42:52
问题 I am running "chalice local" inside virtual environment. I don't see the libraries installed in virtual environment. From inside chalicelib/common.py file, I see the path(sys.path) to be set at: ['/home/sudip/myapp', '/usr/local/bin', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages'] But when I run python3.6 from virtual environment console, I see this: (venv) myapp$ python3.6 Python 3.6

How can i use SOCKS4 and SOCKS5 proxies with aiohttp ClientSession?

懵懂的女人 提交于 2019-12-11 16:12:28
问题 How can i use SOCKS4 and SOCKS5 proxies with aiohttp ClientSession? Need some small example. Thanks! 回答1: Have you tried aiosocks ? import asyncio import aiosocks from aiosocks.connector import SocksConnector conn = SocksConnector(proxy=aiosocks.Socks5Addr(PROXY_ADDRESS, PROXY_PORT), proxy_auth=None, remote_resolve=True) session = aiohttp.ClientSession(connector=conn) async with session.get('http://python.org') as resp: assert resp.status == 200 来源: https://stackoverflow.com/questions