python

Typogrify equivalent for .NET

Does anyone know of, or use a library that has similar functionality to Typogrify (http://code.google.com/p/typogrify/) in a .NET project. Typogrify is a Python/Django library and I am looking for an equivalent that I could use in a .NET project. Edit: Now I'm just looking for any typography processing library for .NET ...

In web2py, can I specify an existing named field as the autonumber ID in a legacy database?

I have dozens of tables in an existing MSSQL database all with autonumber ID primary keys, but none that are named 'id'. They are instead named PropertyID, ClientID, etc. The official documentation seems to suggest renaming each of these fields to 'id': Legacy Databases web2py can connect to legacy databases under some condi...

Switching files to read from in python's .csv reader

I am reading a csv file several times, but cutting its size every time I go through it. So, once I've reached the bottom, I am writing a new csv file which is, say, the bottom half of the .csv file. I then wish to change the csv reader to use this new file instead, but it doesn't seem to be working... Here's what I've done. ...

Python in Plone: trying to append a variable to RESPONSE.redirect

I have a python script in Plone, I'm having trouble appending a variable to RESPONSE.redirect. I get a invalid syntax error. test = '1000' RESPONSE.redirect(("/Plone/user_blast/public_blast_results/%s" % (test)) ...

Passing list elements to a for loop

Hello all - I'm trying to pass elements from a list to a for loop and of course am getting the classic error 'argument 1 must be a string not list' - for the os.chdir() function. Here is a my code, any suggestions as to how I can get around the above error and still pass the elements of my list on to the rest of the script so it loops t...

numpy join entries intersecting at a cell

In numpy, how can I join the entries that intersects at a cell? For example: In the example, I want to join rows/columns B and F into one row/column BF, where each element is the average of the ones with the same color. ...

How to easy_install egg plugin and load it without restarting application?

I'm creating an app that downloads and installs its own egg plugins, but I have a problem loading the egg after easy_install extracts it into place. This is how it works now: App downloads egg into temp folder Installs egg with setuptools.command.easy_install.main() into ~/.app/plugins folder (which is pointed by a pth on dist-packages...

how can i convert xml document/file to dom in python?

I need to do screen scraping and for that i need to convert xml to dom in python please can anybody tell that how can i do this.... ...

Python: appending a variable to Popen

When i try to carry out the code below i get the error "unsupported operand type(s) for %: 'list' and 'str'" from subprocess import Popen z = '10000' Popen(["formatdb", "-p", "T", "-i", "%s.txt"] % (z)).wait() How would I insert my variable z into the name of my text file? ...

Python list comprehension for dictionaries in dictionaries?

I just learned about list comprehension, which is a great fast way to get data in a single line of code. But something's bugging me. In my test I have this kind of dictionaries inside the list: [{'y': 72, 'x': 94, 'fname': 'test1420'}, {'y': 72, 'x': 94, 'fname': 'test277'}] The list comprehension s = [ r for r in list if r['x'] > 92...

Sorting dicts (contained in lists) alphanumerically in Python

I'm having an issue with sorting a list that contains a dict. Currently I am sorting it by a key called 'title' with the following line: list.sort(key=operator.itemgetter('title')) The problem with this is that some of my data gets sorted looking like this: title_text #49 title_text #5 title_text #50 How would I go about sorting it...

Create multiple buttons with consecutive integers in name

I have the following python code and I was wondering if it's possible to create those buttons in a for loop instead? I was thinking of modifying the local namespace but I'm not sure if that's a good idea. I really want the buttons to be named so that it's named consecutively. self.todo1 = wx.TextCtrl(self, -1, "") self.timer_label1 = w...

Python 2.6: containment hierarchy issue: Same Values :S

Hey Everyone, If you've seen my previous post you'll know im working on an airline program using Python. Another issue that poped up was that after I launch one flight, it calculates the duration of the flight and replaces the button which is used to launch the flight. But when I buy another aircraft, it changes both flight statuses to ...

Python httplib ResponseNotReady

I'm writing a REST client for elgg using python, and even when the request succeeds, I get this in response: Traceback (most recent call last): File "testclient.py", line 94, in <module> result = sendMessage(token, h1) File "testclient.py", line 46, in sendMessage res = h1.getresponse().read() File "C:\Python25\lib\httplib...

Weird CAPTCHA behavior. If failed, CAPTCHA hijacks page.

Weird CAPTCHA behavior. If failed, CAPTCHA hijacks page. When submitting the form with errors, the correct page (displaying what fields are incorrect) is displayed for a brief moment then is immediately hijacked by the CAPTCHA form leaving only the CAPTCHA form on the page. The CAPTCHA does not redirect to a new URL, the URL stays the ...

Weird Python behaviour - or am I missing something

The following code: class House: links = [] class Link: pass class Villa(House): pass if __name__ == '__main__': house = House() villa = Villa() link = Link() house.links.append(link) print house.links print villa.links results in this output: [<__main__.Link instance at 0xb65a4b0c>] [<__main_...

a list > a list of lists

In python, how can I split a long list into a list of lists wherever I come across '-'. For example, how can I convert: ['1', 'a', 'b','---', '2','c','d','---','3','123','e','---','4'] to [['1', 'a', 'b'],['2','c','d'],['3','123','e'],['4']] Many thanks in advance. ...

Python ftplib can't get size of file before download?

I'm using ftplib to transfer files. Everything is working great. Now I'm trying to get the size of the target file before downloading. First, I tried just getting size with ftp.size(filename). Server complained that I can't do that in ascii mode. Then I tried setting binary mode using ftp.sendcmd("binary") and ftp.sendcmd("bin"). I...

Documenting public global functions with epydoc

I have a module containing multiple global functions, and a global variable. The variable and some of the functions follow the 'private' naming convention for Python, with a leading underscore for the name. The other functions are intended to be public, and do not have a leading underscore. I have declared __all__, with a list of my pub...

Introspection to get decorator names on a method?

I am trying to figure out how to get the names of all decorators on a method. I can already get the method name and docstring, but cannot figure out how to get a list of decorators. ...