python

Best canvas for drawing in wxPython?

I have to draw a graph of elements composing a topological model of a physical network. There would be nodes and arches, and the latter could be unidirectional or bidirectional. I would like to capture the clicking events for the nodes and the arches (to select the element and show its properties somewhere), and the dragging events for ...

IOError opening an existing file with Python

Running the following code: import os import datetime import ftplib currdate = datetime.datetime.now() formatdate = currdate.strftime("%m-%d-%Y %H%M") def log(): fqn = os.uname()[1] ext_ip = urllib2.urlopen('http://whatismyip.org').read() log = open ('/Users/admin/Documents/locatelog.txt','w') log.write(str("Asset: %s...

Drag-and-drop to canvas in wxPython

Do you know if there is an easy way to drag-and-drop elements (icons or buttons) into a canvas and create different drawings on it as a result? The idea is to have a set of objects and let the user drag them into a drawing space. In the worst case the user could just click on the icon/button, and then click on the canvas and draw the e...

Python OOP - Class relationships

Assuming I have a system of three Classes. The GameClass creates instances of both other classes upon initialization. class FieldClass: def __init__( self ): return def AnswerAQuestion( self ): return 42 class PlayerClass: def __init__( self ): return def DoMagicHere( self ): # Access...

Avoiding unnecessary slice copying in Python.

Is there a common idiom for avoiding pointless slice copying for cases like this: >>> a = bytearray(b'hello') >>> b = bytearray(b'goodbye, cruel world.') >>> a.extend(b[14:20]) >>> a bytearray(b'hello world') It seems to me that there is an unnecessary copy happening when the b[14:20] slice is created. Rather than create a new slice i...

Django i18n: Common causes for translations not appearing

I am making a multilingual Django website. I created a messages file, populated and compiled it. I checked the site (the admin in this case,) in my wanted language (Hebrew) and most phrases appear in Hebrew like they should, but some don't. I checked the source and these still appear as _('Whatever') like they should, also they are trans...

How much leeway do I have to leave myself to learn a new language?

I'm a relatively new hire, and I'm starting on a small, fairly simple project. The language that this project will be implemented in is still to be determined. The question basically boils down to - Java or Python? Here's the dilemma: My manager would prefer it to be done in Python. I don't object to that, but I have no experience in P...

Python:Extend the 'dict' class

I have to solve this exercise: Python's dictionaries do not preserve the order of inserted data nor store the data sorted by the key. Write an extension for the dict class whose instances will keep the data sorted by their key value. Note that the order must be preserved also when new elements are added. and i'm freaking out.....i have...

Turn SSLchecking off in M2Crypto in Python

Is there a way to turn off SSL checking so that WrongHost Exceptions are not generated when using SOAPpy in python. ...

unladen-swallow with numpy/scipy

has anyone used unladen-swallow with numpy/scipy for numeric/scientific applications? Is it significantly faster in your experience? Any opinions would be great. ...

Change the type of a global variable in a function initializing it

I have a __main__ function where I initialize a lot of variables that are to be used in my program, later on. I have a problem where a variable that I temporarely declare as None in the outer scope, is assigned an object of SomeClass, but due to scoping rules I cannot access it's content in the outer scope. Because the constructor of Som...

Perform a SQL JOIN on Django models that are not related?

I have 2 Models, User (django.contrib.auth.models.User) and a model named Log. Both contain an "email" field. Log does not have a ForeignKey pointing to the User model. I'm trying to figure out how I can perform a JOIN on these two tables using the email field as the commonality. There are basically 2 queries I want to be able to per...

Python code optimization (20x slower than C)

I've written this very badly optimized C code that does a simple math calculation: #include <stdio.h> #include <math.h> #include <stdlib.h> #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) > (b)) ? (a) : (b)) unsigned long long int p(int); float fullCheck(int); int main(int argc, char **argv){ int i, g, maxNumber...

Any potential gotchas or things to be aware of for a newcomer to Django?

In other words, what did you not know when you started with Django that you wish someone had told you? I've dabbled some in Django but nothing really serious. However, I'm hoping to change that, and I'm wondering if there's any gotchas/shortcomings/whatever that I need to be aware of as I go. ...

Transforming nested Python loops into list comprehensions

I've started working on some Project Euler problems, and have solved number 4 with a simple brute force solution: def mprods(a,b): c = range(a,b) f = [] for d in c: for e in c: f.append(d*e) return f max([z for z in mprods(100,1000) if str(z)==(''.join([str(z)[-i] for i in range(1,len(str(z))+1)]))]) After solving, I tried t...

Referenced Model Loading in Google App Engine

Hello, In Python, say I've got a model of class A that has a ReferenceProperty b to model class B, which has a ReferenceProperty c to model class C. Assuming an instance of A already exists in the datastore, I can get it by saying: q = A.all() a = q.get() In this scenario, how does entity loading work? Is a.b retrieved when a is ret...

Fastest Way to Delete a Line from Large File in Python

Hi all, I am working with a very large (~11GB) text file on a Linux system. I am running it through a program which is checking the file for errors. Once an error is found, I need to either fix the line or remove the line entirely. And then repeat... Eventually once I'm comfortable with the process, I'll automate it entirely. For n...

how do you specify which python executable to use in Django 1.1.1?

I have a RH system running RHEL 5.3, which comes with python2.4 that can't be removed for numerous reasons. I have been able to build 64-bit RPMS for python 2.6 as an altinstall. It's called with "python26". How can I tell Django to use this command to get to the proper python version, instead of the default "python". I can, of cou...

Client polling (reverse AJAX) for chat requests in Django?

I want to make it that one user on the site can chat request another user on my Django site. I want the requestee to get a realtime box that say: "Do you want to chat?" How does the following client polling approach sound: user1 clicks on users2 nickname, generating a POST request to some /message/requests, which creates a Message of t...

Dealing with BACKSLASH character in non-string literals in Python.

I have the following string read from an XML elememnt, and it is assigned to a variable called filename. I don't know how to make this any clearer as saying filename = the following string, without leading someone to think that I have a string literal then. \\server\data\uploads\0224.1307.Varallo.mov when I try and pass this to os.p...