python-3.5

Test calling a python coroutine (async def) from a regular function

橙三吉。 提交于 2019-12-11 06:58:30
问题 Let's say I have some asyncio coroutine which fetches some data and returns it. Like this: async def fetch_data(*args): result = await some_io() return result Basically this coroutine is called from the chain of coroutines, and initial coroutine is runned by creating a task. But what if for test purposes I want to run only one coroutine this way just when running some file: if __name__ == '__main__': result = await fetch_data(*args) print(result) And obviously I can't do this since I'm trying

Import tensorflow contrib module is slow in tensorflow 1.2.1

半城伤御伤魂 提交于 2019-12-11 06:27:56
问题 Is there a reason for the tensorflow contrib module imports being slower in 1.2.1 than 1.1.0? I am using Python 3.5. The overhead is not significant using the command-line, its perhaps around 2-3 seconds. However in an IDE, it becomes quite significant (~ 10 seconds to import tensorflow.contrib as opposed to (~0.5 seconds) in tensorflow 1.1.0. Thanks in advance. 回答1: It is slow to import because it is doing inspect.stack() many times, which take a lot of time each time. I have reported this

How to iterate each word through nltk synsets and store misspelled words in separate list?

烈酒焚心 提交于 2019-12-11 06:17:12
问题 I am trying to take a text file with messages and iterate each word through NLTK wordnet synset function. I want to do this because I want to create a list of mispelled words. For example if I do: wn.synsets('dog') I get output: [Synset('dog.n.01'), Synset('frump.n.01'), Synset('dog.n.03'), Synset('cad.n.01'), Synset('frank.n.02'), Synset('pawl.n.01'), Synset('andiron.n.01'), Synset('chase.v.01')] now if the word is mispelled like so: wn.synsets('doeg') I get output: [] If I am returned an

Deploying Python Flask App on Apache with Python version installed in Virtual Environment Only

笑着哭i 提交于 2019-12-11 05:52:27
问题 I am working on a CentOS7 development environment. The machine came with Python 2.7.5 pre-installed. I have developed a web application using Python 3.5.1 which along with it's dependencies was installed in the virtual environment only. Python 3 is not installed machine-wide. I am now trying to deploy the application on an Apache server but have run into trouble. Here is what I have done. I installed mod_wsgi using yum. I configured the virtualhost as shown below: <VirtualHost *:80>

Compare IP List to another IP List or IP Range

好久不见. 提交于 2019-12-11 05:48:31
问题 I've created a python project that scans an ip range (ie. x.y.z.0/24) and returns a list of online hosts. It saves the online hosts list to file with just the ip's (ie ['192.168.0.1', '192.168.0.2', '192.168.0.8',...]. I'm having trouble with this next step. I'd like to compare this online hosts list to an IP range to verify that these are computers to eliminate other devices. I have a DHCP Reservation List for computers that I can use. Is there a simple way to do this and update the onHosts

installing lxml on 64 bit windows

纵然是瞬间 提交于 2019-12-11 04:44:31
问题 So I'm trying to install lxml on my machine, and I can't seem to get it to work. I've got Windows 8.1 64-bit and python 3.5 I've used both pip install lxml and easy_install lxml I keep getting this error message: C:\Users\jgarber\Downloads>pip install readability-lxml --upgrade Requirement already up-to-date: readability-lxml in c:\python\lib\site-packages\ readability_lxml-0.6.2-py3.5.egg Requirement already up-to-date: chardet in c:\python\lib\site-packages (from rea dability-lxml)

dictionary update sequence element error

你。 提交于 2019-12-11 04:27:24
问题 I have several dictionary files, I want this code to open each file and add it to a set, for later comparison and matching. Basically I have a different list of all permutations of all possible characters and I need to know if permutation is in dictionary. But when I try to make a set with all dictionary lines I get this error: choices = ['s','m','o','k','e','j','a','c','k'] def parsed(choices): mySet = {} for item in choices: filename = self.location + "/dicts/%s.txt" % (item) mySet.update

Running Python Locally In Aptana Studio 3

ⅰ亾dé卋堺 提交于 2019-12-11 04:11:04
问题 I recently installed Python 3.5.2 on Mac OS X El Capitan (Version 10.11.6). I (thought) I configured Aptana Studio 3 correctly so that it points at Python 3.5 when it runs any Python code. But I'm getting error messages even why I try to run simple commands. If you take a look at the following screenshots: You'll notice that printing(4+8) does print 12, but I get a red X to the left of the print command (which after hovering reveals "undefined variable: print"). I also get Traceback messages

Returning semi-unique values from a list

蓝咒 提交于 2019-12-11 02:08:36
问题 Not sure how else to word this, but say I have a list containing the following sequence: [a,a,a,b,b,b,a,a,a] and I would like to return: [a,b,a] How would one do this in principle? 回答1: You can use itertools.groupby , this groups consecutive same elements in the same group and return an iterator of key value pairs where the key is the unique element you are looking for: from itertools import groupby [k for k, _ in groupby(lst)] # ['a', 'b', 'a'] lst = ['a','a','a','b','b','b','a','a','a'] 回答2

TypeError: len() of unsized object when comparing and I cannot make sense of it

六眼飞鱼酱① 提交于 2019-12-11 01:43:04
问题 I am trying to select sensors by placing a box around their geographic coordinates: In [1]: lat_min, lat_max = lats(data) lon_min, lon_max = lons(data) print(np.around(np.array([lat_min, lat_max, lon_min, lon_max]), 5)) Out[1]: [ 32.87248 33.10181 -94.37297 -94.21224] In [2]: select_sens = sens[(lat_min<=sens['LATITUDE']) & (sens['LATITUDE']<=lat_max) & (lon_min<=sens['LONGITUDE']) & (sens['LONGITUDE']<=lon_max)].copy() Out[2]: -----------------------------------------------------------------