python

trickle down unit tests

If I'm writing a library in C that includes a Python interface, is it OK to just write unit tests for the functions, etc in the Python interface? Assuming the Python interface is complete, it should imply the C code works. Mostly I'm being lazy in that the Python unit test thing takes almost zero effort to use. thanks, -nick ...

How can I connect to a Microsoft Dynamics CRM server using Python?

The Microsoft Dynamics CRM service uses NTLM authentication, which makes connecting to it from a python process using suds somewhat complicated. I'm looking for a code sample that will: Send and receive the response from a RetrieveAttributeRequest Send and receive the response from an Execute request. This must use Python 2.6 or Pyth...

Browser-based MMO best-practice

I am developing an online browser game, based on google maps, with Django backend, and I am getting close to the point where I need to make a decision on how to implement the (backend) timed events - i.e. NPC possession quantity raising (e.g. city population should grow based on some variables - city size, application speed). The possib...

unoconv --stdin option?

Is there some limitation that makes having a --stdin option especially difficult for unoconv (Convert between any document format supported by OpenOffice) to support? It looks likes the file type is used to determine the document type so if standard input is used instead of a file name then the --doctype option would be required. But asi...

simulate private variables in python

I've got few variables I really want to hide because they do not belong outside my class. Also all such non-documented variables render inheritance useless. How do you hide such variables you don't want to show outside your object? To clarify why I need private variables, first one example where inability to hide variables is just an i...

PyScripter for Python 2.7

How tu run PyScripter if you have python 2.7 installed ? There is command line parameter for pyscipter to tell it which pythonXX.dll to use, but i can't get this working. ...

Display custom labels for values in the Django Admin Site

One of my models has a 'status' field which is only ever modified in code. It is an integer from 1 to 6 (although this may change in the future). However, in the Admin site, I would like to display a label for this data. So, instead of displaying '5', I would like it to say 'Error'. This means I would be able to easily filter the object...

Iterating over Dictionaries...For Loops in Python

Am a bit puzzled by the following code: d = {'x': 1, 'y': 2, 'z': 3} for key in d: print key, 'corresponds to', d[key] What i don't understand is the 'key' portion. How does python recognize that it only need to read the key from the dictionary? Is key a special word in python? Or is key simply a variable? Further clarification w...

How to do this (PHP) in python or ruby?

My app takes a loooong list of urls, and split it in X (where X = $threads) so then I can start a thread.php and calculate the urls for it. Then it does GET and POST request to retrieve data I am using this: for($x=1;$x<=$threads;$x++){ $pid[] = exec("/path/bin/php thread.php <options> > /dev/null & echo \$!"); } For "threading"...

Calling a python function over the web using AJAX?

Hi, I want to send a string to a python function I have written and want to display the return value of that function on a web page. After some initial research, WSGI sounds like the way to go. Preferably, I don't want to use any fancy frameworks. I'm pretty sure some one has done this before. Need some reassurance. Thanks! ...

many-to-one attributes in Storm

My schema looks something like this: CREATE TABLE plans ( id SERIAL PRIMARY KEY, description text ); CREATE TABLE projects ( id SERIAL PRIMARY KEY, project_id character varying(240) UNIQUE, plan_id integer REFERENCES plans(id) ON DELETE CASCADE ); And I want to do Storm queries along the lines of plan = store.fin...

color plot animation with play, pause, stop cabability using Tkinter with pylab/matplotlib embedding: can't update figure/canvas ?

I've looked but didn't find previous questions specific enough, so sorry if this is repeated. Goal: GUI to continuously update figure with different matrix data plotted by pylab's pcolor such that there is a running animation. But user should be able to play, pause, stop animation by Tkinter widget buttons. Before I get an answer for ma...

gpsd python client

Hi there! I'm trying to write a very simple python client for Gpsd, but I have this error after some time of execute the script: Traceback (most recent call last): File "gps_cap.py", line 13, in <module> g.stream() File "/usr/lib/python2.6/site-packages/gps/gps.py", line 348, in stream gpsjson.stream(self, flags) File "/usr/li...

Where should utility functions live in Django?

Where should utility functions live in Django? Functions like custom encrypting/decrypting a number, sending tweets, sending email, verifying object ownership, custom input validation, etc. Repetitive and custom stuff that I use in a number of places in my app. I'm definitely breaking DRY right now. I saw some demos where functions were...

Python Tkinter "X" button control (the button that close the window)

I am doing saving jobs when user presses my "Close" button in GUI environment written in Python with Tkinter library. However, if user pushes the X button on top the window to close the window, I can't do anything. How can I control -be aware of- this button? ...

Django, PIP, and Virtualenv

Hi, Got this django project that I assume would run on virtualenv. I installed virtualenv through pip install and created the env but when I try to feed the pip requirements file, I got this: Directory 'tagging' is not installable. File 'setup.py' not found. Storing complete log in /Users/XXXX/.pip/pip.log Here's the entry on the log...

Django Internal Server Error

I'm new at this and stuck. What would cause Django to run without error when I do python manage.py runserver but then throw Internal Server Error when I try to access it through the web? I have another project giving the Congratulations on your first Django-powered page, and I got the same result with the same .wsgi file initially with t...

Python unittest and discovery

I have directories, which contain files named like: 'test_foo.py' Each file is a test case. I would like to 1) run all the tests in a directory from the command line. I am using unittest2, since we are running Python 2.5.1. From one of these directories I tried typing this at the commandline: python -m unittest2 discover -p 'test_*.p...

Creating django objects with a random primary key

Hi guys! I'm working with an API that wants me to generate opaque "reference IDs" for transactions with their API, in other words, unique references that users can't guess or infer in any way. (is 'infer' proper english?) This is what I've hacked together currently: randomRef = randint(0, 99999999999999) while Transaction.objects.filt...

Eric4 Python IDE - autosave and quick script/project start, run

I've got 2 problems with Eric4 IDE. Can't find an option in preferences to autosave my changed files before running script. It's very annoying that I have to save my file and then run script. Second problem is running a script. I can't find any button to run a script/project instantly. 'Run Script' button always opens a setting window....