Re: concatenate function
On 13/03/12 14:35, ferreirafm wrote: Hi List, I've coded three functions that I would like to concatenate. I mean, run them one after another. The third function depends on the results of the second function, which depends on the results of the first one. When I call one function after another, python runs them at the same time causing obvious errors messages. I've tried to call one of them from inside another but no way. Any clues are appreciated. Complete code goes here: http://ompldr.org/vZDB4OQ Do you think you could provide a much shorter example to illustrate what you need? In general, when you want to run one function on the result of another, you can do something like: def increment_all(l); ... return [i+1 for i in l] increment_all(increment_all(range(3)) [2, 3, 4] Here we apply the function increment_all to the result of the function increment_all. If you are talking about the results of each function in terms of it mutating an object, and then the next function mutating the same object in a (possibly) different way, then calling the functions in order will do what you want. l = [0, 3, 5, 2] l.append(10)# [0, 3, 5, 2, 10] l.sort()# [0, 2, 3, 5, 10] l.append(3) # [0, 2, 3, 5, 10, 3] James -- View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574176.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: concatenate function
On 13/03/12 16:02, ferreirafm wrote: Hi James, thank you for your replay. Indeed, the problem is qsub. And as warned by Robert, I don't have functions properly, but just scripts. -- View this message in context: http://python.6.n6.nabble.com/concatenate-function-tp4574176p4574511.html Sent from the Python - python-list mailing list archive at Nabble.com. It looks like you're not calling wait() on your subprocesses: you're effectively launching a bunch of processes, then not waiting for them to finish before you ask the next process to operate on the same file. If you haven't given it a good look-over already, the subprocess documentation [1] is worth taking a little time over. [1]: http://docs.python.org/library/subprocess.html#popen-objects James -- http://mail.python.org/mailman/listinfo/python-list
Re: Raise X or Raise X()?
On 11/03/12 19:04, bvdp wrote: Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: try: for ... for ... for ... if match: raise StopInteration() else ... except StopInteration: print found it I wonder whether you need to use an exception here rather than a yield statement? Exceptions should reflect Exceptional circumstances (and come with associated stack trace, and so on...). The following should do something like what you want, without raising exceptions. # Deeply loop into a collection of collections def find(collection): ...for sub_col in collection: ...for item in sub_col: ...for foo in item.list_field: ...if foo.is_match: ...yield foo # Some junk classes to iterate over class Item(object): ...def __init__(self, some_range): ...self.list_field = [ListedItem(i) for i in some_range] class ListedItem(object): ...def __init__(self, number): ...self.tag = number ...self.is_match = False def __str__(self): ...return str(self.tag) # Construct a list of items l = [[Item(range(i)) for i in range(10)], ... [Item(range(i, 2*i)) for i in range(10,20)]] l[0][9].list_field[3].is_match = True for i in find(l): ... print(i) 3 James -- http://mail.python.org/mailman/listinfo/python-list