python

Convert UTF-8 octets to unicode code points

Hi, I have a set of UTF-8 octets and I need to convert them back to unicode code points. How can I do this in python. e.g. UTF-8 octet ['0xc5','0x81'] should be converted to 0x141 codepoint. ...

What does first argument to `type` do?

Some code. In [1]: A = type('B', (), {}) In [2]: a = A() In [3]: b = B() --------------------------------------------------------------------------- NameError Traceback (most recent call last) /home/shabda/<ipython console> in <module>() NameError: name 'B' is not defined What does first argument to...

What languages other than Python have an explicit self?

Don't have anything to add so, What languages other than Python have an explicit self? [Edit] Obviously all OO languages will have a this or a self for current instance. What I want to know is does any other ask you to explicitly pass this or self as all instance method arguments? ...

Display from a table using Django

Hi all, Can you please give me a small piece of code where we display data from a table if any in Django..... Please point me to a code that goes into views.py and template/index.html to diaply the table............. Thanks.... ...

Search a file for a string, and execute a function if string not found; in python

def checkCache(cachedText): for line in open("cache"): if cachedText + ":" in line: print line open("cache").close() else: requestDefinition(cachedText) This code searches each line of a file (cache) for a specific string (cachedText + ":"). If it does not find the specific stri...

How to setting Camera options in Blender

i try to create car's type game, but when i choose camera view , a view is not real every building have miss shape its look like perspective view .So i finding how to config it ...

How to design an application in a modular way?

I am looking for pointers, suggestions, links, warnings, ideas and even anecdotical accounts about "how to design an application in a modular way". I am going to use python for this project, but advice does not need to necessarily refer to this language, although I am only willing to implement a design based on OOP. Here's some context ...

Which Python language rule allows the descriptor to be found first?

I bumped into the following last night and I'm still at a loss as to explain it: class Foo(object): @property def dave(self): vars(self)['dave'] = 1 return 2 f = Foo() print f.dave print f.dave Running this code produces: 2 2 The question is why? My understanding of attribute access is that the instance dic...

Is there any python package that could configure IP address of network interface?

I am writing a server application which allow remote client to show/add/change/delete IP addresses of network interfaces of the machine where the host is running. The OS is Linux(CentOS 5.2), so I could do that by simply parse and edit configure file. But is there any package that could simplify the job? And if there is none such pack...

How do I mimic browser back arrow in my application page ?

request.path gives me the clicked url. I need a return link on that page which on clicking, should return to Referrer page, just as it would happen in case of browser back arrow . I do not maintain any session and do not want to hardcode the referrer page url. ...

How to create a .py file for Google App Engine?

Hello everybody!!! I am just at the very start of what I think is gonna be a long journey exploring the world of applications in Google App Engine using Python. I have just downloaded Python 2.6.4 from the Python official website and installed it on my computer (I am using Windows XP). I also downloaded the App Engine Python software ...

Highlight a row in wxGrid (with wxPython) when a cell in that row changes programatically

How do I highlight a row after an update of the underlying PyGridTableBase? I can't seem to get my head around it. I am able to create alternate row highlighting lines when the table is first drawn: ### Style the table a little. def GetAttr(self, row, col, prop): attr = gridlib.GridCellAttr() if self.is_header(row): ...

How should I organise my functions with pyparsing?

I am parsing a file with python and pyparsing (it's the report file for PSAT in Matlab but that isn't important). here is what I have so far. I think it's a mess and would like some advice on how to improve it. Specifically, how should I organise my grammar definitions with pyparsing? Should I have all my grammar definitions in one fun...

Removing an element from a list based on a predicate

I want to remove an element from list, such that the element contains 'X' or 'N'. I have to apply for a large genome. Here is an example: input: codon=['AAT','XAC','ANT','TTA'] expected output: codon=['AAT','TTA'] ...

Syntax Error exec-ing python code from database

I'm loading some python code from a database (it's doing dynamic mapping of values that I can change at runtime without a code redeploy). In my code, I'm doing this to execute the database code: if lMapping: print lMapping exec lMapping lValue = mapping(lValue, lCsvRow) and here's the value of lMapping: def mapping(pValue, pCs...

Authenticate imaplib.IMAP4_SSL against an Exchange imap server with AUTH=NTLM

Yesterday, the IT department made changes to the Exchange server. I was previously able to use imaplib to fetch messages from the server. But now it seems they have turned off the authentication mechanism I was using. From the output below, it looks as if the server now supports NTLM authentication only. >>> from imaplib import IMAP4_...

how to set the unique identifier key dynamically from a list containing unique numbers from a csv file?

Hi, I would like to know if there is a way to set the key of an entity in google app engine dynamically from a list of unique numbers stored in a csv file and bulkload it to the datastore. Also is it possible to have an entity model with out any properties and just use the the set of predefined unique numbers as keys. Thanks, Arun ...

searching all fields in a table in django

How to search all fields in a table in django using filter clause ex:table.object.filter(any field in the table="sumthing") Thanks. ...

Simple Automatic Classification of the (R-->R) Functions

Given data values of some real-time physical process (e.g. network traffic) it is to find a name of the function which "at best" matches with the data. I have a set of functions of type y=f(t) where y and t are real: funcs = set([cos, tan, exp, log]) and a list of data values: vals = [59874.141, 192754.791, 342413.392, 1102604.284...

Mechanize submit login form from http to https

I have a web page containing a login form which loads via HTTP, but it submits the data via HTTPS. I'm using python-mechanize to log into this site, but it seems that the data is submitted via HTTP. My code is looks like this: import mechanize b = mechanize.Browser() b.open('http://site.com') form = b.forms().next() # the login form...