python-3.5

asyncio aiohttp progress bar with tqdm

六眼飞鱼酱① 提交于 2019-11-30 13:01:30
问题 I'm attempting to integrate a tqdm progress bar to monitor POST requests generated with aiohttp in Python 3.5. I have a working progress bar but can't seem to gather results using as_completed() . Pointers gratefully received. Examples I've found suggest using the following pattern, which is incompatible with Python 3.5 async def definitions: for f in tqdm.tqdm(asyncio.as_completed(tasks), total=len(coros)): yield from f Working (albeit redacted) async code without the progress bar: def async

How to use async/await in Python 3.5?

爷,独闯天下 提交于 2019-11-30 10:53:42
问题 #!/usr/bin/env python3 # -*- coding: utf-8 -*- import time async def foo(): await time.sleep(1) foo() I couldn't make this dead simple example to run: RuntimeWarning: coroutine 'foo' was never awaited foo() 回答1: Running coroutines requires an event loop . Use the asyncio() library to create one: import asyncio # Python 3.7+ asyncio.run(foo()) or # Python 3.6 and older loop = asyncio.get_event_loop() loop.run_until_complete(foo()) Also see the Tasks and Coroutines chapter of the asyncio

cannot use pycorenlp for python3.5 through terminal

梦想的初衷 提交于 2019-11-30 09:31:36
问题 My default python is 2.7, but have to do this project in python3.5 I installed pycorenlp through this command line: pip3 install pycorenlp . And it is showing I have already installed it: Requirement already satisfied (use --upgrade to upgrade): pycorenlp in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages Requirement already satisfied (use --upgrade to upgrade): requests in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (from

Changing Active Directory user password in Python 3.x

て烟熏妆下的殇ゞ 提交于 2019-11-30 09:24:38
问题 I am trying to make a Python script that will open an LDAP connection to a server running AD, take a search entry (in this case a name), search for that entry and change that users password to a randomly generated password (as well as set the option to change password on logon) and then send them an automated secure email containing the new temporary password. So far I have been able to connect to the server, and search for a single DN which returns. The temporary password is being generated,

Type hinting / annotation (PEP 484) for numpy.ndarray

旧城冷巷雨未停 提交于 2019-11-30 07:49:53
Has anyone implemented type hinting for the specific numpy.ndarray class? Right now, I'm using typing.Any , but it would be nice to have something more specific. For instance if the numpy people added a type alias for their array_like object class. Better yet, implement support at the dtype level, so that other objects would be supported, as well as ufunc . It looks like typing module was developed at: https://github.com/python/typing The main numpy repository is at https://github.com/numpy/numpy Python bugs and commits can be tracked at http://bugs.python.org/ The usual way of adding a

Type hinting / annotation (PEP 484) for numpy.ndarray

半世苍凉 提交于 2019-11-30 07:02:59
问题 Has anyone implemented type hinting for the specific numpy.ndarray class? Right now, I'm using typing.Any, but it would be nice to have something more specific. For instance if the numpy people added a type alias for their array_like object class. Better yet, implement support at the dtype level, so that other objects would be supported, as well as ufunc. 回答1: It looks like typing module was developed at: https://github.com/python/typing The main numpy repository is at https://github.com

How can I execute JavaScript code from Python?

北慕城南 提交于 2019-11-30 05:30:01
Lets say that I have this code inside a JavaScript file: var x = 10; x = 10 - 5; console.log(x); function greet() { console.log("Hello World!"); } greet() How would I use Python to execute this code and "print" x and Hello World! ? Here is some pseudo code that further explains what I'm thinking: # 1. open the script script = open("/path/to/js/files.js", "r") # 2. get the script content script_content = script.read() # 3. close the script file script.close() # 4. execute the script content and "print" "x" and "Hello World!" x = js.exec(script_content) And, the expected result would look like

Python 3.5 vs. 3.6 what made “map” slower compared to comprehensions

雨燕双飞 提交于 2019-11-30 05:11:10
I sometimes used map if there was a function/method that was written in C to get a bit extra performance. However I recently revisited some of my benchmarks and noticed that the relative performance (compared to a similar list comprehension) drastically changed between Python 3.5 and 3.6. That's not the actual code but just a minimal sample that illustrates the difference: import random lst = [random.randint(0, 10) for _ in range(100000)] assert list(map((5).__lt__, lst)) == [5 < i for i in lst] %timeit list(map((5).__lt__, lst)) %timeit [5 < i for i in lst] I realize that it's not a good idea

Exception “ There is no current event loop in thread 'MainThread' ” while running over new loop

老子叫甜甜 提交于 2019-11-30 04:37:29
问题 The is the simple test code and the result. import asyncio async def test(): await asyncio.sleep(1) if __name__ == '__main__': asyncio.set_event_loop(None) # Clear the main loop. loop = asyncio.new_event_loop() # Create a new loop. loop.run_until_complete(test()) # Run coroutine over the new loop Traceback (most recent call last): File "test_test.py", line 11, in <module> loop.run_until_complete(test()) File "/usr/lib/python3.5/asyncio/base_events.py", line 387, in run_until_complete return

Python POST Request Not Returning HTML, Requesting JavaScript Be Enabled

吃可爱长大的小学妹 提交于 2019-11-30 04:27:48
问题 I'm trying to sign in to my Wells Fargo account and scrape my transaction history so that I can use them to track my finances. I am able to do the scraping part if I can get to the HTML of the page. The problem I'm having is getting there and the below code is returning a whole lot of gibberish to me. ####Bring in BeautifulSoup and urllib. import bs4 import urllib.request import requests ####Navigate to the website. url = 'https://connect.secure.wellsfargo.com/auth/login/do' payload = {"j