python

tricky string matching

I want to find the first index of substrings in a larger string. I only want it to match whole words and I'd like it to be case-insensitive, except that I want it to treat CamelCase as separate words. The code below does the trick, but it's slow. I'd like to speed it up. Any suggestions? I was trying some regex stuff, but couldn't f...

Finding fast default aliases in python

Is there a faster way to do this for much larger dicts? aliases = { 'United States': 'USA', 'United Kingdom': 'UK', 'Russia': 'RUS', } if countryname in aliases: countryname = aliases[countryname] ...

Set auto-incrementing attribute in XML node

I'm trying to set an attribute in one of the nodes for my XML as below: rank = 1 for photo in s: image = feed.createElement('Image') images.appendChild(image) image.setAttribute("rank", rank) p = feed.createTextNode(str(main_url+photo.display.url)) image.appendChild(p) rank += 1 This however results in the error: 'int' obj...

How to resolve case problems for non-english languages in django admin panel?

I need to resolve problem with word endings in django admin panel. The language I'm using is russian (using utf-8 charset), so some problems occur, for example, there is a problem with the right endings on the "Add" button for some model names. The simplest thing I found is using jQuery to correct endings "on the fly", but this solution ...

Python - Moving entire text between two .doc files

Hi I have been having this issue for a while and cannot figure how should I start to do this with python. My OS is windows xp pro. I need the script that moves entire (100% of the text) text from one .doc file to another. But its not so easy as it sounds. The target .doc file is not the only one but can be many of them. All the target ....

Easy to use time-stamps in Python

I'm working on a journal-type application in Python. The application basically permits the user write entries in the journal and adds a time-stamp for later querying the journal. As of now, I use the time.ctime() function to generate time-stamps that are visually friendly. The journal entries thus look like: Thu Jan 21 19:59:47 2010 Di...

Python: Optimizing, or at least getting fresh ideas for a tree generator.

I have written a program that generates random expressions and then uses genetic techniques to select for fitness. The following part of the program generates the random expression and stores it in a tree structure. As this can get called billions of times during a run, I thought it should be optimized for time. I'm new to programming...

Python Syntax Error but looks fine to me. Help?

Right now I'm working on a Tetris Game (sorta, I found a Tetris example for Python on a website, I've been copying it but adding some of my own stuff), and just finished writing all the code but have had a couple syntax errors. I've been able to fix all of them but this last syntax error is confusing to me. def pieceDropped(self): ...

Reading path in templates

Hello, is it any way to read path to current page? For example, I am at www.example.com/foo/bar/ - and I want to read '/foo/bar/'. But, all have to be done in template file without modyficating views. I have to many view files to edit each one. Sorry for my english, hope everyone understand. Cheers. ...

TextMate and Django Integration - Supporting {% %} markup

I have installed a TextMate bundle that I believe enables the ability for automatic closing of the "{{" markup (so that it will automatically close the markup with "}}"), but this does not seem to be possible with the other markup that uses "{%" and "%}". So, I was wondering if anyone out there knows how to get TextMate to add the autom...

Google App Engine: Add task to queue from a task

I need to track data from another website. Since it's spread over 60+ pages, I intend to use a daily cron job to add a task to the queue. This task then should take care of one page and depending on some checks, put another instance of itself on the queue for the next page. Now a simple taskqueue.add(url='/path/to_self', params=control...

Python equivalent of IDL's stop and .reset

Hi there, I'm relatively new to python but have a bit of experience using IDL. I was wondering if anyone knows if there are equivalent commands in python for IDL's stop and .reset commands. If I'm running some IDL script I wrote that I put a stop command in, essentially what it does is stop the script there and give me access to the com...

Django, making a page activate for a fixed time

Greetings I am hacking Django and trying to test something such as: Like woot.com , I want to sell "an item per day", so only one item will be available for that day (say the default www.mysite.com will be redirected to that item), Assume my urls for calling these items will be such: www.mysite.com/item/<number> my model for item: c...

Access contents of PyBuffer from C

I have created a buffer object in python like so: f = io.open('some_file', 'rb') byte_stream = buffer(f.read(4096)) I'm now passing byte_stream as a parameter to a C function, through SWIG. I have a typemap for converting the data which looks like this: %typemap(in) unsigned char * byte_stream { PyObject *buf = $input; //some...

Network programming in Python

What library should I use for network programming? Is sockets the best, or is there a higher level interface, that is standard? I need something that will be pretty cross platform (ie. Linux, Windows, Mac OS X), and it only needs to be able to connect to other Python programs using the same library. ...

Preferred way to store/retrieve python data

I would like to include data files with a Python package. Is the best place to put them inside the actual package as suggested here, i.e. setup.py src/ mypkg/ __init__.py module.py data/ tables.dat spoons.dat forks.dat or is there a better way to do this? What is the best...

What's the difference between filter and filter_by in SQLAlchemy?

Hello everyone! Could anyone explain the difference between filter and filter_by functions in SQLAlchemy? I am confused and can't really see the difference. Which one should I be using? Thanks, Boda Cydo ...

Comunicating to server with queries through stream. What is the right way?

I'm writing my first network application. It manipulates jabber client and comunicates with some service with IQ-stanzas. But details are not important. This interaction works through twisted xmlstream (python language). Typical situations are described here: http://juick.com/help/api/xmpp/ To be short, I can send a "query" and server r...

SQLAlchemy printing raw SQL from create()

Hi all I am giving Pylons a try with SQLAlchemy, and I love it, there is just one thing, is it possible to print out the raw SQL CREATE TABLE data generated from Table().create() before it's executed? ...

Running django on IronPython

There have been some questions and answers here on stackoverflow, but no one asked if it's a good solution to run django on IIS. Any experience is welcome, both good and bad. ...