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 now:
class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def doGET
[...]
class ThreadingHTTPServer(ThreadingMixIn, HTTPSe...
What follows is a regular expression I have written to match multi-line pre-processor macros in C / C++ code. I'm by no means a regular expressions guru, so I'd welcome any advice on how I can make this better.
Here's the regex:
^\s*#define(.*\\\n)+[\S]+(?!\\)
It should match all of this:
#define foo(x) if(x) \
doSomething(x)
But ...
I am just getting into Python development and would like to know which single IDE or editor is the best.
I mainly use Linux, but don't let that stop you if you think the best one is Win/Mac only.
...
How do I select a(or some) random row(s) from a table using SQLAlchemy?
...
Is it possible to retrieve items from a Python dictionary in the order that they were inserted?
...
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 of the app root directory, because it makes it harder to import the modules that you'll be testing.
Is there a best practice here?
...
From my experiences building non-trivial applications in Java and C#, I know that using good modular design based on known patterns and "coding to interfaces" are keys to success.
What are the architecture best practices when building large systems in a dynamic language like python or ruby?
...
Do you know if there is a built-in function to build a dictionary from an arbitrary object? I'd like to do something like this:
>>> class Foo:
... bar = 'hello'
... baz = 'world'
...
>>> f = Foo()
>>> props(f)
{ 'bar' : 'hello', 'baz' : 'world' }
NOTE: It should not include methods. Only fields.
Thanks
...
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, 7)
This seems very useful, but it looks like it can also be abused ("Well..function X already computes what we need as an intermediate ...
How do you set up IIS so that you can call python scripts from asp pages?
Ok, so I found the answer to that question here: http://support.microsoft.com/kb/276494
So on to my next question: How do you call a cgi script from within classic asp (vb) code? Particularly one which is not in the web root directory.
...
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/
controller1/
controller2/
...
templates/
template1/
template2/
...
..etc. The controllers will be Python modules handling requests. Th...
I'm currently learning Django though reading the Django Book, but I'm a huge fan of webcasts/screencasts/videos and haven't found any good ones so far. Are there any and which ones would you recommend?
...
I am trying to get some accurate runtime comparisons of PHP vs Python (and potentially any other language that I have to include). Timing within a script is not my problem but timing within a script does not account for everything from the moment the request is made to run the script to output.
1) Is it actually worth taking such things...
I've heard that Python is meant to be faster than PHP in terms of Runtime, I simply took this as a given and sat down today to make a blog post about it. After being told by Vinko Vrsalovic how to time scripts I took converted some code for getting prime numbers into Python and PHP then ran each 3 times and recorded the numbers. All time...
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 alloc/g-c overheads).
I guess I'm looking for an equivalent to C's stricmp().
[Some more context requested, so I'll demonstrate with a trivi...
I want to start using Python for small projects but the fact that a misplaced tab or indent can throw a compile error is really getting on my nerves. Is there some type of setting to turn this off?
I'm currently using NotePad++. Is there maybe an IDE that would take care of the tabs and indenting?
...
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 make my live a lot easier.
notify-extension: http://www.selenic.com/mercurial/wiki/index.cgi/NotifyExtension
Which Mercurial hook or ...
I'm hosting Python script with Python for Delphi components inside my Delphi application. I'd like to create background tasks which keep running by script.
Is it possible to create threads which keep running even if the script execution ends (but not the host process, which keeps going on). I've noticed that the program gets stuck if t...
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 I would make a class with the numbers 1 to 5 as the data in it, then make a second class with the same names for sections (or very similar...
Has anybody created a nice wrapper around Yahoo's geo webservice "GeoPlanet" yet?
...