[Tutor] url parsing

2009-02-15 Thread Jay Jesus Amorin
Hi, Can you please help my how to parse. url = http://this/is/my/url/to/parse how do i parse url to print "http://this/is/my/url/to"; i want to remove the last part of my url with is "parse". I would like to remove the last string of my url. i have try split, but i think it wont work as i dont

[Tutor] advise on using re

2009-02-15 Thread Norman Khine
Hello, What am I doing wrong here. >>> import smtplib, socket, re, os, operator, sys >>> domain = 'abakuc.com' >>> validMXservers = [] >>> MXlocate = re.compile('^.*preference = (\d*).*exchanger = (.*)$', re.IGNORECASE) >>> MXservers = os.popen('nslookup -querytype=MX %s' %domain, 'r') >>> for

Re: [Tutor] url parsing

2009-02-15 Thread عماد نوفل
On Sun, Feb 15, 2009 at 5:09 AM, Jay Jesus Amorin wrote: > Hi, > > Can you please help my how to parse. > > url = http://this/is/my/url/to/parse > > how do i parse url to print "http://this/is/my/url/to"; > > i want to remove the last part of my url with is "parse". I would like to > remove the la

Re: [Tutor] url parsing

2009-02-15 Thread عماد نوفل
On Sun, Feb 15, 2009 at 7:37 AM, Emad Nawfal (عماد نوفل) < emadnaw...@gmail.com> wrote: > > > On Sun, Feb 15, 2009 at 5:09 AM, Jay Jesus Amorin wrote: > >> Hi, >> >> Can you please help my how to parse. >> >> url = http://this/is/my/url/to/parse >> >> how do i parse url to print "http://this/is/my

Re: [Tutor] url parsing

2009-02-15 Thread Andre Engels
On Sun, Feb 15, 2009 at 1:37 PM, Emad Nawfal (عماد نوفل) wrote: > I'm not sure this is the best strategy, but it seems to work: > url ="http://this/is/my/url/to/parse"; m = url.replace("//", '/').split("/") n = m[0]+"//"+"/".join(new[1:]) n > 'http://this/is/my/url/to' What i

Re: [Tutor] url parsing

2009-02-15 Thread Lie Ryan
On Sun, 15 Feb 2009 14:22:09 +0100, Andre Engels wrote: > What is 'new' in your solution? Apart from that, the following looks > simpler: > url = "http://this/is/my/url/to/parse"; parts = url.split('/') sol = '/'.join(parts[:-1]) sol > 'http://this/is/my/url/to' do you want somethi

Re: [Tutor] url parsing

2009-02-15 Thread Jay Jesus Amorin
Thanks this is much more simple and is what i need. On Sun, Feb 15, 2009 at 9:29 PM, Lie Ryan wrote: > On Sun, 15 Feb 2009 14:22:09 +0100, Andre Engels wrote: > > What is 'new' in your solution? Apart from that, the following looks > > simpler: > > > url = "http://this/is/my/url/to/parse";

[Tutor] Reading a Text File with tkFileDialog, askopenfilename+enumerate

2009-02-15 Thread Wayne Watson
Title: Signature.html A three questions about askopenfilename and enumerate. For askopenfilename: 1. Do I have to close the file before exiting from it? 2. How do I read each line of text in the file and quit when an eof is reached? This certainly doesn't do it.     def OpenConfigFile(self):

Re: [Tutor] advise on using re

2009-02-15 Thread Kent Johnson
On Sun, Feb 15, 2009 at 5:53 AM, Norman Khine wrote: MXlocate = re.compile('^.*preference = (\d*).*exchanger = (.*)$', > On the shell, the command > > $ nslookup -querytype=MX abakuc.com > Server: 193.252.19.3 > Address:193.252.19.3#53 > > Non-authoritative answer: > abakuc.c

Re: [Tutor] url parsing

2009-02-15 Thread Kent Johnson
On Sun, Feb 15, 2009 at 5:09 AM, Jay Jesus Amorin wrote: > Hi, > > Can you please help my how to parse. > > url = http://this/is/my/url/to/parse > > how do i parse url to print "http://this/is/my/url/to"; > > i want to remove the last part of my url with is "parse". I would like to > remove the la

Re: [Tutor] Reading a Text File with tkFileDialog, askopenfilename+enumerate

2009-02-15 Thread Alan Gauld
"Wayne Watson" wrote Three questions about askopenfilename and enumerate. For askopenfilename: 1. Do I have to close the file before exiting from it? 2. How do I read each line of text in the file and quit when an eof is reached? This has nothing to do with askopenfilename! Askopenfilenam

[Tutor] General Feedback, Script Structure

2009-02-15 Thread Damon Timm
Hi - Am still new to python -- was writing a script that is used by mdadm (linux software raid utility) when there was a raid "event" ... the script then sends an email (using another python script caled "gmailme") to me with the information from the event and attaches the details of the raid devi

Re: [Tutor] Reading a Text File with tkFileDialog, askopenfilename+enumerate

2009-02-15 Thread Wayne Watson
Title: Signature.html Thanks. A file name! That's funny. Bitten by my early acquaintance a few weeks ago with TkFileDialog, when I innocently stuck the method in the function to come back to. Wrong method! I don't think I'll forget next time. :-) Yes, I agree with wanting to open and close the

Re: [Tutor] url parsing

2009-02-15 Thread Daniele
use this if you want to take a hammer to crack a nut :D import os url = 'http://this/is/my/url/to/parse' os.path.basename(url) #gives "parse" os.path.dirname(url) #gives 'http://this/is/my/url/to' ___ Tutor maillist - Tutor@python.org http://mail.pytho

Re: [Tutor] Reading a Text File with tkFileDialog, askopenfilename+enumerate

2009-02-15 Thread Kent Johnson
On Sun, Feb 15, 2009 at 9:16 AM, Wayne Watson wrote: > 3. Where can I find out more about enumerate, as used here: > > input_file=open('Initial.sen','r') > for (line_cnt, each_line) in enumerate(input_file): > print each_line > input_file.close() > > I used this small program for other purpos

Re: [Tutor] General Feedback, Script Structure

2009-02-15 Thread Kent Johnson
On Sun, Feb 15, 2009 at 11:00 AM, Damon Timm wrote: > Hi - > > Am still new to python -- was writing a script that is used by mdadm > (linux software raid utility) when there was a raid "event" ... the > script then sends an email (using another python script caled > "gmailme") to me with the info

Re: [Tutor] General Feedback, Script Structure

2009-02-15 Thread Damon Timm
Hi Kent - thanks for taking a look! Follow-up below: On Sun, Feb 15, 2009 at 12:20 PM, Kent Johnson wrote: > - put the main code in a main() function rather than splitting it > across the file. That's a good idea - I will do that. Is it proper to create a def main() or just under: if __name__

Re: [Tutor] Reading a Text File with tkFileDialog, askopenfilename+enumerate

2009-02-15 Thread Wayne Watson
Title: Signature.html Yes, true enough about simplicity, but see my response to Alan. Kent Johnson wrote: On Sun, Feb 15, 2009 at 9:16 AM, Wayne Watson wrote: 3. Where can I find out more about enumerate, as used here: input_file=open('Initial.sen','r') for (line_cnt, each_line

Re: [Tutor] Reading a Text File with tkFileDialog, askopenfilename+enumerate

2009-02-15 Thread Alan Gauld
"Wayne Watson" wrote Thanks to your use of the word pillow it's not likely I will be able to find the link to the Library Reference more easily, strange as that may seem. You are right it seems very strange!? My browser's bookmark capabilities have put me in the corner of disorganization,

Re: [Tutor] General Feedback, Script Structure

2009-02-15 Thread Alan Gauld
"Damon Timm" wrote It works fine -- seems to do what I need -- but, to be very frank, I don't think it is very *pretty* ! But, I am not sure what the http://python.pastebin.com/m4e1694d5 Would be interested in any feedback (obviously, I should add some doc strings!). It doesn't look to

Re: [Tutor] General Feedback, Script Structure

2009-02-15 Thread Kent Johnson
On Sun, Feb 15, 2009 at 1:01 PM, Damon Timm wrote: > On Sun, Feb 15, 2009 at 12:20 PM, Kent Johnson wrote: >> - put the main code in a main() function rather than splitting it >> across the file. > > That's a good idea - I will do that. Is it proper to create a def > main() or just under: if __

Re: [Tutor] Reading a Text File with tkFileDialog, askopenfilename+enumerate

2009-02-15 Thread Wayne Watson
Title: Signature.html I'm still looking for an explanation of "for (line_cnt, each_line) in enumerate(input_file)". Why the tuple? Apparently, line_count gets a line number, and each_line gets the string of text. Chrome. I've heard of it. Does it require an install, or is it one of those odd b

Re: [Tutor] Reading a Text File with tkFileDialog, askopenfilename+enumerate

2009-02-15 Thread Kent Johnson
On Sun, Feb 15, 2009 at 1:54 PM, Alan Gauld wrote: > Have you tried GoogleChrome yet? It might suit your style better. > It looks at addresses you type and searches both your history and > bookmarks for previous sites visited that might match. Firefox 3 also does that. Very handy! Kent

Re: [Tutor] Reading a Text File with tkFileDialog, askopenfilename+enumerate

2009-02-15 Thread Kent Johnson
On Sun, Feb 15, 2009 at 2:47 PM, Wayne Watson wrote: > I'm still looking for an explanation of "for (line_cnt, each_line) in > enumerate(input_file)". Why the tuple? Apparently, line_count gets a line > number, and each_line gets the string of text. Do you know about sequence unpacking? In an ass

Re: [Tutor] Reading a Text File with tkFileDialog, askopenfilename+enumerate

2009-02-15 Thread Wayne Watson
Title: Signature.html I don't think so. Not as a Python concept, but it looks sensible in your example. However, why would enumerate produce a line number? How would one know that it does? Ah, I see. enumerate produces a tuple which has the index and a list. It appears the only place this can b

Re: [Tutor] General Feedback, Script Structure

2009-02-15 Thread Damon Timm
Kent and Alan - thanks! I moved things around a bit and I think it "looks" better: http://python.pastebin.com/m64e4565d On Sun, Feb 15, 2009 at 2:25 PM, Kent Johnson wrote: > Exactly. dict.get() does a key lookup with a default for missing keys, > then the result is used as a string format. See

Re: [Tutor] Reading a Text File with tkFileDialog, askopenfilename+enumerate

2009-02-15 Thread Alan Gauld
"Wayne Watson" wrote I'm still looking for an explanation of " for (line_cnt, each_line) in enumerate(input_file)". Why the tuple? Apparently, line_count gets a line number, and each_line gets the string OK, Back up from the specific problem to the more general case. enumerate does not retu

Re: [Tutor] Reading a Text File with tkFileDialog, askopenfilename+enumerate

2009-02-15 Thread John Fouhy
2009/2/16 Alan Gauld : > for index, item in [9,8,7,6]: > print index, item > > > 0 9 > 1 8 > 2 7 > 3 6 You mean: for index, item in enumerate([9,8,7,6]): print index, item :-) -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/

Re: [Tutor] Reading a Text File with tkFileDialog, askopenfilename+enumerate

2009-02-15 Thread Alan Gauld
"John Fouhy" wrote for index, item in [9,8,7,6]: print index, item 0 9 1 8 2 7 3 6 You mean: for index, item in enumerate([9,8,7,6]): print index, item Oops, yes, thanks for catching that. It was fairly fundamental to the discussion! Alan G ___

Re: [Tutor] ConfigParser re-read fails

2009-02-15 Thread Moos Heintzen
It looks way too simplified. I have no idea where the problem is. Would you mind showing the script? gist.github.com is good for posting code. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Reading a Text File with tkFileDialog, askopenfilename+enumerate

2009-02-15 Thread Wayne Watson
Title: Signature.html Thanks. Got it. It finally dawned on me in the midst of responding to Kent. If you ever get a chance to try the Moz experiment above, I'd be interested in your reaction. I see it as my 11:47 post. Alan Gauld wrote: "John Fouhy" wrote for index, item in [9,8,7,6]

Re: [Tutor] *nix tail -f multiple log files with Thread

2009-02-15 Thread bob gailer
David wrote: Hi everyone, I copied a program from C to track multiple log files. I would like to be able to print a label when a log file is updated. Did the C program accomplish that? If so, it might help to see that code. If not why mention it? Your example output falls short of your sta

Re: [Tutor] *nix tail -f multiple log files with Thread

2009-02-15 Thread David
David wrote: bob gailer wrote: Did the C program accomplish that? If so, it might help to see that code. If not why mention it? It is here if you want to check it out; http://dwabbott.com/downloads/logtailer.c.txt Your example output falls short of your stated goal as I understand it! My g

Re: [Tutor] *nix tail -f multiple log files with Thread

2009-02-15 Thread Bill Campbell
On Sun, Feb 15, 2009, bob gailer wrote: > David wrote: >> Hi everyone, >> >> I copied a program from C to track multiple log files. I would like to >> be able to print a label when a log file is updated. > > Did the C program accomplish that? If so, it might help to see that > code. If not why