content stringlengths 85 101k | title stringlengths 0 150 | question stringlengths 15 48k | answers list | answers_scores list | non_answers list | non_answers_scores list | tags list | name stringlengths 35 137 |
|---|---|---|---|---|---|---|---|---|
Q:
What to do with “urlopen error” in python?
How do I rectify the error "urlopen error (11001, 'getaddrinfo failed" in python?
also i use a socks
A:
So urlopen cannot find the URL you desire. What socks proxy are you using -- socksipy, for example? Maybe you haven't integrated it correctly in your use of (I ... | What to do with “urlopen error” in python? | How do I rectify the error "urlopen error (11001, 'getaddrinfo failed" in python?
also i use a socks
| [
"So urlopen cannot find the URL you desire. What socks proxy are you using -- socksipy, for example? Maybe you haven't integrated it correctly in your use of (I imagine) urllib2.\nThis SO question shows and points to some approaches for using a socks proxy with Python (pycurl is the way I'd choose to do it, if it... | [
0
] | [] | [] | [
"python"
] | stackoverflow_0002845602_python.txt |
Q:
PyQt4: Why does Python crash on close when using QTreeWidgetItem?
I'm using Python 3.1.1 and PyQt4 (not sure how to get that version number?). Python is crashing whenever I exit my application. I've seen this before as a garbage collection issue, but this time I'm not sure how to correct the problem.
This code cra... | PyQt4: Why does Python crash on close when using QTreeWidgetItem? | I'm using Python 3.1.1 and PyQt4 (not sure how to get that version number?). Python is crashing whenever I exit my application. I've seen this before as a garbage collection issue, but this time I'm not sure how to correct the problem.
This code crashes:
import sys
from PyQt4 import QtGui
class MyWindow(QtGui.QMainWin... | [
"It does not crash with a recent SIP/PyQt version.\n"
] | [
1
] | [] | [] | [
"pyqt4",
"python",
"python_sip"
] | stackoverflow_0002803704_pyqt4_python_python_sip.txt |
Q:
How to add dll's using py2exe?
I use a c++ dll in python. That dll uses other dlls.
I want to know if it's possible to include all the dll's in my .exe using py2exe without calling them directlly. If so, how can I do it?
Thanks in advance :)
A:
You may need a data_files= referencing all of those DLLs, perhaps wi... | How to add dll's using py2exe? | I use a c++ dll in python. That dll uses other dlls.
I want to know if it's possible to include all the dll's in my .exe using py2exe without calling them directlly. If so, how can I do it?
Thanks in advance :)
| [
"You may need a data_files= referencing all of those DLLs, perhaps with a wildcard. See the docs for an example (about specifically the MS runtime DLL). Note, as the docs say a million times, that you need legal rights to redistribute DLLs and those need to be obtained from the DLL's authors/owners -- don't just ... | [
3
] | [] | [] | [
"py2exe",
"python"
] | stackoverflow_0002845386_py2exe_python.txt |
Q:
QFileDialog and german umlaute within a path
i am working on a project, which i am developing with Python and PyQT4. I have stumbled upon a somewhat odd behaviour of the QFileDialog, that is not occuring when running the project within in my IDE (Eclipse).
The problem is that QFileDialog in ExistingFiles-mode does... | QFileDialog and german umlaute within a path | i am working on a project, which i am developing with Python and PyQT4. I have stumbled upon a somewhat odd behaviour of the QFileDialog, that is not occuring when running the project within in my IDE (Eclipse).
The problem is that QFileDialog in ExistingFiles-mode does fail to return the list of selected files, when o... | [
"\nTry to use lambda x: x.toUtf8(), or toLocal8Bit() or set TextCodec to any codepage you want, it should help. These methods return properly encoded python strings. Avoid using str() on QString, it is unaware of charmap you want.\nWhat is getSelectedFiles()? There is no such method in Qt 4.5 or higher in QFileDial... | [
0,
0
] | [] | [] | [
"diacritics",
"path",
"pyqt",
"pyqt4",
"python"
] | stackoverflow_0002585694_diacritics_path_pyqt_pyqt4_python.txt |
Q:
Python: How do I create a reference to a reference?
I am traditionally a Perl and C++ programmer, so apologies in advance if I am misunderstanding something trivial about Python!
I would like to create a reference to a reference.
Huh? Ok. All objects in Python are actually references to the real object.
So, how ... | Python: How do I create a reference to a reference? | I am traditionally a Perl and C++ programmer, so apologies in advance if I am misunderstanding something trivial about Python!
I would like to create a reference to a reference.
Huh? Ok. All objects in Python are actually references to the real object.
So, how do I create a reference to this reference?
Why do I need/... | [
"Easier done than said:\nostream = sys.stdout\nprint >> ostream, 'hi mom!'\nostream = sys.stderr\nprint >> ostream, 'hi mom!'\nostream = open('mylog.txt', 'a')\n...\n\nAnd look at the standard logging module when you have some more Python under your belt.\nThis answer was based on the presumption, from the level of... | [
6,
1,
1,
0,
0
] | [] | [] | [
"python",
"reference",
"stdout"
] | stackoverflow_0002846308_python_reference_stdout.txt |
Q:
Python: Repeat elements in a list comprehension?
I have the following list comprehension which returns a list of coordinate objects for each location.
coordinate_list = [Coordinates(location.latitude, location.longitude)
for location in locations]
This works.
Now suppose the location object ha... | Python: Repeat elements in a list comprehension? | I have the following list comprehension which returns a list of coordinate objects for each location.
coordinate_list = [Coordinates(location.latitude, location.longitude)
for location in locations]
This works.
Now suppose the location object has a number_of_times member. I want a list comprehensi... | [
"coordinate_list = [x for location in locations\n for x in [Coordinates(location.latitude,\n location.longitude)\n ] * location.number_of_times]\n\nEdit: the OP suggests a loop may be clearer, which, given the length of the identif... | [
7,
6,
0
] | [] | [] | [
"list_comprehension",
"python"
] | stackoverflow_0002846536_list_comprehension_python.txt |
Q:
Passing an argument to create a window using wxpython?
I am trying to learn how to make a GUI in Python. Following an online tutorial, I found that the following code 'works' in creating an empty window:
import wx
from sys import argv
class bucky(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__i... | Passing an argument to create a window using wxpython? | I am trying to learn how to make a GUI in Python. Following an online tutorial, I found that the following code 'works' in creating an empty window:
import wx
from sys import argv
class bucky(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Frame aka window', size=(300, 200))... | [
"The elements of sys.argv are strings; you need to convert them to integers before using them. Consider passing them to the constructor though, instead of relying on global state.\n"
] | [
1
] | [] | [] | [
"python",
"winapi",
"wxpython",
"wxwidgets"
] | stackoverflow_0002846523_python_winapi_wxpython_wxwidgets.txt |
Q:
Java or Python distributed compute job (on a student budget)?
I have a large dataset (c. 40G) that I want to use for some NLP (largely embarrassingly parallel) over a couple of computers in the lab, to which i do not have root access, and only 1G of user space.
I experimented with hadoop, but of course this was de... | Java or Python distributed compute job (on a student budget)? | I have a large dataset (c. 40G) that I want to use for some NLP (largely embarrassingly parallel) over a couple of computers in the lab, to which i do not have root access, and only 1G of user space.
I experimented with hadoop, but of course this was dead in the water-- the data is stored on an external usb hard drive,... | [
"Speak with the IT dept at your school (especially if you are in college), if it is for an assignment or research I bet they would be more than happy to give you more disk space.\n",
"no actual answers; i'd have put this as a comment but on this site you're forced to only answer if you're still a noob\nif it's ge... | [
3,
1,
1,
0
] | [] | [] | [
"hadoop",
"java",
"nlp",
"nltk",
"python"
] | stackoverflow_0002844105_hadoop_java_nlp_nltk_python.txt |
Q:
Summary count for Python logging
At the end of my Python program, I'd like to be able to get a summary of the number of items logged through the standard logging module. I'd specifically like to be able to get a count for each specified name (and possibly its children). E.g. if I have:
input_logger = getLogger('in... | Summary count for Python logging | At the end of my Python program, I'd like to be able to get a summary of the number of items logged through the standard logging module. I'd specifically like to be able to get a count for each specified name (and possibly its children). E.g. if I have:
input_logger = getLogger('input')
input_logger.debug("got input1")... | [
"Using a decorator could be pretty elegant, I haven't tested this but something like this could work:\nclass myDecorator(object):\n def __init__(self, inner):\n self.inner = inner\n self.log = {}\n\n def __getattr__(self,name):\n self.log[name] = self.log.get(name,0)+1\n return get... | [
3,
2
] | [] | [] | [
"logging",
"python"
] | stackoverflow_0002847282_logging_python.txt |
Q:
Dynamically setting the queryset of a ModelMultipleChoiceField to a custom recordset
I've seen all the howtos about how you can set a ModelMultipleChoiceField to use a custom queryset and I've tried them and they work. However, they all use the same paradigm: the queryset is just a filtered list of the same objec... | Dynamically setting the queryset of a ModelMultipleChoiceField to a custom recordset | I've seen all the howtos about how you can set a ModelMultipleChoiceField to use a custom queryset and I've tried them and they work. However, they all use the same paradigm: the queryset is just a filtered list of the same objects.
In my case, I'm trying to get the admin to draw a multiselect form that instead of usi... | [
"You can use a custom widget, override its render method. Here's what I had done for a text field :\nclass UserToAccount(forms.widgets.TextInput):\n def render(self, name, value, attrs=None):\n if isinstance(value, User) :\n value = Account.objects.get(user=value).name\n return super (Us... | [
1,
0,
0
] | [] | [] | [
"django",
"django_admin",
"python"
] | stackoverflow_0002846879_django_django_admin_python.txt |
Q:
what's faster: merging lists or dicts in python?
I'm working with an app that is cpu-bound more than memory bound, and I'm trying to merge two things whether they be lists or dicts.
Now the thing is i can choose either one, but I'm wondering if merging dicts would be faster since it's all in memory? Or is it alwa... | what's faster: merging lists or dicts in python? | I'm working with an app that is cpu-bound more than memory bound, and I'm trying to merge two things whether they be lists or dicts.
Now the thing is i can choose either one, but I'm wondering if merging dicts would be faster since it's all in memory? Or is it always going to be O(n), n being the size of the smaller l... | [
"If you are looking for duplicate elimination, sets are very, very fast.\n>>> x = set(range(1000000,2000000))\n>>> y = set(range(1900000,2900000))\n\nthe following happened in ~0.020s \n>>> z = set.intersection(x,y)\n>>> len(z)\n100000\n\nRegarding output to json, just convert to a list...\njson_encode(list(z))\n\... | [
2,
1,
1,
0,
0
] | [] | [] | [
"list",
"python"
] | stackoverflow_0002846431_list_python.txt |
Q:
"With" statement in Python with multiple files to handle
How do i use the with statement in this case?
f_spam = open(spam,'r')
f_bar = open(eggs,'r')
...
do something with these files
...
f_spam.close()
f_bar.close()
Files number could be greater than two.
A:
You can also do:
from contextlib import nested
wit... | "With" statement in Python with multiple files to handle | How do i use the with statement in this case?
f_spam = open(spam,'r')
f_bar = open(eggs,'r')
...
do something with these files
...
f_spam.close()
f_bar.close()
Files number could be greater than two.
| [
"You can also do:\nfrom contextlib import nested\n\nwith nested(open(spam), open(eggs)) as (f_spam, f_eggs):\n # do something\n\nIn Python 2.7 and 3.1+ you don't need the nested function because with supports the following syntax:\nwith open(spam) as f_spam, open(eggs) as f_eggs:\n # do something\n\n",
"wit... | [
18,
3
] | [] | [] | [
"python"
] | stackoverflow_0002847939_python.txt |
Q:
Catch clearly defined exception from sub.submodule in python
I have 3 files. xxx which imports xxx2 and xxx2 imports xxx3 which one raises OppsError exception.
xxx3.py:
class OppsError(Exception):pass
def go():
raise OppsError()
xxx2.py:
import xxx3
xxx3.go()
xxx.py:
try:
import xxx2
except xxx3.OppsErr... | Catch clearly defined exception from sub.submodule in python | I have 3 files. xxx which imports xxx2 and xxx2 imports xxx3 which one raises OppsError exception.
xxx3.py:
class OppsError(Exception):pass
def go():
raise OppsError()
xxx2.py:
import xxx3
xxx3.go()
xxx.py:
try:
import xxx2
except xxx3.OppsError:
print 'ops'
When i run xxx.py i get error NameError: name... | [
"As far as I know, it is (unless you are willing to replace OppsError with a built-in exception that is already known to xxx or to catch a more general exception instead of OppsError from which OppsError is derived).\n"
] | [
1
] | [] | [] | [
"exception",
"python"
] | stackoverflow_0002848049_exception_python.txt |
Q:
In Python 2.x, using backticks to get decimal string from int object is Horrible?
In Python 2.x, using backticks to get decimal string from int object is Horrible?
Because backticks are repr(), not str()? I have noticed that when I answering this question.
In Python source, they have same function in Python sourc... | In Python 2.x, using backticks to get decimal string from int object is Horrible? | In Python 2.x, using backticks to get decimal string from int object is Horrible?
Because backticks are repr(), not str()? I have noticed that when I answering this question.
In Python source, they have same function in Python source, intobject.c
(reprfunc)int_to_decimal_string, /* tp_repr */
....
(reprfunc... | [
"Well, I wouldn't say it's \"horrible\", but I feel it isn't right for at least four reasons:\n\nstr(my_number) states your intent more clearly than surrounding my_number by backticks. (See \"Readability counts\" in the Zen of Python).\nThe implementation of Python in C is just one possible implementation; there is... | [
7,
2,
0
] | [] | [] | [
"backticks",
"python",
"python_2.x"
] | stackoverflow_0002848090_backticks_python_python_2.x.txt |
Q:
python socket.socket.recv with hidden input
Is there any way to have socket.socket.recv run with hidden input. For example, if I was asking for a password I would want the input to be hidden, as if I were running the "sudo" bash command.
Edit:
socket.socket.recv asks for data on the remote end. When you are connec... | python socket.socket.recv with hidden input | Is there any way to have socket.socket.recv run with hidden input. For example, if I was asking for a password I would want the input to be hidden, as if I were running the "sudo" bash command.
Edit:
socket.socket.recv asks for data on the remote end. When you are connected to the server it will ask you for text and wh... | [
"socket.recv() returns data from a socket, what you do with that data is up to you.\nI guess you are doing something like this:\ns.connect(...)\nwhile True:\n print s.recv(4096)\n\nIn which case your problem is the remote end where someone is presumably typing input.\nCan you clarify your question please? recv() n... | [
1,
1,
1
] | [] | [] | [
"passwords",
"python",
"recv",
"sockets"
] | stackoverflow_0002831542_passwords_python_recv_sockets.txt |
Q:
How do you extend python with C++?
I've successfully extended python with C, thanks to this handy skeleton module. But I can't find one for C++, and I have circular dependency trouble when trying to fix the errors that C++ gives when I compile this skeleton module.
How do you extend Python with C++?
I'd rather not... | How do you extend python with C++? | I've successfully extended python with C, thanks to this handy skeleton module. But I can't find one for C++, and I have circular dependency trouble when trying to fix the errors that C++ gives when I compile this skeleton module.
How do you extend Python with C++?
I'd rather not depend on Boost (or SWIP or other libra... | [
"First of all, even though you don't want to introduce an additional dependency, I suggest you to have a look at PyCXX. Quoting its webpage:\n\nCXX/Objects is a set of C++ facilities to make it easier to write Python extensions. The chief way in which PyCXX makes it easier to write Python extensions is that it grea... | [
14,
7,
1
] | [] | [] | [
"c++",
"python"
] | stackoverflow_0002847617_c++_python.txt |
Q:
How to check a file saving is complete using Python?
I am trying to automate a downloading process. In this I want to know, whether a particular file's save is completed or not. The scenario is like this.
Open a site address using either Chrome or Firefox (any browser)
Save the page to disk using 'Crtl + S' (I wo... | How to check a file saving is complete using Python? | I am trying to automate a downloading process. In this I want to know, whether a particular file's save is completed or not. The scenario is like this.
Open a site address using either Chrome or Firefox (any browser)
Save the page to disk using 'Crtl + S' (I work on windows)
Now if the page is very big, then it takes ... | [
"On Windows you can try to open file in exclusive access mode to check if it's being used (read or written) by some other program. I've used this to wait for complete FTP uploads server-side, here's the code:\ndef check_file_ready(self, path):\n '''Check if file is not opened by another process.'''\n handle =... | [
6
] | [] | [] | [
"python",
"pywin",
"save",
"windows"
] | stackoverflow_0002848008_python_pywin_save_windows.txt |
Q:
How to identify a broadcasted message?
Sometimes I have to send a message to a specific IP and sometimes I have to broadcast the message to all the IP's in my network. At the other end I have to distinguish between a broadcast and a normal one, but recvfrom() just returns the address the message came from;
there i... | How to identify a broadcasted message? | Sometimes I have to send a message to a specific IP and sometimes I have to broadcast the message to all the IP's in my network. At the other end I have to distinguish between a broadcast and a normal one, but recvfrom() just returns the address the message came from;
there is no difference between them. Can anyone hel... | [
"I don't think it's possible with Python's socket module. UDP is a very minimalistic protocol, and the only way to distinguish between a broadcast and a non-broadcast UDP packet is by looking at the destination address. However, you cannot inspect that part of the packet with the BSD socket API (if I remember it co... | [
5
] | [] | [] | [
"python"
] | stackoverflow_0002848098_python.txt |
Q:
To convert PyBytesObject type to PyUnicodeObject type in python3
How to convert pyunicodeobject type to pybytesobject type?
Example:
function(PyBytesObject* byteobj){
....operation..
}
PyUnicodeObject* Uniobj;
function((PyBytesObject*) Uniobj);
got a bus error as a result.
A:
You need to encode it just as you... | To convert PyBytesObject type to PyUnicodeObject type in python3 | How to convert pyunicodeobject type to pybytesobject type?
Example:
function(PyBytesObject* byteobj){
....operation..
}
PyUnicodeObject* Uniobj;
function((PyBytesObject*) Uniobj);
got a bus error as a result.
| [
"You need to encode it just as you would if you were doing it in Python. For utf-8 use:\n\nPyObject* PyUnicode_AsUTF8String(PyObject *unicode)\n\nReturn value: New reference.\n Encode a Unicode object using UTF-8 and return the result as Python bytes object. Error handling is “strict”. Return NULL if an exception ... | [
2
] | [] | [] | [
"cpython",
"python",
"python_3.x",
"python_c_api"
] | stackoverflow_0002848569_cpython_python_python_3.x_python_c_api.txt |
Q:
threading.local equivalent for twisted.web?
In asynchronous environments, threading.local is not guaranteed to be context-local anymore, because several contexts may coexist within a single thread. Most asynchronous frameworks (gevent, eventlet) provide a get_current_context() functionality to identify the current... | threading.local equivalent for twisted.web? | In asynchronous environments, threading.local is not guaranteed to be context-local anymore, because several contexts may coexist within a single thread. Most asynchronous frameworks (gevent, eventlet) provide a get_current_context() functionality to identify the current context. Some offer a way to monkey-patch thread... | [
"I'm assuming you want this API in order to save and retrieve per-request state. If not, then you might want to clarify your question.\nTwisted Web doesn't offer any API along these lines. Since you're in control for the completely lifetime of the request, it's possible for you to store any per-request state your... | [
3
] | [] | [] | [
"python",
"twisted",
"twisted.web"
] | stackoverflow_0002848686_python_twisted_twisted.web.txt |
Q:
Fastest method in merging of the two: dicts vs lists
I'm doing some indexing and memory is sufficient but CPU isn't. So I have one huge dictionary and then a smaller dictionary I'm merging into the bigger one:
big_dict = {"the" : {"1" : 1, "2" : 1, "3" : 1, "4" : 1, "5" : 1}}
smaller_dict = {"the" : {"6" : 1, "7" ... | Fastest method in merging of the two: dicts vs lists | I'm doing some indexing and memory is sufficient but CPU isn't. So I have one huge dictionary and then a smaller dictionary I'm merging into the bigger one:
big_dict = {"the" : {"1" : 1, "2" : 1, "3" : 1, "4" : 1, "5" : 1}}
smaller_dict = {"the" : {"6" : 1, "7" : 1}}
#after merging
resulting_dict = {"the" : {"1" : 1, "... | [
"Hmmm. I would first go for a dict-of-dicts approach, as Python has one of the most fine-tuned dict implementation, so I highly doubt you can get any better with using a dict-of-lists.\nAs for merging the dicts, this should be enough:\nfor key, value in smaller_dict.iteritems():\n try:\n big_dict[key].upd... | [
2,
2,
1
] | [] | [] | [
"performance",
"python"
] | stackoverflow_0002849101_performance_python.txt |
Q:
Create a Python User() class that both creates new users and modifies existing users
I'm trying to figure out the best way to create a class that can modify and create new users all in one. This is what I'm thinking:
class User(object):
def __init__(self,user_id):
if user_id == -1
self.new_us... | Create a Python User() class that both creates new users and modifies existing users | I'm trying to figure out the best way to create a class that can modify and create new users all in one. This is what I'm thinking:
class User(object):
def __init__(self,user_id):
if user_id == -1
self.new_user = True
else:
self.new_user = False
#fetch all records from d... | [
"You can do this with metaclasses. Consider this : \nclass MetaCity:\n def __call__(cls,name):\n “”“\n If it’s in the database, retrieve it and return it\n If it’s not there, create it and return it\n ““”\n theCity = database.get(name) # your custom code to get the ... | [
4,
3,
2,
1
] | [] | [] | [
"oop",
"python"
] | stackoverflow_0002521907_oop_python.txt |
Q:
How different protocols interact with eachother in Twisted
The scenario I want two different protocols interact with each other is as below:
A and B is two different protocols.
First A will interact with the server and retrieve some values.
Only after A finishes retrieving the values , B will start to interact wit... | How different protocols interact with eachother in Twisted | The scenario I want two different protocols interact with each other is as below:
A and B is two different protocols.
First A will interact with the server and retrieve some values.
Only after A finishes retrieving the values , B will start to interact with the server.
Now my problem is that is there an elegant way to ... | [
"It sounds like you've gotten past the first hurdle - figuring out how to have A and B interact at all. That's good, since for most people that's the biggest conceptual challenge. As for making it elegant, if you're after an approach that keeps your protocol code isolated from the application code driving it (ie,... | [
1
] | [] | [] | [
"protocols",
"python",
"twisted"
] | stackoverflow_0002847979_protocols_python_twisted.txt |
Q:
Suggestions for a pluggable task framework in Django
I am developing a website which is aimed at being a GUI for several image processing algorithms (referred to as 'tasks').
At the moment, only one of these algorithms is finished, but there are more to come (which will have a similar, but not quite the same, work... | Suggestions for a pluggable task framework in Django | I am developing a website which is aimed at being a GUI for several image processing algorithms (referred to as 'tasks').
At the moment, only one of these algorithms is finished, but there are more to come (which will have a similar, but not quite the same, workflow)
Basically, the algorithm works as follows (not that ... | [
"I would make an app with a very abstract definition of a Task model. The Task model might contain properties for:\n\nthe input arguments, \nthe function to run, \nthe time that the task was submitted, \nthe time that the task has been actually running, and \nthe result (which would be something like a singleton Ta... | [
0
] | [] | [] | [
"django",
"plugins",
"python"
] | stackoverflow_0002849118_django_plugins_python.txt |
Q:
Why is there {Raw,Safe}ConfigParser in Python 3?
Am surprised there's 3 different forms: RawConfigParser, SafeConfigParser and ConfigParser (docs). I read the differences but why isn't everyone using SafeConfigParser, since it seems, well, safe? I can understand that in the case for Python 2 that the other two wer... | Why is there {Raw,Safe}ConfigParser in Python 3? | Am surprised there's 3 different forms: RawConfigParser, SafeConfigParser and ConfigParser (docs). I read the differences but why isn't everyone using SafeConfigParser, since it seems, well, safe? I can understand that in the case for Python 2 that the other two were kept for backward compatibility.
UPDATE: In Python 3... | [
"In short, use configparser.SafeConfigParser.\nTo quote the docs, SafeConfigParser \"implements a more-sane variant of the magical interpolation feature. This implementation is more predictable as well. New applications should prefer this version if they don’t need to be compatible with older versions of Python.\"\... | [
13
] | [] | [] | [
"backwards_compatibility",
"python",
"python_3.x"
] | stackoverflow_0002848711_backwards_compatibility_python_python_3.x.txt |
Q:
Text in gtk.ComboBox without active item
The following PyGTk code, gives a combo-box without an active item.
This serves a case where we do not want to have a default,
and force the user to select.
Still, is there a way to have the empty combo-bar show something like:
"Select an item..."
without adding a dummy ... | Text in gtk.ComboBox without active item | The following PyGTk code, gives a combo-box without an active item.
This serves a case where we do not want to have a default,
and force the user to select.
Still, is there a way to have the empty combo-bar show something like:
"Select an item..."
without adding a dummy item?
import gtk
import sys
say = sys.stdout.w... | [
"Huge hack ahead (I just added this to your program):\nimport gtk\nimport sys\nsay = sys.stdout.write\n\ndef cb_changed(w):\n say(\"Active index=%d\\n\" % w.get_active())\n\ntopwin = gtk.Window()\ntopwin.set_title(\"No Default\")\ntopwin.set_size_request(0x100, 0x20)\ntopwin.connect('delete-event', gtk.main_quit... | [
0
] | [] | [] | [
"combobox",
"pygtk",
"python"
] | stackoverflow_0002845605_combobox_pygtk_python.txt |
Q:
django: unit testing html tags from response and sessions
Is there a way to test the html from the response of:
response = self.client.get('/user/login/')
I want a detailed check like input ids, and other attributes. Also, how about sessions that has been set? is it possible to check their values in the test?
A:... | django: unit testing html tags from response and sessions | Is there a way to test the html from the response of:
response = self.client.get('/user/login/')
I want a detailed check like input ids, and other attributes. Also, how about sessions that has been set? is it possible to check their values in the test?
| [
"Careful.\n\nAlso, how about sessions that has been set? is it possible to check their values in the test?\n\nTDD is about externally visible behavior. To see if the user has a session, you would provide a link that only works when the user is logged in and has a session. \nThe usual drill is something like the fo... | [
10,
8,
6
] | [] | [] | [
"django",
"python",
"unit_testing"
] | stackoverflow_0002849457_django_python_unit_testing.txt |
Q:
google app engine: go to login page by javascript?
Do anyone know how do use javascript to redirect user login using Google Accounts?
I know there is "users.create_login_url(self.request.path)" but how do that integrated to "`window.location"
Or there is alternative??
A:
You should be able to pass the string tha... | google app engine: go to login page by javascript? | Do anyone know how do use javascript to redirect user login using Google Accounts?
I know there is "users.create_login_url(self.request.path)" but how do that integrated to "`window.location"
Or there is alternative??
| [
"You should be able to pass the string that is created by users.create_login_url(self.request.path) to your template as a template variable, and then the template variable can be inserted into your Javascript with double curly braces (if you are using the bundled Django templates):\nwindow.location = {{ authention_... | [
2,
0
] | [] | [] | [
"google_app_engine",
"javascript",
"python"
] | stackoverflow_0002850074_google_app_engine_javascript_python.txt |
Q:
Producing a static HTML site from XML content
I have a long document in XML from which I need to produce static HTML pages (for distribution via CD). I know (to varying degrees) JavaScript, PHP and Python. The current options I've considered are listed here:
I'm not ruling out JavaScript, so one option would be t... | Producing a static HTML site from XML content | I have a long document in XML from which I need to produce static HTML pages (for distribution via CD). I know (to varying degrees) JavaScript, PHP and Python. The current options I've considered are listed here:
I'm not ruling out JavaScript, so one option would be to use ajax to dynamically load the XML content into... | [
"I think XSLT is by far the easiest and best method -- even taking into account having to learn xslt. \nThere are several styles of xslt programming, but the easiest is \"push processing\" , where you write several templates that describe how your xml input is to be transformed into html output. Then you write a r... | [
4,
2,
1,
0
] | [] | [] | [
"ajax",
"html",
"python",
"xml",
"xslt"
] | stackoverflow_0002850534_ajax_html_python_xml_xslt.txt |
Q:
What's the standard config file name and extension in Python?
I'm creating a config file to hold configuration/properties settings for my project that frequently change, such as file paths. What's the standard name/extension for such a file? (e.g. in Java I've used config.xml, in VB.NET I've used App.config...)
A... | What's the standard config file name and extension in Python? | I'm creating a config file to hold configuration/properties settings for my project that frequently change, such as file paths. What's the standard name/extension for such a file? (e.g. in Java I've used config.xml, in VB.NET I've used App.config...)
| [
"Ok, I've asked around where I work and researched a little, and this is what I've come up with as suggestions:\n\nsettings.ini\napplicationName.config\napplicationName.cfg\n\nIf anyone has any other suggestions, feel free to add...\n",
"First, consider using ConfigParser (configparser in 3.0, so the documentatio... | [
12,
7,
4
] | [] | [] | [
"config",
"file_extension",
"filenames",
"python"
] | stackoverflow_0002850084_config_file_extension_filenames_python.txt |
Q:
Multiple XML Namespaces in tag with LXML
I am trying to use Pythons LXML library to create a GPX file that can be read by Garmin's Mapsource Product. The header on their GPX files looks like this
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx xmlns="http://www.topografix.com/GPX/1/1"
creator="M... | Multiple XML Namespaces in tag with LXML | I am trying to use Pythons LXML library to create a GPX file that can be read by Garmin's Mapsource Product. The header on their GPX files looks like this
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx xmlns="http://www.topografix.com/GPX/1/1"
creator="MapSource 6.15.5" version="1.1"
xmlns:xsi... | [
"The problem is with your attribute name.\nattrib={\"{xsi}schemaLocation\" : schemaLocation},\n\nputs schemaLocation in the xsi namespace. \nI think you meant\nattrib={\"{\" + xsi + \"}schemaLocation\" : schemaLocation}\n\nto use the URL for xsi. This matches your uses of namespace variables in the element name. I... | [
16
] | [] | [] | [
"gpx",
"lxml",
"python",
"xml"
] | stackoverflow_0002850823_gpx_lxml_python_xml.txt |
Q:
Why isn't pyinstaller making me an .exe file?
I am attempting to follow this guide to make a simple Hello World script into an .exe file.
I have Windows Vista with an AMD 64-bit processor
I have installed Python 2.6.5 (Windows AMD64 version)
I have set the PATH (if that's the right word) so that the command line r... | Why isn't pyinstaller making me an .exe file? | I am attempting to follow this guide to make a simple Hello World script into an .exe file.
I have Windows Vista with an AMD 64-bit processor
I have installed Python 2.6.5 (Windows AMD64 version)
I have set the PATH (if that's the right word) so that the command line recognizes Python
I have installed UPX (there only s... | [
"64-bit Python is not supported by pyinstaller under Windows. There's normally no drawback when using 32-bit Python under a 64-bit environment, though, so the easiest option is to install and use that. It also has the added benefit that a executable generated by pyinstaller will work under both 32-bit and 64-bit Wi... | [
6
] | [] | [] | [
"pyinstaller",
"python"
] | stackoverflow_0002831602_pyinstaller_python.txt |
Q:
How can I lookup an attribute in any scope by name?
How can I lookup an attribute in any scope by name? My first trial is to use globals() and locals(). e.g.
>>> def foo(name):
... a=1
... print globals().get(name), locals().get(name)
...
>>> foo('a')
None 1
>>> b=1
>>> foo('b')
1 None
>>> foo('foo')
<function... | How can I lookup an attribute in any scope by name? | How can I lookup an attribute in any scope by name? My first trial is to use globals() and locals(). e.g.
>>> def foo(name):
... a=1
... print globals().get(name), locals().get(name)
...
>>> foo('a')
None 1
>>> b=1
>>> foo('b')
1 None
>>> foo('foo')
<function foo at 0x014744B0> None
So far so good. However it fail... | [
">>> getattr(__builtins__, 'range')\n<built-in function range>\n\n",
"Use __builtin__ (without the s at the end like Triptych and Duncan suggest):\n>>> import __builtin__\n>>> getattr(__builtin__, 'range')\n<built-in function range>\n\n__builtins__ is CPython-implementation specific thus makes your code less port... | [
4,
2,
0
] | [] | [] | [
"python"
] | stackoverflow_0002850966_python.txt |
Q:
Parent Thread exiting before Child Threads [python]
I'm using Python in a webapp (CGI for testing, FastCGI for production) that needs to send an occasional email (when a user registers or something else important happens). Since communicating with an SMTP server takes a long time, I'd like to spawn a thread for t... | Parent Thread exiting before Child Threads [python] | I'm using Python in a webapp (CGI for testing, FastCGI for production) that needs to send an occasional email (when a user registers or something else important happens). Since communicating with an SMTP server takes a long time, I'd like to spawn a thread for the mail function so that the rest of the app can finish u... | [
"Take a look at the thread.join() method. Basically it will block your calling thread until the child thread has returned (thus preventing it from exiting before it should).\nUpdate:\nTo avoid making your main thread unresponsive to new requests you can use a while loop.\nwhile threading.active_count() > 0:\n #... | [
3,
0
] | [] | [] | [
"cgi",
"multithreading",
"python",
"smtp"
] | stackoverflow_0002850566_cgi_multithreading_python_smtp.txt |
Q:
Get list of Python module variables in Bash
For a Bash completion script I need to get all the variables from an installed Python module that match a pattern. I want to use only Python-aware functionality, to avoid having to parse comments and such.
A:
You can use python -c to execute a one-line Python script if... | Get list of Python module variables in Bash | For a Bash completion script I need to get all the variables from an installed Python module that match a pattern. I want to use only Python-aware functionality, to avoid having to parse comments and such.
| [
"You can use python -c to execute a one-line Python script if you want. For example:\nbash$ python -c \"import os; print dir(os)\"\n\nIf you want to filter by a pattern, you could do:\nbash$ python -c \"import os; print [x for x in dir(os) if x.startswith('r')]\"\n['read', 'readlink', 'remove', 'removedirs', 're... | [
3
] | [] | [] | [
"bash",
"python"
] | stackoverflow_0002851243_bash_python.txt |
Q:
In Python, is it better to use list comprehensions or for-each loops?
Which of the following is better to use and why?
Method 1:
for k, v in os.environ.items():
print "%s=%s" % (k, v)
Method 2:
print "\n".join(["%s=%s" % (k, v)
for k,v in os.environ.items()])
I tend to lead towards the first as more u... | In Python, is it better to use list comprehensions or for-each loops? | Which of the following is better to use and why?
Method 1:
for k, v in os.environ.items():
print "%s=%s" % (k, v)
Method 2:
print "\n".join(["%s=%s" % (k, v)
for k,v in os.environ.items()])
I tend to lead towards the first as more understandable, but that might just be because I'm new to Python and list co... | [
"If the iteration is being done for its side effect ( as it is in your \"print\" example ), then a loop is clearer. \nIf the iteration is executed in order to build a composite value, then list comprehensions are usually more readable. \n",
"The particular code examples you have chosen do not demonstrate any adv... | [
42,
26,
15,
15,
4,
3,
2
] | [] | [] | [
"coding_style",
"foreach",
"list_comprehension",
"python"
] | stackoverflow_0002849645_coding_style_foreach_list_comprehension_python.txt |
Q:
Setting up relations/mappings for a SQLAlchemy many-to-many database
I'm new to SQLAlchemy and relational databases, and I'm trying to set up a model for an annotated lexicon. I want to support an arbitrary number of key-value annotations for the words which can be added or removed at runtime. Since there will b... | Setting up relations/mappings for a SQLAlchemy many-to-many database | I'm new to SQLAlchemy and relational databases, and I'm trying to set up a model for an annotated lexicon. I want to support an arbitrary number of key-value annotations for the words which can be added or removed at runtime. Since there will be a lot of repetition in the names of the keys, I don't want to use this s... | [
"There is very similar question with slight interface difference. But it's easy to fix it by defining __getitem__, __setitem__ and __delitem__ methods.\n",
"Simply use Dictionary-Based Collections mapping mapping - out of the box solution to your question. Extract from the link:\nfrom sqlalchemy.orm.collections i... | [
1,
1,
1,
0
] | [] | [] | [
"orm",
"python",
"sqlalchemy"
] | stackoverflow_0002316537_orm_python_sqlalchemy.txt |
Q:
Can I turn off implicit Python unicode conversions to find my mixed-strings bugs?
When profiling our code I was surprised to find millions of calls to
C:\Python26\lib\encodings\utf_8.py:15(decode)
I started debugging and found that across our code base there are many small bugs, usually comparing a string to a... | Can I turn off implicit Python unicode conversions to find my mixed-strings bugs? | When profiling our code I was surprised to find millions of calls to
C:\Python26\lib\encodings\utf_8.py:15(decode)
I started debugging and found that across our code base there are many small bugs, usually comparing a string to a unicode or adding a sting and a unicode. Python graciously decodes the strings and per... | [
"The following should work:\n>>> import sys\n>>> reload(sys)\n<module 'sys' (built-in)>\n>>> sys.setdefaultencoding('undefined')\n>>> u\"abc\" + u\"xyz\"\nu'abcxyz'\n>>> u\"abc\" + \"xyz\"\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\n File \"/System/Library/Frameworks/Python.framew... | [
9
] | [] | [] | [
"debugging",
"decoding",
"python",
"unicode"
] | stackoverflow_0002851481_debugging_decoding_python_unicode.txt |
Q:
Google group word count for members?
I have a google group, and I'd like to figure out how many words each member has posted. Is there a utility to do this?
If not, how can I get started writing a Python script to do this? Should I just grab XML from the group's feed and look through that? (I don't know anything a... | Google group word count for members? | I have a google group, and I'd like to figure out how many words each member has posted. Is there a utility to do this?
If not, how can I get started writing a Python script to do this? Should I just grab XML from the group's feed and look through that? (I don't know anything about Python's handling of XML.)
On the Goo... | [
"It looks like people have wanted a Groups API since about 3 years ago. It looks like you may have to resort to page-scraping.\n"
] | [
0
] | [] | [] | [
"google_groups",
"google_groups_api",
"python",
"xml"
] | stackoverflow_0002852001_google_groups_google_groups_api_python_xml.txt |
Q:
Is there an efficient way to figure out the headers, cookies, and get/post data being passed to a site?
More specifically I'm looking for something, perhaps an add-on for firefox, once enabled it logs all of this information as it's passed to and from the server. I'm doing some web scripting and this would be real... | Is there an efficient way to figure out the headers, cookies, and get/post data being passed to a site? | More specifically I'm looking for something, perhaps an add-on for firefox, once enabled it logs all of this information as it's passed to and from the server. I'm doing some web scripting and this would be really handy.
If anyone is wondering specifically what I'm doing currently I'm trying to make a script to repost... | [
"The Network module of the Firefox Web Developer Toolbar lets you look at the HTTP headers in the request and the response, so it's a good starting point. It won't log everything for you, though, so you will have to copy everything to a text editor if you want to inspect it later.\nSince you also tagged your post w... | [
0,
0,
0,
0
] | [] | [] | [
"html",
"parsing",
"python",
"web",
"webforms"
] | stackoverflow_0002850840_html_parsing_python_web_webforms.txt |
Q:
python: how/where to put a simple library installed in a well-known-place on my computer
I need to put a python script somewhere on my computer so that in another file I can use it. How do I do this and where do I put it? And where in the python documentation do I learn how to do this? I'm a beginner + don't use p... | python: how/where to put a simple library installed in a well-known-place on my computer | I need to put a python script somewhere on my computer so that in another file I can use it. How do I do this and where do I put it? And where in the python documentation do I learn how to do this? I'm a beginner + don't use python much.
library file: MyLib.py put in a well-known place
def myfunc():
....
other fil... | [
"Option 1:\nPut your file at:\n<Wherever your Python is>/Lib/site-packages/myfile.py\nAdd this to your code:\nimport myfile\n\nPros: Easy\nCons: Clutters site-packages\nOption 2:\nPut your file at:\n/Lib/site-packages/mypackage/myfile.py\nCreate an empty text file called:\n<Wherever your Python is>/Lib/site-package... | [
8,
4,
3,
2,
1,
1
] | [] | [] | [
"import",
"path",
"python"
] | stackoverflow_0002851182_import_path_python.txt |
Q:
Extracting words between delimiters [] in python
From the below string, I want to extract the words between delimters [ ] like 'Service Current','Service','9991','1.22':
str='mysrv events Generating Event Name [Service Current], Category [Service] Test [9991] Value [1.22]'
How can I extract the same in python?
Th... | Extracting words between delimiters [] in python | From the below string, I want to extract the words between delimters [ ] like 'Service Current','Service','9991','1.22':
str='mysrv events Generating Event Name [Service Current], Category [Service] Test [9991] Value [1.22]'
How can I extract the same in python?
Thanks in advance
Kris
| [
"First, avoid using str as a variable name. str already has a meaning in Python and by defining it to be something else you will confuse people.\nHaving said that you can use the following regular expression:\n>>> import re\n>>> print re.findall(r'\\[([^]]*)\\]', s)\n['Service Current', 'Service', '9991', '1.22']\n... | [
22,
8,
2
] | [] | [] | [
"python"
] | stackoverflow_0002852484_python.txt |
Q:
Django Deserialization
I am getting the following error:
Traceback (most recent call last):
File "../tests.py", line 92, in test_single_search
for return_obj in serializers.deserialize("json",response, ensure_ascii=False):
File "/Library/Python/2.6/site-packages/django/core/serializers/json.py",
line 38, in... | Django Deserialization | I am getting the following error:
Traceback (most recent call last):
File "../tests.py", line 92, in test_single_search
for return_obj in serializers.deserialize("json",response, ensure_ascii=False):
File "/Library/Python/2.6/site-packages/django/core/serializers/json.py",
line 38, in Deserializer
for obj ... | [
"You need to use response.content rather than just response in your call to deserialize. The response object is an instance of HttpResponse, but has an attribute of content which contains the actual JSON in this case.\n"
] | [
9
] | [] | [] | [
"django",
"python",
"serialization"
] | stackoverflow_0002852583_django_python_serialization.txt |
Q:
How to fix this dll loading python error?
I use one c++ dll in my python code.
When I run my python app on my computer, it works fine but when I copy all to another computer this happen:
Traceback (most recent call last):
File "C:\users\Public\SoundLog\Code\Código Python\SoundLog\SoundLog.py", line 9, in <module>... | How to fix this dll loading python error? | I use one c++ dll in my python code.
When I run my python app on my computer, it works fine but when I copy all to another computer this happen:
Traceback (most recent call last):
File "C:\users\Public\SoundLog\Code\Código Python\SoundLog\SoundLog.py", line 9, in <module>
from Auxiliar import *
File "C:\users\Publ... | [
"You're using a DLL which depends on a Microsoft Visual C++ runtime which isn't installed on the target computer. You have a few options:\n\nInstall or copy the Visual C++ runtime libraries to the target computer. Installation is done by adding merge modules to your installer (if you have one) or by running the red... | [
3
] | [] | [] | [
"python"
] | stackoverflow_0002852652_python.txt |
Q:
python: where to put application data that can be edited by computer users
I'm working on a really simple python package for our internal use, and want to package it as a .egg file, and when it's installed/used I want it to access a text file that is placed in an appropriate place on the computer.
So where is the... | python: where to put application data that can be edited by computer users | I'm working on a really simple python package for our internal use, and want to package it as a .egg file, and when it's installed/used I want it to access a text file that is placed in an appropriate place on the computer.
So where is the best place to put application data in python? (that is meant to be edited by us... | [
"os.path.expanduser('~')\n",
"Each OS will have it's own directory where application data is expected to exist. There does not appear to be a method that provides this path in a platform-independent manner. You can write your own function to do this for you by checking os.name and then returning the appropriate v... | [
3,
0
] | [] | [] | [
"application_data",
"installation",
"python"
] | stackoverflow_0002852606_application_data_installation_python.txt |
Q:
Python required variable style
What is the best style for a Python method that requires the keyword argument 'required_arg':
def test_method(required_arg, *args, **kwargs):
def test_method(*args, **kwargs):
required_arg = kwargs.pop('required_arg')
if kwargs:
raise ValueError('Unexpected keyword a... | Python required variable style | What is the best style for a Python method that requires the keyword argument 'required_arg':
def test_method(required_arg, *args, **kwargs):
def test_method(*args, **kwargs):
required_arg = kwargs.pop('required_arg')
if kwargs:
raise ValueError('Unexpected keyword arguments: %s' % kwargs)
Or somethi... | [
"The first method by far. Why duplicate something the language already provides for you?\nOptional arguments in most cases should be known (only use *args and **kwargs when there is no possible way of knowing the arguments). Denote optional arguments by giving them their default value (def bar(foo = 0) or def bar(f... | [
7,
2,
0
] | [] | [] | [
"python"
] | stackoverflow_0002852623_python.txt |
Q:
Django Grouping Query
I have the following (simplified) models:
class Donation(models.Model):
entry_date = models.DateTimeField()
class Category(models.Model):
name = models.CharField()
class Item(models.Model):
donation = models.ForeignKey(Donation)
category = models.ForeignKey(Category)
I'm tr... | Django Grouping Query | I have the following (simplified) models:
class Donation(models.Model):
entry_date = models.DateTimeField()
class Category(models.Model):
name = models.CharField()
class Item(models.Model):
donation = models.ForeignKey(Donation)
category = models.ForeignKey(Category)
I'm trying to display the total n... | [
"This other post looks like what you're looking for:\nDjango equivalent for count and group by\nDepending on your Django version, you may or may not be able to use it though.\n",
"I realize you've probably already written your raw SQL, but the following came to mind when I saw the way you want to display your dat... | [
0,
0
] | [] | [] | [
"django",
"python"
] | stackoverflow_0002831238_django_python.txt |
Q:
How do I search & replace all occurrences of a string in a ms word doc with python?
I am pretty stumped at the moment. Based on Can I use Win32 COM to replace text inside a word document? I was able to code a simple template system that generates word docs out of a template word doc (in Python).
My problem is that... | How do I search & replace all occurrences of a string in a ms word doc with python? | I am pretty stumped at the moment. Based on Can I use Win32 COM to replace text inside a word document? I was able to code a simple template system that generates word docs out of a template word doc (in Python).
My problem is that text in "Text Fields" is not find that way. Even in Word itself there is no option to se... | [
"Maybe you can use the OpenOffice API using the UNO component technology. With the Python-UNO bridge you can connect to an OpenOffice instance running in headless mode. Look at the tutorial to get started.\nThis is maybe an overkill for your scenario but it's a very powerful and flexible solution.\n"
] | [
2
] | [] | [] | [
"ms_word",
"python",
"vba",
"win32com"
] | stackoverflow_0002852857_ms_word_python_vba_win32com.txt |
Q:
How does one wrap numpy array types?
I'd like to make a class extending the numpy array base type,
class LemmaMatrix(numpy.ndarray):
@classmethod
def init_from_corpus(cls, ...): cls(numpy.empty(...))
But apparently, it will not allow multi-dimensional array types. Is there a way around this? Thanks in adv... | How does one wrap numpy array types? | I'd like to make a class extending the numpy array base type,
class LemmaMatrix(numpy.ndarray):
@classmethod
def init_from_corpus(cls, ...): cls(numpy.empty(...))
But apparently, it will not allow multi-dimensional array types. Is there a way around this? Thanks in advance!
ndarray(empty([3, 3]))
TypeError: on... | [
"import numpy as np\nclass LemmaMatrix(np.ndarray):\n def __new__(subtype,data,dtype=None):\n subarr=np.empty(data,dtype=dtype)\n return subarr\n\nlm=LemmaMatrix([3,3])\nprint(lm)\n# [[ 3.15913337e-260 4.94951870e+173 4.88364603e-309]\n# [ 1.63321355e-301 4.80218258e-309 2.05227026e-287]... | [
5
] | [] | [] | [
"arrays",
"numpy",
"python"
] | stackoverflow_0002853051_arrays_numpy_python.txt |
Q:
All possible permutations of a set of lists in Python
In Python I have a list of n lists, each with a variable number of elements. How can I create a single list containing all the possible permutations:
For example
[ [ a, b, c], [d], [e, f] ]
I want
[ [a, d, e] , [a, d, f], [b, d, e], [b, d, f], [c, d, e], [c,... | All possible permutations of a set of lists in Python | In Python I have a list of n lists, each with a variable number of elements. How can I create a single list containing all the possible permutations:
For example
[ [ a, b, c], [d], [e, f] ]
I want
[ [a, d, e] , [a, d, f], [b, d, e], [b, d, f], [c, d, e], [c, d, f] ]
Note I don't know n in advance. I thought itertoo... | [
"You don't need to know n in advance to use itertools.product\n>>> import itertools\n>>> s=[ [ 'a', 'b', 'c'], ['d'], ['e', 'f'] ]\n>>> list(itertools.product(*s))\n[('a', 'd', 'e'), ('a', 'd', 'f'), ('b', 'd', 'e'), ('b', 'd', 'f'), ('c', 'd', 'e'), ('c', 'd', 'f')]\n\n",
"You can do it with a multi-level list c... | [
117,
7,
6
] | [] | [] | [
"list",
"permutation",
"python"
] | stackoverflow_0002853212_list_permutation_python.txt |
Q:
Loading a DB table into nested dictionaries in Python
I have a table in MySql DB which I want to load it to a dictionary in python.
the table columns is as follows:
id,url,tag,tagCount
tagCount is the number of times that a tag has been repeated for a certain url. So in that case I need a nested dictionary, in ot... | Loading a DB table into nested dictionaries in Python | I have a table in MySql DB which I want to load it to a dictionary in python.
the table columns is as follows:
id,url,tag,tagCount
tagCount is the number of times that a tag has been repeated for a certain url. So in that case I need a nested dictionary, in other words a dictionary of dictionary, to load this table. B... | [
"maybe you could try with normal dicts and tuple keys like \nd = dict()\n\nfor url,tag,tagCount in urlTagCount:\n d[(url, tag)] = tagCount\n\nin any case did you try:\nd = defaultdict(dict)\n\ninstead of\nd = defaultdict(defaultdict)\n\n",
"You need to ensure that the dictionary (and each of the nested diction... | [
1,
1,
0
] | [] | [] | [
"dictionary",
"mysql",
"nested",
"python"
] | stackoverflow_0002853269_dictionary_mysql_nested_python.txt |
Q:
On-Demand Python Thread Start/Join Freezing Up from wxPython GUI
I'm attempting to build a very simple wxPython GUI that monitors and displays external data. There is a button that turns the monitoring on/off. When monitoring is turned on, the GUI updates a couple of wx StaticLabels with real-time data. When mo... | On-Demand Python Thread Start/Join Freezing Up from wxPython GUI | I'm attempting to build a very simple wxPython GUI that monitors and displays external data. There is a button that turns the monitoring on/off. When monitoring is turned on, the GUI updates a couple of wx StaticLabels with real-time data. When monitoring is turned off, the GUI idles.
The way I tried to build it was... | [
"In wxPython, GUI operations need to take place in the main thread. At places in your code you are calling the GUI from a different thread.\nThe easiest solution is to use wx.CallAfter(). A line of code would look like\nwx.CallAfter(self.button.SetLabel, “Start Monitoring”)\n\nwhich will then call self.button.Set... | [
2,
1,
1
] | [] | [] | [
"multithreading",
"python",
"windows_7_x64",
"wxpython"
] | stackoverflow_0002852124_multithreading_python_windows_7_x64_wxpython.txt |
Q:
Searching through large data set
how would i search through a list with ~5 mil 128bit (or 256, depending on how you look at it) strings quickly and find the duplicates (in python)? i can turn the strings into numbers, but i don't think that's going to help much. since i haven't learned much information theory, is ... | Searching through large data set | how would i search through a list with ~5 mil 128bit (or 256, depending on how you look at it) strings quickly and find the duplicates (in python)? i can turn the strings into numbers, but i don't think that's going to help much. since i haven't learned much information theory, is there anything about this in informati... | [
"If it fits into memeory, use set(). I think it will be faster than sort. O(n log n) for 5 million items is going to cost you.\nIf it does not fit into memory, say you've lot more than 5 million record, divide and conquer. Break the records at the mid point like 1 x 2^127. Apply any of the above methods. I guess in... | [
4,
2,
2,
1,
0
] | [] | [] | [
"arrays",
"duplicates",
"python",
"search",
"string"
] | stackoverflow_0002852912_arrays_duplicates_python_search_string.txt |
Q:
What will be the setup process for website development?
I want to create a simple site for my personal usage. And this only in python based technologies. So I want to get a expert oponian on this topic.
What should i used as platform? I did a search for available options and found Django, grok, web2py and many mo... | What will be the setup process for website development? | I want to create a simple site for my personal usage. And this only in python based technologies. So I want to get a expert oponian on this topic.
What should i used as platform? I did a search for available options and found Django, grok, web2py and many more of these. Which one a novice use should use? If I choose t... | [
"If the size of the community matters to you above everything else go consider that PHP has at least 10x more users than any Python framework.\nIf you have an existing database and you do not want to move data over to a new one, you probably should use SQLAlchemy and therefore you need a glued framework (Pylons in ... | [
3,
0,
0
] | [] | [] | [
"python"
] | stackoverflow_0002842748_python.txt |
Q:
Using virtualenv to install different versions of same package
Since I have Django 1.1x on my Debian setup - how can I use virtualenv or similar and not have it mess up my system's default django version which in turn would break all my sites?
Detailed instructions or a great tutorial link would very much be appre... | Using virtualenv to install different versions of same package | Since I have Django 1.1x on my Debian setup - how can I use virtualenv or similar and not have it mess up my system's default django version which in turn would break all my sites?
Detailed instructions or a great tutorial link would very much be appreciated - please don't offer vague advice since I'm still a noob.
Cur... | [
"If you have easy_install, or better yet pip installed, should be as easy as:\n\neasy_install/pip install virtualenv\nmkdir django1.2\nvirtualenv django1.2\n\nThis will put the python binary in a bin folder inside the django1.2 folder. Just use that python binary, and you've got a nice little self-contained environ... | [
2,
2
] | [] | [] | [
"django",
"python",
"virtualenv"
] | stackoverflow_0002851632_django_python_virtualenv.txt |
Q:
Problem with dictionary key in Python
For some project I have to make a dictionary in which the keys are urls,among which I have this url:
http://www.microsoft.com/isapi/redir.dll?prd=windows&sbp=mediaplayer&ar=Media&sba=Guide&pver=6.2
the url is too long to fit in here I guess in one single line.
I can build a d... | Problem with dictionary key in Python | For some project I have to make a dictionary in which the keys are urls,among which I have this url:
http://www.microsoft.com/isapi/redir.dll?prd=windows&sbp=mediaplayer&ar=Media&sba=Guide&pver=6.2
the url is too long to fit in here I guess in one single line.
I can build a dictionary without any errors this url is al... | [
"It is almost inconceivable that the dictionary is \"losing\" your key. I would guess that there is some small change in the string (case, or how the query string is ordered) that results in the same effective URL, but with a slightly different string.\nIf this is the case, find a way to \"normalize\" the URL. \n",... | [
1,
1,
0,
0
] | [] | [] | [
"python"
] | stackoverflow_0002845764_python.txt |
Q:
What scripts should not be ported from bash to python?
I decided to rewrite all our Bash scripts in Python (there are not so many of them) as my first Python project. The reason for it is that although being quite fluent in Bash I feel it's somewhat archaic language and since our system is in the first stages of i... | What scripts should not be ported from bash to python? | I decided to rewrite all our Bash scripts in Python (there are not so many of them) as my first Python project. The reason for it is that although being quite fluent in Bash I feel it's somewhat archaic language and since our system is in the first stages of its developments I think switching to Python now will be the ... | [
"It is OK in the sense that you can do it. But the scripts in /etc/init.d usually need to load config data and some functions (for example to print the nice green OK on the console) which will be hard to emulate in Python.\nSo try to convert those which make sense (i.e. those which contain complex logic). If you ne... | [
3,
2,
1,
0
] | [] | [] | [
"bash",
"linux",
"python",
"scripting"
] | stackoverflow_0002852397_bash_linux_python_scripting.txt |
Q:
Do you know of any python mapreduce ready clustering libraries?
Do you know of any python mapreduce ready clustering libraries?
I have found some good libraries in Java (http://lucene.apache.org/mahout/), I'd prefer to use python though.
https://github.com/klbostee/dumbo/wiki (Python mapreduce API )
Edit ---
I'm l... | Do you know of any python mapreduce ready clustering libraries? | Do you know of any python mapreduce ready clustering libraries?
I have found some good libraries in Java (http://lucene.apache.org/mahout/), I'd prefer to use python though.
https://github.com/klbostee/dumbo/wiki (Python mapreduce API )
Edit ---
I'm looking for mapreduce ready : Canopy, K-means, Means-shift,etc..
| [
"You can use Python in combination with Hadoop, if you like:\nhttp://www.michael-noll.com/wiki/Writing_An_Hadoop_MapReduce_Program_In_Python\n"
] | [
3
] | [] | [] | [
"libraries",
"mapreduce",
"python"
] | stackoverflow_0002853752_libraries_mapreduce_python.txt |
Q:
Automatically support new changes with Python
I was working on a program,that I need to support new additions. Hmmm. Let me give you some background on the program.
It is an educational software program that has quizzes for the user to take, just to gain odd knowledge. Now, It currently supports 6 subjects, all or... | Automatically support new changes with Python | I was working on a program,that I need to support new additions. Hmmm. Let me give you some background on the program.
It is an educational software program that has quizzes for the user to take, just to gain odd knowledge. Now, It currently supports 6 subjects, all organized with directores on the HDD ( i.e. the Scien... | [
"You can add buttons dynamically just fine, nothing is forcing you into the listbox. That said, I don't know why you care so much about \"prettiness\" since you're using Tkinter, which is very ugly by default.\n"
] | [
0
] | [] | [] | [
"python",
"tkinter"
] | stackoverflow_0002853708_python_tkinter.txt |
Q:
How to maintain long-lived python projects w.r.t. dependencies and python versions?
short version: how can I get rid of the multiple-versions-of-python nightmare ?
long version: over the years, I've used several versions of python, and what is worse, several extensions to python (e.g. pygame, pylab, wxPython...). ... | How to maintain long-lived python projects w.r.t. dependencies and python versions? | short version: how can I get rid of the multiple-versions-of-python nightmare ?
long version: over the years, I've used several versions of python, and what is worse, several extensions to python (e.g. pygame, pylab, wxPython...). Each time it was on a different setup, with different OSes, sometimes different architect... | [
"I solve this using virtualenv. I sympathise with wanting to avoid further layers of nightmare abstraction, but virtualenv is actually amazingly clean and simple to use. You literally do this (command line, Linux):\nvirtualenv my_env\n\nThis creates a new python binary and library location, and symlinks to your exi... | [
10,
4,
4,
1,
1,
0,
0,
0
] | [] | [] | [
"dependencies",
"installation",
"multiple_versions",
"python"
] | stackoverflow_0002759623_dependencies_installation_multiple_versions_python.txt |
Q:
How do you PEP 8-name a class whose name is an acronym?
I try to adhere to the style guide for Python code (also known as PEP 8). Accordingly, the preferred way to name a class is using CamelCase:
Almost without exception, class names
use the CapWords convention. Classes for internal use have a leading undersco... | How do you PEP 8-name a class whose name is an acronym? | I try to adhere to the style guide for Python code (also known as PEP 8). Accordingly, the preferred way to name a class is using CamelCase:
Almost without exception, class names
use the CapWords convention. Classes for internal use have a leading underscore in addition.
How can I be consistent with PEP 8 if my cla... | [
"PEP-8 does cover this (at least partially):\n\nNote: When using abbreviations in CapWords, capitalize all the letters of the abbreviation. Thus HTTPServerError is better than HttpServerError.\n\nWhich I would read to mean that NASAJPL() is the recommended name according to PEP-8. \nPersonally I'd find NasaJpl() ... | [
101,
38,
11,
9,
7,
6,
3,
1
] | [] | [] | [
"coding_style",
"naming_conventions",
"python"
] | stackoverflow_0002853531_coding_style_naming_conventions_python.txt |
Q:
Reversing Django URLs With Extra Options
Suppose I have a URLconf like below, and 'foo' and 'bar' are valid values for page_slug.
urlpatterns = patterns('',
(r'^page/(?P<page_slug>.*)/', 'myapp.views.someview'),
)
Then, I could reconstruct the URLs using the below, right?
>>> from django.core.urlresolvers imp... | Reversing Django URLs With Extra Options | Suppose I have a URLconf like below, and 'foo' and 'bar' are valid values for page_slug.
urlpatterns = patterns('',
(r'^page/(?P<page_slug>.*)/', 'myapp.views.someview'),
)
Then, I could reconstruct the URLs using the below, right?
>>> from django.core.urlresolvers import reverse
>>> reverse('myapp.views.someview'... | [
"You should try naming your urlconfs. Example:\nurlpatterns = patterns('',\n url(r'^foo-direct/', 'myapp.views.someview', {'page_slug': 'foo'}, name='foo-direct'),\n url(r'^my-bar-page/', 'myapp.views.someview', {'page_slug': 'bar'}, name='bar-page'),\n)\n\nThen just edit your reverses and you should get it w... | [
21,
7,
4
] | [] | [] | [
"django",
"python"
] | stackoverflow_0000659832_django_python.txt |
Q:
Lisp vs Python -- Static Compilation
Why can Lisp with all its dynamic features be statically compiled but Python cannot (without losing all its dynamic features)?
A:
There is nothing that prevents static compilation of Python. It's a bit less efficient because Python reveals more mutable local scope, also, to... | Lisp vs Python -- Static Compilation | Why can Lisp with all its dynamic features be statically compiled but Python cannot (without losing all its dynamic features)?
| [
"There is nothing that prevents static compilation of Python. It's a bit less efficient because Python reveals more mutable local scope, also, to retain some of the dynamic properties (e.g. eval) you need to include the compiler with the compiled program but nothing prevents that too.\nThat said, research shows tha... | [
13,
4,
4,
4
] | [] | [] | [
"compilation",
"dynamic_languages",
"lisp",
"python"
] | stackoverflow_0002812954_compilation_dynamic_languages_lisp_python.txt |
Q:
How should I build a simple database package for my python application?
I'm building a database library for my application using sqlite3 as the base. I want to structure it like so:
db/
__init__.py
users.py
blah.py
etc.py
So I would do this in Python:
import db
db.users.create('username', 'pa... | How should I build a simple database package for my python application? | I'm building a database library for my application using sqlite3 as the base. I want to structure it like so:
db/
__init__.py
users.py
blah.py
etc.py
So I would do this in Python:
import db
db.users.create('username', 'password')
I'm suffering analysis paralysis (oh no!) about how to handle the d... | [
"No, don't spread a connection over several modules - this is bad design. Have a single class handle the DB connection and provide services to other classes/modules in your application.\nThis isn't different from non-DB-related good design principles. A connection is a global resource. Sharing that resource over ma... | [
5,
3
] | [] | [] | [
"database",
"library_design",
"python",
"sqlite"
] | stackoverflow_0002854305_database_library_design_python_sqlite.txt |
Q:
Any other way to import data files(like .csv) in python sqlite3 module ? [not insert one by one]
In sqlite3's client CLI, there is " .import file TABLE_name " to do it.
But, I do not want to install sqlite3 to my server at present.
In python sqlite3 module, we can creat and edit a DB.
But, I have not found a way t... | Any other way to import data files(like .csv) in python sqlite3 module ? [not insert one by one] | In sqlite3's client CLI, there is " .import file TABLE_name " to do it.
But, I do not want to install sqlite3 to my server at present.
In python sqlite3 module, we can creat and edit a DB.
But, I have not found a way to import data-file to a TABLE,
except inserting rows one by one.
Any other way?
| [
"You could insert at one shot using executemany command instead of inserting one by one\nLets say I have users.csv with following contents\n\"Hugo\",\"Boss\"\n\"Calvin\",\"Klein\"\n\nand basically open with csv module and pass it to .executemany function\nimport csv,sqlite3\n\npersons= csv.reader(open(\"users.csv\"... | [
7
] | [] | [] | [
"executemany",
"import",
"python",
"sqlite"
] | stackoverflow_0002854560_executemany_import_python_sqlite.txt |
Q:
making errorbars not clipped in matplotlib with Python
I am using matplotlib in Python to plot a line with errorbars as follows:
plt.errorbar(xvalues, up_densities, yerr=ctl_sds, fmt='-^', lw=1.2, markersize=markersize,
markeredgecolor=up_color, color=up_color, label="My label", clip_on=False)
plt.xticks(... | making errorbars not clipped in matplotlib with Python | I am using matplotlib in Python to plot a line with errorbars as follows:
plt.errorbar(xvalues, up_densities, yerr=ctl_sds, fmt='-^', lw=1.2, markersize=markersize,
markeredgecolor=up_color, color=up_color, label="My label", clip_on=False)
plt.xticks(xvalues)
I set the ticks on the x-axis using "xticks". How... | [
"In matplotlib, most of the detailed control needs to be done through the Artists. I think this should do what you want:\nimport matplotlib.pyplot as plt\nfrom random import uniform as r\n\nx = range(10)\ne = plt.errorbar(x, [r(2,10) for i in x], [r(.1,1) for i in x], capsize=8, color='r')\n\nfor b in e[1]:\n b... | [
13,
0
] | [] | [] | [
"matplotlib",
"plot",
"python",
"scipy"
] | stackoverflow_0002842123_matplotlib_plot_python_scipy.txt |
Q:
Directly call distutils' or setuptools' setup() function with command name/options, without parsing the command line?
I'd like to call Python's distutils' or setuptools' setup() function in a slightly unconventional way, but I'm not sure whether distutils is meant for this kind of usage.
As an example, let's say I... | Directly call distutils' or setuptools' setup() function with command name/options, without parsing the command line? | I'd like to call Python's distutils' or setuptools' setup() function in a slightly unconventional way, but I'm not sure whether distutils is meant for this kind of usage.
As an example, let's say I currently have a 'setup.py' file, which looks like this (lifted verbatim from the distutils docs--the setuptools usage is ... | [
"Never tried this, but I did happen to look in distutils/core.py, where I notice this near the start of setup():\nif 'script_name' not in attrs:\n attrs['script_name'] = os.path.basename(sys.argv[0])\nif 'script_args' not in attrs:\n attrs['script_args'] = sys.argv[1:]\n\nSo, it looks as if you can \"fake-out... | [
15,
2
] | [] | [] | [
"distutils",
"python",
"setuptools"
] | stackoverflow_0002850971_distutils_python_setuptools.txt |
Q:
Eventlet and locking
Since Eventlet uses green threading and asynchronous I/O, do I still need to set locks before accessing objects? My understanding is that greenlets are all part of one thread and locking isn't necessary. Can anyone confirm or deny this?
A:
Your understanding is correct: "green" threads are n... | Eventlet and locking | Since Eventlet uses green threading and asynchronous I/O, do I still need to set locks before accessing objects? My understanding is that greenlets are all part of one thread and locking isn't necessary. Can anyone confirm or deny this?
| [
"Your understanding is correct: \"green\" threads are not actually threads, they don't get pre-empted at unpredictable points (esp. not \"in the middle\" of an operation), so you have full control of when execution moves away from one (and can thus get dispatched to another) and can save yourself the trouble/overhe... | [
7
] | [] | [] | [
"python"
] | stackoverflow_0002851499_python.txt |
Q:
Advantages of using *args in python instead of passing a list as a parameter
I'm going through python and I was wondering what are the advantages of using the *args as a parameter over just passing a list as a parameter, besides aesthetics?
A:
Generally it's used to either pass a list of arguments to a function ... | Advantages of using *args in python instead of passing a list as a parameter | I'm going through python and I was wondering what are the advantages of using the *args as a parameter over just passing a list as a parameter, besides aesthetics?
| [
"Generally it's used to either pass a list of arguments to a function that would normally take a fixed number of arguments, or in function definitions to allow a variable number of arguments to be passed in the style of normal arguments. For instance, the print() function uses varargs so that you can do things like... | [
3,
2
] | [] | [] | [
"python"
] | stackoverflow_0002855500_python.txt |
Q:
Gzip and subprocess' stdout in python
I'm using python 2.6.4 and discovered that I can't use gzip with subprocess the way I might hope. This illustrates the problem:
May 17 18:05:36> python
Python 2.6.4 (r264:75706, Mar 10 2010, 14:41:19)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
Type "help", "copyrig... | Gzip and subprocess' stdout in python | I'm using python 2.6.4 and discovered that I can't use gzip with subprocess the way I might hope. This illustrates the problem:
May 17 18:05:36> python
Python 2.6.4 (r264:75706, Mar 10 2010, 14:41:19)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
Type "help", "copyright", "credits" or "license" for more inform... | [
"You can't use file-likes with subprocess, only real files. The fileno() method of GzipFile returns the FD of the underlying file, so that's what the echo redirects to. The GzipFile then closes, writing an empty gzip file.\n",
"just pipe that sucker\nfrom subprocess import Popen,PIPE\nGZ = Popen(\"gzip > outfile.... | [
10,
8,
1
] | [
"You don't need to use subprocess to write to the gzip.GzipFile. Instead, write to it like any other file-like object. The result is automagically gzipped!\nimport gzip\nwith gzip.open(\"tmp.gz\", \"wb\") as fh:\n fh.write('echo HI')\n\n"
] | [
-1
] | [
"gzip",
"python",
"subprocess"
] | stackoverflow_0002853339_gzip_python_subprocess.txt |
Q:
gevent install on x86_64 fails: "undefined symbol: evhttp_accept_socket"
I'm trying to install gevent on a fresh EC2 CentOS 5.3 64-bit system.
Since the libevent version available in yum was too old for another package (beanstalkd) I compiled/installed libevent-1.4.13-stable manually using the following command:
.... | gevent install on x86_64 fails: "undefined symbol: evhttp_accept_socket" | I'm trying to install gevent on a fresh EC2 CentOS 5.3 64-bit system.
Since the libevent version available in yum was too old for another package (beanstalkd) I compiled/installed libevent-1.4.13-stable manually using the following command:
./configure --prefix=/usr && make && make install
This is the output from inst... | [
"Easiest fix was to clone the git repository, switch to the wip-all branch, and run python setup.py build_libevent build install which grabs & builds libevent statically against gevent:\n# git clone http://github.com/schmir/gevent.git\n# cd gevent\n# git branch -a\n* upstream\n origin/HEAD\n origin/close-socket-c... | [
3
] | [] | [] | [
"gevent",
"libevent",
"python"
] | stackoverflow_0002849964_gevent_libevent_python.txt |
Q:
adding the feedparser module to python
I recently downloaded and installed feedparser with python,
I tried to run it but Netbeans shouts on import:
ImportError: No module named feedparser
restarted the Netbeans, still no go.
A:
Netbeans by default uses Jython,
if you go to Tools>Python Platforms and see that Jy... | adding the feedparser module to python | I recently downloaded and installed feedparser with python,
I tried to run it but Netbeans shouts on import:
ImportError: No module named feedparser
restarted the Netbeans, still no go.
| [
"Netbeans by default uses Jython, \nif you go to Tools>Python Platforms and see that Jython is the default. \nSwitch it to Python and so the installed libraries would work. \nIf you already have a project, you should right click on it, choose Python and on the platform choose Python instead of Jython.\n",
"You mi... | [
1,
0
] | [] | [] | [
"feedparser",
"netbeans",
"python"
] | stackoverflow_0002852301_feedparser_netbeans_python.txt |
Q:
Using Django with mod_wsgi
When you use Django with mod_wsgi, what exactly happens when a user makes a request to the server from a browser? Does apache load up your Django app when it starts and have it running in a separate process? Does it create a new Python process for every HTTP request?
A:
In embedded mod... | Using Django with mod_wsgi | When you use Django with mod_wsgi, what exactly happens when a user makes a request to the server from a browser? Does apache load up your Django app when it starts and have it running in a separate process? Does it create a new Python process for every HTTP request?
| [
"In embedded mode, the Django app is part of the httpd worker. In daemon mode, the Django app is a separate process and the httpd worker communicates with it over a socket. In either case, the WSGI interface is the same.\n"
] | [
1
] | [] | [] | [
"django",
"mod_wsgi",
"python"
] | stackoverflow_0002856403_django_mod_wsgi_python.txt |
Q:
what is the '' of remote_api in google-app-engine
http://code.google.com/intl/en/appengine/docs/python/tools/uploadingdata.html
the api is :
Downloading Data from App Engine
To start a data download, run appcfg.py download_data with the appropriate arguments:
appcfg.py download_data --config_file=album_loader.py -... | what is the '' of remote_api in google-app-engine | http://code.google.com/intl/en/appengine/docs/python/tools/uploadingdata.html
the api is :
Downloading Data from App Engine
To start a data download, run appcfg.py download_data with the appropriate arguments:
appcfg.py download_data --config_file=album_loader.py --filename=album_data_archive.csv --kind=Album <app-dire... | [
"Please take a look at this article, it explains how to set up downloading data: http://code.google.com/appengine/docs/python/tools/uploadingdata.html\nThe app-directory is the path you set up in the app.yaml file to map to the remote_api:\n- url: /app-directory\n script: $PYTHON_LIB/google/appengine/ext/remote_ap... | [
1
] | [] | [] | [
"google_app_engine",
"python"
] | stackoverflow_0002856178_google_app_engine_python.txt |
Q:
Python (Django). Store telnet connection
I am programming web interface which communicates with cisco switches via telnet. I want to make such system which will be storing one telnet connection per switch and every script (web interface, cron jobs, etc.) will have access to it. This is needed to make a single quer... | Python (Django). Store telnet connection | I am programming web interface which communicates with cisco switches via telnet. I want to make such system which will be storing one telnet connection per switch and every script (web interface, cron jobs, etc.) will have access to it. This is needed to make a single query queue for each device and prevent huge cisco... | [
"The usual way would be to have a process running in the background that keeps hold of the persistent telnet connections and commands queued to go down them.\nThen have the front-end scripts connect to it (eg. via a unix socket) to queue commands and get the results asynchronously.\nBut this might be overkill. How ... | [
1
] | [] | [] | [
"django",
"python",
"telnet",
"telnetlib"
] | stackoverflow_0002856356_django_python_telnet_telnetlib.txt |
Q:
How can I create a key using RSA/ECB/PKCS1Padding in python?
I am struggling to find any method of using RSA in ECB mode with PKCS1 padding in python. I've looked into pyCrypto, but they don't have PKCS1 padding in the master branch (but do in a patch). Nevertheless I found RSA with PKCS1 in the M2Crypto package,... | How can I create a key using RSA/ECB/PKCS1Padding in python? | I am struggling to find any method of using RSA in ECB mode with PKCS1 padding in python. I've looked into pyCrypto, but they don't have PKCS1 padding in the master branch (but do in a patch). Nevertheless I found RSA with PKCS1 in the M2Crypto package, but I'm not sure if I can choose ECB mode...
| [
"Chaining mode such as ECB makes no sense for RSA, unless you are doing it wrong.\nECB is for block ciphers: the input data is split into equal-size blocks, and each block is encrypted separately. This induces some weaknesses so ECB mode is best avoided for block ciphers.\nRSA is not a block cipher. In particular, ... | [
13
] | [] | [] | [
"encryption",
"python",
"rsa"
] | stackoverflow_0002855326_encryption_python_rsa.txt |
Q:
OOWrite is to LaTeX as OODraw is to?
I'm looking for a tool to nicely generate single-page PDFs. My needs are:
Able to put a PDF/EPS/... as a background
Absolute positioning
Able to define tables, lists
Able to rotate blocks
Reasonably easy syntax (will be used to automatically generate many similar looking docum... | OOWrite is to LaTeX as OODraw is to? | I'm looking for a tool to nicely generate single-page PDFs. My needs are:
Able to put a PDF/EPS/... as a background
Absolute positioning
Able to define tables, lists
Able to rotate blocks
Reasonably easy syntax (will be used to automatically generate many similar looking documents)
Easily usable from Python
Free or ve... | [
"Definitely PGF/TikZ. Selling point:\n\nCreated by this code:\n% Rooty helix\n% Author: Felix Lindemann\n\\documentclass{minimal}\n\n\\usepackage{tikz}\n\\usetikzlibrary{calc}\n\\begin{document}\n\n\\pagestyle{empty}\n\\pgfdeclarelayer{background}\n\\pgfdeclarelayer{foreground}\n\\pgfsetlayers{background,main,foreg... | [
12,
3,
0
] | [] | [] | [
"latex",
"pdf",
"python"
] | stackoverflow_0002850000_latex_pdf_python.txt |
Q:
numpy arange with multiple intervals
i have an numpy array which represents multiple x-intervals of a function:
In [137]: x_foo
Out[137]:
array([211, 212, 213, 214, 215, 216, 217, 218, 940, 941, 942, 943, 944,
945, 946, 947, 948, 949, 950])
as you can see, in x_foo are two intervals: one from 211 to 218, ... | numpy arange with multiple intervals | i have an numpy array which represents multiple x-intervals of a function:
In [137]: x_foo
Out[137]:
array([211, 212, 213, 214, 215, 216, 217, 218, 940, 941, 942, 943, 944,
945, 946, 947, 948, 949, 950])
as you can see, in x_foo are two intervals: one from 211 to 218, and one from 940 to 950. these are interva... | [
"import numpy as np\nx = np.array([211, 212, 213, 214, 215, 216, 217, 218, 940, 941, 942, 943, 944,\n 945, 946, 947, 948, 949, 950])\nind = np.where((x[1:] - x[:-1]) > 1)[0]\n\nwill give you the index for the element in x that is equal to 218. Then the two ranges you want are:\nnp.arange(x[0],x[ind],0.1)\n\nand\n... | [
3,
1
] | [] | [] | [
"interpolation",
"numpy",
"python",
"scipy"
] | stackoverflow_0002737487_interpolation_numpy_python_scipy.txt |
Q:
deployment public keys
How do you guys deploy your code on your servers? I am using Fabric and Python and I would like a more automated way of pulling code from the repository through the use of public keys, but without any ops or manual intervention to set up the public keys.
Are you storing them in the code as t... | deployment public keys | How do you guys deploy your code on your servers? I am using Fabric and Python and I would like a more automated way of pulling code from the repository through the use of public keys, but without any ops or manual intervention to set up the public keys.
Are you storing them in the code as text or in a database and gen... | [
"This is what ssh-copy-id is for. It deploys your public key onto a machine for you. Key management isn't something I'd suggest putting into code/VCS. Each user needs to setup their keys so that the local ssh client knows to use them. We use Fabric as well, but it only uses the key that the ssh config is already te... | [
1
] | [] | [] | [
"fabric",
"python"
] | stackoverflow_0002855650_fabric_python.txt |
Q:
Python __setattr__ and __getattr__ for global scope?
Suppose I need to create my own small DSL that would use Python to describe a certain data structure. E.g. I'd like to be able to write something like
f(x) = some_stuff(a,b,c)
and have Python, instead of complaining about undeclared identifiers or attempting to... | Python __setattr__ and __getattr__ for global scope? | Suppose I need to create my own small DSL that would use Python to describe a certain data structure. E.g. I'd like to be able to write something like
f(x) = some_stuff(a,b,c)
and have Python, instead of complaining about undeclared identifiers or attempting to invoke the function some_stuff, convert it to a literal e... | [
"I'm not sure it's a good idea, but I thought I'd give it a try. To summarize:\nclass PermissiveDict(dict):\n default = None\n\n def __getitem__(self, item):\n try:\n return dict.__getitem__(self, item)\n except KeyError:\n return self.default\n\ndef exec_with_default(code... | [
3,
2
] | [
"In response to Wai's comment, here's one fun solution that I've found. First of all, to explain once more what it does, suppose that you have the following code:\ndefinitions = Structure()\ndefinitions.add_definition('f[x]', 'x*2')\ndefinitions.add_definition('f[z]', 'some_function(z)')\ndefinitions.add_definition... | [
-1
] | [
"lookup",
"python",
"quoting",
"redefine",
"variable_assignment"
] | stackoverflow_0002656697_lookup_python_quoting_redefine_variable_assignment.txt |
Q:
How to hide Cygwin Python console window in Windows?
How to hide Cygwin Python console window in Windows?
Neither pythonw, nor renaming to *.pyw does not seem to apply here, since Cygwin is a different build from regular Windows CPython build.
A:
A small .vbs launcher script should do the trick:
COMMAND = "c:\cy... | How to hide Cygwin Python console window in Windows? | How to hide Cygwin Python console window in Windows?
Neither pythonw, nor renaming to *.pyw does not seem to apply here, since Cygwin is a different build from regular Windows CPython build.
| [
"A small .vbs launcher script should do the trick:\nCOMMAND = \"c:\\cygwin\\bin\\python <path_to_your.py>\"\n\nSet wshell = CreateObject(\"WScript.Shell\")\nSet proc = wshell.Environment(\"Process\")\n\nproc(\"PATH\") = \"c:\\cygwin\\bin;\" & proc(\"PATH\")\n\nwshell.Run COMMAND, 0\n\n"
] | [
3
] | [] | [] | [
"cygwin",
"python",
"windows"
] | stackoverflow_0002854832_cygwin_python_windows.txt |
Q:
python binding of variable to particular expression
I am developing a simple application which hava a file Constants.py containing all configuration, it is like this
x = y
during execution of program , the value of y changes , I want value of x o get updated too , automatically, this can be reffered as binding, h... | python binding of variable to particular expression | I am developing a simple application which hava a file Constants.py containing all configuration, it is like this
x = y
during execution of program , the value of y changes , I want value of x o get updated too , automatically, this can be reffered as binding, how can I achieve this
| [
"In Python variable names point at values. x=y tells Python that the variable name x should point at the value that y is currently pointing at.\nWhen you change y, then the variable name y points at a new value, while the variable name x still points at the old value.\nYou can not achieve what you want with plain v... | [
2,
0,
0,
0
] | [] | [] | [
"binding",
"python"
] | stackoverflow_0002856675_binding_python.txt |
Q:
python: calling constructor from dictionary?
I'm not quite sure of the terminology here so please bear with me....
Let's say I have a constructor call like this:
machineSpecificEnvironment = Environment(
TI_C28_ROOT = 'C:/appl/ti/ccs/4.1.1/ccsv4/tools/compiler/c2000',
JSDB = 'c:/bin/jsdb/jsdb.exe',
PYTHON... | python: calling constructor from dictionary? | I'm not quite sure of the terminology here so please bear with me....
Let's say I have a constructor call like this:
machineSpecificEnvironment = Environment(
TI_C28_ROOT = 'C:/appl/ti/ccs/4.1.1/ccsv4/tools/compiler/c2000',
JSDB = 'c:/bin/jsdb/jsdb.exe',
PYTHON_PATH = 'c:/appl/python/2.6.4',
)
except I would ... | [
"machineSpecificEnvironment = Environment(**keys)\n\n",
"You can apply a dict as an argument list by the ** notation\nmachineSpecificEnvironment = Environment(**keys)\n\n"
] | [
5,
3
] | [] | [] | [
"argument_unpacking",
"dictionary",
"python"
] | stackoverflow_0002858070_argument_unpacking_dictionary_python.txt |
Q:
how to load a module within python debugger
This looks like something simple but I could not find the answer so far -
I have just learnt python and need to start learning pdb. In my module I have the usual if __name__ == __main_ trick to execute some code when the module is run as a program.
So far I have been run... | how to load a module within python debugger | This looks like something simple but I could not find the answer so far -
I have just learnt python and need to start learning pdb. In my module I have the usual if __name__ == __main_ trick to execute some code when the module is run as a program.
So far I have been running it via python -m mymod arg1 arg2 syntax
Now ... | [
"Try:\npython -m pdb mymod.py arg1 arg2\n\nThat should start up pdb debugging mymod.py (if mymod.py is not in the current directory then you'll have to specify the path).\nAlternatively set a breakpoint in your code where you want to start debugging. The usual way to get a breakpoint into pdb is:\nif somecondition:... | [
1
] | [] | [] | [
"debugging",
"python"
] | stackoverflow_0002858088_debugging_python.txt |
Q:
Webapp best practice template_dict
After just been coding for about 6-9 months. I probably changed my coding style a number of times after reading some code or read best practices. But one thing I haven't yet come a cross is a good why to populate the template_dict.
As of now I pass the template_dict across a numb... | Webapp best practice template_dict | After just been coding for about 6-9 months. I probably changed my coding style a number of times after reading some code or read best practices. But one thing I haven't yet come a cross is a good why to populate the template_dict.
As of now I pass the template_dict across a number of methods (that changes/modifies it)... | [
"If the functions in question are all methods of some object foo, then each of them can refer to the context they're building up (I imagine that's what you mean by \"template dict\"?) as self.ctx or the like (attribute name's somewhat arbitrary, the key point is that you can keep the context as an attribute of foo,... | [
1
] | [] | [] | [
"google_app_engine",
"python",
"web_applications"
] | stackoverflow_0002857745_google_app_engine_python_web_applications.txt |
Q:
Is there an Oracle wrapper for Python that supports xmltype columns?
It seems cx_Oracle doesn't.
Any other suggestion for handling xml with Oracle and Python is appreciated.
Thanks.
A:
I managed to do this with cx_Oracle.
I used the sys.xmltype.createxml() function in the statement that inserts the rows in a tab... | Is there an Oracle wrapper for Python that supports xmltype columns? | It seems cx_Oracle doesn't.
Any other suggestion for handling xml with Oracle and Python is appreciated.
Thanks.
| [
"I managed to do this with cx_Oracle.\nI used the sys.xmltype.createxml() function in the statement that inserts the rows in a table with XMLTYPE fields; then I used prepare() and setinputsizes() to specify that the bind variables I used for XMLTYPE fields were of cx_Oracle.CLOB type.\n",
"I managed to get this t... | [
1,
1,
0
] | [] | [] | [
"oracle",
"python",
"xml",
"xmltype"
] | stackoverflow_0000936381_oracle_python_xml_xmltype.txt |
Q:
Why does the "is" keyword have a different behavior when there is a dot in the string?
Consider this code:
>>> x = "google"
>>> x is "google"
True
>>> x = "google.com"
>>> x is "google.com"
False
>>>
Why is it like that?
To make sure the above is correct, I have just tested on Python 2.5.4, 2.6.5, 2.7b2, Python 3... | Why does the "is" keyword have a different behavior when there is a dot in the string? | Consider this code:
>>> x = "google"
>>> x is "google"
True
>>> x = "google.com"
>>> x is "google.com"
False
>>>
Why is it like that?
To make sure the above is correct, I have just tested on Python 2.5.4, 2.6.5, 2.7b2, Python 3.1 on windows and Python 2.7b1 on Linux.
It looks like there is consistency across all of th... | [
"is verifies object identity, and any implementation of Python, when it meets literal of immutable types, is perfectly free to either make a new object of that immutable type, or seek through existing objects of that type to see if some of them could be reused (by adding a new reference to the same underlying objec... | [
91,
15
] | [] | [] | [
"equality",
"identity",
"python"
] | stackoverflow_0002858603_equality_identity_python.txt |
Q:
python: equivalent to Javascript "||" to override non-truthful value
In Javascript I can do this:
function A(x) { return x || 3; }
This returns 3 if x is a "non-truthful" value like 0, null, false, and it returns x otherwise. This is useful for empty arguments, e.g. I can do A() and it will evaluate as 3.
Does Py... | python: equivalent to Javascript "||" to override non-truthful value | In Javascript I can do this:
function A(x) { return x || 3; }
This returns 3 if x is a "non-truthful" value like 0, null, false, and it returns x otherwise. This is useful for empty arguments, e.g. I can do A() and it will evaluate as 3.
Does Python have an equivalent? I guess I could make one out of the ternary opera... | [
"You can use or to do the same thing but you have to be careful because some unexpected things can be considered False in that arrangement. Just make sure you want this behavior if you choose to do it that way:\n>>> \"\" or 1\n1\n>>> \" \" or 1\n' '\n>>> 0 or 1\n1\n>>> 10 or 1\n10\n>>> ['a', 'b', 'c'] or 1\n['a', ... | [
10,
5
] | [] | [] | [
"python"
] | stackoverflow_0002858723_python.txt |
Q:
use python / django to let users login to my site using their google credentials
I want to let users use their google account to login to my website. Exactly the way SO lets me. Can anyone please point in the right direction? I'm assuming the oAuth library is to be used but what I'd really like is a snippet of cod... | use python / django to let users login to my site using their google credentials | I want to let users use their google account to login to my website. Exactly the way SO lets me. Can anyone please point in the right direction? I'm assuming the oAuth library is to be used but what I'd really like is a snippet of code I can directly copy paste and get this to work.
| [
"It's not OAuth particularly that you need (OAuth is for authorising access for one website to specific private content held on another), but OpenID - which is meant for authentication rather than authorisation. (Some sites, like Twitter, do provide authentication services via OAuth, but that's not what it's primar... | [
3,
1,
1
] | [] | [] | [
"django",
"oauth",
"python"
] | stackoverflow_0002847629_django_oauth_python.txt |
Q:
Python: converting string to flags
If I have a string that is the output of matching the regexp [MSP]*, what's the cleanest way to convert it to a dict containing keys M, S, and P where the value of each key is true if the key appears in the string?
e.g.
'MSP' => {'M': True, 'S': True, 'P': True}
'PMMM' => {'M... | Python: converting string to flags | If I have a string that is the output of matching the regexp [MSP]*, what's the cleanest way to convert it to a dict containing keys M, S, and P where the value of each key is true if the key appears in the string?
e.g.
'MSP' => {'M': True, 'S': True, 'P': True}
'PMMM' => {'M': True, 'S': False, 'P': True}
'' =... | [
"Why not use a frozenset (or set if mutability is needed)?\ns = frozenset('PMMM')\n# now s == frozenset({'P', 'M'})\n\nthen you can use \n'P' in s\n\nto check whether the flag P exists.\n",
"In newer versions of Python you can use a dict comprehension:\ns = 'MMSMSS'\nd = { c: c in s for c in 'MSP' }\n\nIn older v... | [
6,
3
] | [] | [] | [
"dictionary",
"python",
"string"
] | stackoverflow_0002858880_dictionary_python_string.txt |
Q:
Problems with Threading in Python 2.5, KeyError: 51, Help debugging?
I have a python script which runs a particular script large number of times (for monte carlo purpose) and the way I have scripted it is that, I queue up the script the desired number of times it should be run then I spawn threads and each thread ... | Problems with Threading in Python 2.5, KeyError: 51, Help debugging? | I have a python script which runs a particular script large number of times (for monte carlo purpose) and the way I have scripted it is that, I queue up the script the desired number of times it should be run then I spawn threads and each thread runs the script once and again when its done.
Once the script in a particu... | [
"What you have right now is a new lock for every iteration in each thread's run method. In effect, there is no locking going on at all. If you want to protect writes to a file, you need to make sure that all threads that access the same file use the same lock object. The simplest way to do that is to create it at t... | [
1,
0
] | [] | [] | [
"multithreading",
"python",
"windows"
] | stackoverflow_0002858960_multithreading_python_windows.txt |
Q:
Connection to DB2 in Python
I'm trying to create a database connection in a python script to my DB2 database. When the connection is done I've to run some different SQL statements.
I googled the problem and has read the ibm_db API (http://code.google.com/p/ibm-db/wiki/APIs) but just can't seem to get it right.
Her... | Connection to DB2 in Python | I'm trying to create a database connection in a python script to my DB2 database. When the connection is done I've to run some different SQL statements.
I googled the problem and has read the ibm_db API (http://code.google.com/p/ibm-db/wiki/APIs) but just can't seem to get it right.
Here is what I got so far:
import sy... | [
"it should be:\nquery_str = \"SELECT COUNT(*) FROM accounts\"\n\nconn = ibm_db.pconnect(\"dsn=write\",\"usrname\",\"secret\")\nquery_stmt = ibm_db.prepare(conn, query_str)\nibm_db.execute(query_stmt)\n\n",
"I'm sorry, of cause you need to error message. When trying to run my script it gives me this error:\nTrac... | [
4,
0
] | [] | [] | [
"database",
"db2",
"python"
] | stackoverflow_0002859081_database_db2_python.txt |
Q:
Best way to test instance methods without running __init__
I've got a simple class that gets most of its arguments via init, which also runs a variety of private methods that do most of the work. Output is available either through access to object variables or public methods.
Here's the problem - I'd like my unit... | Best way to test instance methods without running __init__ | I've got a simple class that gets most of its arguments via init, which also runs a variety of private methods that do most of the work. Output is available either through access to object variables or public methods.
Here's the problem - I'd like my unittest framework to directly call the private methods called by in... | [
"For new-style classes, call object.__new__(), passing the class as a parameter. For old-style classes, call types.InstanceType() passing the class as a parameter.\nimport types\n\nclass C(object):\n def __init__(self):\n print 'init'\n\nclass OldC:\n def __init__(self):\n print 'initOld'\n\nc = object.__ne... | [
5,
4
] | [] | [] | [
"python",
"unit_testing"
] | stackoverflow_0002859429_python_unit_testing.txt |
Q:
Reverse mapping from a table to a model in SQLAlchemy
To provide an activity log in my SQLAlchemy-based app, I have a model like this:
class ActivityLog(Base):
__tablename__ = 'activitylog'
id = Column(Integer, primary_key=True)
activity_by_id = Column(Integer, ForeignKey('users.id'), nullable=False)
... | Reverse mapping from a table to a model in SQLAlchemy | To provide an activity log in my SQLAlchemy-based app, I have a model like this:
class ActivityLog(Base):
__tablename__ = 'activitylog'
id = Column(Integer, primary_key=True)
activity_by_id = Column(Integer, ForeignKey('users.id'), nullable=False)
activity_by = relation(User, primaryjoin=activity_by_id ... | [
"One way to solve this is polymorphic associations. It should solve all 3 of your issues and also make database foreign key constraints work. See the polymorphic association example in SQLAlchemy source. Mike Bayer has an old blogpost that discusses this in greater detail.\n",
"Definitely go through the blogpost... | [
1,
1
] | [] | [] | [
"python",
"sqlalchemy"
] | stackoverflow_0002850988_python_sqlalchemy.txt |
Q:
Creating an interface and swappable implementations in python
Would it be possible to create a class interface in python and various implementations of the interface.
Example: I want to create a class for pop3 access (and all methods etc.). If I go with a commercial component, I want to wrap it to adhere to a co... | Creating an interface and swappable implementations in python | Would it be possible to create a class interface in python and various implementations of the interface.
Example: I want to create a class for pop3 access (and all methods etc.). If I go with a commercial component, I want to wrap it to adhere to a contract.
In the future, if I want to use another component or code m... | [
"For people coming from a strongly typed language background, Python does not need a class interface. You can simulate it using a base class.\nclass BaseAccess:\n def open(arg):\n raise NotImplementedError()\n\nclass Pop3Access(BaseAccess):\n def open(arg):\n ...\n\nclass AlternateAccess(BaseAccess):\n def... | [
6,
2,
1,
0
] | [] | [] | [
"oop",
"python"
] | stackoverflow_0002860106_oop_python.txt |
Q:
How to access __init__.py variables from deeper parts of a package
I apologize for yet another __init__.py question.
I have the following package structure:
+contrib
+--__init__.py
|
+database
+--__init__.py
|
+--connection.py
In the top-level __init__.py I define: USER='me'. If I import c... | How to access __init__.py variables from deeper parts of a package | I apologize for yet another __init__.py question.
I have the following package structure:
+contrib
+--__init__.py
|
+database
+--__init__.py
|
+--connection.py
In the top-level __init__.py I define: USER='me'. If I import contrib from the command line, then I can access contrib.USER.
Now, I wa... | [
"Adding import contrib to connection.py is the way to go. Yes, the contrib module is already imported (you can find out from sys.modules). The problem is there is no reference to the module from your code in connection.py. Doing another import will give you the reference. You do not need to worry about additional l... | [
13,
0
] | [] | [] | [
"python"
] | stackoverflow_0002860482_python.txt |
Q:
Google Wave Robot / Python Variable question
I'm experimenting/having a little fun with wave robot python apiv2.
I made a little 8ball app for the robot which works fine, and now I'm trying to make a trivia app.
I've never programmed in Python but I'm pretty sure my syntax is correct. Here is the relevant code:
el... | Google Wave Robot / Python Variable question | I'm experimenting/having a little fun with wave robot python apiv2.
I made a little 8ball app for the robot which works fine, and now I'm trying to make a trivia app.
I've never programmed in Python but I'm pretty sure my syntax is correct. Here is the relevant code:
elif (bliptxt == "\n!strivia"):
reply = blip.reply... | [
"It seems that you should rename triviaStatus to trivia_status and make sure that trivia_status has some value e.g., bind it to None before the first use. Otherwise your code might raise UnboundLocalError or NameError exceptions due to triviaStatus/trivia_status doesn't refer to any object.\n"
] | [
1
] | [] | [] | [
"google_wave",
"python",
"scope"
] | stackoverflow_0002860677_google_wave_python_scope.txt |
Q:
Fabfiles With Command Line Arguments
Is there a clean way to have your fabfile take command line arguments? I'm writing an installation script for a tool that I want to be able to specify an optional target directory via the command line.
I wrote some code to test what would happen if I passed in some command lin... | Fabfiles With Command Line Arguments | Is there a clean way to have your fabfile take command line arguments? I'm writing an installation script for a tool that I want to be able to specify an optional target directory via the command line.
I wrote some code to test what would happen if I passed in some command line arguments:
# fabfile.py
import sys
def ... | [
"I ended up using the per-task arguments. It seems like a better idea than doing unattached command line arguments.\n"
] | [
4
] | [] | [] | [
"fabric",
"python"
] | stackoverflow_0002859424_fabric_python.txt |
Q:
Mercurial fails while commiting/updating/etc. using Mercuriual+TrueCrypt+MAC
While trying to work with Mercurial on project located on TrueCrypt partition I always get en error as follows:
** unknown exception encountered, details follow
** report bug details to http://mercurial.selenic.com/bts/
** or mercurial@se... | Mercurial fails while commiting/updating/etc. using Mercuriual+TrueCrypt+MAC | While trying to work with Mercurial on project located on TrueCrypt partition I always get en error as follows:
** unknown exception encountered, details follow
** report bug details to http://mercurial.selenic.com/bts/
** or mercurial@selenic.com
** Mercurial Distributed SCM (version 1.5.2+20100502)
** Extensions load... | [
"This bug was added in 1.5.2 (sorry about that), we released 1.5.3 shortly afterwards, please use it.\n"
] | [
2
] | [] | [] | [
"mercurial",
"python",
"truecrypt"
] | stackoverflow_0002859913_mercurial_python_truecrypt.txt |
Q:
Emacs: Inferior-mode python-shell appears "lagged"
I'm a Python(3.1.2)/emacs(23.2) newbie teaching myself tkinter using the pythonware tutorial found here. Relevant code is pasted below the question.
Question: when I click the Hello button (which should call the say_hi function) why does the inferior python shell ... | Emacs: Inferior-mode python-shell appears "lagged" | I'm a Python(3.1.2)/emacs(23.2) newbie teaching myself tkinter using the pythonware tutorial found here. Relevant code is pasted below the question.
Question: when I click the Hello button (which should call the say_hi function) why does the inferior python shell (i.e. the one I kicked off with C-c C-c) wait to execute... | [
"I'd guess that not being attached to a tty, the Python interpreter (via C stdio) switches to block buffered from line buffered and doesn't flush stdout until it closes. Running os.isatty(1) in an \"Inferior Python:run Shell Compile\" buffer returns false, thus adding weight to this guess.\ndef say_hi(self):\n p... | [
4
] | [] | [] | [
"emacs",
"python"
] | stackoverflow_0002861178_emacs_python.txt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.