python

Create a python function procedurally (specifically the arguments).

Question How do you procedurally create a function in Python which takes specific named arguments but allow those argument names to be data-driven? Example Say, you want to create a class decorator, with_init, which adds an __init__ method with specific named arguments such that the following two classes are equivalent. class C1(obje...

Python Type Conversion

Whats the best way to convert int's, long's, double's to strings and vice versa in python. I am looping through a list and passing longs to a dict that should be turned into a unicode string. I do for n in l:     {'my_key':n[0],'my_other_key':n[1]} Why are some of the most obvious things so complicated? ...

In Django, how do I clear a sessionkey?

I set a session like this: request.session['mykey']= 33 How do I clear it? I just want to DELETE it. ...

Help on my django models for my shoe review website.

What i'm trying to achieve at this point: Allow me to add new shoe objects, and shoe review objects. complete Allow "Owner Reviews" on each shoe complete (I think, but there might be somewhere in my model I can improve) Allow ratings of attributes defined by me which are linked to a particular shoe. Preferably, having an easy way to it...

How does one monkey patch a function in python?

I'm having trouble replacing a function from a different module with another function and it's driving me crazy. Let's say I have a module bar.py that looks like this: from a_package.baz import do_something_expensive def a_function(): print do_something_expensive() And I have another module that looks like this: from bar import...

Emacs collaborative buffers open in the wrong mode

I am using Emacs and Rudel to collaborate with a remote programmer. Rudel has a concept of published buffers. When my partner publishes a buffer, I can subscribe to it and the we can both edit it simultaneously. My problem is that when he publishes a Python file with a *.py extension and I subscribe to it, my buffer is not set to pyth...

Python check for blank CSV value not working

I have a CSV file and I am running a script against it to insert into a database. If the value is blank then I don't want to insert it. Here is what I have if attrs[attr] != '' and attrs[attr] != None: log.info('Attriute ID: %s' % attr) log.info('Attriute Value: %s' % attrs[attr]) sql = insert_attr_q...

Is it possible to dock wx.auiManager panes onto tops/bottoms of another panes?

Hello, with this code: import wx import wx.aui class MyFrame(wx.Frame): def __init__(self, parent, id=-1, title='wx.aui Test', pos=wx.DefaultPosition, size=(800, 600), style=wx.DEFAULT_FRAME_STYLE): wx.Frame.__init__(self, parent, id, title, pos, size, style) self._mgr = wx.aui.A...

Getting a Jabber status via Python

I'm developing a website using the Django framework, and I need to retrieve Jabber (okay, Google Talk) statuses for a user. Most of the Jabber python libraries seem like an incredible amount of overkill (and overhead) for a simple task. Is there any simple way to do this? I know very little about XMPP/Jabber, though of course I'm willi...

C#: Equivalent of the python try/catch/else block

In Python, there is this useful exception handling code: try: # Code that could raise an exception except Exception: # Exception handling else: # Code to execute if the try block DID NOT fail I think it's useful to be able to separate the code that could raise and exception from your normal code. In Python, this was possib...

wsdl2py requests

I'm trying to get results from a SOAP service called Chrome ADS (for vehicle data). They provided php and Java samples, but I need python (our site is in Django). My question is: What should I be passing as a request to the SOAP service when using wsdl2py-generated classes? Following the examples I'm using a DataVersionsRequest object ...

Debugging Python Crash

I am building Python 2.6 4 from source on a Linux server and am experiencing a Segmentation Fault when running the tests (make test) (test_hashlib.py and test_hmac.py). When I opened the core dump file in gdb, I am told that the error is at 0x00002b73379ac446 in ??. I then recompiled python with both my CFLAGS and CPPFLAGS set to -g to...

Regex redefinition error

I am using python, and run into some redefinition error, I know they are redefinition but logically its not possible to reach that since its an or. Is there a way to get around this? I appreciate for any help in advance /python-2.5/lib/python2.5/re.py", line 233, in _compile raise error, v # invalid expression sre_constants.error: r...

I'm making a resume...what would you consider as intermediate python programming skills?

I've made a couple of scripts. One is a stock screener that can search through every stock. Another creates a heatmap that tells you what's performed well and badly over the past day. They aren't really that useful, just did them to work on my programming skills. I was able to throw some SQL in my scripts too. Would you call that in...

Python and a "time value of money" problem.

(I asked this question earlier today, but I did a poor job of explaining myself. Let me try again) I have a client who is an industrial maintenance company. They sell service agreements that are prepaid 20 hour blocks of a technician's time. Some of their larger customers might burn through that agreement in two weeks while customers w...

How do I remove a column from a table in beautifulsoup (Python)

I have an html table, and I would like to remove a column. What is the easiest way to do this with BeautifulSoup or any other python library? ...

TypeError: unsupported operand type(s) for -: 'str' and 'int'

New to python and programing how come I'm getting this error? def cat_n_times(s, n): while s != 0: print(n) s = s - 1 text = input("What would you like the computer to repeat back to you: ") num = input("How many times: ") cat_n_times(num, text) ...

How do I loop through every 4th pixel in every 4th row, using Python?

Write a function called listenToPicture that takes one picture as an argument. It first shows the picture. Next , it will loop through every 4th pixel in every 4th row and do the following. It will compute the total of the red, green and blue levels of the pixel, divide that by 9, then add the result to 24. That number will be the note...

Getting "OperationalError" when running Django development server from within Eclipse

I'm trying to set up a Django project in Eclipse, and I'm getting stuck while trying to set up the development server for Run & Debug configurations. I've been following the following example: http://pydev.blogspot.com/2006/09/configuring-pydev-to-work-with-django.html. I've created a new run configuration in Eclipse, set the project a...

Apache using Python 2.4, Python 2.5 scripts failing

Using CentOS5, I have Apache configured with the following directives. Alias /pscript/ /var/www/pscript/ <Directory "/var/www/pscript/"> Options +ExecCGI DirectoryIndex thetest.py AddHandler cgi-script .py </Directory> When I call www.domain.com/pscript/ then my python script runs and prints out my sys.path, which is displ...