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:
Using os.execvp in Python
I have a question about using os.execvp in Python. I have the following bit of code that's used to create a list of arguments:
args = [ "java"
, classpath
, "-Djava.library.path=" + lib_path()
, ea
, "-Xmx1000m"
, "-server"
, "code_swarm"
... | Using os.execvp in Python | I have a question about using os.execvp in Python. I have the following bit of code that's used to create a list of arguments:
args = [ "java"
, classpath
, "-Djava.library.path=" + lib_path()
, ea
, "-Xmx1000m"
, "-server"
, "code_swarm"
, params
]
When I outpu... | [
"If your \"classpath\" variable contains for instance \"-classpath foo.jar\", it will not work, since it is thinking the option name is \"-classpath foo.jar\". Split it in two arguments: [..., \"-classpath\", classpath, ...].\nThe other ways (copy and paste and system()) work because the shell splits the command li... | [
11,
0
] | [] | [] | [
"exec",
"python",
"shell"
] | stackoverflow_0000210978_exec_python_shell.txt |
Q:
Starting a new database driven python web application would you use a javascript widget framework? If so which framework?
I am starting a new web application project. I want to use python as I am using it at my bread-and-butter-job.
However I don't want to reinvent the wheel. Some things I have thought about:
AJA... | Starting a new database driven python web application would you use a javascript widget framework? If so which framework? | I am starting a new web application project. I want to use python as I am using it at my bread-and-butter-job.
However I don't want to reinvent the wheel. Some things I have thought about:
AJAX would be nice if it’s not too much of a hazzle.
It is best if the licensing allows commercialization but is not crucial at t... | [
"jQuery? Though its UI components are perhaps not up to the very best (but lots of work appears to be done in that area), jQuery itself seems to be on track to become the de facto JS standard library. It is both MIT or GPL licensed so commercial use is ok (and costless).\n",
"I heartily suggest Django + Prototype... | [
4,
1,
1,
1,
1
] | [] | [] | [
"frameworks",
"javascript",
"python"
] | stackoverflow_0000205204_frameworks_javascript_python.txt |
Q:
Tutorial for Python - Should I use 2.x or 3.0?
Python 3.0 is in beta with a final release coming shortly. Obviously it will take some significant time for general adoption and for it to eventually replace 2.x.
I am writing a tutorial about certain aspects of programming Python. I'm wondering if I should do it in... | Tutorial for Python - Should I use 2.x or 3.0? | Python 3.0 is in beta with a final release coming shortly. Obviously it will take some significant time for general adoption and for it to eventually replace 2.x.
I am writing a tutorial about certain aspects of programming Python. I'm wondering if I should do it in Python 2.x or 3.0? (not that the difference is huge... | [
"Start with 2.x. Most existing libraries will be on 2.x for a long time. Last year, Guido himself said that it would be \"two years\" until you needed to learn 3.0; there's still another year left. Personally, I think it will be longer. People writing code on 2.x can learn how to use the 2to3 tool and have code... | [
14,
11,
2,
2,
0,
0
] | [] | [] | [
"python",
"python_2.x",
"python_3.x"
] | stackoverflow_0000209888_python_python_2.x_python_3.x.txt |
Q:
Socket programming for mobile phones in Python
I've written code for communication between my phone and comp thru TCP sockets. When I type out the code line by line in the interactive console it works fine. However, when i try running the script directly through filebrowser.py it just wont work. I'm using Nokia N9... | Socket programming for mobile phones in Python | I've written code for communication between my phone and comp thru TCP sockets. When I type out the code line by line in the interactive console it works fine. However, when i try running the script directly through filebrowser.py it just wont work. I'm using Nokia N95. Is there anyway I can run this script directly wi... | [
"Have you read Hack a Mobile Phone with Linux and Python? It is rather old, but maybe you find it helpful.\n",
"If the code is working in the interactive interpreter when typed, but not when run directly then I would suggest seeing if your code has reached a deadlock on the socket, for example both ends are waiti... | [
1,
0,
0,
0
] | [] | [] | [
"mobile",
"python",
"sockets"
] | stackoverflow_0000141647_mobile_python_sockets.txt |
Q:
How to create a numpy record array from C
On the Python side, I can create new numpy record arrays as follows:
numpy.zeros((3,), dtype=[('a', 'i4'), ('b', 'U5')])
How do I do the same from a C program? I suppose I have to call PyArray_SimpleNewFromDescr(nd, dims, descr), but how do I construct a PyArray_Descr th... | How to create a numpy record array from C | On the Python side, I can create new numpy record arrays as follows:
numpy.zeros((3,), dtype=[('a', 'i4'), ('b', 'U5')])
How do I do the same from a C program? I suppose I have to call PyArray_SimpleNewFromDescr(nd, dims, descr), but how do I construct a PyArray_Descr that is appropriate for passing as the third argu... | [
"Use PyArray_DescrConverter. Here's an example:\n#include <Python.h>\n#include <stdio.h>\n#include <numpy/arrayobject.h>\n\nint main(int argc, char *argv[])\n{\n int dims[] = { 2, 3 };\n PyObject *op, *array;\n PyArray_Descr *descr;\n\n Py_Initialize();\n import_array();\n op = Py_BuildValu... | [
11,
6
] | [] | [] | [
"c",
"numpy",
"python"
] | stackoverflow_0000214549_c_numpy_python.txt |
Q:
A good multithreaded python webserver?
I am looking for a python webserver which is multithreaded instead of being multi-process (as in case of mod_python for apache). I want it to be multithreaded because I want to have an in memory object cache that will be used by various http threads. My webserver does a lot o... | A good multithreaded python webserver? | I am looking for a python webserver which is multithreaded instead of being multi-process (as in case of mod_python for apache). I want it to be multithreaded because I want to have an in memory object cache that will be used by various http threads. My webserver does a lot of expensive stuff and computes some large ar... | [
"CherryPy. Features, as listed from the website:\n\nA fast, HTTP/1.1-compliant, WSGI thread-pooled webserver. Typically, CherryPy itself takes only 1-2ms per page!\nSupport for any other WSGI-enabled webserver or adapter, including Apache, IIS, lighttpd, mod_python, FastCGI, SCGI, and mod_wsgi\nEasy to run multiple... | [
16,
7,
6,
3,
2,
2,
2,
2,
1,
1,
0
] | [] | [] | [
"apache",
"mod_python",
"python",
"webserver"
] | stackoverflow_0000213483_apache_mod_python_python_webserver.txt |
Q:
wxpython - Expand list control vertically not horizontally
I have a ListCtrl that displays a list of items for the user to select. This works fine except that when the ctrl is not large enough to show all the items, I want it to expand downwards with a vertical scoll bar rather than using a horizontal scroll bar a... | wxpython - Expand list control vertically not horizontally | I have a ListCtrl that displays a list of items for the user to select. This works fine except that when the ctrl is not large enough to show all the items, I want it to expand downwards with a vertical scoll bar rather than using a horizontal scroll bar as it expands to the right.
The ListCtrl's creation:
self.subject... | [
"Use the wxLC_REPORT style.\nimport wx\n\nclass Test(wx.Frame):\n def __init__(self):\n wx.Frame.__init__(self, None)\n self.test = wx.ListCtrl(self, style = wx.LC_REPORT | wx.LC_NO_HEADER)\n\n for i in range(5):\n self.test.InsertColumn(i, 'Col %d' % (i + 1))\n self.te... | [
3,
1
] | [] | [] | [
"python",
"wxpython",
"wxwidgets"
] | stackoverflow_0000215132_python_wxpython_wxwidgets.txt |
Q:
In Django, how could one use Django's update_object generic view to edit forms of inherited models?
In Django, given excerpts from an application animals likeso:
A animals/models.py with:
from django.db import models
from django.contrib.contenttypes.models import ContentType
class Animal(models.Model):
content... | In Django, how could one use Django's update_object generic view to edit forms of inherited models? | In Django, given excerpts from an application animals likeso:
A animals/models.py with:
from django.db import models
from django.contrib.contenttypes.models import ContentType
class Animal(models.Model):
content_type = models.ForeignKey(ContentType,editable=False,null=True)
name = models.CharField()
class Dog(An... | [
"Alright, here's what I've done, and it seems to work and be a sensible design (though I stand to be corrected!).\nIn a core library (e.g. mysite.core.views.create_update), I've written a decorator:\nfrom django.contrib.contenttypes.models import ContentType\nfrom django.views.generic import create_update\n\ndef up... | [
1,
0
] | [] | [] | [
"decorator",
"django",
"forms",
"inheritance",
"python"
] | stackoverflow_0000213237_decorator_django_forms_inheritance_python.txt |
Q:
How to convert a C string (char array) into a Python string when there are non-ASCII characters in the string?
I have embedded a Python interpreter in a C program. Suppose the C program reads some bytes from a file into a char array and learns (somehow) that the bytes represent text with a certain encoding (e.g.,... | How to convert a C string (char array) into a Python string when there are non-ASCII characters in the string? | I have embedded a Python interpreter in a C program. Suppose the C program reads some bytes from a file into a char array and learns (somehow) that the bytes represent text with a certain encoding (e.g., ISO 8859-1, Windows-1252, or UTF-8). How do I decode the contents of this char array into a Python string?
The Pyt... | [
"PyString_Decode does this:\nPyObject *PyString_Decode(const char *s,\n Py_ssize_t size,\n const char *encoding,\n const char *errors)\n{\n PyObject *v, *str;\n\n str = PyString_FromStringAndSize(s, size);\n if (str == NULL)\n return NULL;\n v = PyString_AsDecod... | [
6,
3,
2
] | [] | [] | [
"c",
"character_encoding",
"embedding",
"python"
] | stackoverflow_0000213628_c_character_encoding_embedding_python.txt |
Q:
Python's unittest logic
Can someone explain this result to me. The first test succeeds but the second fails, although the variable tested is changed in the first test.
>>> class MyTest(unittest.TestCase):
def setUp(self):
self.i = 1
def testA(self):
self.i = 3
self.assertEqual(self.... | Python's unittest logic | Can someone explain this result to me. The first test succeeds but the second fails, although the variable tested is changed in the first test.
>>> class MyTest(unittest.TestCase):
def setUp(self):
self.i = 1
def testA(self):
self.i = 3
self.assertEqual(self.i, 3)
def testB(self):
... | [
"From http://docs.python.org/lib/minimal-example.html :\n\nWhen a setUp() method is defined, the\n test runner will run that method prior\n to each test.\n\nSo setUp() gets run before both testA and testB, setting i to 1 each time. Behind the scenes, the entire test object is actually being re-instantiated for e... | [
11,
9,
0,
0
] | [
"The setUp method, as everyone else has said, runs before every test method you write. So, when testB runs, the value of i is 1, not 3.\nYou can also use a tearDown method which runs after every test method. However if one of your tests crashes, your tearDown method will never run.\n"
] | [
-1
] | [
"python",
"unit_testing"
] | stackoverflow_0000072422_python_unit_testing.txt |
Q:
Python templates for web designers
What are some good templating engines for web designers? I definitely have my preferences as to what I'd prefer to work with as a programmer. But web designers seem to have a different way of thinking about things and thus may prefer a different system.
So:
Web designers: wha... | Python templates for web designers | What are some good templating engines for web designers? I definitely have my preferences as to what I'd prefer to work with as a programmer. But web designers seem to have a different way of thinking about things and thus may prefer a different system.
So:
Web designers: what templating engine do you prefer to wor... | [
"Django's templating engine is quite decent. It's pretty robust while not stepping on too many toes. If you're working with Python I would recommend it. I don't know how to divorce it from Django, but I doubt it would be very difficult seeing as Django is quite modular.\nEDIT: Apparently the mini-guide to using... | [
6,
6,
5,
2,
2,
1,
1
] | [] | [] | [
"python",
"templating"
] | stackoverflow_0000214536_python_templating.txt |
Q:
How do I find all cells with a particular attribute in BeautifulSoup?
I am trying to develop a script to pull some data from a large number of html tables. One problem is that the number of rows that contain the information to create the column headings is indeterminate. I have discovered that the last row of th... | How do I find all cells with a particular attribute in BeautifulSoup? | I am trying to develop a script to pull some data from a large number of html tables. One problem is that the number of rows that contain the information to create the column headings is indeterminate. I have discovered that the last row of the set of header rows has the attribute border-bottom for each cell with a v... | [
"Is there any reason \n\nborderCells = soup.findAll(\"td\", style=re.compile(\"border-bottom\")})\n\nwouldn't work? It's kind of hard to figure out exactly what you're asking for, since your description of the original tables is pretty ambiguous, and it's not really clear what allCells is supposed to be either.\nI... | [
3,
0,
0
] | [] | [] | [
"beautifulsoup",
"parsing",
"python"
] | stackoverflow_0000215667_beautifulsoup_parsing_python.txt |
Q:
Python for web development in Apache
I've been playing with mod_python in apache2 which seems to work differently than python does in general - there's a bit different syntax and things you need to do. It's not very well documented and after a few days of playing with it, I'm really not seeing the point of mod_pyt... | Python for web development in Apache | I've been playing with mod_python in apache2 which seems to work differently than python does in general - there's a bit different syntax and things you need to do. It's not very well documented and after a few days of playing with it, I'm really not seeing the point of mod_python at all, especially when things like ph... | [
"\nDon't use mod_python. A common mistake is take mod_python as \"mod_php, but for python\" and that is not true. Use mod_wsgi instead.\nChoose a web framework. CherryPy. Pylons. Django.\nLook at wsgi.org\n\n",
"mod_python wasn't really made for doing basic webprogramming. I suggest you go with a framework:\n\nd... | [
29,
6
] | [] | [] | [
"apache",
"mod_python",
"python"
] | stackoverflow_0000215815_apache_mod_python_python.txt |
Q:
What's the difference between a parent and a reference property in Google App Engine?
From what I understand, the parent attribute of a db.Model (typically defined/passed in the constructor call) allows you to define hierarchies in your data models. As a result, this increases the size of the entity group. However... | What's the difference between a parent and a reference property in Google App Engine? | From what I understand, the parent attribute of a db.Model (typically defined/passed in the constructor call) allows you to define hierarchies in your data models. As a result, this increases the size of the entity group. However, it's not very clear to me why we would want to do that. Is this strictly for ACID complia... | [
"There are several differences:\n\nAll entities with the same ancestor are in the same entity group. Transactions can only affect entities inside a single entity group.\nAll writes to a single entity group are serialized, so throughput is limited.\nThe parent entity is set on creation and is fixed. References can b... | [
15,
8
] | [] | [] | [
"api",
"google_app_engine",
"python"
] | stackoverflow_0000215570_api_google_app_engine_python.txt |
Q:
Python embedded in CPP: how to get data back to CPP
While working on a C++ project, I was looking for a third party library for something that is not my core business. I found a really good library, doing exactly what's needed, but it is written in Python. I decided to experiment with embedding Python code in C++,... | Python embedded in CPP: how to get data back to CPP | While working on a C++ project, I was looking for a third party library for something that is not my core business. I found a really good library, doing exactly what's needed, but it is written in Python. I decided to experiment with embedding Python code in C++, using the Boost.Python library.
The C++ code looks somet... | [
"First of all, change your function to return the value. printing it will complicate things since you want to get the value back. Suppose your MyModule.py looks like this:\nimport thirdparty\n\ndef MyFunc(some_arg):\n result = thirdparty.go()\n return result\n\nNow, to do what you want, you have to go beyond ... | [
10,
4,
1,
0
] | [] | [] | [
"boost_python",
"c++",
"python"
] | stackoverflow_0000215752_boost_python_c++_python.txt |
Q:
Why do I receive an ImportError when running one of the CherryPy tutorials
I have installed CherryPy 3.1.0,. Here is what happens when I try to run tutorial 9:
$ cd /Library/Python/2.5/site-packages/cherrypy/tutorial/
$ python tut09_files.py
Traceback (most recent call last):
File "tut09_files.py", line 48, in <... | Why do I receive an ImportError when running one of the CherryPy tutorials | I have installed CherryPy 3.1.0,. Here is what happens when I try to run tutorial 9:
$ cd /Library/Python/2.5/site-packages/cherrypy/tutorial/
$ python tut09_files.py
Traceback (most recent call last):
File "tut09_files.py", line 48, in <module>
from cherrypy.lib import static
ImportError: cannot import name stat... | [
"This works for me, and I'm also using CherryPy 3.1.0, so I'm not sure what to tell you.\nLook in your /Library/Python/2.5/site-packages/cherrypy/lib directory for a file named static.py; if this file exists then I'm not sure what to tell you. If it doesn't then something has happened to your CherryPy and I'd advi... | [
1,
1
] | [] | [] | [
"cherrypy",
"python"
] | stackoverflow_0000209429_cherrypy_python.txt |
Q:
Hooking up GUI interface with asynchronous (s)ftp operation
Trying to implement a progress dialog window for file uploads that looks like a cross between IE download dialog and Firefox download dialog with a python GUI library on Windows.
What asynchronous (S)FTP libraries are there for python? Ideally I should b... | Hooking up GUI interface with asynchronous (s)ftp operation | Trying to implement a progress dialog window for file uploads that looks like a cross between IE download dialog and Firefox download dialog with a python GUI library on Windows.
What asynchronous (S)FTP libraries are there for python? Ideally I should be able to do file upload resumes and track the progress of each p... | [
"\"ftplib\" is the standard ftp library built in to Python. In Python 2.6, it had a callback parameter added to the method used for uploading.\nThat callback is a function you provide to the library; it is called once for every block that is completed.\nYour function can send a message to the GUI (perhaps on a diff... | [
1,
1,
1,
0
] | [] | [] | [
"ftp",
"python",
"sftp",
"user_interface",
"windows"
] | stackoverflow_0000207230_ftp_python_sftp_user_interface_windows.txt |
Q:
Keyboard interruptable blocking queue in Python
It seems
import Queue
Queue.Queue().get(timeout=10)
is keyboard interruptible (ctrl-c) whereas
import Queue
Queue.Queue().get()
is not. I could always create a loop;
import Queue
q = Queue()
while True:
try:
q.get(timeout=1000)
except Queue.Empty... | Keyboard interruptable blocking queue in Python | It seems
import Queue
Queue.Queue().get(timeout=10)
is keyboard interruptible (ctrl-c) whereas
import Queue
Queue.Queue().get()
is not. I could always create a loop;
import Queue
q = Queue()
while True:
try:
q.get(timeout=1000)
except Queue.Empty:
pass
but this seems like a strange thing t... | [
"Queue objects have this behavior because they lock using Condition objects form the threading module. So your solution is really the only way to go.\nHowever, if you really want a Queue method that does this, you can monkeypatch the Queue class. For example:\ndef interruptable_get(self):\n while True:\n ... | [
6,
4
] | [] | [] | [
"concurrency",
"multithreading",
"python",
"python_2.x"
] | stackoverflow_0000212797_concurrency_multithreading_python_python_2.x.txt |
Q:
Python/editline on OS X: £ sign seems to be bound to ed-prev-word
On Mac OS X I can’t enter a pound sterling sign (£) into the Python interactive shell.
* Mac OS X 10.5.5
* Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
* European keyboard (£ is shift-3)
When I type shift-3 in the Python interactive shell, I se... | Python/editline on OS X: £ sign seems to be bound to ed-prev-word | On Mac OS X I can’t enter a pound sterling sign (£) into the Python interactive shell.
* Mac OS X 10.5.5
* Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
* European keyboard (£ is shift-3)
When I type shift-3 in the Python interactive shell, I seem to invoke the previous word function, i.e. the cursor will move to t... | [
"This may be an editline issue; libedit may not accept UTF-8 characters:\n\nhttp://tracker.firebirdsql.org/browse/CORE-362#action_11593\nhttp://marc.info/?t=119056021900002&r=1&w=2\n\n"
] | [
1
] | [] | [] | [
"editline",
"macos",
"python",
"terminal",
"unix"
] | stackoverflow_0000217020_editline_macos_python_terminal_unix.txt |
Q:
How close are development webservers to production webservers?
Most python frameworks will have a development webserver of some kind that will have a warning that it isn't for use as production servers. How much different do they tend to be from their production equivalents?
I haven't quite decided which framewor... | How close are development webservers to production webservers? | Most python frameworks will have a development webserver of some kind that will have a warning that it isn't for use as production servers. How much different do they tend to be from their production equivalents?
I haven't quite decided which framework to go with, much less what production server to use, so it's kinda... | [
"The lower environments should try to match the production environment as closely as possible given the resources available. This applies to all development efforts regardless of whether they are python-based or even web-based. In practical terms, most organizations are not willing to spend that type of money. In t... | [
5,
2,
2,
1,
0
] | [] | [] | [
"python",
"web_frameworks",
"webserver"
] | stackoverflow_0000216489_python_web_frameworks_webserver.txt |
Q:
Smart Sudoku Golf
The point of this question is to create the shortest not abusively slow Sudoku solver. This is defined as: don't recurse when there are spots on the board which can only possibly be one digit.
Here is the shortest I have so far in python:
r=range(81)
s=range(1,10)
def R(A):
bzt={}
for i i... | Smart Sudoku Golf | The point of this question is to create the shortest not abusively slow Sudoku solver. This is defined as: don't recurse when there are spots on the board which can only possibly be one digit.
Here is the shortest I have so far in python:
r=range(81)
s=range(1,10)
def R(A):
bzt={}
for i in r:
if A[i]!=0... | [
"I haven't really made much of a change - the algorithm is identical, but here are a few further micro-optimisations you can make to your python code.\n\nNo need for !=0, 0 is false in a boolean context.\na if c else b is more expensive than using [a,b][c] if you don't need short-circuiting, hence you can use h[ [0... | [
3,
3,
2
] | [] | [] | [
"code_golf",
"perl",
"python",
"sudoku"
] | stackoverflow_0000216141_code_golf_perl_python_sudoku.txt |
Q:
What's a good library to manipulate Apache2 config files?
I'd like to create a script to manipulate Apache2 configuration directly, reading and writing its properties (like adding a new VirtualHost, changing settings of one that already exists).
Are there any libs out there, for Perl, Python or Java that automates... | What's a good library to manipulate Apache2 config files? | I'd like to create a script to manipulate Apache2 configuration directly, reading and writing its properties (like adding a new VirtualHost, changing settings of one that already exists).
Are there any libs out there, for Perl, Python or Java that automates that task?
| [
"Rather than manipulate the config files, you can use mod_perl to embed Perl directly into the config files. This could allow you, for example, to read required vhosts out of a database.\nSee Configure Apache with Perl Example for quick example and Apache Configuration in Perl for all the details.\n",
"In Perl, ... | [
7,
7,
4,
2,
2,
0
] | [] | [] | [
"apache",
"java",
"perl",
"python"
] | stackoverflow_0000215542_apache_java_perl_python.txt |
Q:
String Simple Substitution
What's the easiest way of me converting the simpler regex format that most users are used to into the correct re python regex string?
As an example, I need to convert this:
string = "*abc+de?"
to this:
string = ".*abc.+de.?"
Of course I could loop through the string and build up anothe... | String Simple Substitution | What's the easiest way of me converting the simpler regex format that most users are used to into the correct re python regex string?
As an example, I need to convert this:
string = "*abc+de?"
to this:
string = ".*abc.+de.?"
Of course I could loop through the string and build up another string character by character,... | [
"Those don't look like regexps you're trying to translate, they look more like unix shell globs. Python has a module for doing this already. It doesn't know about the \"+\" syntax you used, but neither does my shell, and I think the syntax is nonstandard.\n>>> import fnmatch\n>>> fnmatch.fnmatch(\"fooabcdef\", \"... | [
5,
2,
1,
0,
0
] | [] | [] | [
"python",
"string"
] | stackoverflow_0000217881_python_string.txt |
Q:
Troubleshooting py2exe packaging problem
I've written a setup.py script for py2exe, generated an executable for my python GUI application and I have a whole bunch of files in the dist directory, including the app, w9xopen.exe and MSVCR71.dll. When I try to run the application, I get an error message that just says... | Troubleshooting py2exe packaging problem | I've written a setup.py script for py2exe, generated an executable for my python GUI application and I have a whole bunch of files in the dist directory, including the app, w9xopen.exe and MSVCR71.dll. When I try to run the application, I get an error message that just says "see the logfile for details". The only probl... | [
"You may need to fix log handling first, this URL may help.\nLater you may look for answer here.\nMy answer is very general because you didn't give any more specific info (like py2exe/python version, py2exe log, other used 3rd party libraries).\n",
"See http://www.wxpython.org/docs/api/wx.App-class.html for wxPyt... | [
1,
1
] | [] | [] | [
"py2exe",
"python",
"user_interface"
] | stackoverflow_0000217666_py2exe_python_user_interface.txt |
Q:
how to generate unit test code for methods
i want to write code for unit test to test my application code. I have different methods and now want to test these methods one by one in python script.
but i do not how to i write. can any one give me example of small code for unit testing in python.
i am thankful
A:
... | how to generate unit test code for methods | i want to write code for unit test to test my application code. I have different methods and now want to test these methods one by one in python script.
but i do not how to i write. can any one give me example of small code for unit testing in python.
i am thankful
| [
"Read the unit testing framework section of the Python Library Reference.\nA basic example from the documentation:\nimport random\nimport unittest\n\nclass TestSequenceFunctions(unittest.TestCase):\n\n def setUp(self):\n self.seq = range(10)\n\n def testshuffle(self):\n # make sure the shuffled ... | [
7,
4,
1
] | [] | [] | [
"python",
"unit_testing"
] | stackoverflow_0000217900_python_unit_testing.txt |
Q:
Group by date in a particular format in SQLAlchemy
I have a table called logs which has a datetime field.
I want to select the date and count of rows based on a particular date format.
How do I do this using SQLAlchemy?
A:
I don't know of a generic SQLAlchemy answer. Most databases support some form of date f... | Group by date in a particular format in SQLAlchemy | I have a table called logs which has a datetime field.
I want to select the date and count of rows based on a particular date format.
How do I do this using SQLAlchemy?
| [
"I don't know of a generic SQLAlchemy answer. Most databases support some form of date formatting, typically via functions. SQLAlchemy supports calling functions via sqlalchemy.sql.func. So for example, using SQLAlchemy over a Postgres back end, and a table my_table(foo varchar(30), when timestamp) I might do ... | [
5,
1,
0
] | [] | [] | [
"python",
"sql",
"sqlalchemy"
] | stackoverflow_0000216657_python_sql_sqlalchemy.txt |
Q:
How can you use BeautifulSoup to get colindex numbers?
I had a problem a week or so ago. Since I think the solution was cool I am sharing it here while I am waiting for an answer to the question I posted earlier. I need to know the relative position for the column headings in a table so I know how to match the c... | How can you use BeautifulSoup to get colindex numbers? | I had a problem a week or so ago. Since I think the solution was cool I am sharing it here while I am waiting for an answer to the question I posted earlier. I need to know the relative position for the column headings in a table so I know how to match the column heading up with the data in the rows below. I found s... | [
"The code below produces [3, 7, 11, 15] which is what I understand you seek\nfrom BeautifulSoup import BeautifulSoup\nfrom re import compile\n\nsoup = BeautifulSoup(\n '''<HTML><BODY>\n <TABLE>\n <TR style=\"font-size: 1pt\" valign=\"bottom\">\n <TD width=\"60%\"> </TD> <!-- colindex=01 type=maindata --... | [
1
] | [] | [] | [
"beautifulsoup",
"html",
"parsing",
"python"
] | stackoverflow_0000215702_beautifulsoup_html_parsing_python.txt |
Q:
How to make Apache/mod_python process collect its zombies?
Apache/2.2.6 (Unix) DAV/2 mod_python/3.2.8 Python/2.4.4 configured ...
One of apache processes spawns some long-running python script asynchronously, and apparently doesn't seem to collect its child process table entry. After that long-run-in-subprocess p... | How to make Apache/mod_python process collect its zombies? | Apache/2.2.6 (Unix) DAV/2 mod_python/3.2.8 Python/2.4.4 configured ...
One of apache processes spawns some long-running python script asynchronously, and apparently doesn't seem to collect its child process table entry. After that long-run-in-subprocess python script finishes - defunct python process has been left.
# ... | [
"File a bug report.\nEDIT: I'm serious. Leaving zombies behind is a bug, and there is almost certainly nothing you can do from within Python.\nUpgrade to the latest versions, look for bug reports, post on the mailing list, switch to another product.\n",
"Drop mod_python in favor of mod_wsgi (is used for wsgi), wh... | [
1,
1
] | [] | [] | [
"apache",
"apache2",
"mod_python",
"python"
] | stackoverflow_0000208085_apache_apache2_mod_python_python.txt |
Q:
How to implement a Decorator with non-local equality?
Greetings, currently I am refactoring one of my programs, and I found an interesting problem.
I have Transitions in an automata. Transitions always have a start-state and an end-state. Some Transitions have a label, which encodes a certain Action that must be p... | How to implement a Decorator with non-local equality? | Greetings, currently I am refactoring one of my programs, and I found an interesting problem.
I have Transitions in an automata. Transitions always have a start-state and an end-state. Some Transitions have a label, which encodes a certain Action that must be performed upon traversal. No label means no action. Some tra... | [
"I think its clear that nobody really understands your question. I would suggest putting it in context and making it shorter. As an example, here's one possible implementation of the state pattern in python, please study it to get an idea.\nclass State(object):\n def __init__(self, name):\n self.name = na... | [
2,
0
] | [] | [] | [
"decorator",
"multiple_inheritance",
"python"
] | stackoverflow_0000127736_decorator_multiple_inheritance_python.txt |
Q:
How can I port a legacy Java/J2EE website to a modern scripting language (PHP,Python/Django, etc)?
I want to move a legacy Java web application (J2EE) to a scripting language - any scripting language - in order to improve programming efficiency.
What is the easiest way to do this? Are there any automated tools tha... | How can I port a legacy Java/J2EE website to a modern scripting language (PHP,Python/Django, etc)? | I want to move a legacy Java web application (J2EE) to a scripting language - any scripting language - in order to improve programming efficiency.
What is the easiest way to do this? Are there any automated tools that can convert the bulk of the business logic?
| [
"Here's what you have to do.\nFirst, be sure you can walk before you run. Build something simple, possibly tangentially related to your main project.\nDO NOT build a piece of the final project and hope it will \"evolve\" into the final project. This never works out well. Why? You'll make dumb mistakes. But you... | [
11,
7,
6,
1
] | [] | [] | [
"django",
"jakarta_ee",
"java",
"php",
"python"
] | stackoverflow_0000199556_django_jakarta_ee_java_php_python.txt |
Q:
What is the best way on python 2.3 for windows to execute a program like ghostscript with multiple arguments and spaces in paths?
Surely there is some kind of abstraction that allows for this?
This is essentially the command
cmd = self._ghostscriptPath + 'gswin32c -q -dNOPAUSE -dBATCH -sDEVICE=tiffg4
-r196X... | What is the best way on python 2.3 for windows to execute a program like ghostscript with multiple arguments and spaces in paths? | Surely there is some kind of abstraction that allows for this?
This is essentially the command
cmd = self._ghostscriptPath + 'gswin32c -q -dNOPAUSE -dBATCH -sDEVICE=tiffg4
-r196X204 -sPAPERSIZE=a4 -sOutputFile="' + tifDest + " " + pdfSource + '"'
os.popen(cmd)
this way looks really dirty to me, there must be s... | [
"Use subprocess, it superseeds os.popen, though it is not much more of an abstraction:\nfrom subprocess import Popen, PIPE\noutput = Popen([\"mycmd\", \"myarg\"], stdout=PIPE).communicate()[0]\n\n#this is how I'd mangle the arguments together\noutput = Popen([\n self._ghostscriptPath, \n 'gswin32c',\n '-q',\... | [
6
] | [] | [] | [
"ghostscript",
"python",
"windows"
] | stackoverflow_0000221097_ghostscript_python_windows.txt |
Q:
How can I write a method within a Django model to retrieve related objects?
I have two models. We'll call them object A and object B. Their design looks something like this:
class Foo(models.Model):
name = models.CharField()
class Bar(models.Model):
title = models.CharField()
Foo= models.ForeignKey... | How can I write a method within a Django model to retrieve related objects? | I have two models. We'll call them object A and object B. Their design looks something like this:
class Foo(models.Model):
name = models.CharField()
class Bar(models.Model):
title = models.CharField()
Foo= models.ForeignKey('myapp.Foo')
Now, suppose I want to make a method within Foo that returns all B... | [
"You get this for free:\nhttp://docs.djangoproject.com/en/dev/topics/db/queries/#backwards-related-objects\nBy default, you can access a Manager which gives you access to related items through a RELATEDCLASSNAME_set attribute:\nsome_foo.bar_set.all()\n\nOr you can use the related_name argument to ForeignKey to spec... | [
10
] | [] | [] | [
"django",
"frameworks",
"model_view_controller",
"python"
] | stackoverflow_0000221328_django_frameworks_model_view_controller_python.txt |
Q:
load dll from python
I'm building a python application from some source code I've found Here
I've managed to compile and fix some problems by searching the web, but I'm stuck at this point:
When running the application this message appears.
alt text http://img511.imageshack.us/img511/4481/loadfr0.png
This python a... | load dll from python | I'm building a python application from some source code I've found Here
I've managed to compile and fix some problems by searching the web, but I'm stuck at this point:
When running the application this message appears.
alt text http://img511.imageshack.us/img511/4481/loadfr0.png
This python app, usues swig to link to ... | [
"Looking at your update, it looks like you need to install Pycairo since you're missing the _cairo module installed as part of Pycairo. See the Pycairo downloads page for instructions on how to obtain/install binaries for Windows.\n",
"You probably need to install the VC++ runtime redistributables. The links to t... | [
2,
0,
0,
0
] | [] | [] | [
"dynamic_linking",
"python",
"scons",
"swig"
] | stackoverflow_0000220902_dynamic_linking_python_scons_swig.txt |
Q:
What is the meaning of '(?i)password' in python regular expression?
Pexpect can be used to automate tasks in python (does not need TCL to be installed). One of the simplest routines of this class is the 'run()' routine. It accepts a dictionary of expected question patterns as keys and the responses as values. For ... | What is the meaning of '(?i)password' in python regular expression? | Pexpect can be used to automate tasks in python (does not need TCL to be installed). One of the simplest routines of this class is the 'run()' routine. It accepts a dictionary of expected question patterns as keys and the responses as values. For example
pexpect.run ('scp foo myname@host.example.com:.', events={'(?i)pa... | [
"https://docs.python.org/library/re.html#regular-expression-syntax\n\n(?...) This is an extension\n notation (a \"?\" following a \"(\" is not\n meaningful otherwise). The first\n character after the \"?\" determines\n what the meaning and further syntax of\n the construct is. Extensions usually\n do not c... | [
10,
5
] | [] | [] | [
"python",
"regex"
] | stackoverflow_0000222536_python_regex.txt |
Q:
I’m stunned: weird problem with python and sockets + threads
I have a python script that is a http-server: http://paste2.org/p/89701, when benchmarking it against ApacheBench (ab) with a concurrency level (-c switch) that is lower then or equal to the value i specified in the socket.listen()-call in the sourcecode... | I’m stunned: weird problem with python and sockets + threads | I have a python script that is a http-server: http://paste2.org/p/89701, when benchmarking it against ApacheBench (ab) with a concurrency level (-c switch) that is lower then or equal to the value i specified in the socket.listen()-call in the sourcecode everything works fine, but as soon as put the concurrency level i... | [
"I cannot confirm your results, and your server is coded fishy. I whipped up my own server and do not have this problem either. Let's move the discussion to a simpler level:\nimport thread, socket, Queue\n\nconnections = Queue.Queue()\nnum_threads = 10\nbacklog = 10\n\ndef request():\n while 1:\n conn = c... | [
7,
4,
0,
0,
0
] | [] | [] | [
"apache",
"multithreading",
"python",
"sockets"
] | stackoverflow_0000219547_apache_multithreading_python_sockets.txt |
Q:
Sorting a tuple that contains tuples
I have the following tuple, which contains tuples:
MY_TUPLE = (
('A','Apple'),
('C','Carrot'),
('B','Banana'),
)
I'd like to sort this tuple based upon the second value contained in inner-tuples (i.e., sort Apple, Carrot, Banana rather than A, B, C).
Any thoughts?
... | Sorting a tuple that contains tuples | I have the following tuple, which contains tuples:
MY_TUPLE = (
('A','Apple'),
('C','Carrot'),
('B','Banana'),
)
I'd like to sort this tuple based upon the second value contained in inner-tuples (i.e., sort Apple, Carrot, Banana rather than A, B, C).
Any thoughts?
| [
"from operator import itemgetter\n\nMY_SORTED_TUPLE = tuple(sorted(MY_TUPLE, key=itemgetter(1)))\n\nor without itemgetter:\nMY_SORTED_TUPLE = tuple(sorted(MY_TUPLE, key=lambda item: item[1]))\n\n",
"From Sorting Mini-HOW TO\n\nOften there's a built-in that will\n match your needs, such as str.lower().\n The ope... | [
25,
7,
2
] | [
"I achieved the same thing using this code, but your suggestion is great. Thanks!\ntemplist = [ (line[1], line) for line in MY_TUPLE ] \ntemplist.sort()\nSORTED_MY_TUPLE = [ line[1] for line in templist ]\n\n"
] | [
-2
] | [
"python",
"sorting",
"tuples"
] | stackoverflow_0000222752_python_sorting_tuples.txt |
Q:
cherrypy not closing the sockets
I am using cherrypy as a webserver. It gives good performance for my application but there is a very big problem with it. cherrypy crashes after couple of hours stating that it could not create a socket as there are too many files open:
[21/Oct/2008:12:44:25] ENGINE HTTP Server
ch... | cherrypy not closing the sockets | I am using cherrypy as a webserver. It gives good performance for my application but there is a very big problem with it. cherrypy crashes after couple of hours stating that it could not create a socket as there are too many files open:
[21/Oct/2008:12:44:25] ENGINE HTTP Server
cherrypy._cpwsgi_server.CPWSGIServer(('0... | [
"I imagine you're storing (in-memory) some piece of data which has a reference to the socket; if you store the request objects anywhere, for instance, that would likely do it.\nThe last-ditch chance for sockets to be closed is when they're garbage-collected; if you're doing anything that would prevent garbage colle... | [
4
] | [] | [] | [
"cherrypy",
"python",
"sockets"
] | stackoverflow_0000222736_cherrypy_python_sockets.txt |
Q:
Python code generator for Visual Studio?
I had an idea, if I add a python .py file to my C# project, and tag the file with a custom generator that would execute the python file, and treat the output as the result of the code generation, ie. put it into a C# file, that would allow me to do quite a lot of code gener... | Python code generator for Visual Studio? | I had an idea, if I add a python .py file to my C# project, and tag the file with a custom generator that would execute the python file, and treat the output as the result of the code generation, ie. put it into a C# file, that would allow me to do quite a lot of code generation as part of the build process.
Does anyon... | [
"I think Cog does what you want.\n",
"I recall that in previous versions of VS, there was a way to add custom build steps to the build process. I used that a lot to do exactly the kind of automated code generation you describe.\nI imagine the custom build step feature is still there in 2008.\n",
"OK, I see. Wel... | [
4,
2,
2,
1,
1
] | [] | [] | [
"code_generation",
"python",
"visual_studio_2008"
] | stackoverflow_0000024193_code_generation_python_visual_studio_2008.txt |
Q:
When does urllib2 actually download a file from a url?
url = "http://example.com/file.xml"
data = urllib2.urlopen(url)
data.read()
The question is, when exactly will the file be downloaded from the internet? When i do urlopen or .read()? On my network interface I see high traffic both times.
A:
Witout looking ... | When does urllib2 actually download a file from a url? | url = "http://example.com/file.xml"
data = urllib2.urlopen(url)
data.read()
The question is, when exactly will the file be downloaded from the internet? When i do urlopen or .read()? On my network interface I see high traffic both times.
| [
"Witout looking at the code, I'd expect that the following happens:\n\nurlopen() opens the connection, and sends the query. Then the server starts feeding the reply. At this point, the data accumulates in buffers until they are full and the operating system tells the server to hold on for a while.\nThen data.read()... | [
5,
5
] | [] | [] | [
"python"
] | stackoverflow_0000223356_python.txt |
Q:
What would be a better implementation of all combinations in lexicographic order of a jagged list?
I was put in a position today in which I needed to enumerate all possible combinations of jagged list. For instance, a naive approach would be:
for a in [1,2,3]:
for b in [4,5,6,7,8,9]:
for c in [1,2]:
... | What would be a better implementation of all combinations in lexicographic order of a jagged list? | I was put in a position today in which I needed to enumerate all possible combinations of jagged list. For instance, a naive approach would be:
for a in [1,2,3]:
for b in [4,5,6,7,8,9]:
for c in [1,2]:
yield (a,b,c)
This is functional, but not general in terms of the number of lists that can be... | [
"The naive approach can be written more compactly as a generator expression:\n((a,b,c) for a in [1,2,3] for b in [4,5,6,7,8,9] for c in [1,2])\n\nThe general approach can be written much more simply using a recursive function:\ndef combinations(*seqs):\n if not seqs: return (item for item in ())\n first, rest = s... | [
6
] | [] | [] | [
"algorithm",
"python"
] | stackoverflow_0000224145_algorithm_python.txt |
Q:
Including PYDs/DLLs in py2exe builds
One of the modules for my app uses functions from a .pyd file. There's an option to exclude dlls (exclude_dlls) but is there one for including them? The build process doesn't seem to be copying the .pyd in my module despite copying the rest of the files (.py). I also need to in... | Including PYDs/DLLs in py2exe builds | One of the modules for my app uses functions from a .pyd file. There's an option to exclude dlls (exclude_dlls) but is there one for including them? The build process doesn't seem to be copying the .pyd in my module despite copying the rest of the files (.py). I also need to include a .dll. How do I get py2exe to incl... | [
".pyd's and .DLL's are different here, in that a .pyd ought to be automatically found by modulefinder and so included (as long as you have the appropriate \"import\" statement) without needing to do anything. If one is missed, you do the same thing as if a .py file was missed (they're both just modules): use the \... | [
12,
2,
2,
2
] | [] | [] | [
"dll",
"installation",
"py2exe",
"pyd",
"python"
] | stackoverflow_0000220777_dll_installation_py2exe_pyd_python.txt |
Q:
Best approach with dynamic classes using Python globals()
I'm working on a web application that will return a variable set of modules depending on user input. Each module is a Python class with a constructor that accepts a single parameter and has an '.html' property that contains the output.
Pulling the class dyn... | Best approach with dynamic classes using Python globals() | I'm working on a web application that will return a variable set of modules depending on user input. Each module is a Python class with a constructor that accepts a single parameter and has an '.html' property that contains the output.
Pulling the class dynamically from the global namespace works:
result = globals()[cl... | [
"A flaw with this approach is that it may give the user the ability to to more than you want them to. They can call any single-parameter function in that namespace just by providing the name. You can help guard against this with a few checks (eg. isinstance(SomeBaseClass, theClass), but its probably better to avo... | [
6,
4,
0
] | [] | [] | [
"coding_style",
"namespaces",
"python"
] | stackoverflow_0000222133_coding_style_namespaces_python.txt |
Q:
How do you use the cursor for reading multiple files in database in python
In python how do you read multiple files from a mysql database using the cursor or loop one by one and store the output in a separate table?
A:
I don't understand your question (what are files?, what's your table structure?), but here goe... | How do you use the cursor for reading multiple files in database in python | In python how do you read multiple files from a mysql database using the cursor or loop one by one and store the output in a separate table?
| [
"I don't understand your question (what are files?, what's your table structure?), but here goes a simple sample:\n>>> import MySQLdb\n>>> conn = MySQLdb.connect(host=\"localhost\",\n user=\"root\",\n password=\"merlin\",\n db=\"files\")\... | [
1,
0
] | [] | [] | [
"mysql",
"python"
] | stackoverflow_0000224771_mysql_python.txt |
Q:
Incoming poplib refactoring using windows python 2.3
Hi Guys could you please help me refactor this so that it is sensibly pythonic.
import sys
import poplib
import string
import StringIO, rfc822
import datetime
import logging
def _dump_pop_emails(self):
self.logger.info("open pop account %s with username: %s... | Incoming poplib refactoring using windows python 2.3 | Hi Guys could you please help me refactor this so that it is sensibly pythonic.
import sys
import poplib
import string
import StringIO, rfc822
import datetime
import logging
def _dump_pop_emails(self):
self.logger.info("open pop account %s with username: %s" % (self.account[0], self.account[1]))
self.popinstan... | [
"I don't see anything significant wrong with that code -- is it behaving incorrectly, or are you just looking for general style guidelines?\nA few notes:\n\nInstead of logger.info (\"foo %s %s\" % (bar, baz)), use \"foo %s %s\", bar, baz. This avoids the overhead of string formatting if the message won't be printed... | [
3,
1,
0
] | [] | [] | [
"email",
"poplib",
"python",
"refactoring"
] | stackoverflow_0000224660_email_poplib_python_refactoring.txt |
Q:
Parsing different date formats from feedparser in python?
I'm trying to get the dates from entries in two different RSS feeds through feedparser.
Here is what I'm doing:
import feedparser as fp
reddit = fp.parse("http://www.reddit.com/.rss")
cc = fp.parse("http://contentconsumer.com/feed")
print reddit.entries[0].... | Parsing different date formats from feedparser in python? | I'm trying to get the dates from entries in two different RSS feeds through feedparser.
Here is what I'm doing:
import feedparser as fp
reddit = fp.parse("http://www.reddit.com/.rss")
cc = fp.parse("http://contentconsumer.com/feed")
print reddit.entries[0].date
print cc.entries[0].date
And here's how they come out:
20... | [
"Parsing of dates is a pain with RSS feeds in-the-wild, and that's where feedparser can be a big help.\nIf you use the *_parsed properties (like updated_parsed), feedparser will have done the work and will return a 9-tuple Python date in UTC.\nSee http://packages.python.org/feedparser/date-parsing.html for more gor... | [
17
] | [] | [] | [
"datetime",
"feedparser",
"parsing",
"python",
"rss"
] | stackoverflow_0000225274_datetime_feedparser_parsing_python_rss.txt |
Q:
Cursor event handling in python+Tkinter
I'm building a code in which I'd like to be able to generate an event when the user changes the focus of the cursor from an Entry widget to anywhere, for example another entry widget, a button...
So far i only came out with the idea to bind to TAB and mouse click, although i... | Cursor event handling in python+Tkinter | I'm building a code in which I'd like to be able to generate an event when the user changes the focus of the cursor from an Entry widget to anywhere, for example another entry widget, a button...
So far i only came out with the idea to bind to TAB and mouse click, although if i bind the mouse click to the Entry widget ... | [
"The events <FocusIn> and <FocusOut> are what you want. Run the following example and you'll see you get focus in and out bindings whether you click or press tab (or shift-tab) when focus is in one of the entry widgets.\nfrom Tkinter import *\n\ndef main():\n global text\n\n root=Tk()\n\n l1=Label(root,tex... | [
5,
0
] | [] | [] | [
"events",
"mouse_cursor",
"python",
"tkinter"
] | stackoverflow_0000210522_events_mouse_cursor_python_tkinter.txt |
Q:
Help with event in python Entry widget
I'm writing some code in python and I'm having trouble when trying to retrieve content of an Entry widget.
The thing is: I want to limit the characters that can be typed, so I'm trying to clear the Entry widget when I reach the specific number of characters (2 in this case),... | Help with event in python Entry widget | I'm writing some code in python and I'm having trouble when trying to retrieve content of an Entry widget.
The thing is: I want to limit the characters that can be typed, so I'm trying to clear the Entry widget when I reach the specific number of characters (2 in this case), but it looks like I always miss the last typ... | [
"At first, after you do the deletion, the event goes on with its normal processing, i.e. the character gets inserted. You need to signal to Tkinter that the event should be ignored.\nSo in your code above, add the marked line:\nif len(self.__value) > 2:\n widgetName.delete(2,4)\n return \"break\" # add this l... | [
3,
1
] | [] | [] | [
"events",
"python",
"tkinter",
"widget"
] | stackoverflow_0000206916_events_python_tkinter_widget.txt |
Q:
Get Bound Event Handler in Tkinter
After a bind a method to an event of a Tkinter element is there a way to get the method back?
>>> root = Tkinter.Tk()
>>> frame = Tkinter.Frame(root, width=100, height=100)
>>> frame.bind('<Button-1>', lambda e: pprint('Click')) # function needed
>>> frame.pack()
>>> bound_event_... | Get Bound Event Handler in Tkinter | After a bind a method to an event of a Tkinter element is there a way to get the method back?
>>> root = Tkinter.Tk()
>>> frame = Tkinter.Frame(root, width=100, height=100)
>>> frame.bind('<Button-1>', lambda e: pprint('Click')) # function needed
>>> frame.pack()
>>> bound_event_method = frame.???
| [
"The standard way to do this in Tcl/Tk is trivial: you use the same bind command but without the final argument. \nbind .b <Button-1> doSomething\nputs \"the function is [bind .b <Button-1>]\"\n=> the function is doSomething\n\nYou can do something similar with Tkinter but the results are, unfortunately, not quite ... | [
3,
2,
0
] | [] | [] | [
"events",
"python",
"tkinter",
"user_interface"
] | stackoverflow_0000138029_events_python_tkinter_user_interface.txt |
Q:
How can I generate a report file (ODF, PDF) from a django view
I would like to generate a report file from a view&template in django.
Preferred file formats would be OpenOffice/ODF or PDF.
What is the best way to do this?
I do want to reuse the page layout defined in the template, possibly by redefining some block... | How can I generate a report file (ODF, PDF) from a django view | I would like to generate a report file from a view&template in django.
Preferred file formats would be OpenOffice/ODF or PDF.
What is the best way to do this?
I do want to reuse the page layout defined in the template, possibly by redefining some blocks in a derived template.
Ideally, the report should be inserted into... | [
"pisa/xhtml2pdf should get you covered for PDF. It even includes an example Django project.\n",
"Try ReportLab for PDF output:\nhttp://www.reportlab.org/\n"
] | [
4,
3
] | [] | [] | [
"django",
"pdf",
"pdf_generation",
"python"
] | stackoverflow_0000224796_django_pdf_pdf_generation_python.txt |
Q:
Solving an inequality for minimum value
I'm working on a programming problem which boils down to a set of an equation and inequality:
x[0]*a[0] + x[1]*a[1] + ... x[n]*a[n] >= D
x[0]*b[0] + x[1]*b[1] + ... x[n]*b[n] = C
I want to solve for the values of X that will give the absolute minimum of C, given the input ... | Solving an inequality for minimum value | I'm working on a programming problem which boils down to a set of an equation and inequality:
x[0]*a[0] + x[1]*a[1] + ... x[n]*a[n] >= D
x[0]*b[0] + x[1]*b[1] + ... x[n]*b[n] = C
I want to solve for the values of X that will give the absolute minimum of C, given the input D and lists and A and B consisting of a[0 - n... | [
"This looks like a linear programming problem. The Simplex algorithm normally gives good results. It basically walks the boundaries of the subspace delimited by the inequalities, looking for the optimum.\nThink of it visually: each inequality denotes a half-space, a plane in n-dimensional space that you have to be ... | [
11,
3,
2,
1,
0
] | [] | [] | [
"equation",
"inequality",
"language_agnostic",
"linear_programming",
"python"
] | stackoverflow_0000227282_equation_inequality_language_agnostic_linear_programming_python.txt |
Q:
What's a good resource for learning CGI programming in Python?
I need to write a browser interface for an application running embedded on a single board computer (Gumstix Verdex for anyone who's interested), so I won't be able to use any web frameworks due to space and processor constraints (and availability for t... | What's a good resource for learning CGI programming in Python? | I need to write a browser interface for an application running embedded on a single board computer (Gumstix Verdex for anyone who's interested), so I won't be able to use any web frameworks due to space and processor constraints (and availability for the environment I'm running in). I'm limited to the core Python and ... | [
"One of the biggest resources for CGI programming is the CGI homepage. Once you're done with that, familiarizing yourself with the cgi and cgitb modules should be your next task.\nBut don't discount learning WSGI (libref) and using a CGI-to-WSGI adaptor such as flup.\n",
"\nhttp://www.cs.virginia.edu/~lab2q/\nhtt... | [
2,
1,
1
] | [] | [] | [
"cgi",
"python"
] | stackoverflow_0000227318_cgi_python.txt |
Q:
Python Find Question
I am using Python to extract the filename from a link using rfind like below:
url = "http://www.google.com/test.php"
print url[url.rfind("/") +1 : ]
This works ok with links without a / at the end of them and returns "test.php". I have encountered links with / at the end like so "http://www... | Python Find Question | I am using Python to extract the filename from a link using rfind like below:
url = "http://www.google.com/test.php"
print url[url.rfind("/") +1 : ]
This works ok with links without a / at the end of them and returns "test.php". I have encountered links with / at the end like so "http://www.google.com/test.php/". I... | [
"Just removing the slash at the end won't work, as you can probably have a URL that looks like this:\nhttp://www.google.com/test.php?filepath=tests/hey.xml\n\n...in which case you'll get back \"hey.xml\". Instead of manually checking for this, you can use urlparse to get rid of the parameters, then do the check oth... | [
9,
4,
1,
0,
0
] | [
"You could use\nprint url[url.rstrip(\"/\").rfind(\"/\") +1 : ]\n\n",
"filter(None, url.split('/'))[-1]\n\n(But urlparse is probably more readable, even if more verbose.)\n"
] | [
-1,
-1
] | [
"python",
"url"
] | stackoverflow_0000229352_python_url.txt |
Q:
Python debugger: Stepping into a function that you have called interactively
Python is quite cool, but unfortunately, its debugger is not as good as perl -d.
One thing that I do very commonly when experimenting with code is to call a function from within the debugger, and step into that function, like so:
# NOTE... | Python debugger: Stepping into a function that you have called interactively | Python is quite cool, but unfortunately, its debugger is not as good as perl -d.
One thing that I do very commonly when experimenting with code is to call a function from within the debugger, and step into that function, like so:
# NOTE THAT THIS PROGRAM EXITS IMMEDIATELY WITHOUT CALLING FOO()
~> cat -n /tmp/show_per... | [
"And I've answered my own question! It's the \"debug\" command in pydb:\n~> cat -n /tmp/test_python.py\n 1 #!/usr/local/bin/python\n 2\n 3 def foo():\n 4 print \"hi\"\n 5 print \"bye\"\n 6\n 7 exit(0)\n 8\n\n~> pydb /tmp/test_python.py\n(/tmp/test_python.py:7): <module... | [
47,
25,
4,
2,
2
] | [] | [] | [
"debugging",
"pdb",
"python"
] | stackoverflow_0000228642_debugging_pdb_python.txt |
Q:
Is there a free python debugger that has watchpoints?
pdb and winpdb both seem to be missing this essential (to me) feature. I saw something suggesting WingIDE has it but I'd prefer a solution that is free, and if I do have to pay, I'd prefer to pay for something that is better than Wing.
A:
You should check ou... | Is there a free python debugger that has watchpoints? | pdb and winpdb both seem to be missing this essential (to me) feature. I saw something suggesting WingIDE has it but I'd prefer a solution that is free, and if I do have to pay, I'd prefer to pay for something that is better than Wing.
| [
"You should check out Eric4\nIt's a very good Python IDE with a builtin debugger.\nThe debugger has views for global variables, local variables and watchpoints.\n",
"Please look what pydev in eclipse offers...\n",
"Take a look at PyScripter. It has an integrated debugger, watch windows and much more.\nIt's open... | [
4,
2,
1,
1,
1
] | [] | [] | [
"debugging",
"pdb",
"python",
"watchpoint"
] | stackoverflow_0000207904_debugging_pdb_python_watchpoint.txt |
Q:
Given a list of variable names in Python, how do I a create a dictionary with the variable names as keys (to the variables' values)?
I have a list of variable names, like this:
['foo', 'bar', 'baz']
(I originally asked how I convert a list of variables. See Greg Hewgill's answer below.)
How do I convert this to ... | Given a list of variable names in Python, how do I a create a dictionary with the variable names as keys (to the variables' values)? | I have a list of variable names, like this:
['foo', 'bar', 'baz']
(I originally asked how I convert a list of variables. See Greg Hewgill's answer below.)
How do I convert this to a dictionary where the keys are the variable names (as strings) and the values are the values of the variables?
{'foo': foo, 'bar': bar, '... | [
"Forget filtering locals()! The dictionary you give to the formatting string is allowed to contain unused keys:\n>>> name = 'foo'\n>>> zip = 123\n>>> unused = 'whoops!'\n>>> locals()\n{'name': 'foo', 'zip': 123, ... 'unused': 'whoops!', ...}\n>>> '%(name)s %(zip)i' % locals()\n'foo 123'\n\nWith the new f-string fea... | [
16,
5,
4,
1
] | [] | [] | [
"dictionary",
"list",
"python"
] | stackoverflow_0000230896_dictionary_list_python.txt |
Q:
Unexpected list comprehension behaviour in Python
I believe I'm getting bitten by some combination of nested scoping rules and list comprehensions. Jeremy Hylton's blog post is suggestive about the causes, but I don't really understand CPython's implementation well-enough to figure out how to get around this.
He... | Unexpected list comprehension behaviour in Python | I believe I'm getting bitten by some combination of nested scoping rules and list comprehensions. Jeremy Hylton's blog post is suggestive about the causes, but I don't really understand CPython's implementation well-enough to figure out how to get around this.
Here is an (overcomplicated?) example. If people have a ... | [
"The problem is that with return self.display you return a reference to this list (not a copy). So what you end up with is a list where each element is a reference to self.display. To illustrate, look at the following:\n>>> a = [1,2]\n>>> b = [a,a]\n>>> b\n[[1, 2], [1, 2]]\n>>> a.append(3)\n>>> b\n[[1, 2, 3], [1, 2... | [
15,
4
] | [] | [] | [
"language_implementation",
"list_comprehension",
"python"
] | stackoverflow_0000225675_language_implementation_list_comprehension_python.txt |
Q:
How to do Makefile dependencies for python code
I have a bunch of C files that are generated by a collection of python programs that have a number of shared python modules and I need to account for this in my make system.
It is easy enough to enumerate which python program need to be run to generate each C file. W... | How to do Makefile dependencies for python code | I have a bunch of C files that are generated by a collection of python programs that have a number of shared python modules and I need to account for this in my make system.
It is easy enough to enumerate which python program need to be run to generate each C file. What I can't find a good solution for is determining w... | [
"modulefinder can be used to get the dependency graph.\n",
"The import statements are pretty much all the dependencies there are. There are are two relevant forms for the import statements:\nimport x, y, z\nfrom x import a, b, c\n\nYou'll also need the PYTHONPATH and sites information that is used to build sys.p... | [
3,
1
] | [] | [] | [
"dependencies",
"makefile",
"python"
] | stackoverflow_0000232162_dependencies_makefile_python.txt |
Q:
Default parameters to actions with Django
Is there a way to have a default parameter passed to a action in the case where the regex didnt match anything using django?
urlpatterns = patterns('',(r'^test/(?P<name>.*)?$','myview.displayName'))
#myview.py
def displayName(request,name):
# write name to response... | Default parameters to actions with Django | Is there a way to have a default parameter passed to a action in the case where the regex didnt match anything using django?
urlpatterns = patterns('',(r'^test/(?P<name>.*)?$','myview.displayName'))
#myview.py
def displayName(request,name):
# write name to response or something
I have tried setting the third p... | [
"The problem is that when the pattern is matched against 'test/' the groupdict captured by the regex contains the mapping 'name' => None:\n>>> url.match(\"test/\").groupdict()\n{'name': None}\n\nThis means that when the view is invoked, using something I expect that is similar to below:\nview(request, *groups, **gr... | [
9,
0
] | [] | [] | [
"django",
"django_urls",
"python"
] | stackoverflow_0000234695_django_django_urls_python.txt |
Q:
how do I implement a custom code page used by a serial device so I can convert text to it in Python?
I have a scrolling LED sign that takes messages in either ASCII or (using some specific code) characters from a custom code page.
For example, the euro sign should be sent as
<U00>
and ä is
<U64>
(You can find th... | how do I implement a custom code page used by a serial device so I can convert text to it in Python? | I have a scrolling LED sign that takes messages in either ASCII or (using some specific code) characters from a custom code page.
For example, the euro sign should be sent as
<U00>
and ä is
<U64>
(You can find the full code page in the documentation)
My question is, what is the most pythonic way to implement this cus... | [
"\nPick a name for your encoding, maybe \"led_display\", whatever.\nImplement and register a codec with the standard library.\nPythonic profit!\n\n"
] | [
3
] | [] | [] | [
"encoding",
"python",
"utf"
] | stackoverflow_0000235416_encoding_python_utf.txt |
Q:
How can I use Python for large scale development?
I would be interested to learn about large scale development in Python and especially in how do you maintain a large code base?
When you make incompatibility changes to the signature of a method, how do you find all the places where that method is being called. In... | How can I use Python for large scale development? | I would be interested to learn about large scale development in Python and especially in how do you maintain a large code base?
When you make incompatibility changes to the signature of a method, how do you find all the places where that method is being called. In C++/Java the compiler will find it for you, how do you... | [
"Don't use a screw driver as a hammer\nPython is not a statically typed language, so don't try to use it that way.\nWhen you use a specific tool, you use it for what it has been built. For Python, it means:\n\nDuck typing : no type checking. Only behavior matters. Therefore your code must be designed to use this fe... | [
69,
40,
24,
16,
16,
8,
3,
2
] | [] | [] | [
"development_environment",
"python"
] | stackoverflow_0000236407_development_environment_python.txt |
Q:
How to disable HTML encoding when using Context in django
In my django application I am using a template to construct email body, one of the parameters is url, note there are two parametes separated by ampersand in the url.
t = loader.get_template("sometemplate")
c = Context({
'foo': 'bar',
'url': 'http://12... | How to disable HTML encoding when using Context in django | In my django application I am using a template to construct email body, one of the parameters is url, note there are two parametes separated by ampersand in the url.
t = loader.get_template("sometemplate")
c = Context({
'foo': 'bar',
'url': 'http://127.0.0.1/test?a=1&b=2',
})
print t.render(c)
After rendering it... | [
"To turn it off for a single variable, use mark_safe:\nfrom django.utils.safestring import mark_safe\n\nt = loader.get_template(\"sometemplate\")\nc = Context({\n 'foo': 'bar',\n 'url': mark_safe('http://127.0.0.1/test?a=1&b=2'),\n})\nprint t.render(c)\n\nAlternatively, to totally turn autoescaping off from you... | [
24,
9
] | [] | [] | [
"django",
"django_templates",
"python"
] | stackoverflow_0000237235_django_django_templates_python.txt |
Q:
Daylight savings time change affecting the outcome of saving and loading an icalendar file?
I have some unit tests that started failing today after a switch in daylight savings time.
We're using the iCalendar python module to load and save ics files.
The following script is a simplified version of our test. The s... | Daylight savings time change affecting the outcome of saving and loading an icalendar file? | I have some unit tests that started failing today after a switch in daylight savings time.
We're using the iCalendar python module to load and save ics files.
The following script is a simplified version of our test. The script works fine in 'summer' and fails in 'winter', as of this morning. The failure can be repro... | [
"Without looking at your code (and the quoted test-run-script my brain fails to understand right now)\nI notice that you try to get a time that is in a different timezone than the one you are at.\n(Think of DST as a another TIMEZONE instead of +-1 hour from current timezone). \nThis could (depending on how you do i... | [
1
] | [] | [] | [
"icalendar",
"python",
"unit_testing"
] | stackoverflow_0000237731_icalendar_python_unit_testing.txt |
Q:
What is your convention to distinguish between object methods to be called by the outside, and object methods to be called by a subclass?
I know most of the ins and outs of Python's approach to private variables/members/functions/...
However, I can't make my mind up on how to distinguish between methods for extern... | What is your convention to distinguish between object methods to be called by the outside, and object methods to be called by a subclass? | I know most of the ins and outs of Python's approach to private variables/members/functions/...
However, I can't make my mind up on how to distinguish between methods for external use or subclassing use.
Consider the following example:
class EventMixin(object):
def subscribe(self, **kwargs):
'''kwargs shoul... | [
"use no underscores for the external API,\none underscore for the subclassable API,\nand two underscores for the private/internal API\n\nThis is a reasonable and relatively common way of doing it, yes. The double-underline-for-actually-private (as opposed to ‘protected’ in C++ terms) is in practice pretty rare. You... | [
3,
2,
2
] | [] | [] | [
"private",
"python",
"subclass"
] | stackoverflow_0000236359_private_python_subclass.txt |
Q:
Splitting strings in python
I have a string which is like this:
this is [bracket test] "and quotes test "
I'm trying to write something in Python to split it up by space while ignoring spaces within square braces and quotes. The result I'm looking for is:
['this','is','bracket test','and quotes test ']
A:
Here'... | Splitting strings in python | I have a string which is like this:
this is [bracket test] "and quotes test "
I'm trying to write something in Python to split it up by space while ignoring spaces within square braces and quotes. The result I'm looking for is:
['this','is','bracket test','and quotes test ']
| [
"Here's a simplistic solution that works with your test input:\nimport re\nre.findall('\\[[^\\]]*\\]|\\\"[^\\\"]*\\\"|\\S+',s)\n\nThis will return any code that matches either \n\na open bracket followed by zero or more non-close-bracket characters followed by a close bracket, \na double-quote followed by zero or m... | [
8,
5,
1,
0,
0
] | [
"Works for quotes only. \nrrr = []\nqqq = s.split('\\\"')\n[ rrr.extend( qqq[x].split(), [ qqq[x] ] )[ x%2]) for x in range( len( qqq ) )]\nprint rrr\n\n"
] | [
-2
] | [
"parsing",
"python",
"split",
"string",
"tokenize"
] | stackoverflow_0000234512_parsing_python_split_string_tokenize.txt |
Q:
Is there a windows implementation to python libsvn?
Because windows is case-insensitive and because SVN is case-sensitive and because VS2005 tends to rename files giving them the lower-case form which messes my repositories' history, I've tried to add the pre-commit hook script from http://svn.collab.net/repos/svn... | Is there a windows implementation to python libsvn? | Because windows is case-insensitive and because SVN is case-sensitive and because VS2005 tends to rename files giving them the lower-case form which messes my repositories' history, I've tried to add the pre-commit hook script from http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/case-insensitive.py.
Sure eno... | [
"There are two alternative Python bindings for libsvn:\n\npysvn.\nsubvertpy. \n\nSubvertpy is quite new and is written by the author of bzr-svn: the transparent svn inter-operation bridge for bzr.\nFor a while, bzr-svn used the upstream SWIG Python bindings, and the author contributed a lot of bug fixes. It helped ... | [
4,
3
] | [] | [] | [
"hook",
"pre_commit",
"python",
"svn"
] | stackoverflow_0000238151_hook_pre_commit_python_svn.txt |
Q:
Solving the shared-server security problem for Python
So my group is trying to set up a shared-server environment for various and sundry web services. I think we've settled on setting disable_functions and disable_classes site wide in php.ini and php_admin_value to force open_basedir in each app's httpd.conf
for... | Solving the shared-server security problem for Python | So my group is trying to set up a shared-server environment for various and sundry web services. I think we've settled on setting disable_functions and disable_classes site wide in php.ini and php_admin_value to force open_basedir in each app's httpd.conf
for php scripts, and passenger's user switching for ruby scrip... | [
"Well, there is a system called virtualenv which allows you to run Python in a sort of safe environment, and configure/load/shutdown these environments on the fly. I don't know much about it, but you should take a serious look into it; here is the description from its web page (just Google it and you'll find it):\n... | [
3
] | [] | [] | [
"mysql",
"php",
"python",
"ruby",
"security"
] | stackoverflow_0000234590_mysql_php_python_ruby_security.txt |
Q:
How can I support wildcards in user-defined search strings in Python?
Is there a simple way to support wildcards ("*") when searching strings - without using RegEx?
Users are supposed to enter search terms using wildcards, but should not have to deal with the complexity of RegEx:
"foo*" => str.startswith("foo")... | How can I support wildcards in user-defined search strings in Python? | Is there a simple way to support wildcards ("*") when searching strings - without using RegEx?
Users are supposed to enter search terms using wildcards, but should not have to deal with the complexity of RegEx:
"foo*" => str.startswith("foo")
"*foo" => str.endswith("foo")
"*foo*" => "foo" in str
(it gets more ... | [
"You could try the fnmatch module, it's got a shell-like wildcard syntax.\n"
] | [
14
] | [] | [] | [
"parsing",
"python",
"search",
"string",
"wildcard"
] | stackoverflow_0000238600_parsing_python_search_string_wildcard.txt |
Q:
How do I install plpython on MacOs X 10.5?
I have just installed PostgreSQL 8.3.4 on Mac OS X 10.5 (using ports), but I cannot figure out how to enable PL/Python. When I run the CREATE LANGUAGE plpythonu I get the following errors:
ERROR: could not access file "$libdir/plpython": No such file or directory
STATEME... | How do I install plpython on MacOs X 10.5? | I have just installed PostgreSQL 8.3.4 on Mac OS X 10.5 (using ports), but I cannot figure out how to enable PL/Python. When I run the CREATE LANGUAGE plpythonu I get the following errors:
ERROR: could not access file "$libdir/plpython": No such file or directory
STATEMENT: CREATE LANGUAGE plpythonu;
psql:<stdin>:18:... | [
"Silly me:\n[lib/postgresql83] > variants postgresql83\n postgresql83 has the variants:\n universal\n python: add support for python\n krb5: add support for Kerberos 5 authentication\n perl: add Perl support\n\n(I'd had universal.)\nThis means that you have to install the right variant of PostgreSQL to ... | [
3
] | [] | [] | [
"macos",
"postgresql",
"python"
] | stackoverflow_0000238882_macos_postgresql_python.txt |
Q:
Refactoring "to hit" values for a game
I'm making a game and one of the methods calculates a character's base hit numbers based on skill values. The method currently calculates each value individually, since each skill can be used at short, medium, and long range.
I originally thought I could combine the skills in... | Refactoring "to hit" values for a game | I'm making a game and one of the methods calculates a character's base hit numbers based on skill values. The method currently calculates each value individually, since each skill can be used at short, medium, and long range.
I originally thought I could combine the skills into a tuple and iterate over it, dynamically ... | [
"It feels like what you really want is a class representing the weapon, with attributes to handle the base values and calculate hit values with various modifiers. Here's a simple example:\nSHORT_RANGE = 'S'\nMEDIUM_RANGE = 'M'\nLONG_RANGE = 'L'\nSHORT_RANGE_MODIFIER = 0.6\nMEDIUM_RANGE_MODIFIER = 0.3\nLONG_RANGE_MO... | [
6,
1,
0,
0,
0
] | [] | [] | [
"python",
"refactoring"
] | stackoverflow_0000237876_python_refactoring.txt |
Q:
getting pywin32 to work inside open office 2.4 built in python 2.3 interpreter
I need to update data to a mssql 2005 database so I have decided to use adodbapi, which is supposed to come built into the standard installation of python 2.1.1 and greater.
It needs pywin32 to work correctly and the open office python ... | getting pywin32 to work inside open office 2.4 built in python 2.3 interpreter | I need to update data to a mssql 2005 database so I have decided to use adodbapi, which is supposed to come built into the standard installation of python 2.1.1 and greater.
It needs pywin32 to work correctly and the open office python 2.3 installation does not have pywin32 built into it. It also seems like this built ... | [
"maybe the best way to install pywin32 is to place it in \n(openofficedir)\\program\\python-core-2.3.4\\lib\\site-packages\nit is easy if you have a python 2.3 installation (with pywin installed) under \nC:\\python2.3 \nmove the C:\\python2.3\\Lib\\site-packages\\ to your\n(openofficedir)\\program\\python-core-2.3... | [
1,
0,
0
] | [] | [] | [
"adodbapi",
"openoffice.org",
"python",
"pywin32"
] | stackoverflow_0000239009_adodbapi_openoffice.org_python_pywin32.txt |
Q:
Python file interface for strings
Is there a Python class that wraps the file interface (read, write etc.) around a string? I mean something like the stringstream classes in C++.
I was thinking of using it to redirect the output of print into a string, like this
sys.stdout = string_wrapper()
print "foo", "bar", "b... | Python file interface for strings | Is there a Python class that wraps the file interface (read, write etc.) around a string? I mean something like the stringstream classes in C++.
I was thinking of using it to redirect the output of print into a string, like this
sys.stdout = string_wrapper()
print "foo", "bar", "baz"
s = sys.stdout.to_string() #now s =... | [
"Yes, there is StringIO:\nimport StringIO\nimport sys\n\n\nsys.stdout = StringIO.StringIO()\nprint \"foo\", \"bar\", \"baz\"\ns = sys.stdout.getvalue()\n\n",
"For better performance, note that you can also use cStringIO. But also note that this isn't very portable to python 3.\n"
] | [
12,
2
] | [] | [] | [
"file",
"python",
"string"
] | stackoverflow_0000239912_file_python_string.txt |
Q:
How do you programmatically reorder children of an ATFolder subclass?
I have Plone product that uses a custom folder type for containing a set of custom content objects. The folder type was created by subclassing BaseFolder and it has a schema with a couple of text fields. Currently, when custom objects are adde... | How do you programmatically reorder children of an ATFolder subclass? | I have Plone product that uses a custom folder type for containing a set of custom content objects. The folder type was created by subclassing BaseFolder and it has a schema with a couple of text fields. Currently, when custom objects are added to the custom folder, the objects are sorted alphabetically by their id. ... | [
"Quickest solution: subclass from ATFolder instead of BaseFolder. That gives you all the \"normal\" reordering and other commmon plone folder capabilities (which I suspect you also want).\nIf you want to be more selective, look into Products/ATContentTypes/content/base.py: ATCTOrderedFolder and OrderedBaseFolder.\n... | [
4
] | [] | [] | [
"archetypes",
"plone",
"python",
"zope"
] | stackoverflow_0000237211_archetypes_plone_python_zope.txt |
Q:
How can I call a DLL from a scripting language?
I have a third-party product, a terminal emulator, which provides a DLL that can be linked to a C program to basically automate the driving of this product (send keystrokes, detect what's on the screen and so forth).
I want to drive it from a scripting language (I'm ... | How can I call a DLL from a scripting language? | I have a third-party product, a terminal emulator, which provides a DLL that can be linked to a C program to basically automate the driving of this product (send keystrokes, detect what's on the screen and so forth).
I want to drive it from a scripting language (I'm comfortable with Python and slightly less so with Per... | [
"One way to call C libraries from Python is to use ctypes:\n>>> from ctypes import *\n>>> windll.user32.MessageBoxA(None, \"Hello world\", \"ctypes\", 0);\n\n",
"In Perl, Win32::API is an easy way to some interfacing to DLLs. There is also Inline::C, if you have access to a compiler and the windows headers.\nPerl... | [
15,
12,
5,
4,
3
] | [] | [] | [
"dll",
"perl",
"python"
] | stackoverflow_0000239020_dll_perl_python.txt |
Q:
I want a program that writes every possible combination to a different line of a text file
I want to write a program that would print every combination of a set of variables to a text file, creating a word list. Each answer should be written on a separate line and write all of the results for 1 digit, 2 digits, an... | I want a program that writes every possible combination to a different line of a text file | I want to write a program that would print every combination of a set of variables to a text file, creating a word list. Each answer should be written on a separate line and write all of the results for 1 digit, 2 digits, and 3 digits to a single text file.
Is there a simple way I can write a python program that can ac... | [
"# Given two lists of strings, return a list of all ways to concatenate\n# one from each.\ndef combos(xs, ys):\n return [x + y for x in xs for y in ys]\n\ndigits = ['0', '1']\nfor c in combos(digits, combos(digits, digits)):\n print c\n\n#. 000\n#. 001\n#. 010\n#. 011\n#. 100\n#. 101\n#. 110\n#. 111\n\n",
"... | [
3,
3,
2,
2
] | [] | [] | [
"python",
"recursion"
] | stackoverflow_0000241533_python_recursion.txt |
Q:
Environment Variables in Python on Linux
Python's access to environment variables does not accurately reflect the operating system's view of the processes environment.
os.getenv and os.environ do not function as expected in particular cases.
Is there a way to properly get the running process' environment?
To demo... | Environment Variables in Python on Linux | Python's access to environment variables does not accurately reflect the operating system's view of the processes environment.
os.getenv and os.environ do not function as expected in particular cases.
Is there a way to properly get the running process' environment?
To demonstrate what I mean, take the two roughly equi... | [
"That's a very good question.\nIt turns out that the os module initializes os.environ to the value of posix.environ, which is set on interpreter start up. In other words, the standard library does not appear to provide access to the getenv function.\nThat is a case where it would probably be safe to use ctypes on u... | [
16,
12,
4,
3,
1
] | [] | [] | [
"environment_variables",
"gdb",
"python"
] | stackoverflow_0000235435_environment_variables_gdb_python.txt |
Q:
Reading collections of extended elements in an RSS feed with Universal Feed Parser
Is there any way to read a collection of extension elements with Universal Feed Parser?
This is just a short snippet from Kuler RSS feed:
<channel>
<item>
<!-- snip: regular RSS elements -->
<kuler:themeItem>
<kuler:... | Reading collections of extended elements in an RSS feed with Universal Feed Parser | Is there any way to read a collection of extension elements with Universal Feed Parser?
This is just a short snippet from Kuler RSS feed:
<channel>
<item>
<!-- snip: regular RSS elements -->
<kuler:themeItem>
<kuler:themeID>123456</kuler:themeID>
<!-- snip -->
<kuler:themeSwatches>
<... | [
"Universal Feed Parser is really nice for most feeds, but for extended feeds, you might wanna try something called BeautifulSoup. It's an XML/HTML/XHTML parsing library which is originally designed for screenscraping; turns out it's also brilliant for this sort of thing. The documentation is pretty good, and it's g... | [
3
] | [] | [] | [
"adobe",
"feed",
"python",
"rss"
] | stackoverflow_0000241503_adobe_feed_python_rss.txt |
Q:
WindowsError: priveledged instruction when saving a FreeImagePy Image in script, works in IDLE
I'm working on a program to do some image wrangling in Python for work. I'm using FreeImagePy because PIL doesn't support multi-page TIFFs. Whenever I try to save a file with it from my program I get this error message... | WindowsError: priveledged instruction when saving a FreeImagePy Image in script, works in IDLE | I'm working on a program to do some image wrangling in Python for work. I'm using FreeImagePy because PIL doesn't support multi-page TIFFs. Whenever I try to save a file with it from my program I get this error message (or something similar depending on which way I try to save):
Error returned. TIFF FreeImage_Save: ... | [
"Looks like a permission issues, make sure you don't have the file open in another application, and that you have write permissions to the file location your trying to write to.\n",
"That's what I thought too, but I figured it out a couple hours ago. Apparently if the directory/file I'm trying to write to doesn'... | [
1,
0
] | [] | [] | [
"exception",
"python",
"windowserror"
] | stackoverflow_0000240031_exception_python_windowserror.txt |
Q:
What would you recommend for a high traffic ajax intensive website?
For a website like reddit with lots of up/down votes and lots of comments per topic what should I go with?
Lighttpd/Php or Lighttpd/CherryPy/Genshi/SQLAlchemy?
and for database what would scale better / be fastest MySQL ( 4.1 or 5 ? ) or PostgreSQ... | What would you recommend for a high traffic ajax intensive website? | For a website like reddit with lots of up/down votes and lots of comments per topic what should I go with?
Lighttpd/Php or Lighttpd/CherryPy/Genshi/SQLAlchemy?
and for database what would scale better / be fastest MySQL ( 4.1 or 5 ? ) or PostgreSQL?
| [
"I can't speak to the MySQL/PostgreSQL question as I have limited experience with Postgres, but my Masters research project was about high-performance websites with CherryPy, and I don't think you'll be disappointed if you use CherryPy for your site. It can easily scale to thousands of simultaneous users on commod... | [
8,
8,
3,
2,
2
] | [] | [] | [
"cherrypy",
"high_load",
"lighttpd",
"php",
"python"
] | stackoverflow_0000204802_cherrypy_high_load_lighttpd_php_python.txt |
Q:
How does one add a svn repository build number to Python code?
EDIT: This question duplicates How to access the current Subversion build number? (Thanks for the heads up, Charles!)
Hi there,
This question is similar to Getting the subversion repository number into code
The differences being:
I would like to add ... | How does one add a svn repository build number to Python code? |
EDIT: This question duplicates How to access the current Subversion build number? (Thanks for the heads up, Charles!)
Hi there,
This question is similar to Getting the subversion repository number into code
The differences being:
I would like to add the revision number to Python
I want the revision of the repository... | [
"There is a command called svnversion which comes with subversion and is meant to solve exactly that kind of problem.\n",
"Stolen directly from django:\ndef get_svn_revision(path=None):\n rev = None\n if path is None:\n path = MODULE.__path__[0]\n entries_path = '%s/.svn/entries' % path\n\n if ... | [
3,
3,
2,
1,
1,
0
] | [] | [] | [
"python",
"svn"
] | stackoverflow_0000242295_python_svn.txt |
Q:
How do I get the name of a function or method from within a Python function or method?
I feel like I should know this, but I haven't been able to figure it out...
I want to get the name of a method--which happens to be an integration test--from inside it so it can print out some diagnostic text. I can, of course,... | How do I get the name of a function or method from within a Python function or method? | I feel like I should know this, but I haven't been able to figure it out...
I want to get the name of a method--which happens to be an integration test--from inside it so it can print out some diagnostic text. I can, of course, just hard-code the method's name in the string, but I'd like to make the test a little more... | [
"This seems to be the simplest way using module inspect:\nimport inspect\ndef somefunc(a,b,c):\n print \"My name is: %s\" % inspect.stack()[0][3]\n\nYou could generalise this with:\ndef funcname():\n return inspect.stack()[1][3]\n\ndef somefunc(a,b,c):\n print \"My name is: %s\" % funcname()\n\nCredit to S... | [
57,
24,
16,
10,
3
] | [] | [] | [
"python"
] | stackoverflow_0000245304_python.txt |
Q:
Upload a file in Django and then send it somewhere else through REST?
I am building a simple Django app that will use scribd to display documents. I would like to have a page where the administrator can upload documents to scribd through the website, since I need to know a few things about it before it gets to scr... | Upload a file in Django and then send it somewhere else through REST? | I am building a simple Django app that will use scribd to display documents. I would like to have a page where the administrator can upload documents to scribd through the website, since I need to know a few things about it before it gets to scribd. What is the best/easiest way to do this, display an upload page and th... | [
"That is quite a few questions. \nHandling the file upload is pretty straight-forward with Django, see the File Uploads documentation for examples. In short you can access the uploaded file via request.FILES['file'].\nTo call the scribd api you can use urllib2; see this Hackoarama page for instructions. urllib2 can... | [
3,
1
] | [] | [] | [
"api",
"django",
"python",
"rest",
"scribd"
] | stackoverflow_0000245725_api_django_python_rest_scribd.txt |
Q:
Porting MATLAB functions to Scilab. How do I use symbolic?
I'm porting some MATLAB functions to Scilab. The cool thing is that there is a conversion toolbox that make things very easy.
The problem is I did not find the counterpart to the syms function, and the symbolic toolbox in general. (I'd like a port of the C... | Porting MATLAB functions to Scilab. How do I use symbolic? | I'm porting some MATLAB functions to Scilab. The cool thing is that there is a conversion toolbox that make things very easy.
The problem is I did not find the counterpart to the syms function, and the symbolic toolbox in general. (I'd like a port of the Control System Toolbox too, amd I'm still searching for some func... | [
"See Bye MATLAB, hello Python, thanks Sage for a first-hand experience of migrating from MATLAB to Python.\n",
"Not to discourage your project, but if you just want a free and open source alternative to MATLAB, have you looked at the Octave project? Contributing there might be more productive than building your o... | [
3,
1
] | [] | [] | [
"matlab",
"porting",
"python",
"scilab",
"sympy"
] | stackoverflow_0000244803_matlab_porting_python_scilab_sympy.txt |
Q:
Microphone access in Python
Can I access a users microphone in Python?
Sorry I forgot not everyone is a mind reader:
Windows at minimum XP but Vista support would be VERY good.
A:
I got the job done with pyaudio
It comes with a binary installer for windows and there's even an example on how to record through the... | Microphone access in Python | Can I access a users microphone in Python?
Sorry I forgot not everyone is a mind reader:
Windows at minimum XP but Vista support would be VERY good.
| [
"I got the job done with pyaudio\nIt comes with a binary installer for windows and there's even an example on how to record through the microphone and save to a wave file. Nice! I used it on Windows XP, not sure how it will do on Vista though, sorry.\n",
"Best way to go about it would be to use the ctypes library... | [
17,
4,
2
] | [] | [] | [
"microphone",
"python",
"windows"
] | stackoverflow_0000193789_microphone_python_windows.txt |
Q:
Alternatives to a wizard
I'm making a program that fits the wizard concept ideally; the user is walked through the steps to create a character for a game.
However, I'm realizing that the limitations of the wizard are making it difficult to design "elegant" logic flow. For example, because all pages of the wizard a... | Alternatives to a wizard | I'm making a program that fits the wizard concept ideally; the user is walked through the steps to create a character for a game.
However, I'm realizing that the limitations of the wizard are making it difficult to design "elegant" logic flow. For example, because all pages of the wizard are initalized at the same time... | [
"Here is a simple example. This way you can make your \"wizard\" work like a finite state machine where states are different pages that are initialized on demand. Also, the data is shared between pages.\nimport wx\nimport wx.lib.newevent\n\n\n(PageChangeEvent, EVT_PAGE_CHANGE) = wx.lib.newevent.NewEvent()\n\n\nclas... | [
5,
1,
0,
0,
0
] | [] | [] | [
"python",
"wizard",
"wxpython"
] | stackoverflow_0000224337_python_wizard_wxpython.txt |
Q:
Map two lists into one single list of dictionaries
Imagine I have these python lists:
keys = ['name', 'age']
values = ['Monty', 42, 'Matt', 28, 'Frank', 33]
Is there a direct or at least a simple way to produce the following list of dictionaries ?
[
{'name': 'Monty', 'age': 42},
{'name': 'Matt', 'age': 2... | Map two lists into one single list of dictionaries | Imagine I have these python lists:
keys = ['name', 'age']
values = ['Monty', 42, 'Matt', 28, 'Frank', 33]
Is there a direct or at least a simple way to produce the following list of dictionaries ?
[
{'name': 'Monty', 'age': 42},
{'name': 'Matt', 'age': 28},
{'name': 'Frank', 'age': 33}
]
| [
"Here is the zip way\ndef mapper(keys, values):\n n = len(keys)\n return [dict(zip(keys, values[i:i + n]))\n for i in range(0, len(values), n)]\n\n",
"It's not pretty but here's a one-liner using a list comprehension, zip and stepping:\n[dict(zip(keys, a)) for a in zip(values[::2], values[1::2])]... | [
14,
3,
2,
2,
2,
1,
1,
0
] | [] | [] | [
"dictionary",
"list",
"python"
] | stackoverflow_0000244438_dictionary_list_python.txt |
Q:
HTTP compliance testing
What would you use to perform a compliance testing of an HTTP proxy? I've seen two projects so far:
Web Polygraph (the feedback I got from a coworker is mostly negative)
Funkload
A:
Take a look here: http://www.measurement-factory.com/
The Co-Advisor product might be what you are after. ... | HTTP compliance testing | What would you use to perform a compliance testing of an HTTP proxy? I've seen two projects so far:
Web Polygraph (the feedback I got from a coworker is mostly negative)
Funkload
| [
"Take a look here: http://www.measurement-factory.com/\nThe Co-Advisor product might be what you are after. Note that this is by the same mob that created Web-Polygraph/\n"
] | [
1
] | [] | [] | [
"http",
"python",
"standards_compliance",
"testing"
] | stackoverflow_0000246123_http_python_standards_compliance_testing.txt |
Q:
Is there something between a normal user account and root?
I'm developing an application that manages network interfaces on behalf of the user and it calls out to several external programs (such as ifconfig) that requires root to make changes. (Specifically, changing the IP address of a local interface, etc.) Duri... | Is there something between a normal user account and root? | I'm developing an application that manages network interfaces on behalf of the user and it calls out to several external programs (such as ifconfig) that requires root to make changes. (Specifically, changing the IP address of a local interface, etc.) During development, I have been running the IDE as root (ugh) and th... | [
"Your idea about the daemon has much merit, despite the complexity it introduces. As long as the actions don't require some user interface interaction as root, a daemon allows you to control what operations are allowed and disallowed.\nHowever, you can use SUDO to create a controlled compromise between ROOT and nor... | [
7,
3,
1,
1,
1,
0,
0
] | [] | [] | [
"linux",
"python",
"root"
] | stackoverflow_0000248730_linux_python_root.txt |
Q:
Translate SVN path to local file system path in Python
I'm writing a utility in Python that will attach changed files in Subversion to an email and send it when a subset of folders that are under source control in SVN have been changed. I am using the pysvn library to access the repository.
I have a copy of the f... | Translate SVN path to local file system path in Python | I'm writing a utility in Python that will attach changed files in Subversion to an email and send it when a subset of folders that are under source control in SVN have been changed. I am using the pysvn library to access the repository.
I have a copy of the files on my local file system and I do an update to check if ... | [
"Stay with the slice operator, but do not change the loop variable inside the loop. for fun, try the generator expression (or keep the listcomp).\nbaselen = len(self.basePath)\nreturn (path[baselen:].replace(\"/\", \"\\\\\") for path in paths)\n\nEdit: `lstrip()' is not relevant here. From the manual:\n\nstr.lstrip... | [
3,
0,
0
] | [] | [] | [
"python",
"svn"
] | stackoverflow_0000249330_python_svn.txt |
Q:
How to determine if a directory is on same partition
Say I have an input file, and a target directory. How do I determine if the input file is on the same hard-drive (or partition) as the target directory?
What I want to do is the copy a file if it's on a different, but move it if it's the same. For example:
targe... | How to determine if a directory is on same partition | Say I have an input file, and a target directory. How do I determine if the input file is on the same hard-drive (or partition) as the target directory?
What I want to do is the copy a file if it's on a different, but move it if it's the same. For example:
target_directory = "/Volumes/externalDrive/something/"
input_fo... | [
"In C, you would use stat() and compare the st_dev field. In python, os.stat should do the same.\nimport os\ndef same_partition(f1, f2):\n return os.stat(f1).st_dev == os.stat(f2).st_dev\n\n",
"Another way is the “better to ask forgiveness than permission” approach—just try to rename it, and if that fails, cat... | [
13,
3
] | [] | [] | [
"filesystems",
"linux",
"macos",
"python"
] | stackoverflow_0000249775_filesystems_linux_macos_python.txt |
Q:
What is the best way to serve static web pages from within a Django application?
I am building a relatively simple Django application and apart from the main page where most of the dynamic parts of the application are, there are a few pages that I will need that will not be dynamic at all (About, FAQ, etc.). What ... | What is the best way to serve static web pages from within a Django application? | I am building a relatively simple Django application and apart from the main page where most of the dynamic parts of the application are, there are a few pages that I will need that will not be dynamic at all (About, FAQ, etc.). What is the best way to integrate these into Django, idealing still using the Django templa... | [
"Have you looked at flat pages in Django? It probably does everything you're looking for.\n",
"If you want to just create a template for each of them, you could use the direct_to_template generic view to serve it up.\nAnother option would be the django.contrib.flatpages app, which would let you configure the sta... | [
7,
6
] | [] | [] | [
"django",
"python",
"static",
"templates"
] | stackoverflow_0000252035_django_python_static_templates.txt |
Q:
Is it possible to communicate with a sub subprocess with subprocess.Popen?
I'm trying to write a python script that packages our software. This script needs to build our product, and package it. Currently we have other scripts that do each piece individually which include csh, and perl scripts. One such script is ... | Is it possible to communicate with a sub subprocess with subprocess.Popen? | I'm trying to write a python script that packages our software. This script needs to build our product, and package it. Currently we have other scripts that do each piece individually which include csh, and perl scripts. One such script is run like:
sudo mod args
where mod is a perl script; so in python I would do
pr... | [
"I think you should remove the sudo in your Popen call and require the user of your script to type sudo.\nThis additionally makes more explicit the need for elevated privileges in your script, instead of hiding it inside Popen.\n",
"I would choose to go with Pexpect. \nimport pexpect\nchild = pexpect.spawn ('sudo... | [
4,
4,
1,
0
] | [] | [] | [
"python",
"subprocess"
] | stackoverflow_0000250700_python_subprocess.txt |
Q:
Python: using a recursive algorithm as a generator
Recently I wrote a function to generate certain sequences with nontrivial constraints. The problem came with a natural recursive solution. Now it happens that, even for relatively small input, the sequences are several thousands, thus I would prefer to use my algo... | Python: using a recursive algorithm as a generator | Recently I wrote a function to generate certain sequences with nontrivial constraints. The problem came with a natural recursive solution. Now it happens that, even for relatively small input, the sequences are several thousands, thus I would prefer to use my algorithm as a generator instead of using it to fill a list ... | [
"def getPermutations(string, prefix=\"\"):\n if len(string) == 1:\n yield prefix + string\n else:\n for i in xrange(len(string)):\n for perm in getPermutations(string[:i] + string[i+1:], prefix+string[i]):\n yield perm\n\nOr without an accumulator:\ndef getPermutations(... | [
118,
29,
20
] | [] | [] | [
"generator",
"python",
"recursion"
] | stackoverflow_0000248830_generator_python_recursion.txt |
Q:
How do I coherently organize modules for a PyGTK desktop application?
I am working on a desktop application in PyGTK and seem to be bumping up against some limitations of my file organization. Thus far I've structured my project this way:
application.py - holds the primary application class (most functional rout... | How do I coherently organize modules for a PyGTK desktop application? | I am working on a desktop application in PyGTK and seem to be bumping up against some limitations of my file organization. Thus far I've structured my project this way:
application.py - holds the primary application class (most functional routines)
gui.py - holds a loosely coupled GTK gui implementation. Handles sig... | [
"In the project Wader we use python gtkmvc, that makes much easier to apply the MVC patterns when using pygtk and glade, you can see the file organization of our project in the svn repository:\nwader/\n cli/\n common/\n contrib/\n gtk/\n controllers/\n models/\n views/\n test/\n utils/\n\n",
"This ... | [
7,
2,
2,
2,
0,
0
] | [] | [] | [
"gtk",
"module",
"organization",
"pygtk",
"python"
] | stackoverflow_0000216093_gtk_module_organization_pygtk_python.txt |
Q:
script languages on windows mobile - something similar to python @ nokia s60
I try to find something similar to nokia's python for windows mobile based devices - a script interpreter [in this case also able to create standalone apps] with easy access to all phone interfaces - ability to make a phone call, send SMS... | script languages on windows mobile - something similar to python @ nokia s60 | I try to find something similar to nokia's python for windows mobile based devices - a script interpreter [in this case also able to create standalone apps] with easy access to all phone interfaces - ability to make a phone call, send SMS, make a photo, send a file over GPRS, etc...
While there is 2.5 pythonce availabl... | [
"It sounds as if this is an opportunity for you to develop some C extension modules for the PythonCE project.\n",
"Well there is Mortscript. a widely used scripting for Windows Mobile. Not sure if it can access all the phones functions. I believe there is TCL for Windows Mobile as well.\n",
"IronPython?\n"
] | [
3,
0,
0
] | [] | [] | [
"mobile",
"python",
"windows_mobile"
] | stackoverflow_0000251506_mobile_python_windows_mobile.txt |
Q:
Why won't Django 1.0 admin application work?
I've just started playing with Django and am loosely following the tutorial with my own set of basic requirements. The models I've sketched out so far are a lot more comprehensive than the tutorial, but they compile fine. Otherwise, everything should have been the same.... | Why won't Django 1.0 admin application work? | I've just started playing with Django and am loosely following the tutorial with my own set of basic requirements. The models I've sketched out so far are a lot more comprehensive than the tutorial, but they compile fine. Otherwise, everything should have been the same.
My problem is with the admin application. I can l... | [
"It's because you left out a / in urls.py. Change the admin line to the following:\n(r'^admin/(.*)', admin.site.root),\n\nI checked this on my server and got the same error with your line from urls.py.\n"
] | [
12
] | [] | [] | [
"admin",
"django",
"python"
] | stackoverflow_0000252531_admin_django_python.txt |
Q:
Finding invocations of a certain function in a c++ file using python
I need to find all occurrences of a function call in a C++ file using python, and extract the arguments for each call.
I'm playing with the pygccxml package, and extracting the arguments given a string with the function call is extremely easy:
fr... | Finding invocations of a certain function in a c++ file using python | I need to find all occurrences of a function call in a C++ file using python, and extract the arguments for each call.
I'm playing with the pygccxml package, and extracting the arguments given a string with the function call is extremely easy:
from pygccxml.declarations import call_invocation
def test_is_call_invocati... | [
"XML-GCC can't do that, because it only reports the data types (and function signatures). It ignores the function bodies. To see that, create a.cc:\nvoid foo()\n{}\n\nvoid bar()\n{\n foo();\n}\n\nand then run gccxml a.cc -fxml=a.xml. Look at the generated a.xml, to see that the only mentioning of foo (or its... | [
2
] | [] | [] | [
"c++",
"parsing",
"python"
] | stackoverflow_0000252951_c++_parsing_python.txt |
Q:
How to configure the import path in Visual Studio IronPython projects
I have built the IronPythonIntegration solution that comes with the Visual Studio 2005 SDK (as explained at http://www.izume.com/2007/10/13/integrating-ironpython-with-visual-studio-2005), and I can now use IronPython projects inside Visual Stud... | How to configure the import path in Visual Studio IronPython projects | I have built the IronPythonIntegration solution that comes with the Visual Studio 2005 SDK (as explained at http://www.izume.com/2007/10/13/integrating-ironpython-with-visual-studio-2005), and I can now use IronPython projects inside Visual Studio 2005. However, to let a Python file import from the standard library I n... | [
"Set the environment variable IRONPYTHONPATH in your operating system to 'c:\\Python24\\lib'. (Or anywhere else you need).\n"
] | [
2
] | [] | [] | [
"ironpython",
"ironpython_studio",
"python",
"visual_studio"
] | stackoverflow_0000253018_ironpython_ironpython_studio_python_visual_studio.txt |
Q:
Looking a generic Python script to add a field and populate the field with conditions
I am looking for a script to allow users to add a text field to a .dbf table(e.g. landuse categories) and allow them to input/update the rows basing on what values in the GRIDCODE (numeric categories) field they think should be a... | Looking a generic Python script to add a field and populate the field with conditions | I am looking for a script to allow users to add a text field to a .dbf table(e.g. landuse categories) and allow them to input/update the rows basing on what values in the GRIDCODE (numeric categories) field they think should be assigned into text categories.i.e. if GRIDCODE value is 4, the corresponding field value of... | [
"When you say dbf table, are you referring to ESRI shape file dbf files, which are in fact dbase files? If so you could implement such a thing pretty easily with the python wrapper for shapelib, which also supports dbf files.\n"
] | [
2
] | [] | [] | [
"python",
"sql",
"sql_update"
] | stackoverflow_0000253761_python_sql_sql_update.txt |
Q:
What Python bindings are there for CVS or SVN?
I once did a cursory search and found no good CVS bindings for Python. I wanted to be able to write helper scripts to do some fine-grained manipulation of the repository and projects in it. I had to resort to using popen and checking stdout and stderr and then parsi... | What Python bindings are there for CVS or SVN? | I once did a cursory search and found no good CVS bindings for Python. I wanted to be able to write helper scripts to do some fine-grained manipulation of the repository and projects in it. I had to resort to using popen and checking stdout and stderr and then parsing those. It was messy and error-prone.
Are there a... | [
"For cvs, pyCVS may be worth a look.\nFor svn, there is pysvn, which is pretty good.\n",
"Tailor, a Python program which lets different version control systems interoperate, simply calls the external programs cvs and svn when working with repositories of those formats. This seems pretty ugly, but reduces Tailor'... | [
8,
1
] | [] | [] | [
"cvs",
"python",
"svn",
"version_control"
] | stackoverflow_0000253375_cvs_python_svn_version_control.txt |
Q:
Bizarre python ImportError
Here's my setup: a Mac, running OS X Tiger. Windows XP running in a virtual machine (Parallels). Windows XP has my Mac home directory mapped as a network drive.
I have two files in a directory of my Mac home directory:
foo.py
pass
test.py
import foo
If I run test.py from within my vi... | Bizarre python ImportError | Here's my setup: a Mac, running OS X Tiger. Windows XP running in a virtual machine (Parallels). Windows XP has my Mac home directory mapped as a network drive.
I have two files in a directory of my Mac home directory:
foo.py
pass
test.py
import foo
If I run test.py from within my virtual machine by typing 'python ... | [
"Add import sys; print sys.path to the start of test.py. See what it prints out in the failing case. If \".\" isn't on the list, that may be your problem.\n",
"As a random guess: are the permissions on foo.py accessable from the windows client? (eg try opening with notepad from the virtual machine).\nIf that's ... | [
2,
1
] | [] | [] | [
"import",
"python",
"windows_xp"
] | stackoverflow_0000252287_import_python_windows_xp.txt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.