When I access csv.reader from a script, every thing works well but when I access it from a method inside my class, I get the following error:
AttributeError: 'GetInstgramUsernames' object has no attribute 'reader'
I have looked at these two similar issues my problem is different
Based on those two links, I have ensured that
- A. I am pointing to the correct CSV libray
- B. I don't have a csv.py file in my project
I am new to Python so it could just be a simple oversight, but I have included the code and comments on what works and what doesn't
import csv
print(csv.__file__)
# displays: 
# D:\ProgramData\Anaconda2\lib\csv.pyc
reader = csv.reader(open('D:\\dev\\scrapy\\instagram_influencers\\instagram_influencers\\input\\user_names.csv','r'))
print(list(reader))
# displays
# [['user_name'], ['mensfashionpost'], ['creativefasion']]
class GetInstgramUsernames(object):
    def read(self):
        # same line as above but produces an error
        # AttributeError: 'GetInstgramUsernames' object has no attribute 'reader'
        self.xyz = csv.reader(open('D:\\dev\\scrapy\\instagram_influencers\\instagram_influencers\\input\\user_names.csv','r'))
        print(list(self.xyz))
csv = GetInstgramUsernames()
csv.read()
And the actual console output
python xmen.py
D:\ProgramData\Anaconda2\lib\csv.pyc
[['user_name'], ['mensfashionpost'], ['creativefasion']]
Traceback (most recent call last):
File "xmen.py", line 25, in <module>
    csv.read()
File "xmen.py", line 18, in read
    self.xyz = csv.reader(open('D:\\dev\\scrapy\\instagram_influencers\\instagram_influencers\\input\\user_names.csv','r'))
AttributeError: 'GetInstgramUsernames' object has no attribute 'reader'    D:\dev\scrapy\instagram_influencers>
 
    