[Tutor] String Attribute
alan.gauld at btinternet.com
Sun Aug 2 16:06:56 CEST 2015
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
> Revised code:
> fname = raw_input("Enter file name: ")
> if len(fname) < 1 : fname = "mbox-short.txt"
> fh = open(fname)
> count = 0
> addresses =
> for line in fh:
> if line.startswith('From'):
You are still not checking for 'From ' - with a space. Thats why you still
get 54 instead of 27.
> line2 = line.strip ()
> line3 = line2.split()
> line4 = line3
> count = count + 1
> print addresses
To get a vertical printout try this:
Which converts the list into a string with a newline between each element.
Alternatively do it the manual way:
for addr in addresses: print addr
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:
More information about the Tutor