python

how to link python static library with my c++ program

I am implementing a C++ program that uses python/C++ Extensions. As of now I am explicitly linking my program to python static library I compiled. I am wondering is there any way to link my program with system installed python(i mean the default python installation that comes with linux) ...

Python: loop through a file for specific lines

I have the following lines in a file where I want to take the third column; In the file I don't have the numbers column: Red; Blue; Green; White; Orange; Green; White; Orange; Blue; Green; White; Red; Blue; Green; White; Blue; Green; White; Orange; Orange Green; White; Orange; White; Orange Green; I used this code line to do that: l...

Question on Django: Displaying many to many fields

I seem to have a problem with Django when it comes Rendering ManyToManyField in a template. I can make it work partially, but I cannot make it work properly as I want it. Firstly I have an invoice template which displays Invoice details from my data base #invoice_details.html {% extends "base.html" %} {% block content %} <h2>Invoice D...

TDD/BDD framework for use with Django?

I'm trying to decide which approach to take to testing a Django app I'm writing. I've seen Cucumber and that put me onto lettuce (URL is lettuce.it) and pycurracy. I like the look of these frameworks since hopefully non-technical people will be able to write definitions. I want to be able to: run functional tests integrated with Djang...

How to connect pyqtSignal between classes in PyQT

Hello. I'd like to ask you for an advice. How to connect pyqtSignal between two different objects (classes) PROPERLY? I mean best practice. Look what I have done to achieve the goal: The Thermometer class is notified when Pot increases its temperature: from PyQt4 import QtCore class Pot(QtCore.QObject): temperatureRaisedSignal = Qt...

Clustering problem

Hi all I've been tasked to find N clusters containing the most points for a certain data set given that the clusters are bounded by a certain size. Currently, I am attempting to do this by plugging in my data into a kd-tree, iterating over the data and finding its nearest neighbor, and then merging the points if the cluster they make do...

Saving a deep copy of an object, then modifying it and saving another copy?

I have a 'GameBoard' class and am doing a search on it. I want to save the current gameboard in a list, change the state of the gameboard, save THAT one in a list, and so on (so I would have incremental versions of the gameboard as a game progresses). I'm currently doing this with copy.deepcopy, but it doesn't seem to be saving and mov...

How to raise a warning in Python without stopping (interrupting) the program?

Hi, I am dealing with a problem how to raise a Warning in Python without having to let the program crash / stop / interrupt. I use following simple function that only checks if the user passed to it a non-zero number. If the user passes a zero, the program should warn the user, but continue normally. It should work like the following co...

Django proxy model and ForeignKey

How to make entry.category to be instance of CategoryProxy? See code for details: class Category(models.Model): pass class Entry(models.Model): category = models.ForeignKey(Category) class EntryProxy(Entry): class Meta: proxy = True class CategoryProxy(Category): class Meta: proxy = True entry = EntryProx...

Setting Python Path in Windows XAMPP using WSGI

I'm setting up a development version of a live server on Webfaction, running Django apps in a virtual Apache server environment (running without any errors) on my local machine - XP, running XAMPP Lite with Python 2.6 - which I can commit changes from via Git. XAMPP is up and running OK with Python, and the server starts perfectly with ...

Using sqlchemy in Pyqt, is it possible?

Hi i am new to Pyqt and i am wondering if it is possible to have goodness of sqlalchemy e.g. connection pooling and managing, abstracting away all the menial low level details? ...

How to test with Python's unittest that a warning has been thrown?

Hi, I have a following function in Python and I want to test with unittest that if the function gets 0 as argument, it throws a warning. I already tried assertRaises, but since I don't raise the warning, that doesn't work. def isZero( i): if i != 0: print "OK" else: warning = Warning( "the input is 0!...

How to adapt my current splash screen to allow other pieces of my code to run in the background?

Currently I have a splash screen in place. However, it does not work as a real splash screen - as it halts the execution of the rest of the code (instead of allowing them to run in the background). This is the current (reduced) arquitecture of my program, with the important bits displayed in full. How can I adapt the splash screen curr...

subprocess replacement of popen2 with Python

I tried to run this code from the book 'Python Standard Library' of 'Fred Lunde'. import popen2, string fin, fout = popen2.popen2("sort") fout.write("foo\n") fout.write("bar\n") fout.close() print fin.readline(), print fin.readline(), fin.close() It runs well with a warning of ~/python_standard_library_oreilly_lunde/scripts/pope...

Tunneling Connections From a Local Host to a Server, While the Server use a proxy.pac to access the internet

I get access to part of the Internet by ssh login a server, like: ssh -D 9999 -C user@server Then set sock proxy on browser 127.0.0.1:9999 The server is behind a firewall. On the server I can access the Internet using a 'proxy.pac' file with username and password The problem is: can I ssh to the server while having the server use th...

Anyone have a favorite Python coding style enforcer?

I'm trying to find a Python coding style enforcer (tool, not person!). Any recommendations? --Steve ...

How to return the maximum element of a list in Python?

Hello, I am trying to simplify this function at his maximum, how can I do? def eleMax(items, start=0, end=None): if end is None: end = len(items) return max(items[start:end]) I though of def eleMax(items, start=0, end=-1): return max(items[start:end]) But the last element is deleted from the list. Thank for y...

C++ and Embedded Python - NUL Terminated Strings

I'm working on embedding Python 2.6 into an existing c++ application. So far I have the Libraries linked in and am able to successfully initialize the Python Interpreter and can also transfer data to Python. I'm having trouble retrieving it, and hope someone can steer me the right direction. I'm working with this: Py_Initialize(); p...

How to properly iterate over a huge QuerySet in django?

I need to retrieve 5 objects that match a certain complex criteria, and I can't/don't want to pass that criteria to the WHERE clause(filter in django), so I need to iterate over the results, testing each record for the criteria until I get my 5 objects, after that I want to throw the query set away and never see it again. In most cases...

Problem sorting IntegerProperty in Google App Engine

http://code.google.com/appengine/articles/update_schema.html Trying to work this out for a nice little updater across my web application. The only difference is rather than sorting on a StringProperty as shown in the example I am using an IntegerProperty. No matter which way round I turn the query I cannot get it to respond correctly t...