python

Django: tracking all the database changes with values

Hi All, I have to implement an application in django which will track all the changes in the database with the previous values,current value,action,date,time, user(who performed the changes) etc. Is there any application/module available in python or django which can perform these actions with may be after some changes. I have seen "f...

python parsing a block of text betwen 2 known lines

Hi, I am trying to get a block of lines between 2 known lines using pyparsing. For example: ABC .... DEF My python code: end = Literal("\n").suppress() firstLine = Literal("ABC") + SkipTo(end) secondLine = Literal("DEF") + SkipTo(end) line = SkipTo(end) test = firstLine + OneOrMore(line) + secondLine test.searchString(myText) -->...

Proper location to set up MySQLdb connection in Pylons: app_globals? Thread safety?

I want to use MySQLdb in Pylons, but can't figure out where to actually connect. It would seem that making the connection in app_globals.py would be convenient: class Globals(object): def __init__(self): self.db = MySQLdb.connect() Then controllers can access the db via the globals. However, this seems to lead to problems ...

signed bitwise arithmetic in Python

I got stuck with the following Python code >>> a = 0xff >>> b = 1 << 8 >>> ~a & ~b -512 Why is it -512? In binary notation it should look like this: a 0 1111 1111 -> 255 b 01 0000 0000 -> 256 ~a 1 0000 0000 -> -256 ~b 10 1111 1111 -> -257 ~a&~b 00 0000 0000 -> 0 I expected 0 as with signed int...

python - why use def main()

Possible Duplicate: What does <if name==main:> do? Hi there, Just being doing some things with python, and from what i've seen (code samples/tutorials) that code uses def main() # my code here if __name__ == "__main__": main() but why, is there any reason not do def your functions at the top of the file, then just...

Best python/Django code generator?

Hello, very quick question. I am wondering if there are any software Django software that generates python coding automatically. If there are any, please let me know. ...

BeautifulSoup is too slow. Can lxml do this?

I've got the following BeautifulSoup code, a bit simplified. soup = BeautifulSoup(html) for item in soup.findAll('div',id=compile('^result_')): q = item.find('a',{'class':'title'}) if q: ... q = item.find('div',{'class':['one','two']}) if q: ... I profiled it, and it's quite slow. I want to try lxml instead but it seem...

Python verify url goes to a page

I have a list of urls (1000+) which have been stored for over a year now. I want to run through and verify them all to see if they still exist. What is the best / quickest way to check them all and return a list of ones which do not return a site? ...

Django multidb: write to multiple databases

With Django multidb, it's fairly easy to write a router that runs a master/slave infrastructure. But is it possible to write a router that writes to multiple databases? My use case is a collection of projects, all running on the same domain. To save users from registering/login in on every site, I'd like to synchronize the contrib.auth a...

Django : ORM objects come with nothing in _meta.local_fields

[python 2.6 - django 1.1.1] Hello. I'm writing a custom serializer for my django application. All the objects that I use are proxy objects derived from django model classes and implement special members that I must serialize (hence the custom serializer). So I've begun to implement a new abstract serializer that inherits django.core....

If I have an fcgi server running and visit it with a browser, what should happen?

I have the following setup - and don't get any response when I visit the server in a browser. Should I expect some? Here's the test setup, using python & flup. #test.py def myapp(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) return ['abc\n'] import os os.environ['FCGI_WEB_SERVER_ADDRS']="12...

python read from keyboard and detect end space or end of linue

I need a python code which does these 1.user enters a char 2.python gets it and displays whether its alphabets or numeric or space or newline char. output will be one of the following - its alphabets its numeric its space its newline ...

Cython problem in Windows XP: "error: Unable to find vcvarsall.bat"

Cython version is 0.13, Python 3.1 I have tried all "solutions" in Cython FAQ, but to no avail. My version of Visual Studio is 7.1 and its directory doesn't contain vcvarsall.bat. Is this problem have a solution? ...

Auto increment of Concatenated alpha-numeric. (Python)

I have defined a function that generates ID. I need to increment the numbers every time I call the function. So I used max() function to find the last largest value stored in the list. According to the requirements my ID should also consist of a string in front of the integers. So I have concatenated a string with some numbers which ha...

Python: Can I use a class attribute as a default value for an instance method?

I am writing a new class in Python (2.5). My immediate goal is to: GOAL: Use the value of a class (static) attribute as the default value for an instance attribute I can add logic to the __init__ method to do this, and it works fine. In an effort to tidy up the body of the __init__ method, however, I tried to set a default value for o...

Image analyze? - Python

i try agin, i need to analyze a picture pixel by pixel and return it in XML or Array output, eg. xml <picture> <pixelline id="1"> <pixel id="1" color="#000000" /> <pixel id="2" color="#000000" /> <pixel id="3" color="#000000 /> <pixel id="4" color="#000000" /> </pixelline> <pixelline id="2"> <pixel id="1" color="#000000" /> <pixel id="2...

Explicitly declaring a variable type in python.

Hi, I use pyscripter for coding, it supports auto-completion. So, when I say: a = [] a. It gives me all the list functions. similarly with strings I do b=''. But for file type, I have to use file. and choose the function and write it's arguments and then replace file with the variable name. Is there a way to declare a variable type...

Django-CMS 500 error when clicking to add a plugin

Hey guys, when clicking to add a new plugin ("Add Plugin" on a "Page" I get a 500 error. Using firebug I got this traceback: Environment: Request Method: POST Request URL: http://192.168.1.10:81/admin/cms/page/1/add-plugin/ Django Version: 1.2.3 Python Version: 2.6.6 Installed Applications: ['django.contrib.auth', 'django.contrib.cont...

return a function object with parameter binded?

All, def a(p): return p+1 def b(func, p): return func(p) b(a,10) # 11 here I do not want the result "11" actually, what I want is a function object with the parameter has been binded, let's name it c. when I use c() or something alike, it will give me the result 11, possible? Thanks! ...

Retrieving hierarchial data from datastore

Hi! I am building an app with Google App Engine (and Python). I have two questions about retrieving data from datastore. I have information about users and information about posts made by users. Here is part of DB Models: class User(db.Model): country = db.StringProperty() # many other entities class Post(db.Model): auth...