python

PHP vs. application server?

For those of you who have had the opportunity of writing web applications in PHP and then as an application server (eg. Python-based solutions like CherryPy or Pylons), in what context are application servers a better alternative to PHP? I tend to favor PHP simply because it's available on just about any web server (especially shared ho...

"MetaClass", "__new__", "cls" and "super" - can someone explain the mechanism exactly

I have read posts like these: What is a metaclass in Python? What are your (concrete) use-cases for metaclasses in Python? Python's Super is nifty, but you can't use it but somehow I got confused, many confusions like when and why i would have to do something like this #refer link1 return super(MyType, cls).__new__(cls, name, bas...

Checking if two strings are permutations of each other in Python

I'm checking if two strings a and b are permutations of each other, and I'm wondering what the ideal way to do this is in Python. From the Zen of Python, "There should be one -- and preferably only one -- obvious way to do it," but I see there are at least two ways: sorted(a) == sorted(b) and all(a.count(char) == b.count(char) for ch...

Python-PostgreSQL psycopg2 interface --> executemany

Hi again, I am currently analyzing a wikipedia dump file; I am extracting a bunch of data from it using python and persisting it into a PostgreSQL db. I am always trying to make things go faster for this file is huge (18GB). In order to interface with PostgreSQL, I am using psycopg2, but this module seems to mimic many other such DBAPIs...

Desktop graphics - or "skinned" windows

I'm looking for a way to draw animations right on the desktop. No window frames and with transparent background. I'm using Python in windows XP for it, but it doesn't have to be cross platform, although it'd be a nice bonus. Does anyone know about a python library that can do this? ...

How to instantiate a class in python

So, I'm trying to learn Python. It seems pretty easy, but evidently, I don't understand how classes are used. The following code gives me an error when I try to use the class. class mystuff: def average(a,b,c): #get the average of three numbers result=a+b+c result=result/3 return...

In Python, how do I find the date of the first Monday of a given week?

If I have a certain week number (eg 51) and a given year (eg 2008), how do I find the date of the first Monday of that same week? Many thanks ...

commands to send messages in Python via the Poplib module?

I've found a number of tutorials online involving downloading messages via Poplib, but haven't been able to find anything explaining how to create new messages. Does this exist? ...

Confusing [...] List in Python: What is it?

So I was writing up a simple binary tree in Python and came across [...] I don't believe this to be related to the Ellipsis object, more it seems to have something to do with an infinity loop (due to Python's shallow copy?). The source of this infinity loop and why it doesn't get expanded while expanding when accessed is something I'm c...

Reading the target of a .lnk file in Python?

Hi, I'm trying to read the target file/directory of a shortcut (.lnk) file from Python. Is there a headache-free way to do it? The .lnk spec [PDF] is way over my head. I don't mind using Windows-only APIs.My ultimate goal is to find the "(My) Videos" folder on Windows XP and Vista. On XP, by default, it's at %HOMEPATH%\My Documents\My Vi...

Why doesn't Python have multline comments?

Ok, I'm aware that triple-quotes strings can serve as multiline comments e.g. """Hello, I am a multiline comment""" and '''Hello, I am a multiline comment''' But technically speaking these are strings, correct? I've Googled and read the Python style guide but was unable to find a technical answer to why there is no formal...

Fast file/directory scan method for windows?

I'm looking for a high performance method or library for scanning all files on disk or in a given directory and grabbing their basic stats - filename, size, and modification date. I've written a python program that uses os.walk along with os.path.getsize to get the file list, and it works fine, but is not particularly fast. I noticed o...

Using external GUI libraries to make user interfaces in Autodesk Maya

I develop tools in Autodesk Maya. Many of the tools I build have simple windowed GUIs for the animators and modellers to use. These GUIs often contain what you'd normally expect to see in any basic window; labels, lists, menus, buttons, textfields, etc. However, there are limitations to the complexity of the UIs you can build with the...

Python Proxy Script

I'm writing a simple python script so I can test my websites from a different ip address. The url of a page is given in the querystring, the script fetches the page and displays it to the user. The code below is used to rewrite the tags that contain urls but I don't think it's complete/totally correct. def rel2abs(rel_url, base=loc): ...

Split by \b when your regex engine doesn't support it

How can I split by word boundary in a regex engine that doesn't support it? python's re can match on \b but doesn't seem to support splitting on it. I seem to recall dealing with other regex engines that had the same limitation. example input: "hello, foo" expected output: ['hello', ', ', 'foo'] actual python output: >>> re.comp...

Why can't I subclass datetime.date?

Why doesn't the following work (Python 2.5.2)? >>> import datetime >>> class D(datetime.date): def __init__(self, year): datetime.date.__init__(self, year, 1, 1) >>> D(2008) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: function takes exactly 3 arguments (1 given) I wanted to c...

Assigning a 'for loop' to a variable in a python program

hi, Im writing a program at the moment(below) that interacts with a MySQL database and im having a problem. As you can see ive written a query that will look for products in the products table that corresponds to the barcode that the user has inputted. If the barcode that is inputted by the user is found in the products table, I want to ...

Extended slice that goes to beginning of sequence with negative stride

Bear with me while I explain my question. Skip down to the bold heading if you already understand extended slice list indexing. In python, you can index lists using slice notation. Here's an example: >>> A = list(range(10)) >>> A[0:5] [0, 1, 2, 3, 4] You can also include a stride, which acts like a "step": >>> A[0:5:2] [0, 2, 4] ...

Failing to send email with the Python example

I've been trying (and failing) to figure out how to send email via Python. Trying the example from here: http://docs.python.org/library/smtplib.html#smtplib.SMTP but added the line server = smtplib.SMTP_SSL('smtp.gmail.com', 465) after I got a bounceback about not having an SSL connection. Now I'm getting this: Traceback (most rece...

Tix and Python 3.0

Has anyone seen anything in Tix work under python 3.0? I've tried to work through the examples but when creating anything it states that cnf is unsubscriptable. I also noticed that none of the Dir Select stuff (DirList DirTree) works under 2.6.1. Why doesn't Python either dump Tix or support it? Its got a lot of good stuff to make ea...