python

Is it possible to change an instance's method implementation without changing all other instances of the same class?

Hi there! I do not know python very much (never used it before :D), but I can't seem to find anything online. Maybe I just didn't google the right question, but here I go: I want to change an instance's implementation of a specific method. When I googled for it, I found you could do it, but it changes the implementation for all other i...

How can I send an iCalendar email attachment with Django?

I want to send an iCalendar http://en.wikipedia.org/wiki/ICalendar email attachment using Django. Is there an open source library to build an iCalendar file in Python and/or available for Django? ...

Multi Language Starter Templates

I'm currently working through some code katas in multiple languages (Ruby, Perl, Python)/frameworks (Rails, Django, Mojo). It seems every time I start a new project from scratch I end up tweaking files to my liking, even after using things like newgem, module-starter, script/generate, startapp, etc. For those who program in many differe...

Python PyQT4 - Adding an unknown number of QComboBox widgets to QGridLayout

Hi all, I want to retrieve a list of people's names from a queue and, for each person, place a checkbox with their name to a QGridLayout using the addWidget() function. I can successfully place the items in a QListView, but they just write over the top of each other rather than creating a new row. Does anyone have any thoughts on how I ...

mod_python django logging problem

I use logging settings as below in the settings.py file: logging.basicConfig(level=LOG_LEVEL, format=LOG_FORMAT); handler = logging.handlers.RotatingFileHandler( LOG_FILE_PATH, 'a', LOG_FILE_SIZE,LOG_FILE_NUM ); formatter = logging.Formatter ( LOG_FORMAT ); handler.setFormatter(formatter); logging.getLogger().addHandler(handler) ...

Common errors when moving a django app from dev to prod?

Hello, I am developping a django app on Windows, SQLite and the django dev server . I have deployed it to my host server which is running Linux, Apache, FastCgi, MySQL. Unfortunately, I have an error returned by the server on the prod while everything ok on the dev machine. I've asked my provider for a pre-production solution in order ...

ConfigParser with Unicode items

Hi all, my troubles with ConfigParser continue. It seems it doesn't support Unicode very well. The config file is indeed saved as UTF-8, but when ConfigParser reads it it seems to be encoded into something else. I assumed it was latin-1 and I thougt overriding optionxform could help: -- configfile.cfg -- [rules] Häjsan = 3 ☃ = my snowm...

How to split a string by commas positioned outside of parenthesis?

Hi, I got a string of such format: "Wilbur Smith (Billy, son of John), Eddie Murphy (John), Elvis Presley, Jane Doe (Jane Doe)" so basicly it's list of actor's names (optionally followed by their role in parenthesis). The role itself can contain comma (actor's name can not, I strongly hope so). My goal is to split this string into ...

Watching sockets with Glib on Windows puts them in non-blocking mode

The following code does not work correctly on Windows (but does on Linux): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setblocking(True) sock.connect(address) gobject.io_add_watch( sock.fileno(), gobject.IO_OUT | gobject.IO_ERR | gobject.IO_HUP, callback) Snippets o...

Python logging using a decorator

This is the first example we meet when we face with decorators. But I'm not able to realize what exactly I would like. A simple decorator named LOG. It should work like this: @LOG def f(a, b=2, *c, **d): pass And the result should be something like: f(1, pippo=4, paperino='luca') ===== Enter f ===== a = 1 b = 2 pippo = 4 paperin...

Given a latitude and longitude, and distance, I want to find a bounding box

Given a latitude and longitude, and distance, I want to find a bounding box where the distances are less than the given distance. This questions was asked here: http://stackoverflow.com/questions/238260/how-to-calculate-the-bounding-box-for-a-given-lat-lng-location I donot want this partcularly accurate, so I have modified and simplif...

How to assert that zero or only one of N given arguments is passed

I have a definition like this def bar(self, foo=None, bar=None, baz=None): pass I want to make sure a maximum of one of foo, bar, baz is passed. I can do if foo and bar: raise Ex() if foo and baz: raise Ex() .... But there got be something simpler. ...

Python library path

I have a python file "testHTTPAuth.py" which uses module deliciousapi and is kept in "deliciousapi.py". I have kept the files like testHTTPAuth.py lib deliciousapi.py But when i run: "python testHTTPAuth.py" it's giving error import deliciousapi ImportError: No module named deliciousapi How can handle these python librari...

Trying to compile Python using TDM-GCC on Win32, error in posixmodule.c

This is the line typedef BOOL (WINAPI *CRYPTACQUIRECONTEXTA)(HCRYPTPROV *phProv, LPCSTR pszContainer, LPCSTR pszProvider, DWORD dwProvType, DWORD dwFlags ); Where I get the error: Python-2.6.4\Modules\posixmodule.c|8299|error: expected ')' before '*' token| The compiler is GCC: gcc (TDM-1 mingw32) 4.4.1...

Overriding Django views with decorators

I have a situation that requires redirecting users who are already logged in away from the login page to another page. I have seen mention that this can be accomplished with decorators which makes sense, but I am fairly new to using them. However, I am using the django login and a third party view (from django-registration). I do not ...

Is it still Python 2.6 versus Python 3?

G'day, I'm wanting to go back to Python after not using it for a while and I saw this question "Python Version for a Newbie" while wondering about getting back into Python 2.6 or Python 3. Almost all of the questions' answers were along the lines that most of the code out there, libraries, legacy systems, etc., is 2.5 or 2.6 rather tha...

How to handle multiple Set-Cookie header in HTTP response

Hello! I'm trying to write simple proxy server for some purpose. In it I use httplib to access remote web-server. But there's one problem: web server returns TWO Set-Cookie headers in one response, and httplib mangles them together in httplib.HTTPResponse.getheaders(), effectively joining cookies with comma [which is strange, because get...

Problem compiling Python 2.6.4 on AIX 5.3

I'm trying to build Python 2.6.4 on AIX 5.3. I'm running configure like this: ./configure --prefix=/home/chenf/python --disable-ipv6 --disable-shared --with-libs='/usr/lib/libncurses.a' --without-threads --disable-threads --with-ncurses=/utv/sad/ncurses/lib/libncurses.a I seem to be having linking problems with ncurses (see below), w...

Strange Problem with RPy2

Hello, After installing RPy2 from http://rpy.sourceforge.net/rpy2.html I'm trying to use it in Python 2.6 IDLE but I'm getting this error: >>> import rpy2.robjects as robjects >>> robjects.r['pi'] <RVector - Python:0x0121D8F0 / R:0x022A1760> What I'm doing wrong? ...

Generating a dynamic time delta: python

Hello all. Heres my situation: import foo, bar, etc frequency = ["hours","days","weeks"] class geoProcessClass(): def __init__(self,geoTaskHandler,startDate,frequency,frequencyMultiple=1,*args): self.interval = self.__determineTimeDelta(frequency,frequencyMultiple) def __determineTimeDelta(self,frequency,frequencyMu...