python

Python and SQLite: insert into table

I have a list that has 3 rows each representing a table row: >>> print list [laks,444,M] [kam,445,M] [kam,445,M] How to insert this list into a table? My table structure is: tablename(name varchar[100], age int, sex char[1]) Or should I use something other than list? Here is the actual code part: for record in self.server: ...

How to know requested module name in Django

In Django if a request is made to another module. Can we know where the request has made from through the request variable... In the below example I have to know that the request was made from a.html ort that corresponding module Ex: a.html <html> <form onsubmit=/b> </form> </html> ...

Python RegEx Discrepancy vs Kodos and RegExr: Can't Filter Specific Character in Python

Hi, I'm using Python 2.6.3. When I do: import re, urllib f = urllib.urlopen(website) z = f.read() a = re.findall(r'(\b\d*\SLegos\b)[^\\/bLegos\b]', z) print a I get: ['/Legos', '/Legos', '525Legos', '53Legos', '11Legos', '8Legos', '10Legos', '2Legos', '0Legos', '0Legos', '0Legos', '0Legos', '9Legos', '1Legos', '0Legos', '0Legos', '0...

Django/GAE anonymous users data

Hi, in my application I have per-user models, let me explain with a simple example: class Item(db.Model): master = db.ReferenceProperty(User,collection_name="items") name = db.StringProperty() description = db.StringProperty() value = db.StringProperty() def __unicode__(self): return u"%s"%self.name So I can store informations on...

Python functional programming snippets

I've seen some elegant python snippets using list comprehension and map reduce. Can you share some of these code or a web site. Thanks. ...

How to create twisted.words.xish.domish.Element entirely from raw XML

I was surprised that XML basic object (twisted.words.xish.domish.Element) could not be created entirely from XML string. The most alike way is: msg = "<iq to='[email protected]' id='id123' type='get'> \ <query xmlns='http://juick.com/query#messages' mid='123456'/> \ </iq>" iq = domish.Element(('','')) iq.addRawXml(msg) ...

C++ I/O with Python

I am writing a module in Python which runs a C++ Program using subprocess module. Once I get the output from C++, I need to store the that in Python List . How do I do that ? ...

Is it possible to implement a "change password at next logon" type feature in the django admin?

I want to be able to set an option in the user's settings that forces them to change their password upon the next login to the admin interface. Is this possible? How would it go about being implemented? I'm using the default auth model right now but not opposed to modifying or changing it. Thanks for any help. ...

Python readline on a pipe that has been opened as non-blocking

I have a Linux fifo that has been opened in non-blocking mode. As expected, when I call read on the file object, it returns immediately. I use select to make sure there is no busy waiting, but that my program is still notified when there is any data available. Out of curiosity, I tried the readline function and was surprised to find that...

Extracting Values from a String

Hello, I am trying to extract values from a string, I have tried to get re.match working but have not had any luck. The string is: '/opt/ad/bin$ ./ptzflip\r\nValue = 1800\r\nMin = 0\r\nMax = 3600\r\nStep = 1\r\n' I have tried: map(int,re.search("Value\s*=\s*").group(1)) and also: '/opt/ad/bin$ ./ptzflip\r\nValue = 1800\r\nMin = ...

Chat application using django

If i devlop a chat application using django will it have some performance problem? Can i do server push in django? I want to have PM and room discussions as well. ...

Using Third-Party Modules with Python in an Automator Service

I have installed Py-Appscript on my machine and it can be used with the Python installation at /Library/Frameworks/Python.framework/Versions/Current/bin/python. I am trying to use this installation of Py-Appscript with an Automator service. To do this, I use the Run Shell Script action and then set the Shell to usr/bin/python (which is ...

Serializing objects containing django querysets.

Django provides tools to serialize querysets (django.core.serializers), but what about serializing querysets living inside other objects (like dictionaries)? I want to serialize the following dictionary: dictionary = { 'alfa': queryset1, 'beta': queryset2, } I decided to do this using simplejson (comes with django). I extended simpl...

Why can't Python decorators be chained across definitions?

Why arn't the following two scripts equivalent? (Taken from another question: Understanding Python Decorators) def makebold(fn): def wrapped(): return "<b>" + fn() + "</b>" return wrapped def makeitalic(fn): def wrapped(): return "<i>" + fn() + "</i>" return wrapped @makebold @makeitalic def hello(): ...

How can I configure Geany to compile and run my Python programs?

Under the Build menu, I can see 'Execute' option, but it is greyed out. The only option available is 'Set Includes and Arguments'. When I click that both fields are already filled out. What do I have to write there? ...

Is it possible to have an admin inline without original data being shown?

In the django admin I have a model with an inline. I would like to be able to only show "add new" lines for the inline, and not show any preexisting, original data in the table belonging to the inline. Is this possible? I have tried every combination of max_num and extra, and it always shows existing table data. Thanks ...

split a string in python

All, I have a string in python say a="Show details1\nShow details2\nShow details3\nShow details4\nShow details5\n" How do we split the above with the delimiter \n (a newline). The result should be as ['Show details1', 'Show details2', ..., 'Show details5'] ...

How do I declare an attribute in Python without a value?

In C# I would go: string UserName; string Password; But now, in Python: class User: UserName Password I recieve an error that UserName isn't defined. I can't declare a variable without a variable? ...

Mod_Python + Django library import issue

Hello, I recently had a site that was running perfect for months, all of a sudden it decided to dump itself for no approximate reason. I am running django + mod_python + apache, and the system decided it was time to start ignoring the import of the pycurl library, my intial first thought was that somehow the library had become corrupte...

how to draw a rectangle in iron python. demos required

Hello everybody, can some one please show a demo of drawing a rectangle in iron python and appending it to form. p.s real problem is there is no such documentory in web about drawing in iron python.. and that sucks hard. Sincerely, Eugene. ...