calthoff / self_taught

This repository contains the exercises for "The Self-Taught Programmer: The Definitive Guide to Programming Professionally."
http://theselftaughtprogrammer.io
267 stars 226 forks source link

Error when running code #14

Open mardirousi opened 6 years ago

mardirousi commented 6 years ago

http://tinyurl.com/go9wepf

I get this error when running the code.

Traceback (most recent call last): File "/Users/mardirousi/Desktop/Python/Ch 9/csv/csv.py", line 1, in import csv File "/Users/mardirousi/Desktop/Python/Ch 9/csv/csv.py", line 5, in write = csv.writer(f, delimiter=",") AttributeError: module 'csv' has no attribute 'writer'

RobertSchusterFrontEndWebDeveloper commented 6 years ago

I was having the same issue and found that if all the files were placed into the same folder as this python file, on my pc this worked. Windows 10 version. I was able to open a cvs file named "Grocery inventory.csv" and txt file named "file.txt".

chapter 9 exercise 1

import os os.path.join("Users", "gr8-g", "Grocery inventory.csv")

import csv

with open("Grocery inventory.csv", "r", newline='') as f: r = csv.reader(f, delimiter=",") for row in r: print(",".join(row))

with open("file.txt", "r") as f: print(f.read())

End of script

Hope this helps Rob