#python - Wed 14 Mar 2007 between 11:03 and 11:14

J_PI have the app where have always log. But I would like save one light log where always have the last 20 lines the complete log. So I think in append in this file and after delete first.. and so one...
Yhg1syes. unfortunately, files don't work like that.
Yhg1s: but append process needed too read all file before write ?
Brackihow can i add tuples?
J_PBracki: append
Yhg1sJ_P: no, you can just append to the end of the file.
Brackino i want (1,2) + (3,4) = (4,6)
Yhg1sJ_P: the problem is that you can't "move" the start of the file. The file starts at location 0, and if you want to delete the first (say) 40 bytes, you have to move all other bytes 40 bytes forward.
J_PYhg1s: So the problem is only to delete frist line right ?
Yhg1sBracki: add each item.
Wild_CatBracki: tuple(i + j for i, j in zip(tuple_a, tuple_b))
er wait, no, that doesn't work.
J_PYhg1s: So the problem is only to delete frist line right ?
Yhg1sJ_P: the problem is what I just sketched.
J_PYhg1s: in last line to add is not have this problema
Yhg1s: ok
thanks Yhg1s
Yhg1sWild_Cat: works fine.
Wild_Catoh, you're right, it does. It's not exactly pretty, though.
Yhg1s'map(operator.add, t1, t2)'
HowardTheCowardis there a string method which reverts the order of the chars in a string?
computerlinguistreduce(lambda (x1,x2),(y1,y2): (x1+y1,x2+y2), [(1,2),(3,4)])
(can be extended to more than two tuples)
HowardTheCoward'abc'.some_method() == 'cba' ?
Yhg1sHowardTheCoward: [::-1]
HowardTheCowardYhg1s: thank you, but that's very cryptic for me. could you please provide a link to docs where i could read about this?
ironfroggyHowardTheCoward: look up "slicing"
HowardTheCowardand btw is this a feature of 2.5 or can be used in 2.4 too?
Yhg1sHowardTheCoward: it's just normal slicing, with the third argument ('step'.)
Cowmooyou could use reversed()
Yhg1sHowardTheCoward: it's existed since Python 2.1 or so.
ironfroggyCowmoo: much less effecient.
Cowmoosure sure
Yhg1sBracki: another one that takes an arbitrary number of tuples, like computerlinguist's: map(lambda *args: sum(args), *list_of_tuples)
Juhaz_but much more memory efficient
Yhg1sJuhaz_: which is?
Yhg1sreversed()? only if all you do is iterate over it.

Page: 2 9 16 23 30 37 44 51 58 65