0

I am trying to use the csv.reader function in Python 3.

dir('csv') displays (I have deleted some to shorten the post):

Code:

['__add__', ..., 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', ..., 'zfill']

What it does not show is 'reader'.

Is there any way to add the 'reader' function to the csv module?

2
  • on further analysis, I see that the program I was trying to run works fine if I copy and paste each line into a python-3 prompt, but if I try to run it through a terminal, I get an error: Commented Jul 17, 2018 at 13:54
  • I solved this by restarting my computer...as blhsingh mentions below, the key is to import csv, then dir(csv) -- Thanks for your help!! Commented Jul 19, 2018 at 20:28

1 Answer 1

3

'csv' is just a string, so when you do dir('csv') it just gives you all the attributes and methods available to str.

If you do dir(csv) (without the quotes) instead you will be able to see all the attributes and methods that the csv module has (providing that you have imported the csv module first):

>>> import csv
>>> dir(csv)
['Dialect', 'DictReader', 'DictWriter', 'Error', 'OrderedDict', 'QUOTE_ALL', 'QUOTE_MINIMAL', 'QUOTE_NONE', 'QUOTE_NONNUMERIC', 'Sniffer', 'StringIO', '_Dialect', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '__version__', 'excel', 'excel_tab', 'field_size_limit', 'get_dialect', 'list_dialects', 're', 'reader', 'register_dialect', 'unix_dialect', 'unregister_dialect', 'writer']
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.