notify when process finishes (on unix)
Hi, I'd like to write a script that sends me an email when a unix (Linux) process ends running (or CPU drops below some threshold). Could anyone point me to the relevant functions, or show me an example? Thanks bahoo -- http://mail.python.org/mailman/listinfo/python-list
subprocess.Popen fails, but os.system works
Hi, I am using Windows + Python 2.5. This line of code fails (see error message at the end), last_line = subprocess.Popen([D:/release/win.exe 0.5 1000 100 D:/ images/img.ppm out.ppm], stdout=subprocess.PIPE).communicate()[0] but using os.system works: os.system('D:/release/win.exe 0.5 1000 100 D:/images/img.ppm out.ppm') -- C:/Python25/pythonw.exe -u D:/run.pyw Traceback (most recent call last): File D:/run.pyw, line 59, in module process_dir(mydir) File D:/run.pyw, line 52, in process_dir segmentation (dir,f) File D:/run.pyw, line 35, in segmentation last_line = subprocess.Popen([D:/release/win.exe 0.5 1000 100 D:/ images/img.ppm out.ppm], stdout=subprocess.PIPE).communicate()[0] File C:\Python25\lib\subprocess.py, line 593, in __init__ errread, errwrite) File C:\Python25\lib\subprocess.py, line 793, in _execute_child startupinfo) WindowsError: [Error 22] The filename, directory name, or volume label syntax is incorrect --- Can anyone tell me why? Thanks bahoo -- http://mail.python.org/mailman/listinfo/python-list
recursively removing files and directories
Hi, I found a message on Jan 16, 2006 regarding the same topic, except that I wanted to remove only certain files that satisfy the format ABC_XXX_XXX.dat, but not the other files. Once the files are removed, if a folder becomes empty, I want to remove the folder as well. The solution to the Jan 16 2006 message required many lines of python code. I was wondering if there is a simpler solution to my problem at hand, perhaps by using more specialized functions? Thanks! bahoo -- http://mail.python.org/mailman/listinfo/python-list
recursively archiving files
Hi, Can I use python to recursively compress files under subdirectories with a certain format such as ABC_XXX_XXX.dat into a .gz or .zip file? I used to do it with tar on unix, but I don't like to put commands into a single line, as it is often more prone to error. Thanks bahoo -- http://mail.python.org/mailman/listinfo/python-list
How to have a list of lists (or array of lists)
Hi, I want to have many lists, such as list0, list1, list2, ..., each one holding different number of items. Is there something like list[0] list[1] list[2] so that I can iterate through this list of lists? Thanks! bahoo -- http://mail.python.org/mailman/listinfo/python-list
how to remove multiple occurrences of a string within a list?
Hi, I have a list like ['0024', 'haha', '0024'] and as output I want ['haha'] If I myList.remove('0024') then only the first instance of '0024' is removed. It seems like regular expressions is the rescue, but I couldn't find the right tool. Thanks! bahoo -- http://mail.python.org/mailman/listinfo/python-list
Re: how to remove multiple occurrences of a string within a list?
On Apr 3, 2:31 pm, Matimus [EMAIL PROTECTED] wrote: It depends on your application, but a 'set' might really be what you want, as opposed to a list. s = set([0024,haha,0024]) s set([0024,haha]) s.remove(0024) s set([haha]) This sounds cool. But is there a command I can convert the set back to a list? -- http://mail.python.org/mailman/listinfo/python-list
Need help on reading line from file into list
Hi, I have a text file containing a single line of text, such as 0024 How should I read it into a list? I tried this, but the join did not work as expected. Any suggestions? infile = open('my_file.txt','r') for line in infile: line.join(line) my_list.extend( line ) -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help on reading line from file into list
On Apr 3, 5:06 pm, Bruno Desthuilliers [EMAIL PROTECTED] wrote: bahoo a écrit : Hi, I have a text file containing a single line of text, such as 0024 How should I read it into a list? You mean ['0024'], or ['0', '0', '2', '4'] ? I tried this, but the join did not work as expected. What did you expect ? help(str.join) join(...) S.join(sequence) - string Return a string which is the concatenation of the strings in the sequence. The separator between elements is S. Any suggestions? Honestly, the first would be to learn to ask questions, and the second to pay more attention to what's written in the doc. But let's try : infile = open('my_file.txt','r') for line in infile: line.join(line) my_list.extend( line ) If you have a single line of text, you don't need to iterate. file has a readlines() method that will return a list of all lines. It also has a read() method that reads the whole content. Notice that none of these methods will strip newlines characters. Also, str has a strip() method that - by default - strip out any 'whitespace' characters - which includes newline characters. And finally, passing a string as an argument to list's constructor gives you a list of the characters in the string. This is all you need to know to solve your problem - or at least the two possible definitions of it I mentionned above. open('source.txt').readlines() ['0024\n'] map(str.strip, open('source.txt').readlines()) ['0024'] open('source.txt').read() '0024\n' list(open('source.txt').read().strip()) ['0', '0', '2', '4'] Thanks, this helped a lot. I am now using the suggested map(str.strip, open('source.txt').readlines()) However, I am a C programmer, and I have a bit difficulty understanding the syntax. I don't see where the str came from, so perhaps the output of open('source.txt').readlines() is defaulted to str? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
How to check if OS is unix or pc
In Matlab, there is a isunix command. Is there something similar in python? Thanks! bahoo -- http://mail.python.org/mailman/listinfo/python-list
Re: how to remove multiple occurrences of a string within a list?
On Apr 3, 4:21 pm, Steve Holden [EMAIL PROTECTED] wrote: bahoo wrote: On Apr 3, 2:31 pm, Matimus [EMAIL PROTECTED] wrote: It depends on your application, but a 'set' might really be what you want, as opposed to a list. s = set([0024,haha,0024]) s set([0024,haha]) s.remove(0024) s set([haha]) This sounds cool. But is there a command I can convert the set back to a list? That would be list(). So what you want is s = set([0024,haha,0024]) s.remove(0024) l = list(s) or something like it. It seems, a priori, unlikely that you only want to remove items with that specific value, Is this part of some larger problem? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenwebhttp://del.icio.us/steve.holden Recent Ramblings http://holdenweb.blogspot.com Thanks for all the suggestions. The larger problem is, I have a list of strings that I want to remove from another list of strings. So I guess what I will do is, use a for loop, and within the for loop, do the list to set and then back to list. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to remove multiple occurrences of a string within a list?
On Apr 3, 3:01 pm, 7stud [EMAIL PROTECTED] wrote: On Apr 3, 12:20 pm, bahoo [EMAIL PROTECTED] wrote: Hi, I have a list like ['0024', 'haha', '0024'] and as output I want ['haha'] If I myList.remove('0024') then only the first instance of '0024' is removed. It seems like regular expressions is the rescue, but I couldn't find the right tool. Thanks! bahoo Here are a couple of ways: target = 0024 l = [0024, haha, 0024] while(True): try: l.remove(target) except ValueError: break print l - for index, val in enumerate(l): if val==target: del l[index] print l This latter suggestion (with the for loop) seems to be buggy: if there are multiple items in the list l equal to target, then only the first one will be removed! Thanks anyways. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to remove multiple occurrences of a string within a list?
On Apr 3, 6:05 pm, Steven Bethard [EMAIL PROTECTED] wrote: bahoo wrote: The larger problem is, I have a list of strings that I want to remove from another list of strings. If you don't care about the resulting order:: items = ['foo', 'bar', 'baz', 'bar', 'foo', 'frobble'] to_remove = ['foo', 'bar'] set(items) - set(to_remove) set(['frobble', 'baz']) If you do care about the resulting order:: to_remove = set(to_remove) [item for item in items if item not in to_remove] ['baz', 'frobble'] STeVe This is amazing. I love python! -- http://mail.python.org/mailman/listinfo/python-list
transfer data from one machine to another
Hi, I have ssh access to two linux machines (both WITHOUT root account), and I'd like to copy data from one to another. Since the directory structure is different, I want to specify in a script (ideally in python, because that's what I want to learn) what to copy over like this: source: /home/john/folderA destination: /home/smith/folderB I'm a newbie on linux and ssh networking and python, so your suggestions are welcome! A small working example would be appreciated! bahoo -- http://mail.python.org/mailman/listinfo/python-list