python

Suggestions on manipulating an SVG map

Hi, I'm working on a map of the native languages of California for Wikipedia. The map contains areas that each correspond to a language. The original looks like this (click it to see the SVG): I want to make "locator maps" for each of those individual languages by hand (in Inkscape), like this one, for a language called Cahuilla (whi...

find corresponding key,values and return?

I have a dictionary cities = {1:'Kompong Som', 2: 'Kompong Thom', 3: 'Phnom Penh'} tags = {1: 'school', 2: 'public', 3: 'private'} kwargs = {'city': '2', 'tag': '3'}#should be improve I want to get output like this : kwargs = {'city': 'Kompong Thom', 'tag': 'private'} EDIT passed from URL keyword = customer_type=&last_contact...

How to disable shell interception of control characters?

Hi. I'm writing a curses application in Python under UNIX. I want to enable the user to use C-Y to yank from a kill ring a la Emacs. The trouble is, of course, that C-Y is caught by my shell which then sends SIGTSTP to my process. In addition, C-Z also results in SIGTSTP being sent, so catching the signal means that C-Y and C-Z are not...

How to search and replace utf-8 special characters in Python?

I'm a Python beginner, and I have a utf-8 problem. I have a utf-8 string and I would like to replace all german umlauts with ASCII replacements (in German, u-umlaut 'ü' may be rewritten as 'ue'). u-umlaut has unicode code point 252, so I tried this: >>> str = unichr(252) + 'ber' >>> print repr(str) u'\xfcber' >>> print repr(str).repl...

how does send email with django-registration .

include mail Confirmation thanks ...

How to provide a default value for base class attribute from subclass in Django?

Scenario: class BaseClass(models.Model): base_field = models.CharField(max_length=15, default=None) class SubClass(BaseClass): # TODO set default value if base_field's value is None ... ie. I need to be able to load a fixture into the database, providing a default value only if the base_field is None. Any help greatly app...

How to import models in other projects in Django

Is it possible to import models from apps in different Django projects? I hope to move some common models in a base projects from which every child projects can share the same data in these common models. Edit I have to place from baseproject.appname.models import basemodel before os.environ['DJANGO_SETTINGS_MODULE'] = 'childproje...

How to stop "warnings" when using vim omni-completion with python?

I am trying vim's python omni-completion script, it works, but I got problem. After I start vim, the 1st time I press to ask vim to complete python code, many warning shown up. That's because some python libs in my project use md5, which will trigger a warning message in python 2.6 That's very ignoring, how to stop vim/python from is...

Why can't Python handle true/false values as I expect?

As part of answering another question, I wrote the following code whose behaviour seems bizarre at first glance: print True # outputs true True = False; print True # outputs false True = True; print True # outputs false True = not True; print True # outputs true Can anyone explain this strange behaviour...

python memory del list[:] vs list = []

In python I have noticed that if you do mylist = [] for i in range(0,100000000): mylist.append('something here to take memory') mylist = [] it would seem the second call mylist = [] would remove the reference and it would get collected but, as I watch them memory it does not. when I use del mylist[:] it almost deletes ev...

is there a way to view the source of a module from within the python console?

if I'm in the python console and I want to see how a particular module works, is there an easy way to dump the source? ...

Merging two event loops (Cherrypy and Wxpython)

Okay, I have an application written with cherrypy, and I want to build a wxpython gui for it. The problem is that both modules use a close loop for event handling, which (I assume) means while one is running the other will be locked. I asked for some advice and it was suggested that I merge the two event loops rather than using the stoc...

translate one language to another?

is it possible to translate one language to another with an interpreter? heard that quercus could translate php to java? at first, i thought it was a cheap lousy solution which could give code errors, but it seems that it´s fully possible to do so. could you translate php to other languages, like python or ruby? c++ to java and so on? ...

Generating SQL "IN" clauses: how to safely handle input + empty value lists?

In my Python code I often find myself doing the following (using DB-API): yValues = pickInterestingValuesOfY() sql = "..." # includes a clause stating that "y must be in yValues" c.execute(sql, yValues) In the end, the SQL being executed could be something as simple as SELECT x FROM table1 WHERE y IN (1,2,3); The issue is that th...

How to protect Python source code?

Is it possible to distribute only the bytecode version (.pyc file) of a Python script instead of the original .py file? My app embeds the Python interpreter and calls PyImport_Import to load a script. How can I tell it to look for a .pyc file and import that? ...

is there a way to have a python application run invisibly?

I have a cherrypy application that I want to control over http with a simple gui. The problem is I don't want both the cherrypy window and the gui running at the same time. Is there a way I can make the cherrypy applications window visible? Its being written for windows, which probably makes a difference ...

python optimized mode

Python can run script in optimized mode (-O) that turns off debugs like assert and if I remember also remove docstrings. I have no seen it used really and maybe it is just artifact of the past times. Is it being used? What for? Why isn't this useless thing being removed in Python 3? ...

is there any difference between 'a.b.a' and 'b.b.a'.

class a(object): class b: a='aaa' print a.b.a#print 'aaa' b=a() print b.b.a#print 'aaa' thanks ...

Python function local variable scope during exceptions

Background: I'm doing COM programming of National Instruments' TestStand in Python. TestStand complains if objects aren't "released" properly (it pops up an "objects not released properly" debug dialog box). The way to release the TestStand COM objects in Python is to ensure all variables no longer contain the object—e.g. del() them, or ...

Help with Python strings

I have a program which reads commands from a text file for example, the command syntax will be as follows and is a string 'index command param1 param2 param3' The number of parameters is variable from 0 up to 3 index is an integer command is a string all the params are integers I would like to split them so that I have a list as fol...