python

What Web/application servers to use for Python

Hello, I would like to start writing Python web apps, first start simple like servlets in Java, then move to some web frameworks. What server could I use to develop the apps? Is there a Tomcat version for Python? Is Apache with mod_python the way to go or something else? Thank you! PS: It is for Python 2.6.5, if that makes a differe...

python logger logging same entry numerous times

I have a such logger initializing function: def generate_logger(): import logging LOG_FILENAME = os.path.join(PROJECT_DIR, "mylog.log") FORMAT = "%(asctime)s : %(message)s" logger = logging.getLogger() logger.setLevel(logging.INFO) fh = logging.FileHandler(LOG_FILENAME) formatter = logging.Formatter(FORMAT) ...

Attaching a decorator to all functions within a class

I don't really need to do this, but was just wondering, is there a way to bind a decorator to all functions within a class generically, rather than explicitly stating it for every function. I suppose it then becomes a kind of aspect, rather than a decorator and it does feel a bit odd, but was thinking for something like timing or auth i...

Using web2py on Eclipse

I am trying to use the steps I found on the net to make web2py work on Eclipse, but I must have something setup wrong because Eclipse gives me error on the imports. For instance the instructions say to do this at the top of controllers: if 0: from gluon.globals import * from gluon.html import * from gluon....

Python module to convert from document to html

Is there any python package which converts the uploaded Ms Word document to html content.As in my application am uploading a document and i want to convert it into html any suggestion o nthis will help Thanks ...

How can Python lists within objects be freed?

I have a Python class containing a list, to which I append() values. If I delete an object of this class then create a second object later on in the same script, the second object's list is the same as the first's was at the time of deletion. For example: class myObj: a = [] b = False o = myObj() o.a.append("I'm still here!")...

Trying to come up with a recursive function to expand a tree in Python

I have table that looks like this: id | parentid | name --------------------- 1 | 0 | parent1 --------------------- 2 | 0 | parent2 --------------------- 3 | 1 | child1 --------------------- 4 | 3 | subchild1 I'm now trying to come up with an efficient way to take that database data and create a Py...

Python: wx.ListCtrl -> how to make one of the items a picture that once clicked opens a file

I have a wx.ListCtrl instance to which I use InsertColumn like this: Path | Size | ... | Last run For each item to be displayed I have a function that sets all the fields: setStringItem(index, 0, path) setStringItem(index, 1, size) ... I want on column 6 (Last run) to do the following: 1) add a picture 2) the picture should be clicka...

Is there any language which is just "perfect" for web scraping?

I have used 3 languages for Web Scraping - Ruby, PHP and Python and honestly none of them seems to perfect for the task. Ruby has an excellent mechanize and XML parsing library but the spreadsheet support is very poor. PHP has excellent spreadsheet and HTML parsing library but it does not have an equivalent of WWW:Mechanize. Python ...

Java or any other language: Which method/class invoked mine?

I would like to write a code internal to my method that print which method/class has invoked it. (My assumption is that I can't change anything but my method..) How about other programming languages? EDIT: Thanks guys, how about JavaScript? python? C++? ...

How can I benchmark different languages / frameworks?

I'd like to compare the performance of different languages and/or different frameworks within the same language. This is aimed at server-side languages used for web development. I know an apples to apples comparison is not possible, but I'd like it to be as unbiased as possible. Here are some ideas : Simple "Hello World" page Object in...

Python doesn't have opcode cacher?

Hi, I'm currently using PHP. I plan to start using Django for some of my next project. But I don't have any experience with Python. After some searching, I still can't find a Python opcode cacher. (There are lots of opcode cacher for PHP: APC, eAccelerator, Xcache, ...) ...

Caching options in Python or speeding up urlopen

Hey all, I have a site that looks up info for the end user, is written in Python, and requires several urlopen commands. As a result it takes a bit for a page to load. I was wondering if there was a way to make it faster? Is there an easy Python way to cache or a way to make the urlopen scripts fun last? The urlopens access the Amazon ...

Detect "overall average" color of the picture.

I have a picture (jpg file, for example). I need to know "overall average" the color of the picture. I mean the prevailing color in this picture. I can not strictly furmulate my task. I will cite an example: (Image above: at the top - the original image, at the bottom - the "overall average" color which is associated with picture) ...

How to read only last buffer from telnetlib command

Hi, I have following python code: import telnetlib ts = telnetlib.Telnet('192.168.0.2') ts.set_debuglevel(10) ts.read_until("assword:", 5) ts.write("xxxxx\n") ts.write("enable\n") ts.read_until("assword:", 5) ts.write("xxxxx\n") ts.write("term len 0\n") ts.write("show start\n") But how can i read the buffer only from "show start" com...

Regular expression: if, else if, else

Hi, I am trying to parse FSM statements of the Gezel language (http://rijndael.ece.vt.edu/gezel2/) using Python and regular expressions regex_cond = re.compile(r'.+((else\tif|else|if)).+') line2 = '@s0 else if (insreg==1) then (initx,PING,notend) -> sinitx;' match = regex_cond.match(line2); I have problems to distinguish if and els...

How can I create python strings with placeholders with arbitrary number of elements

I can do string="%s"*3 print string %(var1,var2,var3) but I can't get the vars into another variable so that I can create a list of vars on the fly with app logic. for example if condition: add a new %s to string variable vars.append(newvar) else: remove one %s from string vars.pop() print string with placeholders Any id...

Python: Why does subprocess() start 2 processes in Ubuntu, and 1 in OpenSUSE?

I've written small gui-frontend in Python that lets users play internet radio channels. The program uses Pythons subprocess() to initizalize mplayer in order to tune into a channel, e.g.: runn = "mplayer http://77.111.88.131:8010" p = subprocess.Popen(runn, shell=True) pid = int(p.pid) wait = os.waitpid(p.pid, 1) Then saves p.pid, and ...

Python file.read() seeing junk characters at the beginning of a file

I'm trying to use Python to concatenate a few javascript files together before minifying them, basically like so: outfile = open("output.js", "w") for somefile in a_list_of_file_names: js = open(somefile) outfile.write(js.read()) js.close() outfile.close() The minifier complains about illegal characters and syntax errors a...

Converting graph traversal to multiprocessing in Python

I've been working on a graph traversal algorithm over a simple network and I'd like to run it using multiprocessing since it it going to require a lot of I/O bounded calls when I scale it over the full network. The simple version runs pretty fast: already_seen = {} already_seen_get = already_seen.get GH_add_node = GH.add_node GH_add_e...