Maric Michaud wrote: > Le Samedi 10 Juin 2006 17:44, TheSaint a écrit :
>> > begin using more explicit variable names. Frankly it's a very rooted way of programming, since C64 basic :-) A part of this, how python catch variables, the longer the slower, isn't it? Even supposing to use a set of similar name of variables. Of course nowadays this operations ending up in term of msecs. I still be used in old fashion. I'll change it by the time of necessity. > and I generally avoid creating names I use only once, so : > > if not os.listdir('/media') : Great idea and common sense :-) > There more expressive or more direct ways of doing all these, I like one > liners (but a two steps can be more clear) : I like the clearer. I think python does it as we would think it off. >> x = ptn.readlines() > > this time we cut in two steps but this also just filtering. I found the bothering of having to remove the trailing LF "\n". Perhaps need some new function to strip the last LF, for all of the files opened. >> if len(c) != 1: >> sys.exit(0) # if none or more than one match exit >> > why ? > > os.system('umount "%s"' % devices[0]) I wasn't able to handle more than one mount a time. Furthermore, the script is executed every minute in a cron schedule. I don't expect to remove devices in so fast fashion :-) BTW, this operation is necessary because the kernel doesn't do it on its own, for pendrives and Compact Flash into PCMCIA socket. (Kernel 2.6.15 actually) One more point, suppose to use multiple removal, how will it remove also the icon(s) from the KDE desktop? Good to applying myself on studying on it :-) > this will do exactly the same > > for icon_file in (open(dskt + e) for e in os.listdir(dskt) if '.desktop' > in e) : > for line in icon_file : > if 'URL=/media' in line : > icon = icon.name > dvc = line[11:-1] > break > A simple question, how do I'll get out of all loops, once found the right result? F -- http://mail.python.org/mailman/listinfo/python-list