python

convert string rep of hexadecimal into actual hexadecimal

Possible Duplicate: how to parse hex or decimal int in Python i have a bunch of Hexadecimal colors in a database stored as strings. e.g. '0xFFFF00' when i get them from the database i need to convert this string into an actual hexadecimal number, so 0xFFFF00 how can i do this in python ...

lxml bug with descendant::*/td or not?

Hello I'm use lxml to parsing big table and now have trouble: >>> winvps[0].getnext().xpath("descendant::*") 118: [<Element td at 3a30180>, <Element a at 3a301b0>, <Element font at 3a301e0>, <Element b at 3a30210>, <Element td at 3a30240>, <Element td at 3a30270>, <Element font at 3a302a0>, <Element td at 3a302d0>, <Element td ...

Python doesn't save data to sqlite db.

This is my code: conn = sqlite3.connect(nnpcconfig.commondb) cur = conn.cursor() query = ['2124124', 'test2', 'test3', 'test4', 'test5'] cur.execute("insert into users(id, encpass, sname, name, fname) values (?, ?, ?, ?, ?)", query) conn.commit cur.execute("select * from users") for row in cur: print row This code works, returning...

Pylons - catching errors before redirect to document/error for logging

I want to log 404 and 500 errors in a pylons app before they redirect to my custom error message (/error/document). My problem is that since Pylons does the redirect, I am unable to determine the page on which the error occurred inside the error controller. So without building a parser for the paster.log I don't know a good way to sele...

Select Children of an Object With ForeignKey in Django?

I'm brand new to Django, so the answer to this is probably very simple. However, I can't figure it out. Say I have two bare-bones Models. class Blog(models.Model): title = models.CharField(max_length=160) text = models.TextField() class Comment(models.Model): blog = models.ForeignKey(Blog) text = models.TextField() I...

How to rename a directory in Mercurial and continue to track all file changes

I decided to rename some directories in my home/hobby Python package (doc to docs, test to tests, util to utils) because, now that I've thought more about it, I think the new names are more appropriate. My general thinking now is that if containers are named after their contents their names should be plural nouns. Now that I'm ready for...

Implementing parser for markdown-like language

I have markup language which is similar to markdown and the one used by SO. Legacy parser was based on regexes and was complete nightmare to maintain, so I've come up with my own solution based on EBNF grammar and implemented via mxTextTools/SimpleParse. However, there are issues with some tokens which may include each other, and I don...

pyAMF for GAE (Google App Engine), little help needed:

# I need this behaviour: # 1) check if the service from flash is included in the services array # 2) if not, return false or an error | if yes, step 3 # 3) combine the rootPath('app.controllers') with the service name('sub1.sub2.sub3.function_name') # 4) and then get the function('function_name') from the 'app.controllers.sub1.sub2.sub3....

Traversing an ftp folder with python

I need to write a python script that traverses a folder on a FTP server. for file in ftpfolder: #get it #do something untoward with it Snippets and non-wheel-reinvention advice welcome. ...

Adding tests to sdist, but not installing

Hi, I'd like to add tests to the sdist package in my setuptools distribution, but I don't want them installed / in bdist. I already have: setup( ... packages = find_packages(exclude='tests'), test_suite = "tests", ... ) But currently the tests/* are always included. How can I change that? ...

Encode and pad netbios name using python

Hi Everyones, I'm trying to create a simple script that will convert a string (max 15 chars) to a netbios name (see http://support.microsoft.com/kb/194203) : name = sys.argv[1].upper() converted = ''.join([chr((ord(c)>>4) + ord('A'))+chr((ord(c)&0xF) + ord('A')) for c in name]) print converted Trying to convert the name : "testing" w...

Can I look at the actual line that was the source of an element parsed from an html document using lxml

I have been having fun manipulating html with lxml. Now I want to do some manipulation of the actual file, after finding a particular element that meets my needs I want to know if it is possible to retrieve the source of the element. I jumped up and down in my chair after seeing sourceline as a method of my element but that did not giv...

python string format suppress/silent keyerror/indexerror

Hi, Is there a way to use python string.format such that no exception is thrown when an index is missing, instead an empty string is inserted. result = "i am an {error} example string {error2}".format(hello=2,error2="success") here,result should be : "i am an example string success" Right now, python throws a keyerror and stops ...

Unicode case conversion

I am given either a single character or a string, and am using Python. How do I find out if a specific character has a lowercase equivalent according to the standards (standard and special case mappings) proposed by Unicode? And how do I find out if a string has one or more characters that have a lowercase equivalent according to the s...

Does Python 2.5.2 follow Unicode for lower() and upper()?

I'm making a Google AppEngine Application. Does the Python 2.5.2 runtime environment follow the Unicode Standards? (For example, the lower() and upper() methods on unicode objects.) ...

UnicodeDecodeError on import of a .pyd file

Hi, I've started to slowly dabble with the Python/C API and after much fiddling and finagling, I was able to build a spam.pyd file. However, I must be missing something with this process and was hoping that someone could point me in the right direction. I thought that once spam.pyd was created, I could call it from Python via import sp...

How to change a module variable from another module?

Suppose I have a package named bar, and it contains bar.py: a = None def foobar(): print a and __init__.py: from bar import a, foobar Then I execute this script: import bar print bar.a bar.a = 1 print bar.a bar.foobar() Here's what I expect: None 1 1 Here's what I get: None 1 None Can anyone explain my misconception?...

Automatic login and uploading a file into a web server

i have a system given to me by a client to upload a file to send money to my clients. the way it works is this. i have to login credentials. the first one i log in to upload a CSV file with the clients phone number and money he needs to withdraw. then the second login is used to approve the file that has been uploaded so that money can b...

google appengine datastore client

Is there a tool/client to view inside and make queries for google appengine datastore? ...

Multiplying a string with a number in python

Hello, I need a string consisting of a repetition of a particular character.At the python console, if i type : n = '0'*8 Then n gets assigned a string consisting of 8 zeroes,which is what i expect. But, if i have the same in a python program (.py file), then the program aborts with an error saying 'can't multiply sequence by non-int...