python

Django How to show user's name in his profile in admin console

I attached a UserProfile class to User this way: class UserProfile(models.Model): url = models.URLField() home_address = models.TextField() user = models.ForeignKey(User, unique=True) I have also implemented auto-creating of UserProfile if needed this way: def user_post_save(sender, instance, signal, *args, **kwargs): ...

Howto Format dict string outputs nicely

I wonder if there is an easy way to format Strings of dict-outputs such as this: { 'planet' : { 'name' : 'Earth', 'has' : { 'plants' : 'yes', 'animals' : 'yes', 'cryptonite' : 'no' } } } ..., where a simple str(dict) just would give you a quite unreadable ... {'planet' : {'has': {'plants': 'yes', 'an...

Is this a good reason to check types in Python?

I know that checking types in Python is bad and you should probably never do it. But I can't seem to find the disadvantage to this. class O(object): def __init__(self, name): '''Can only be called in derived classes.''' if type(self) is O: message = "%(class)s cannot be instantiated, it must be ...

How to install Trac Plugin and what is a python egg?

In Trac on Admin -> Plugins there is an option to install Plug-ins. Now this option expect you to upload an Python egg. This would be all well but for the fact that all the Trac plug-ins I found are either plain .py files or zip files and are incompatible with the upload function (I tried it). This leaves my with a bunch of questions: ...

Determine whether a key is present in a Python dict

Possible Duplicate: 'has_key()' or 'in'? I have a Python dictionary like : mydict = {'name':'abc','city':'xyz','country','def'} I want to check if a key is in dictionary or not. I am eager to know that which is more preferable from the following two cases and why? 1> if mydict.has_key('name'): 2> if 'name' in mydict: ...

Integrating C++ code with any web technology on Linux

hello, i am writing an program in c++ and i need an web interface to control the program and which will be efficient and best programming language ... ...

Python RegEx Matching Newline

I have the following regular expression: [0-9]{8}.*\n.*\n.*\n.*\n.* Which I have tested in Expresso against the file I am working and the match is sucessfull. I want to match the following: Reference number 8 numbers long Any character, any number of times New Line Any character, any number of times New Line Any character, any numb...

Serializing IronPython Objects Which Inherit From CLR Types

This may be a bit of a weird question, but is there any reliable way to serialize IronPython objects whose classes extend CLR types? For instance: class Foo(System.Collections.Generic.List[str]): def Test(self): print "test!" System.Collections.Generic.List<string> is serializable with Pickle, as it implements the ISerial...

Retrieve User Entry IDs from MAPI

Hi folks, I extended the win32comext MAPI with the Interface IExchangeModifyTable to edit ACLs via the MAPI. I can modify existing ACL entries, but I stuck in adding new entries. I need the users entry ID to add it, according this C example (Example Source from MSDN) STDMETHODIMP AddUserPermission( LPSTR szUserAlias, LPMAPISES...

error during "import ibm_db"

I am getting this error ! Traceback (most recent call last): File "/home/e**/RRR/RRR_Success.py", line 37, in ? import ibm_db ImportError: libdb2.so.1: cannot open shared object file: No such file or directory Please help me to solve this problem ...

What is the equivalent for heapq of Python in Java?

I would like to know if there is any api available for Java which is just like heapq in Python. ...

unable to compile python program using jython

Hi, I'm trying to compile a python program using jython and it's throwing below error C:\jython2.2.1>jython test.py Traceback (innermost last): (no code object) at line 0 File "test.py", line 30 html = html if html else download(url, user_agent).read() ^ SyntaxError: invalid synta...

When to use * and ** as a function argument in python function

When can I pass * and ** in the argument of a Python function? i.e.: def fun_name(arg1, *arg2 , ** arg3): ...

Translate matlab to python/numpy

hi, i am looking for a automatic translator from Matlab to python. I downloaded and installed LiberMate but it not documented anywhere and i wasn't able to make it work. Has anybody dealt with this kind of challenge before? Any advice welcome. ...

Getting pdb in emacs to use python process from current virtualenv

I am debugging some python code in emacs using pdb and getting some import issues. The dependencies are installed in one of my bespoked virtualenv environments. Pdb is stubbornly using /usr/bin/python and not the python process from my virtualenv. I use virtualenv.el to support switching of environments within emacs and via the posta...

Django - alert when memcached is down

Is there some ready-made addon that alerts admins about memcached instance being inaccessible from a Django application? I don't mean here monitoring memcached daemon itself, but something that checks if my Django app benefits from caching. My basic idea is to check if cache.get that follow cache.set actually returns something, and if n...

Linear feedback shift register?

Lately I bumped repeatedly into the concept of LFSR, that I find quite interesting because of its links with different fields and also fascinating in itself. It took me some effort to understand, the final help was this really good page, much better than the (at first) cryptic wikipedia entry. So I wanted to write some small code for a p...

socket in python

hello ,,, i tried to do client and server and look what i do #Server import socket Host='' Port=305 OK=socket.socket() OK.bind((Host,Port)) OK.listn(1) OK.accept() and another one for client #Client impot socket Host='192.168.1.4' Port=305 OK=socket.socket() OK.connect((Host,Port)) First thing : for now every thing is ok but i w...

Python lxml and stdin

I have a xml file, book.xml (http://msdn.microsoft.com/en-us/library/ms762271(VS.85).aspx) I would like to cat books.xml and get all book ids and genres for the book id. Similar to cat books.xml | python reader.py Any tips or help would be appreciated. Thanks. ...

Disable Window's automated handling of errors in subprocesses.

I'm trying to write a test suite for a compiler (LLVM) and it works perfectly fine on every platform except for Windows. On Windows I get the "critical-error-handler" message box which stops the tests indefinitely. This problem makes it very difficult to test because, with compilers, a problem often means invalid code on the assembly l...