python

Python, lambda, find minimum

I have foreach function which calls specified function on every element which it contains. I want to get minimum from thise elements but I have no idea how to write lambda or function or even a class that would manage that. Thanks for every help. I use my foreach function like this: o.foreach( lambda i: i.call() ) or o.foreach( I.ca...

python line.split semantic error fromtext file

this section of code is supposed to make a list containing the values of the second column in the text file, but it takes the second letter. anyone know what my problem is? TEXTFILE opi 60 kid 60 pou 60 ret 60 kai 60 bob 100 for line in lst: line.split(' ') fire.append(int(line[1])) ...

__init__.py descends dirtree for python, but not from c++; causes "import matplotlib" error.

Why or how does the file __init__.py cause the python interpreter to search subdirectories for a module -- and why does the interpreter not honor this convention when invoked from C++? Here's what I know: Using strace on my program, I can see that the same python2.5 interpreter is being executed for both the interactive case and the ...

How do I blit a PNG with some transparency onto a surface in Pygame?

I'm trying to blit a PNG image onto a surface, but the transparent part of the image turns black for some reason, here's the simple code: screen = pygame.display.set_mode((800, 600), pygame.DOUBLEBUF, 32) world = pygame.Surface((800, 600), pygame.SRCALPHA, 32) treeImage = pygame.image.load("tree.png") world.blit(treeImage, (0,0), (0,0...

Python/Django n00b question about json encoding

Hello, I'm loading a json string in Django using simplejson obj = json.loads('{"name": "joe"}') person = obj.name this throws an error: 'dict' object has no attribute 'name' but when I pass 'obj' down to the view template and print it out via {{ obj.name }} it works! Why?? Many thanks, g ...

What is the difference between "is" and "==" in python?

Possible Duplicate: Python == vs is comparing strings, is fails sometimes, why? Is a == b the same as a is b ? If not, what is the difference? Edit: Why does a = 1 a is 1 return True, but a = 100.5 a is 100.5 return False? ...

Please help me in understanding Class in Python

Hi, I am newbie and finding it very hard to grasp the syntax of Class in python. I have a background of C/C++, java and objective C. A very big difference which i am noticing in python is that you don't explicitly declare the "data members" in the class and you just randomly add them? And it leads to quite big confusion. Let say i have...

Is there any way to "clear" a surface?

Just wondering... Is there any way to clear a surface from anything that has been blitted to it? ...

least square solution to camera matrix [numpy]

I would like to use use numpy's least square algorithm to solve for a camera matrix from 6 known 3D -> 2D point correspondence. I have been using this website as a reference: http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL%5FCOPIES/OWENS/LECT9/node4.html Currently my camera matrix seems to have very small values: [[ -1.01534118e-11 ...

How to run django development server at startup?

I added following command to Sessions -> Startup program but it didn't work. I'm using Ubuntu. sudo -u www-data python manage.py 192.168.1.2:8001 192.168.1.2 is the ip address on ath0. Is it still not available for binding at the stage when this command is executed? What I currently do is add another cronjob to restart the developmen...

ToscaWidgets CalendarDatePicker pylons

How does one set the date on the CalendarDatePicker. i.e. it defaults to current date and I want to display it with another date which I will set from my controller. I am displaying the CalendarDatePicker widget in a TableForm from tw.form. I have looked at this for a few hours and can't work out how to do this so any pointers greatly a...

Besides NLTK, what is the best information retrieval library for Python?

For use to analyze documents on the Internet! ...

What's the simplest cross-platform way to pop up graphical dialogs in Python?

I want the simplest possible way to pop up simple dialogs in Python scripts. Ideally, the solution would: Work on Windows, OS X, Gnome, KDE Look like a native dialog on any OS Require minimal code To pop up a simple standard dialog should require only minimal code. Essentially you're just saying "Pop up a standard dialog with this ...

Terminate a multi-thread python program

How to make a multi-thread python program response to Ctrl+C key event? Edit: The code is like this: import threading current = 0 class MyThread(threading.Thread): def __init__(self, total): threading.Thread.__init__(self) self.total = total def stop(self): self._Thread__stop() def run(self): ...

pyGTK ComboBox List Height

I'm just getting started with pyGtk programming, so bear with me. I have a dialog with a ComboBox. The list that shows up when I click on the combo box has 70+ times in it. It extends from the top of the screen to the bottom. I can live with it, but I'd rather have the ComboBox perform like an html select element(i.e. top of menu is ...

What is wrong with my django's model field ?

I am trying to do a PhoneField that convert the value as a standardized value. In this case, I want to use this clean method. def clean(self): phone = self.cleaned_data.get('phone') # Is it already standardized ? if phone.startswith('+'): mo = re.search(r'^\+\d{2,3}\.\d{9,11}$', phone) if not mo: raise...

Is there any Python module similar to Distributed Ruby

I am new to Python. Just want to know is there any module in python similar to ruby's drb? Like a client can use object provided by the drb server? ...

How do I make powerpoint play presentations/load up ppts automatically?

I was wondering how I can make a script load powerpoint file, advance slides automatically and put it on full screen. Is there a way to make windows do that? Can I just load powerpoint.exe and maybe use some sort of API/Pipe to give commands from another script. To make a case: I'm making a script that automatically scans a folder in wi...

How do we override the choice field display of a reference property in appengine using Django?

The default choice field display of a reference property in appengine returns the choices as the string representation of the entire object. What is the best method to override this behaviour? I tried to override str() in the referenced class. But it does not work. ...

How would one implement Lazy Evaluation in C?

Take for example, The follow python code: def multiples_of_2(): i = 0 while True: i = i + 2 yield i How do we translate this into C code? Edit: I am looking to translate this python code into a similar generator in C, with next() function. What I am not looking for is how to create a function in C to output multiples of ...