Re: [Tutor] String Attribute

2015-08-02 Thread Alan Gauld
On 02/08/15 10:15, Ltc Hotspot wrote: Question1: Why did the following strip function fail: line2 = line.strip (',') What makes you think it failed? I see no error messages below. Question2: How do I code a vertical column output See below. Revised code: fname = raw_input("Enter f

Re: [Tutor] String Attribute

2015-08-02 Thread Ltc Hotspot
Hi Alan, Question1: Why did the following strip function fail: line2 = line.strip (',') View instructions for 'str.strip([*chars*])¶ ' which is available at https://docs.pythonorg/2.7/library/stdtypes.html?highlig

Re: [Tutor] String Attribute

2015-08-02 Thread Alan Gauld
On 02/08/15 02:20, Ltc Hotspot wrote: Hi Alan, I made a mistake and incorrectly assumed that differences between 54 lines of output and 27 lines of output is the result of removing duplicate email addresses, Apparently, this is not the case and I was wrong :( The solution to the problem is in t

Re: [Tutor] String Attribute

2015-08-02 Thread Ltc Hotspot
Hi Emile, I made a mistake and incorrectly assumed that differences between 54 lines of output and 27 lines of output is the result of removing duplicate email addresses, i.e., gsil...@umich.edu gsil...@umich.edu, c...@iupui.edu, c...@iupui.edu Apparently, this is not the case and I was wrong :(

Re: [Tutor] String Attribute

2015-08-02 Thread Ltc Hotspot
Hi Alan, I made a mistake and incorrectly assumed that differences between 54 lines of output and 27 lines of output is the result of removing duplicate email addresses, i.e., gsil...@umich.edu gsil...@umich.edu, c...@iupui.edu, c...@iupui.edu Apparently, this is not the case and I was wrong :(

Re: [Tutor] String Attribute

2015-08-01 Thread Emile van Sebille
On 8/1/2015 4:21 PM, Ltc Hotspot wrote: Hi Emile, Question: What is the source of the line 7 syntax: mbox.split? I read mbox from the file. eg, mbox = open("mbox-short.txt",'r').read() and it looks to me that if you insert the above in front of the for loop below you'll get further. Emil

Re: [Tutor] String Attribute

2015-08-01 Thread Emile van Sebille
On 8/1/2015 4:07 PM, Ltc Hotspot wrote: Hi Alan, Question1: The output result is an address or line? It's a set actually. Ready to be further processed I imagine. Or to print out line by line if desired. Question2: Why are there 54 lines as compared to 27 line in the desired output? Be

Re: [Tutor] String Attribute

2015-08-01 Thread Alan Gauld
On 02/08/15 00:07, Ltc Hotspot wrote: Question1: The output result is an address or line? Its your assignment,. you tell me. But from your previous mails I'm assuming you want addresses? Question2: Why are there 54 lines as compared to 27 line in the desired output? Because the set removes

Re: [Tutor] String Attribute

2015-08-01 Thread Ltc Hotspot
Hi Alan, Question1: The output result is an address or line? Question2: Why are there 54 lines as compared to 27 line in the desired output? Here is the latest revised code: fname = raw_input("Enter file name: ") if len(fname) < 1 : fname = "mbox-short.txt" fh = open(fname) count = 0 addresses =

Re: [Tutor] String Attribute

2015-08-01 Thread Ltc Hotspot
Hi Emile, Question: What is the source of the line 7 syntax: mbox.split? Here is a copy of the Traceback message: NameError Traceback (most recent call last) C:\Users\vm\Desktop\apps\docs\Python\8_5_v_26.py in () 5 addresses = set() 6 for addr in [ fromline.split()[0] > 7 for f

Re: [Tutor] String Attribute

2015-08-01 Thread Emile van Sebille
On 8/1/2015 12:00 PM, Ltc Hotspot wrote: Hi Everyone: Let me repost the question: You will parse the From line using split() and print out the second word in the line (i.e. the entire address of the person who sent the message). Then print out a count at the end. *Hint:* make sure not to incl

Re: [Tutor] String Attribute

2015-08-01 Thread Alan Gauld
On 01/08/15 19:48, Ltc Hotspot wrote: There is an indent message in the revised code. Question: Where should I indent the code line for the loop? Do you understand the role of indentation in Python? Everything in the indented block is part of the structure, so you need to indent everything that

Re: [Tutor] String Attribute

2015-08-01 Thread Ltc Hotspot
Hi Everyone: Let me repost the question: You will parse the From line using split() and print out the second word in the line (i.e. the entire address of the person who sent the message). Then print out a count at the end. *Hint:* make sure not to include the lines that start with 'From:'. You

Re: [Tutor] String Attribute

2015-08-01 Thread Ltc Hotspot
Hi Emile, I just noticed there are duplicates Here is the complete line output as requested, below: stephen.marqu...@uct.ac.za lo...@media.berkeley.edu zq...@umich.edu rjl...@iupui.edu zq...@umich.edu rjl...@iupui.edu c...@iupui.edu c...@iupui.edu gsil...@umich.edu gsil...@umich.edu zq...@umich

Re: [Tutor] String Attribute

2015-08-01 Thread Ltc Hotspot
Hi Alan, There is an indent message in the revised code. Question: Where should I indent the code line for the loop? View the revised codes with loop indents, below: --->Revised Code v.2 wo/indent from lines 8-12: fname = raw_input("Enter file name: ") if len(fname) < 1 : fname = "mbox-short.t

Re: [Tutor] String Attribute

2015-08-01 Thread Emile van Sebille
Hi Hal, Seeing now that the output is only extracted from six address blocks, can you paste in the full contents of the file mbox-short.txt? (or the first 5-10 address sets if this is only representative) I think if we have a better understanding of the structure of the content you're parsin

Re: [Tutor] String Attribute

2015-08-01 Thread Cameron Simpson
On 31Jul2015 17:21, Ltc Hotspot wrote: Mark: Is this any better, message sent from GMail? Regards, Hal Looks better to me. Cheers, Cameron Simpson On Fri, Jul 31, 2015 at 5:02 PM, Mark Lawrence wrote: On 31/07/2015 19:57, ltc.hots...@gmail.com wrote: I believe that this is the third ti

Re: [Tutor] String Attribute

2015-08-01 Thread Alan Gauld
On 01/08/15 00:59, ltc.hots...@gmail.com wrote: for line in fh: line2 = line.strip() line3 = line2.split() line4 = line3[0] →→Apparently, the data content in the file is lost from the address sort function to line2? : It is not lost, it is an empty line. In [47]: print line2.sp

Re: [Tutor] String Attribute

2015-08-01 Thread Ltc Hotspot
Mark: Is this any better, message sent from GMail? Regards, Hal On Fri, Jul 31, 2015 at 5:02 PM, Mark Lawrence wrote: > On 31/07/2015 19:57, ltc.hots...@gmail.com wrote: > > I believe that this is the third time that you've been asked to do > something about the amount of whitespace that you're

Re: [Tutor] String Attribute

2015-08-01 Thread Ltc Hotspot
Hi Mark, Desired output on execution of the script: stephen.marqu...@uct.ac.za lo...@media.berkeley.edu zq...@umich.edu rjl...@iupui.edu zq...@umich.edu rjl...@iupui.edu [...] Regards, Hal On Fri, Jul 31, 2015 at 5:21 PM, Ltc Hotspot wrote: > Mark: > Is this any better, message sent from G

Re: [Tutor] String Attribute

2015-08-01 Thread ltc.hotspot
Sent from Surface From: Alan Gauld Sent: ‎Friday‎, ‎July‎ ‎31‎, ‎2015 ‎4‎:‎54‎ ‎PM To: Tutor@python.org On 31/07/15 19:57, ltc.hots...@gmail.com wrote: > for line in fh: > line2 = line.strip() > line3 = line2.split() > line4 = line3[0] You need to check that there actually

Re: [Tutor] String Attribute

2015-07-31 Thread Mark Lawrence
On 31/07/2015 19:57, ltc.hots...@gmail.com wrote: I believe that this is the third time that you've been asked to do something about the amount of whitespace that you're sending to this list. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our langua

Re: [Tutor] String Attribute

2015-07-31 Thread ltc.hotspot
Emile, --> Captured is a printout from line3 to addresses, below: In [46]: print line3 [] In [47]: print line2.split() [] In [48]: print line2 In [49]: print line.strip() In [50]: print fh In [51]: print addresses set(['1.0', 'sou...@collab.sakaiproject.org;', 'Jan', 'mail.umich.ed

Re: [Tutor] String Attribute

2015-07-31 Thread Alan Gauld
On 31/07/15 19:57, ltc.hots...@gmail.com wrote: for line in fh: line2 = line.strip() line3 = line2.split() line4 = line3[0] You need to check that there actually is something in the list to access. If you get a line with only one word in it, or even a blank line this will fail. addr

Re: [Tutor] String Attribute

2015-07-31 Thread Emile van Sebille
On 7/31/2015 11:57 AM, ltc.hots...@gmail.com wrote: →Question: Why is the list index out of range on line # 9: IndexError Traceback (most recent call last) C:\Users\vm\Desktop\apps\docs\Python\assinment_8_5_v_20.py in () 7 line2 = line.strip() 8 line3 = line2.s

Re: [Tutor] String Attribute

2015-07-31 Thread ltc.hotspot
Hi Martin, Hal is not have a great day, indeed to day: Here is the raw data entered: fname = raw_input("Enter file name: ") if len(fname) < 1 : fname = "mbox-short.txt" fh = open(fname) count = 0 addresses = set() for line in fh: line2 = line.strip() line3 = line2.split() line4 = line3[

Re: [Tutor] String Attribute

2015-07-31 Thread Martin A. Brown
Greetings again Hal, Thank you for posting your small amounts of code and results inline. Thanks for also including clear questions. Your "surface" still seems to add extra space, so, if you could trim that, you may get even more responses from others who are on the Tutor mailing list. Now

Re: [Tutor] String Attribute

2015-07-31 Thread Alan Gauld
On 31/07/15 15:39, ltc.hots...@gmail.com wrote: fname = raw_input("Enter file name: ") if len(fname) < 1 : fname = "mbox-short.txt" fh = open(fname) count = 0 for line in fh: if not line.startswith('From'): continue line2 = line.strip() line3 = line2.split() line4 = line3[1]

Re: [Tutor] String Attribute

2015-07-31 Thread ltc.hotspot
Hi Alan, Here is the revised code below: fname = raw_input("Enter file name: ") if len(fname) < 1 : fname = "mbox-short.txt" fh = open(fname) count = 0 for line in fh: if not line.startswith('From'): continue line2 = line.strip() line3 = line2.split() line4 = line3[1]

Re: [Tutor] String Attribute

2015-07-31 Thread Alan Gauld
On 31/07/15 01:25, ltc.hots...@gmail.com wrote: fname = raw_input("Enter file name: ") if len(fname) < 1 : fname = "mbox-short.txt" fh = open(fname) count = 0 for line in fh: if not line.startswith('From'): continue line2 = line.strip() line3 = line2.split() line4 = line3[1]

Re: [Tutor] String Attribute

2015-07-31 Thread ltc.hotspot
Hi Alan, I rewrote the code as follows: fname = raw_input("Enter file name: ") if len(fname) < 1 : fname = "mbox-short.txt" fh = open(fname) count = 0 for line in fh: if not line.startswith('From'): continue line2 = line.strip() line3 = line2.split() line4 = lin

Re: [Tutor] String Attribute

2015-07-30 Thread Mark Lawrence
On 30/07/2015 23:34, ltc.hots...@gmail.com wrote: sure Sent from Surface From: Mark Lawrence Sent: ‎Thursday‎, ‎July‎ ‎30‎, ‎2015 ‎3‎:‎25‎ ‎PM To: Tutor@python.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscri

Re: [Tutor] String Attribute

2015-07-30 Thread Alan Gauld
On 30/07/15 23:51, ltc.hots...@gmail.com wrote: fname = raw_input("Enter file name: ") if len(fname) < 1 : fname = "mbox-short.txt" # assign fname fh=open(fname,'r') # Open a new file handle for line in fh: print line if 'From' in line.split()[0] and '@' in line: sender = line.split()[

Re: [Tutor] String Attribute

2015-07-30 Thread Alan Gauld
On 30/07/15 22:17, ltc.hots...@gmail.com wrote: fname = raw_input("Enter file name: ") if len(fname) < 1 : fname = "mbox-short.txt" # assign fname fh=open(fname,'r') # Open a new file handle for line in fh: print line if 'From' in line.split()[0] and '@' in line: sender = line.split()[

Re: [Tutor] String Attribute

2015-07-30 Thread ltc.hotspot
Hi Mark, I’m still confused because line 4 reads: fh=open(fname,'r') # Open a new file handle, not fn = open(fname) Therefore, can you write down line by line from error to correction? Here is the revised code: fname = raw_input("Enter file name: ") if len(fname) < 1 : fname = "mbox-shor

Re: [Tutor] String Attribute

2015-07-30 Thread ltc.hotspot
sure Sent from Surface From: Mark Lawrence Sent: ‎Thursday‎, ‎July‎ ‎30‎, ‎2015 ‎3‎:‎25‎ ‎PM To: Tutor@python.org ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listi

Re: [Tutor] String Attribute

2015-07-30 Thread ltc.hotspot
Hi everyone, Revised code: fname = raw_input("Enter file name: ") if len(fname) < 1 : fname = "mbox-short.txt" # assign fname fh=open(fname,'r') # Open a new file handle for line in fh: print line if 'From' in line.split()[0] and '@' in line: sender = line.split()[1] fn.seek

Re: [Tutor] String Attribute

2015-07-30 Thread Mark Lawrence
On 30/07/2015 20:07, ltc.hots...@gmail.com wrote: When you post here can you please find a mechanism that gives us more text than whitespace, thank you. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence

Re: [Tutor] String Attribute

2015-07-30 Thread ltc.hotspot
Sent from Surface From: ltc.hots...@gmail.com Sent: ‎Thursday‎, ‎July‎ ‎30‎, ‎2015 ‎11‎:‎47‎ ‎AM To: Steven D'Aprano Hi Steve: New revision code: count = 0 fn = raw_input("Enter file name: ") if len(fn) < 1 : fname = "mbox-short.txt" for line in fn: if 'From' in line.spl

Re: [Tutor] String Attribute

2015-07-29 Thread Steven D'Aprano
On Tue, Jul 28, 2015 at 11:33:53PM +, ltc.hots...@gmail.com wrote: > > Hi Everyone: > > What is the source of the syntax error to the String Attribute? > > Go to the following URL links and view a copy of the raw data file code and > sample data: Please don't send people to URLs to view y

Re: [Tutor] String Attribute

2015-07-29 Thread Alan Gauld
On 29/07/15 00:33, ltc.hots...@gmail.com wrote: Hi Everyone: What is the source of the syntax error to the String Attribute? Normally I'd ask you to post the full text of any errors. They usually contain a lot of useful information. They also help us identify which syntax error you are askin

[Tutor] String Attribute

2015-07-29 Thread ltc.hotspot
Hi Everyone: What is the source of the syntax error to the String Attribute? Go to the following URL links and view a copy of the raw data file code and sample data: 1.) http://tinyurl.com/p2xxxhl 2.) http://tinyurl.com/nclg6pq Here is the desired output: stephen.marqu...@uct.ac.za