[Tutor] Syntax error and EOL Error

Nym City nymcity at yahoo.com
Sun Sep 13 16:20:00 CEST 2015


Hello,
Sorry for the late response. It took me sometime to find the solution. Below is my updated code which seems to be working fine now. Just wanted to share with the group here.

import csv
DomainList = []

domains = open('domainlist.csv', 'r')
DomainList = csv.reader(domains)
DomainList = [column[1] for column in DomainList]
strip_list = [item.rstrip('/') for item in DomainList]
print('\n'.join(strip_list))
 Thank you. 


     On Monday, September 7, 2015 5:25 AM, Alan Gauld <alan.gauld at btinternet.com> wrote:
   
 

 On 07/09/15 01:40, Nym City via Tutor wrote:
> Hello,
> Thank you for your response. I have made updates and here is the new code:
> import csv
> DomainList = []
>
> domains = open('domainlist.csv', 'rb')
> DomainList = csv.reader(domains)
> DomainList = [column[1] for column in DomainList(str.rstrip('/'))]

Since DomainList is a csv.reader object what made you think you could 
call it with a string argument? You were not doing that previously?

> For "DomainList = [column[1] for column in DomainList(str.rstrip('/'))]"
> line, I am getting following error:TypeError: '_csv.reader' object is not callable

Which is true, and should be obvious how to fix. Stop calling it.
That means don't have parentheses after it.

> Doing some research, i thought it might be because I am importing
 > the csv as 'r' only

You are not importing the csv as 'r' you are opening your file as 'r'.
This has nothing to do with the error.
That is because you are calling a non callable object.

> Also, not sure if the next error is because of the above issue but
 > I get syntax error when I do the last print

Can you tell us how you managed to get that second error?
The interpreter should have stopped after the first error so you
should never get a second error. You must have modified the
code in some way.

You would need to show us the actual code you ran to reach the print 
statement, otherwise we can't begin to guess what might be causing the 
syntax error.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


 
  


More information about the Tutor mailing list