[Tutor] Syntax error and EOL Error

Nym City nymcity at yahoo.com
Mon Sep 7 02:40:33 CEST 2015


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('/'))]
print(DomainList)
For "DomainList = [column[1] for column in DomainList(str.rstrip('/'))]" line, I am getting following error:TypeError: '_csv.reader' object is not callable
Doing some research, i thought it might be because I am importing the csv as 'r' only so i tried changing it to 'rb' and 'w' but received the same error.
Also, not sure if the next error is because of the above issue but I get syntax error when I do the last print and I do not see any syntax issue with it.
As always, thanks in advance. 
 Thank you. 


     On Friday, September 4, 2015 3:23 AM, Peter Otten <__peter__ at web.de> wrote:
   
 

 Nym City via Tutor wrote:

>  import csv
> DomainList = []
> 
> domains = open('domainlist.csv', 'r')
> DomainList = csv.reader(domains)
> DomainList = [column[1] for column in DomainList]
> DomainList = (str(DomainList).rstrip('/')
> print('\n'.join(DomainList))
> 
> 
> I keep getting EOL error on the second the last line and syntax error on
> the last print line. Even when I change the print line to say the
> following: print(DomainList) Please advise. Thank you in advance.
> Thank you.

Look at the lines preceding the one triggering the SyntaxError. Usually 
there is an opening (, [ or { which doesn't have a matching closing 
counterpart. 

In your case count the parens in the line

> DomainList = (str(DomainList).rstrip('/')

By the way, even without error this line will not have the desired effect.
Given 

>>> DomainList = ["facebook.com/", "twitter.com/"]

converting to string gives

>>> str(DomainList)
"['facebook.com/', 'twitter.com/']"

and as that doesn't end with a "/" applying the rstrip() method has no 
effect. Instead you can modify the line

> DomainList = [column[1] for column in DomainList]

where you can invoke the rstrip() method on every string in the list.

_______________________________________________
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