python

How get hours:minutes

Hi, I have a script here (not my own) which calculates the length of a movie in my satreceiver. It displays the length in minutes:seconds I want to have that in hours:minutes What changes do I have to make? This is the peace of script concerned: if len > 0: len = "%d:%02d" % (len / 60, len % 60) else: len = "" res = [ None ] I...

Managing *args variance in calls to functions

Have a method with the following signature: def foo(self, bar, *uks): return other_method(..., uks) Normally this is called as: instance.foo(1234, a, b, c, d) However in some cases I need to do something like this: p = [a, b, c, d] instance.foo(1234, p) At the receiving end this does not work, because other_method sees *args...

Tuples in Dicts

Is it possible in python to add a tuple as a value in a dictionary? And if it is,how can we add a new value, then? And how can we remove and change it? ...

term by term division in python (division termino a termino en python )

english: hello all, need to define a function that can be divided term by term matrix or in the worst cases, between arrays of lists so you get the result in a third matrix, thanks for any response español: hola a todos, necesito definir una funcion que permita dividir termino a termino de matrices o en el peor de los casos, entre ...

Convert \r text to \n so readlines() works as intended

In Python, you can read a file and load its lines into a list by using f = open('file.txt','r') lines = f.readlines() Each individual line is delimited by \n but if the contents of a line have \r then it is not treated as a new line. I need to convert all \r to \n and get the correct list lines. If I do .split('\r') inside the lines ...

problem filtering mousePressEvent with installEventFilter

I am having problem filtering the "mousePressEvent " with installEventFilter MyTestxEdit is a widget that holds QTextEdit I want that all the events of QTextEdit will be handle by MyTestxEdit I have used the installEventFilter This Trick works well for events like keyPressEvent but doesn't handle the mousePressEvent what am i doing wr...

Piping Cygwin into a Python program

Hello guys, As a i'm new to the whole Piping thing and Python I had recently encountered a problem trying to pipe Cygwin's stdin & stdout into a python program usin Python's subprocess moudle. for example I took a simple program: cygwin = subprocess.Popen('PathToCygwin',shell=False,stdin=subprocess.PIPE,stdout=subprocess.PIPE) cygwin.s...

How do I build the pypy JIT in 64-bit Linux ?

It looks like pypy's JIT won't compile by default in 64-bit Linux. How do I cross-compile a 32-bit JITting pypy on that machine? ...

When should I use uuid.uuid1() vs. uuid.uuid4() in python?

I understand the differences between the two from the docs. uuid1(): Generate a UUID from a host ID, sequence number, and the current time uuid4(): Generate a random UUID. So uuid1 uses machine/sequence/time info to generate a UUID. What are the pros and cons of using each? I know uuid1() can have privacy concerns, since it's based ...

C lib with Python bindings where both want to render

I'm sketching on some fluid dynamics in Python. After a while, I'm looking for a bit more speed, so I rewrote the actual logic in C and put up some Python bindings (using SWIG). My problem now is that I don't how to render it in a good way. The logic is run pixel by pixel so pixels are what I want to track and render. Python gives my a...

Python Webdriver doesn't wait until the page is downloaded in Firefox when used with proxy

Hello, when I set the Firefox proxy with python webdriver, it doesn't wait until the page is fully downloaded, this doesn't happen when I don't set one. How can I change this behavior? Or how can I check that the page download is over? ...

GAE Image Posting to Datastore through Django Form

I'm working on a little side project that involves posting an avatar to a users profile page, seems straight forward enough. I'm following the instructions from the "Using the Images Python API" on the GAE web site. The sample they provide doesn't seem to work with Django though. Searching around here, I found a thread with a similar i...

Nested Lambdas in Python

Hi, I'm a beginning python programmer, and I'd like someone to clarify the following behavior. I have the following code: env = lambda id: -1 def add(id, val, myenv): return lambda x: val if x == id else myenv(id) test_env = add("a", 1, env) test_env_2 = add("b", 2, test_env) When I look up "a" in test_env, it functions correc...

Efficient way of calling set of functions in Python

I have a set of functions: functions=set(...) All the functions need one parameter x. What is the most efficient way in python of doing something similar to: for function in functions: function(x) ...

How to install EasyGUI on Mac OS X 10.6 (Snow Leopard)?

I would like to install EasyGUI on Mac OS X 10.6, but am running into trouble. Has anyone successfully done this? If so, what explicit set of steps did you follow? Thank you. ...

Creation of PyTuple in C++ module crashes

Having some trouble with this code. Trying to return a tuple of tuples (coordinates) from a C++ module Im writing. It looks right to me, the dirty list contains two Coords so len is 2, the x and y values of the items in the list are 0,0 and 0,1 respectively. First time Im attempting this so I might very well have misunderstood the docs o...

Knowing if any key is pressed, wxPython

Hi, I have a timer, and need to know if any of the keys is pressed on any cycle. How do I do it? ...

is there a Java equivalent of Python's defaultdict?

In Python, the defaultdict class provides a convenient way to create a mapping from key -> [list of values], in the following example, from collections import defaultdict d = defaultdict(list) d[1].append(2) d[1].append(3) # d is now {1: [2, 3]} Is there an equivalent to this in Java? Why I chose Tendayi Mawushe's solution This solu...

Parsing XML in Python using ElementTree example

Hello, I'm having a hard time finding a good, basic example of how to parse XML in python using Element Tree. From what I can find, this appears to be the easiest library to use for parsing XML. Here is a sample of the XML I'm working with: <timeSeriesResponse> <queryInfo> <locationParam>01474500</locationParam> <va...

Python - Simple algorithmic task on lists (standard question for a job-interview)

There are 2 input lists L and M, for example: L = ['a', 'ab', 'bba'] M = ['baa', 'aa', 'bb'] How to obtain 2 non-empty output lists U and V such that: ''.join(U) == ''.join(V)) is True, and every element of U is in L, and every element of V is in M? For example, one possible solution for the two input lists above is: U=['bba'...