python

gae error:AttributeError: 'NoneType' object has no attribute 'user_is_member'

class Thread(db.Model): members = db.StringListProperty() def user_is_member(self, user): return str(user) in self.members and thread = Thread.get(db.Key.from_path('Thread', int(id))) is_member = thread.user_is_member(user) but the error is : Traceback (most recent call last): File "D:\Program Files\Google\google_appeng...

Python: Open() using a variable

Good day, I've ran into a problem with opening a file with randomly generated name in Python 2.6. import random random = random.randint(1,10) localfile = file("%s","wb") % random Then I get an error message about the last line TypeError: unsupported operand type(s) for %: 'file' and 'int' I just couldn't figure this out by m...

Calling activateWindow on QDialog sends window to background

I am debugging certain application written with C++/Qt4. On Linux it has problems that with certain window managers (gnome-wm/metacity), the main window (based on QDialog) is created in the background (it's not raised). I managed to re-create the scenario using PyQt4 and following code: from PyQt4.QtCore import * from PyQt4.QtGui import...

Is it possible to have all "git diff" commands use the "Python diff", in all git projects?

When including the line *.py diff=python in a local .gitattributes file, git diff produces nice labels for the different diff hunks of Python files (with the name of the function where the lines changes are, etc.). Is is possible to ask git to use this diff mode for all Python files across all git projects? I tried to set a global ~...

python date difference in minutes

How to calculate the difference in time in minutes for the following timestamp in python 2010-01-01 17:31:22 2010-01-03 17:31:22 ...

Python Glade GTKBuilder Checkbutton

How do I find if a GTKBuilder Checkbutton is checked? ...

Testing sample code in python modules

I'm in the process of writing a python module that includes some samples. These samples aren't unit-tests, and they are too long and complex to be doctests. I'm interested in best practices for automatically checking that these samples run. My current project layout is pretty standard, except that there is an extra top level makefile th...

Multithreaded python script silently dies - how to debug

I have a python script that creates and starts 3 threads, and then goes to a KeyboardInterrupt-catching-loop, to send the threads stop signal when ctrl+c is pressed. The threads' run method has a top level try-except which logs every exception, also the top level code that creates threads is wrapped into try-except to log every exceptio...

Python Array problem

I have an array that I have to add a new value to array value. I am new to arrays. how do I loop thru the array and add to the value in the existing array. ...

ManyToManyField error when having recursive structure. How to solve it?

Hello, I have the following table in the model with a recursive structure (a page can have children pages) class DynamicPage(models.Model): name = models.CharField("Titre",max_length=200) parent = models.ForeignKey('self',null=True,blank=True) I want to create another table with ManyToMany relation with this one. class...

show() doesn't redraw anymore

Hi All I am working in linux and I don't know why using python and matplotlib commands draws me only once the chart I want. The first time I call show() the plot is drawn, wihtout any problem, but not the second time and the following. I close the window showing the chart between the two calls. Do you know why and hot to fix it? Thank...

Python metaprogramming help

im looking into mongoengine, and i wanted to make a class an "EmbeddedDocument" dynamically, so i do this def custom(cls): cls = type( cls.__name__, (EmbeddedDocument,), cls.__dict__.copy() ) cls.a = FloatField(required=True) cls.b = FloatField(required=True) return cls A = custom( A ) and tried it on some classes, bu...

Python add to a function dynamically

how do i add code to an existing function, either before or after? for example, i have a class: class A(object): def test(self): print "here" how do i edit the class wit metaprogramming so that i do this class A(object): def test(self): print "here" print "and here" maybe some way of appendi...

Log flexlm licence usage from remote machine

We have several software packages (SolidWorks, Pro/ENGINEER, OrCAD, Minitab... ) that use FlexLM to manage network licences. I have written a python program to poll the FlexLM daemons every few mintues using lmutil lmstat -a. However, this requires lmutil to be installed on the same machine as the python program. Our FlexLM licence da...

Python Split usage

I'm cocking this up and it should be really simple but the value of sortdate is none (note im only doing this because converting a string to a date in Python is a bugger). DateToPass = str(self.request.get('startdate')) mybreak.startdate = DateToPass faf = DateToPass.split('-') sortdate = str(faf[2] + faf[1] + faf[0]) That should work...

setup.py install dependency too?

I have a python source distribution, and it depends on some other modules that I've also made. The directory tree looks like this. I've written a setup.py file for one of those modules (pydirac225, for those of you who are following along at home), and I want to have that setup.py called from the main setup.py? Another module dependenc...

Is there some module for Python that works with Firefox ?

Is there some module for Python that tells me when some page finish the loading, or something else on Firefox? ...

Overriding Built-in Classes (Python)

How can I view and override the full definition for built in classes? I have seen the library docs but am looking for something more. For e.g. is it possible to override the Array Class such that the base index starts from 1 instead of 0, or to override .sort() of list to a sorting algorithm of my own liking? ...

How do I let my console window always on top with Python?

How I let the window always on top? ...

python c extension, problems with dlopen on mac os

I've taken a library that is distributed as a binary lib (.a) and header, written some c++ code against it, and want to wrap the results up in a python module. I've done this here. The problem is that when importing this module on Mac OSX (I've tried 10.5 and 10.6), I get the following error: dlopen(/Library/Python/2.5/site-packages/...