python

Parsing CSV data in python

I am getting this sort of CSV data while making Http request to the CSV file. Very malformed string. response = '"Subject";"Start Date";"Start Time";"End Date";"End Time";"All day event";"Description""Play football";"16/11/2009";"10:00 PM";"16/11/2009";"11:00 PM";"false";"""Watch 2012";"20/11/2009";"07:00 PM";"20/11/2009";"08:00 PM";"f...

How do I get the selected text in desktop application using python-dbus?

For example, I open a pdf file or a web page in gnome, use mouse double click some text, so a word is selected, how can I get this word in a background running daemon written with python-dbus? Some simple but working piece of script is appreciated greatly. Thanks! ...

Python 3 Library for Realtime Midi Communication

Hi, Can anyone suggest a good Python 3 Library for sending / receiving reatime MIDI? ...

Calling Method from Different Python File

As I'm currently learning Django / Python, I've not really been using the concept of Classes, yet. As far as I'm aware the method isn't static.. it's just a standard definition. So let's say I have this Package called Example1 with a views.py that contains this method: def adder(x,y): return x + y Then I have an Example2 which also...

How to use python win32com to save as excel file

I have a small python code to open an Excel file. Now I want to "Save As" with a different name but same format. How do I do that.. Any help will be great. FK ...

sorting function in python.

Hi, I'm trying to sort a list of objects according to my criteria. Here is my sorting function: def sort_pots(self, pot1, pot2): coeff1 = ((pot1.movable + pot1.convertible) / pot1.total) coeff2 = ((pot2.movable + pot2.convertible) / pot2.total) if coeff1 > coeff2: return 1 elif coeff1 == coeff2: retur...

How is a union different from a struct? Do other languages have similar constructs?

Possible Duplicate: Difference between a Structure and a Union in C I see this code for a union in C: union time { long simpleDate; double perciseDate; } mytime; What is the difference between a union and a structure in C? Where would you use a union, what are its benefits? Is there a similar construct...

compute crc of file in python

I want calculate crc of file, and get output like [E45A12AC] I don't want md5 or other. #!/usr/bin/env python import os, sys import zlib def crc(fileName): fd = open(fileName,"rb") content = fd.readlines() fd.close() for eachLine in content: zlib.crc32(eachLine) for eachFile in sys.argv[1:]: crc(eachFile) calculates for...

Convert float to string with cutting zero decimals afer point in Python

Hi all! I am feeling difficult to convert a float to string in the following manner: 20.02 --> 20.02 20.016 --> 20.02 20.0 --> 20 Seems "%g" format is the best for that, but I am getting strange results: In [30]: "%.2g" % 20.03 Out[30]: '20' In [31]: "%.2g" % 20.1 Out[31]: '20' In [32]: "%.2g" % 20.3 Out[32]: '20' In [33]: "%....

How to sort model by values in a dictionary?

In Django, I have a model, and I will have a dictionary having the id's of objects in this model as keys, and a weight as values. I would like to use these weights in an order_by: MyModel.objects.filter(title__icontains=query).order_by( 'value_from_the_dictionary' ) How to make this work? I can't put the weights in the model, as they...

Why does my Python program average only 33% CPU per process? How can I make Python use all available CPU?

I use Python 2.5.4. My computer: CPU AMD Phenom X3 720BE, Mainboard 780G, 4GB RAM, Windows 7 32 bit. I use Python threading but can not make every python.exe process consume 100% CPU. Why are they using only about 33-34% on average?. I wish to direct all available computer resources toward these large calculations so as to complete t...

Differences between Go and Cython

Today a great friend of mine asked me what are the main differences between the newest Go language and Cython, which is a set of C-extensions for Python. I don't have much knowledge on Python, can anyone tell me why Go is better/worse than Cython? Best regards, Miguel Rentes ...

Conflicting Python Packages How can it be Resolved?

So we went to implement something today, and discovered that there already is several applications relying on the old implementation of our inhouse python library. Called cis_py. Now all applications for our implementation currently sit in a folder called, bin. This is where cis_py currently resides. Now we went to deploy one of our big...

Windows with Plesk Panel installs ActiveState Python 2.5.0 - any thoughts?

I expect to run Pylons on a Windows Server 2003 and IIS 6 on a Virtual Private Server (VPS). Most work with the VPS is done through the Plesk 8.6 panel. The Plesk panel has a lot of maintenance advantages for us. However, this Plesk configuration installs ActiveState Python 2.5.0. The Parallels Plesk documents for 8.6 and version 9 insis...

Is `import module` better coding style than `from module import function`?

Let from module import function be called the FMIF coding style. Let import module be called the IM coding style. Let from package import module be called the FPIM coding style. Why is IM+FPIM considered a better coding style than FMIF? (See this post for the inspiration for this question.) Here are some criteria which lead me to pre...

Does Django cache templates automatically?

I'm new to Django and trying to implement a voting system between two images. However, it looks like the page is being cached or something because when I refresh it, some values are wrong. I have no cache setup in my Settings. Here is the View: def rate(request, type): photos = Photo.objects.order_by('?')[:2] c = Context({"ph...

Embedding a control in a QTableView?

I'm working a small qt app (using PyQt4) and I've come up with an idea but I'm unsure as to how to implement it. I have a QTableView that represents some data and I'd like to add another column to the QTableView that contains a checkbox control that could be wired up to some piece of the model. For example, something like this: Note t...

Automating old DOS application using Python

Is there a way to automate an old DOS application (16-bit, probably needs an emulator such as DOSBox) from Python (on Windows)? I would like to send keys and strings to the application, detect updates to the DOS "screen" and get the application output. It would be even better if the DOS application could run "hidden", i.e., not showing ...

Read from File, or STDIN

I've written a command line utility that uses getopt for parsing arguments given on the command line. I would also like to have a filename be an optional argument, such as it is in other utilities like grep, cut etc. So, I would like it to have the following usage tool -d character -f integer [filename] How can I implement the followi...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python? ...