python

how to format variables before db to avoid errors

I am recieving errors like this one: _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't Stop.mp3' LIMIT 1' at line 1") Because I am trying to compare a URL that exists in my DB to one in a variable before I...

Matching Popen.communicate() output with regular expressions doesn't work

I have code that roughly looks like this (the entire code is a bit too long to copy here): import re from subprocess import Popen, PIPE goodOutput = re.compile(r'\S+: 0x[0-9a-fA-F]{8} \d \d\s+->\s+0x[0-9a-fA-F]{8}') p = Popen(['/tmp/myexe', param], stdout=PIPE, stderr=PIPE, cwd='/tmp') stdout, stderr = p.communicate() ret = goodOutp...

Serializing decimal points in Django, getting error: 'ValuesListQuerySet' object has no attribute '_meta'

Is there a way I can serialize a FloatField model instance in django? I have the following in a management command: def chart_data(request): i = 1 chart = open_flash_chart() chart.title = t for manager in FusionManagers.objects.all(): net_data = manager.netio_set.values_list('Net', flat=True) clean = seria...

How to setup springpython with Jython and Eclipse/PyDev?

I'm having trouble setting up SpringPython with PyDev and Jython I've installed Spring python by: jython setup.py install and the setup installed the library to my jython installation successfully. See!: In my PyDev project i've selected the jython interpreter and have c:\jython2.5.1\Lib\site-packages in my Library paths: My ...

How do I down-cast a c++ object from a python SWIG wrapper?

The problem: I've wrapped some c++ code in python using SWIG. On the python side, I want to take a wrapped c++ pointer and down-cast it to be a pointer to a subclass. I've added a new c++ function to the SWIG .i file that does this down-casting, but when I call it from python, I get a TypeError. Here are the details: I have two c++ cl...

I'm trying to pick a framework for a product I'm about to build, and so far I'm leaning toward Nagare... Any thoughts?

http://www.nagare.org/ As far as the type of product and framework usage, think something like Facebook (it's not exactly a social network, but close enough for evaluation in this context). Basically, I'm just looking for something robust, scalable, easy to work with (small learning curve is a plus), compatible with older browsers, and...

problem with running jpype with mod_python

Hi, As Python's urllib module is too slow, I'm using Java code wrapped with JPype in my web site. When I tested my web site with Django web server, there was no problem. However when I switched the web server to apache2 + mod_python, following error occurs. I googled many times but couldn't find the answer. Is there any solution to the ...

Python/Django: Adding custom model methods?

Using for example class model(models.Model) .... def my_custom_method(self, *args, **kwargs): #do something When I try to call this method during pre_save, save, post_save etc, Python raises a TypeError; unbound method. How can one add custom model methods which can be executed in the same way like model.objects.get()...

Reverting the 'global <var>' statement

Hello everyone! I am learning Python and just had this question. It possibly has no practical worth, I'm asking this out maybe because of a pedantic curiosity. I have a function: def f(): x = 12 #this is a local variable global x #this is a global I declared before x = 14 #changes global x <How can I return the...

TKinter: how to create a histogram ?

How can I create a histogram with TKinter and python ? ...

Cooperative multitasking using TPL

Hi, We are porting modeling application, which uses IronPython scripts for custom actions in modeling process. The existing application executes each Python script in separate thread and uses cooperative model for this. Now we want to port it to TPL, but first we want to measure context switching . Basically, what we have right now: ...

"import numpy" results in error in one eclipse workspace, but not in another

Whenever I try importing numpy in my new installation of Eclipse and Pydev, I get the following error: Traceback (most recent call last): File "Q:\temp\test.py", line 1, in <module> import numpy File "C:\Python26\lib\site-packages\numpy\__init__.py", line 132, in <module> import add_newdocs File "C:\Python26\lib\site-packa...

How to interchange data between two python applications?

I have two python applications. I need to send commands and data between them (between two processes). What is the best way to do that? One program is a daemon who should accept commands and parameters from another GUI application. How can I make daemon to monitor comands from GUI, while making it's job? I prefer solution would be cros...

translating arrays from c to python ctypes

I have the below arrays on C how can i interpert them to ctypes datatypes inside structre struct a { BYTE a[30]; CHAR b[256]; }; should i interpert a fixed array as the datatype * the size i want like the below and if yes how can i call this structure as a parameter to fun that takes instance from this structure class a(st...

How can I base64-encode unicode strings in JavaScript and Python?

I need an encript arithmetic, which encript text to text. the input text could be unicode, and the output should be a-z A-Z 0-9 - . (64 char max) and it could be decrypt to unicode again. it should implement in javascript and python. If there is already some library could do this, great, if there is not, could you tell me. Let me ta...

Find oldest/youngest datetime object in a list

I've got a list of datetime objects, and I want to find the oldest or youngest one. Some of these dates might be in the future. from datetime import datetime datetime_list = [ datetime(2009, 10, 12, 10, 10), datetime(2010, 10, 12, 10, 10), datetime(2010, 10, 12, 10, 10), datetime(2011, 10, 12, 10, 10), #future datet...

Why Azure lose to GAE? What do you think?

Well it's not like I dislike MS products. Actually I became MS fan in last years. Silverligt + ASP.NET MVC + WPF + Windows Mobile 7 + Bing + IE9 + Windows7. I'm in heaven :) And more over i hate Google and almost all Google products (i don't know why, but for me all Google sites\apps look ugly and primitive) But when I had to chose clo...

Getting a result from a modal window in pygtk

I need to open a new window from my applications main window. This new window need to be modal, I need to be able to get a result from the modal window based on user interaction with it. I have figured out how to make the window modal. But I can't figure out how to return a result from the modal window and pass it back to the main windo...

TKinter: a slider widget ?

Is there a slider widget in TKinter libraries ? I need a slider to set a specific value ...

Can you recommend a database schema migration tool that is not tied to a particular framework or ORM?

I've used South migrations in the past, but am now looking for a database migration tool that is not tied to a particular framework or Object Relational Mapper (South is for Django). I need it simply for managing schema updates (and rollbacks) and nothing else. Various tools and applications use the same database, so I'd like a dedicated...