python-3.3

Non-blocking multiprocessing.connection.Listener?

旧城冷巷雨未停 提交于 2019-12-21 07:20:11
问题 I use multiprocessing.connection.Listener for communication between processes, and it works as a charm for me. Now i would really love my mainloop to do something else between commands from client. Unfortunately listener.accept() blocks execution until connection from client process is established. Is there a simple way of managing non blocking check for multiprocessing.connection? Timeout? Or shall i use a dedicated thread? # Simplified code: from multiprocessing.connection import Listener

unhashable type: 'dict' Type Error [duplicate]

99封情书 提交于 2019-12-21 06:16:27
问题 This question already has answers here : TypeError: unhashable type: 'dict', when dict used as a key for another dict [duplicate] (2 answers) Closed 3 years ago . Suppose I have this dictionary: items = {1: {'title': u'testing123', 'description': u'testing456'}, 2: {'description': u'testing123', 'description': u'testing456'}, 3: {'description': u'testing123', 'description': u'testing456'}, 4: {'description': u'testing123', 'description': u'testing456'}, 5: {'description': u'testing123',

unhashable type: 'dict' Type Error [duplicate]

不打扰是莪最后的温柔 提交于 2019-12-21 06:16:21
问题 This question already has answers here : TypeError: unhashable type: 'dict', when dict used as a key for another dict [duplicate] (2 answers) Closed 3 years ago . Suppose I have this dictionary: items = {1: {'title': u'testing123', 'description': u'testing456'}, 2: {'description': u'testing123', 'description': u'testing456'}, 3: {'description': u'testing123', 'description': u'testing456'}, 4: {'description': u'testing123', 'description': u'testing456'}, 5: {'description': u'testing123',

subprocess popen.communicate() vs. stdin.write() and stdout.read()

耗尽温柔 提交于 2019-12-21 02:27:11
问题 I have noticed two different behaviors with two approaches that should have result in the same outcome. The goal - to execute an external program using subprocess module, send some data and read the results. The external program is PLINK, platform is WindowsXP, Python version 3.3. The main idea- execution=["C:\\Pr..\\...\\plink.exe", "-l", username, "-pw", "***", IP] a=subprocess.Popen(execution, bufsize=0, stdout=PIPE, stdin=PIPE, stderr=STDOUT, shell=False) con=a.stdout.readline() if (con

Reverse for 'index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

此生再无相见时 提交于 2019-12-20 18:09:15
问题 I'm trying to get django-register to work on my website but I keep getting this error which I do not understand I'm using django 1.6 on Python 3.3 NoReverseMatch at /accounts/register/ Reverse for 'index' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: [] Request Method: GET Request URL: http://127.0.0.1:8000/accounts/register/ Django Version: 1.6.1 Exception Type: NoReverseMatch Exception Value: Reverse for 'index' with arguments '()' and keyword arguments '{}'

itertools.accumulate() versus functools.reduce()

 ̄綄美尐妖づ 提交于 2019-12-20 12:28:26
问题 In Python 3.3, itertools.accumulate(), which normally repeatedly applies an addition operation to the supplied iterable, can now take a function argument as a parameter; this means it now overlaps with functools.reduce(). With a cursory look, the main differences between the two now would seem to be: accumulate() defaults to summing but doesn't let you supply an extra initial condition explicitly while reduce() doesn't default to any method but does let you supply an initial condition for use

Python 3.3 source code setup: modules were not found: _lzma _sqlite3 _tkinter

北城余情 提交于 2019-12-20 10:09:02
问题 I am trying to set up the compiled version of CPython, on Ubuntu 12.04, by following the python developer guide. Even after installing the dependent packages lzma and sqlite3, build fails indicating that the dependent modules were not found. Exact Error: *Python build finished, but the necessary bits to build these modules were not found: _lzma _sqlite3 _tkinter To find the necessary bits, look in setup.py in detect_modules() for the module's name.* I could not locate the package tkinter.

list comprehension to repeat element in a list by element value

好久不见. 提交于 2019-12-20 07:44:20
问题 I can't quite figure out the code to do this, there are similar posts: Repeating elements in list comprehension but I want to repeat a value in the list by the value in the list In [219]: l = [3,1] [i for x in range(i) for i in l] --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-219-84d6f25dfd96> in <module>() 1 l = [3,1] 2 ----> 3 [i for x in range(i) for i in l] TypeError: 'tuple' object cannot be

Creating global variable in python 3 from functions

不问归期 提交于 2019-12-20 06:27:55
问题 I was wondering why I can't access the variable: "variable_for_raw_data" after the function ends. The code is like this: def htmlfrom(Website_URL): import urllib.request response = urllib.request.urlopen(Website_URL) variable_for_raw_data =(input("What will this data be saved as: ")) global variable_for_raw_data variable_for_raw_data = response.read() Now why can't I access the variable "variable_for_raw_data" after the functions ends? Things to note: Python 3.3 urllib NOT urllib2 回答1: It

How to sort a list according to another list? Python

人盡茶涼 提交于 2019-12-20 03:23:50
问题 So if I have one list: name = ['Megan', 'Harriet', 'Henry', 'Beth', 'George'] And I have another list where each value represents the names in the right order score_list = [9, 6, 5, 6, 10] So Megan = 9 and Beth = 6 (this is from a dictionary by the way) How would I sort name alphabetically but keep the score_list matching name? I have done the with sorting numbers using the bubble sort method but not strings. 回答1: You can sort them at the same time as tuples by using zip . The sorting will be