python

Stable python serialization (e.g. no pickle module relocation issues)

Hi all, I am considering the use of Quantities to define a number together with its unit. This value most likely will have to be stored on the disk. As you are probably aware, pickling has one major issue: if you relocate the module around, unpickling will not be able to resolve the class, and you will not be able to unpickle the inform...

Python/PySerial and CPU usage

Hi folks, I've created a script to monitor the output of a serial port that receives 3-4 lines of data every half hour - the script runs fine and grabs everything that comes off the port which at the end of the day is what matters... What bugs me, however, is that the cpu usage seems rather high for a program that's just monitoring a s...

How do I use colour with Windows command prompt using Python?

I'm trying to patch a waf issue, where the Windows command prompt output isn't coloured when it's supposed to be. I'm trying to figure out how to actually implement this patch, but I'm having trouble finding sufficient resources - could someone point me in right direction? Update 1 Please don't suggest anything that requires Cygwin. ...

How to freeze/grayish window in pygtk?

I want main window to "gray, freeze, stop working", when some other window is opened. Is there some default way to do it? Pretty much the same as gtk.Dialog is working. EDIT: Currently I'm just replacing all contents by a text line, but I guess there should be better way. ...

How to create probability density function graph using csv dictreader, matplotlib and numpy?

I'm trying to create a simple probability density function(pdf) graph using data from one column of a csv file using csv dictreader, matplotlib and numpy... Is there an easy way to use CSV DictReader combined with numpy arrays? Below is code that doesn't work. The error message is TypeError: len() of unsized object, which I'm guessing ...

Gender problem in a django i18n translation

I need to solve a gender translation problem, and Django doesn't seem to have gettext contexts implemented yet... I need to translate from english: <p>Welcome, {{ username }}</p> In two forms of spanish, one for each gender. If user is a male: <p>Bienvenido, {{ username }}</p> and if is a female: <p>Bienvenida, {{ username }}</p>...

Python/Suds: Type not found: 'xs:complexType'

I have the following simple python test script that uses Suds to call a SOAP web service (the service is written in ASP.net): from suds.client import Client url = 'http://someURL.asmx?WSDL' client = Client( url ) result = client.service.GetPackageDetails( "MyPackage" ) print result When I run this test script I am getting the fol...

Using settings.LANGUAGES with properly translated names using gettext()

From Django Documentation: If you define a custom LANGUAGES setting, it's OK to mark the languages as translation strings (as in the default value displayed above) -- but use a "dummy" gettext() function, not the one in django.utils.translation. You should never import django.utils.translation from within your setti...

How do I efficiently do a bulk insert-or-update with SQLAlchemy?

I'm using SQLAlchemy with a Postgres backend to do a bulk insert-or-update. To try to improve performance, I'm attempting to commit only once every thousand rows or so: trans = engine.begin() for i, rec in enumerate(records): if i % 1000 == 0: trans.commit() trans = engine.begin() try: inserter.execute(...)...

What is cross browser support for JavaScript 1.7's new features? Specifically array comprehensions and the "let" statement.

https://developer.mozilla.org/en/New_in_JavaScript_1.7 A lot of these new features are borrowed from Python, and would allow the creation of less verbose apps, which is always a good thing. How many times have you typed for (i = 0; i < arr.length; i++) { /* ... */ } for really simple operations? Wouldn't this be easier: [/* ... ...

How Can I Empty the Used Memory With Python ?

I have just written a .psf file in Python for executing an optimization algorithm for Abaqus package, but after some analysis it stops. Could you please help me and write Python code to free the memory? Thanks ...

Converting list of integers into a binary "string" in python

I have a list of numbers that i would like to send out onto a socket connection as binary data. As an example, i start off with the following list: data = [2,25,0,0,ALPHA,0,23,18,188] In the above list, ALPHA can be any value between 1 and 999. Initially, I was converting this into a string using hexdata = ''.join([chr(item) for i...

Prevent python imports compiling

I have have a python file that imports a few frequently changed python files. I have had trouble with the imported files not recompiling when I change them. How do I stop them compiling? ...

iTunes COM interface

Hi. I would like to be able to control iTunes with python. I know this is possible and I successfully tested some examples I have seen here at stackoverflow and in other sites, too. However, I would like to read the documentation about this. I have registered in Mac Dev Center, and when try to access the [link] where the docs are, but ...

In-memory size of python stucture

Does someone know of a good reference card for the memory size of python data stucture on 32 and 64 bit platforms ? If not, this would be nice to have it on SO. The more exhaustive the better ! So how many bytes are used by those python structures (depending on the len and the content type when relevant) ? - int - float - reference...

Using Heapy's Memory Profile Browser with Twisted.web

I am trying to profile twisted python code with Heapy. For example (pseudo code): from twisted.web import resource, server from twisted.internet import reactor from guppy import hpy class RootResource(resource.Resource): render_GET(self, path, request): return "Hello World" if __name__ == '__main__': h = hpy() por...

Extending Jython Syntax

I would like to add syntax to Jython to enable a nicer API for users. For instance, matrix libraries like NumPy would benefit from having both matrix and elementwise operations like Matlab's :* vs. * infix operators. You can create a matrix in Octave using: A = [ 1, 1, 2; 3, 5, 8; 13, 21, 34 ] which is considerably nicer than NumPy's...

Why does weakproxy not always preserve equivalence in python ?

MySQLDb uses weak proxy to prevent circular dependencies between cursors and connections. But you would expect from the documentation on weakref that you could still tests for equivalence. Yet: In [36]: interactive.cursor.connection.thread_id() Out[36]: 4267758 In [37]: interactive.web_logic.conns.primary.thread_id() Out[37]: 4267758 ...

Regular Expression to match cross platform newline characters

My program can accept data that has newline characters of \n, \r\n or \r (eg Unix, PC or Mac styles) What is the best way to construct a regular expression that will match whatever the encoding is? Alternatively, I could use universal_newline support on input, but now I'm interested to see what the regex would be. ...

import csv file into mysql database using django web application

hi everyone!i try to upload a csv file into my web application and store it into mysql database but failed.Please can anyone help me? my user.py script: def import_contact(request): if request.method == 'POST': form = UploadContactForm(request.POST, request.FILES) if form.is_valid(): csvfile = request.FILES['file'] print csvfile ...