2,209,294 questions
25
votes
13
answers
82k
views
Best way to extract text from a Word doc without using COM/automation? [closed]
Is there a reasonable way to extract plain text from a Word file that doesn't depend on COM automation? (This is a a feature for a web app deployed on a non-Windows platform - that's non-negotiable ...
59
votes
12
answers
56k
views
What is a tuple useful for? [closed]
I am learning Python for a class now, and we just covered tuples as one of the data types. I read the Wikipedia page on it, but, I could not figure out where such a data type would be useful in ...
13
votes
9
answers
10k
views
Splitting tuples in Python - best practice?
I have a method in my Python code that returns a tuple - a row from a SQL query. Let's say it has three fields: (jobId, label, username)
For ease of passing it around between functions, I've been ...
35
votes
8
answers
33k
views
Always including the user in the django template context
I am working on a small intranet site for a small company, where user should be able to post. I have imagined a very simple authentication mechanism where people just enter their email address, and ...
2
votes
1
answer
5k
views
cx_Oracle: how do I get the ORA-xxxxx error number?
In a try/except block, how do I extract the Oracle error number?
7
votes
2
answers
3k
views
PGP signatures from Python?
What is the easiest way to create and verify PGP/GPG signatures from within a Python application?
I can call pgp or gpg using subprocess and parse the output, but I was looking for a way that didn't ...
27
votes
2
answers
15k
views
What is the best way to do Bit Field manipulation in Python?
I'm reading some MPEG Transport Stream protocol over UDP and it has some funky bitfields in it (length 13 for example). I'm using the "struct" library to do the broad unpacking, but is there a simple ...
386
votes
13
answers
662k
views
Search and replace a line in a file in Python
I want to loop over the contents of a text file and do a search and replace on some lines and write the result back to the file. I could first load the whole file in memory and then write it back, but ...
183
votes
18
answers
141k
views
Using Django time/date widgets in custom form
How can I use the nifty JavaScript date and time widgets that the default admin uses with my custom view?
I have looked through the Django forms documentation, and it briefly mentions django.contrib....
3
votes
2
answers
2k
views
Retrieving an Oracle timestamp using Python's Win32 ODBC module
Given an Oracle table created using the following:
CREATE TABLE Log(WhenAdded TIMESTAMP(6) WITH TIME ZONE);
Using the Python ODBC module from its Win32 extensions (from the win32all package), I tried ...
4
votes
3
answers
732
views
Why is the subprocess.Popen class not named Subprocess? [closed]
The primary class in the subprocess module is name Popen, and represents a subprocess. Popen sounds like someone was trying to force the name to follow some function naming format, rather than chosing ...
24
votes
6
answers
32k
views
What's the easiest way to read a FoxPro DBF file from Python?
I've got a bunch of FoxPro (VFP9) DBF files on my Ubuntu system, is there a library to open these in Python? I only need to read them, and would preferably have access to the memo fields too.
Update:...
1
vote
6
answers
562
views
How can I simply inherit methods from an existing instance?
Below I have a very simple example of what I'm trying to do. I want to be able to use HTMLDecorator with any other class. Ignore the fact it's called decorator, it's just a name.
import cgi
class ...
65
votes
8
answers
47k
views
Resources for lexing, tokenising and parsing in python
Can people point me to resources on lexing, parsing and tokenising with Python?
I'm doing a little hacking on an open source project (hotwire) and wanted to do a few changes to the code that lexes, ...
3488
votes
28
answers
1.5m
views
What does ** (double star/asterisk) and * (star/asterisk) do for parameters?
What do *args and **kwargs mean in these function definitions?
def foo(x, y, *args):
pass
def bar(x, y, **kwargs):
pass
See What do ** (double star/asterisk) and * (star/asterisk) mean in a ...
13
votes
4
answers
12k
views
Setup django with WSGI and apache
I have been sold on mod_wsgi and apache rather than mod_python.
I have all the parts installed (django, apache, mod_wsgi) but have run into a problem deploying.
I am on osx 10.5 with apache 2.2 and ...
14
votes
1
answer
18k
views
"The system cannot find the file specified" when invoking subprocess.Popen in python
I'm trying to use svnmerge.py to merge some files. Under the hood it uses python, and when I use it I get an error - "The system cannot find the file specified". Colleagues at work are ...
711
votes
28
answers
1.0m
views
C-like structures in Python
Is there a way to conveniently define a C-like structure in Python? I'm tired of writing stuff like:
class MyStruct():
def __init__(self, field1, field2, field3):
self.field1 = field1
...
147
votes
10
answers
125k
views
How to escape os.system() calls?
When using os.system() it's often necessary to escape filenames and other arguments passed as parameters to commands. How can I do this? Preferably something that would work on multiple operating ...
29
votes
13
answers
30k
views
Is Python good for big software projects (not web based)? [closed]
Right now I'm developing mostly in C/C++, but I wrote some small utilities in Python to automatize some tasks and I really love it as language (especially the productivity).
Except for the ...
14
votes
1
answer
878
views
Why does Python's iter() on a mapping return iterkeys() instead of iteritems()?
It seems like if you want to get the keys of a mapping, you ask for them; otherwise, give me the whole mapping (constituted by a set of key-value pairs). Is there a historical reason for this?
10
votes
3
answers
2k
views
Scaffolding in pylons
Is there anything similar to rails' scaffolding for pylons? I've been poking around google, but only found this thing called dbsprockets, which is fine, although probably way too much for my needs. ...
11
votes
4
answers
9k
views
How do I make Windows aware of a service I have written in Python?
In another question I posted yesterday, I got very good advice on how a Python script could be run as a service in Windows. What I'm left wondering is: How is Windows aware of the services that can be ...
6
votes
3
answers
1k
views
Django ImageField core=False in newforms admin
In the transition to newforms admin I'm having difficulty figuring out how specify core=False for ImageFields.
I get the following error:
TypeError: __init__() got an unexpected keyword argument '...
28
votes
6
answers
13k
views
Are Python threads buggy?
A reliable coder friend told me that Python's current multi-threading implementation is seriously buggy - enough to avoid using altogether. What can said about this rumor?