python

need to put a nested Dict into a text file

I have a nested dict like this d={ time1 : column1 : {data1,data2,data3} column2 : {data1,data2,data3} column3 : {data1,data2,data3} #So on. time2 : {column1: } #Same as Above } data1,data2,data3 represent the type of data and not the data itself I need to put this dict into a file like ...

Executing a MySQL query on command line via os.system in Python

I am trying to pass the 'day' from the while loop into a sql statement that then gets passed into a MySQL command line to be executed with -e I can not use the DB module or other python libraries to access MySQL, it needs to be done via command line. It also looks like I might need to convert the day to a string before concatenating to...

Find unique elements in tuples in a python list

Is there a better way to do this in python, or rather: Is this a good way to do it? x = ('a', 'b', 'c') y = ('d', 'e', 'f') z = ('g', 'e', 'i') l = [x, y, z] s = set([e for (_, e, _) in l]) I looks somewhat ugly but does what i need without writing a complex "get_unique_elements_from_tuple_list" function... ;) edit: expected value ...

Why does Django post_save signal give me pre_save data?

Im trying to connect a "Information" object to many "Customers" (see code below) When one Information object is updated, I want to send email to each Customer that is connected to the Information. However, when I log the sold_to field that the signal recieves I always get what the data is like BEFORE the save. I'm guessing this is bec...

Convolution of two functions in Python

Hi! I will have to implement a convolution of two functions in Python, but SciPy/Numpy appear to have functions only for the convolution of two arrays. Before I try to implement this by using the the regular integration expression of convolution, I would like to ask if someone knows of an already available module that performs these op...

signals or triggers in SQLAlchemy

Hi, does SQLAlchemy have something similar to Django's signal concept? Basically, I'd like to trigger a few functions when I pre-save or post-save some entity objects. Thanks. Edit: I JUST want equivalent of django-signals in SQLAlchemy. ...

Is there a good html parser like HtmlAgilityPack (.NET) for Python?

I'm looking for a good html parser like HtmlAgilityPack (open-source .NET project: http://www.codeplex.com/htmlagilitypack), but for using with Python. Anyone knows? ...

Is there a way to modify a class in a class method in Python?

I wanted to do something like setattr to a class in class method in Python, but the class doesn't exist so I basically get: NameError: global name 'ClassName' is not defined Is there a way for a class method to modify the class? Something like this but that actually works: class ClassName(object): def HocusPocus(name): se...

Screen Scrape Form Results

I was recently requested by a client to build a website for their insurance business. As part of this, they want to do some screen scraping of the quote site for one of their providers. They asked if their was an API to do this, and were told there wasn't one, but that if they could get the data from their engine they could use it as t...

Dropping the Unicode markers in Html output

I have a python list which holds a few email ids accepted as unicode strings: [u'[email protected]',u'[email protected]',u'[email protected]'] This is assigned to values['Emails'] and values is passed to render as html. The Html renders as this: Emails: [u'[email protected]',u'[email protected]',u'[email protected]'] I would like it to ...

List Comprehensions in Python : efficient selection in a list

Hi Let's suppose that I have a list of elements, and I want to select only some of them, according to a certain function (for example a distance to an other element). I want to have as a result a list of tuple, with the distance and the element. So, I wrote the following code result = [ ( myFunction(C), C) for C in originalList if myF...

Should I Start With Python 3.0?

Recently I decided to expand my programming horizons and learn the python programming language. While I have used python a little bit for classes in college and for a project or two at work I am by no means an expert. My question is as follows: should I bother with the 2.x releases or should I jump straight to 3.0? I am leaning towards 3...

GIL in Python 3.1

Does anybody knows fate of Global Interpreter Lock in Python 3.1 against C++ multithreading integration ...

Are there any cleverly efficient algorithms to perform a calculation over the space of partitionings of a string?

I'm working on a statistical project that involves iterating over every possible way to partition a collection of strings and running a simple calculation on each. Specifically, each possible substring has a probability associated with it, and I'm trying to get the sum across all partitions of the product of the substring probability in ...

How to write native newline character to a file descriptor in Python?

The os.write function can be used to writes bytes into a file descriptor (not file object). If I execute os.write(fd, '\n'), only the LF character will be written into the file, even on Windows. I would like to have CRLF in the file on Windows and only LF in Linux. What is the best way to achieve this? I'm using Python 2.6, but I'm also...

Error starting Django with Pinax

Upon trying to start a Pinax app, I receive the following error: Error: No module named notification Below are the steps I took svn co http://svn.pinaxproject.com/pinax/trunk/ pinax cd pinax/pinax/projects/basic_project ./manage.py syncdb Any suggestions? ...

Python TypeError unsupported operand type(s) for %: 'file' and 'unicode'

I'm working on a django field validation and I can't figure out why I'm getting a type error for this section: def clean_tid(self): data = self.cleaned_data['tid'] stdout_handel = os.popen("/var/www/nsmweb/jre1.6.0_14/bin/java -jar /var/www/nsmweb/sla.jar -t %s grep -v DAN") % data result = stdout_handel.read() Do I have ...

Lightweight markup language for Python

Programming a Python web application, I want to create a text area where the users can enter text in a lightweight markup language. The text will be imported to a html template and viewed on the page. Today I use this command to create the textarea, which allows users to enter any (html) text: my_text = cgidata.getvalue('my_text', 'defa...

How do I associate input to a Form with a Model in Django?

In Django, how do I associate a Form with a Model so that data entered into the form are inserted into the database table associated with the Model? How do I save that user input to that database table? For example: class PhoneNumber(models.Model): FirstName = models.CharField(max_length=30) LastName = models.CharField(max_len...

How to stop WSGI from hanging apache

I have django running through WSGI like this : <VirtualHost *:80> WSGIScriptAlias / /home/ptarjan/django/django.wsgi WSGIDaemonProcess ptarjan processes=2 threads=15 display-name=%{GROUP} WSGIProcessGroup ptarjan Alias /media /home/ptarjan/django/mysite/media/ </VirtualHost> But if in python I do : def handler(request...