2,209,294 questions
1
vote
6
answers
2k
views
Classes in Python
In Python is there any way to make a class, then make a second version of that class with identical dat,a but which can be changed, then reverted to be the same as the data in the original class?
So ...
-1
votes
3
answers
1k
views
Which is the most useful Mercurial hook for programming in a loosely connected team?
I recently discovered the notify extension in Mercurial which allows me quickly send out emails whenever I push changes, but I'm pretty sure I'm still missing out on a lot of functionality which could ...
53
votes
16
answers
118k
views
Ignore case in Python strings [duplicate]
What is the easiest way to compare strings in Python, ignoring case?
Of course one can do (str1.lower() <= str2.lower()), etc., but this created two additional temporary strings (with the obvious ...
5
votes
2
answers
5k
views
What's a good way to find relative paths in Google App Engine?
So I've done the trivial "warmup" apps with GAE. Now I'd like to build something with a more complex directory structure. Something along the lines of:
siteroot/
models/
controllers/
...
95
votes
9
answers
78k
views
Is it pythonic for a function to return multiple values?
In python, you can have a function return multiple values. Here's a contrived example:
def divide(x, y):
quotient = x/y
remainder = x % y
return quotient, remainder
(q, r) = divide(22,...
577
votes
18
answers
147k
views
Where do the Python unit tests go? [closed]
If you're writing a library, or an app, where do the unit test files go?
It's nice to separate the test files from the main app code, but it's awkward to put them into a "tests" subdirectory inside ...
107
votes
9
answers
61k
views
Getting random row through SQLAlchemy
How do I select one or more random rows from a table using SQLAlchemy?
22
votes
3
answers
40k
views
How do I write a python HTTP server to listen on multiple ports?
I'm writing a small web server in Python, using BaseHTTPServer and a custom subclass of BaseHTTPServer.BaseHTTPRequestHandler. Is it possible to make this listen on more than one port?
What I'm doing ...
-1
votes
2
answers
2k
views
Can distutils create empty __init__.py files?
If all of my __init__.py files are empty, do I have to store them into version control, or is there a way to make distutils create empty __init__.py files during installation?
12
votes
8
answers
23k
views
Automate firefox with python? [closed]
Been scouring the net for something like firewatir but for python. I'm trying to automate firefox on linux. Any suggestions?
3
votes
6
answers
19k
views
Storing multiple arrays in Python
I am writing a program to simulate the actual polling data companies like Gallup or Rasmussen publish daily: www.gallup.com and www.rassmussenreports.com
I'm using a brute force method, where the ...
107
votes
5
answers
189k
views
How to document Python code using Doxygen [closed]
I like Doxygen to create documentation of C or PHP code. I have an upcoming Python project and I think I remember that Python doesn't have /* .. */ comments, and also has its own self-documentation ...
17
votes
2
answers
8k
views
Does re.compile() or any given Python library call throw an exception?
I can't tell from the Python documentation whether the re.compile(x) function may throw an exception (assuming you pass in a string). I imagine there is something that could be considered an invalid ...
147
votes
21
answers
299k
views
round() doesn't seem to be rounding properly
The documentation for the round() function states that you pass it a number, and the positions past the decimal to round. Thus it should do this:
n = 5.59
round(n, 1) # 5.6
But, in actuality, good ...
717
votes
19
answers
895k
views
Single quotes vs. double quotes in Python [closed]
According to the documentation, they're pretty much interchangeable. Is there a stylistic reason to use one over the other?
6
votes
3
answers
2k
views
How can I get Emacs' key bindings in Python's IDLE?
I use Emacs primarily for coding Python but sometimes I use IDLE. Is there a way to change the key bindings easily in IDLE to match Emacs?
113
votes
15
answers
52k
views
What's the best Django search app? [closed]
I'm building a Django project that needs search functionality, and until there's a django.contrib.search, I have to choose a search app. So, which is the best? By "best" I mean...
easy to install / ...
14
votes
11
answers
12k
views
Any good AJAX framework for Google App Engine apps? [closed]
I am trying to implement AJAX in my Google App Engine application, and so I am looking for a good AJAX framework that will help me. Anyone has any idea?
I am thinking about Google Web Toolkit, how ...
16
votes
6
answers
1k
views
What are some strategies to write python code that works in CPython, Jython and IronPython
Having tries to target two of these environments at the same time I can safely say the if you have to use a database etc. you end up having to write unique code for that environment. Have you got a ...
267
votes
12
answers
252k
views
What are some good Python ORM solutions? [closed]
I'm evaluating and looking at using CherryPy for a project that's basically a JavaScript front-end from the client-side (browser) that talks to a Python web service on the back-end. So, I really need ...
6
votes
3
answers
2k
views
Getting international characters from a web page? [duplicate]
I want to scrape some information off a football (soccer) web page using simple python regexp's. The problem is that players such as the first chap, ÄÄRITALO, comes out as ÄÄRITALO!
...
3
votes
2
answers
604
views
Large Python Includes
I have a file that I want to include in Python but the included file is fairly long and it'd be much neater to be able to split them into several files but then I have to use several include ...
77
votes
12
answers
50k
views
Cross-platform space remaining on volume using python
I need a way to determine the space remaining on a disk volume using python on linux, Windows and OS X. I'm currently parsing the output of the various system calls (df, dir) to accomplish this - is ...
1078
votes
12
answers
1.6m
views
How to get an absolute file path in Python
Given a path such as "mydir/myfile.txt", how do I find the file's absolute path in Python? E.g. on Windows, I might end up with:
"C:/example/cwd/mydir/myfile.txt"
13
votes
3
answers
11k
views
Passing on named variable arguments in python
Say I have the following methods:
def methodA(arg, **kwargs):
pass
def methodB(arg, *args, **kwargs):
pass
In methodA I wish to call methodB, passing on the kwargs. However, it seems that if ...