Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AttributeError: 'list' object has no attribute 'strip

I cant figure out why this isnt working and just throwing me an error. I tried to move some things areounf and its still not working. It has to be something about it not reading to the list or something like that.

from Country import Country
import csv


class CountryIRSystem:
  def __init__(self):
    self.__list_countries = []

  def search_name (self, country_name):
    for country in self.__list_countries:
      if country.country_name == country_name:
        return country_name
    return None

  def create_info(self, country_data):

    with open(country_data, "r") as csvfile:
      csvreader = csv.reader(csvfile)
      for line in csvreader:
        line = line.strip("\n")
        words = line.split()

        country = Country()

        country.country_name = words[2]
        country.country_code = words[3]
        country.acc_to_clean_fuel = words[4]
        country.acc_to_elec = words[5]
        country.annual_freshwater_withdrawl = words[6]
        country.armed_forces_tot = words[7]
        country.expense_gdp = words[8]

        self.__list_countries.append(country)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

for line in csvreader:
    line = line.strip("\n")
    words = line.split()

csvreader returns a list of field values, not a plain line of text.

So you can just do this instead:

for words in csvreader:
    ...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading