Q:

NameError: name 'Factory' is not define i don't know why

I am new to Python 2.7 and practicing to write to a csv file using the faker module which creates dummy test data.  I am writing the header first.
I am getting an error Factory is not defined.
I'm not sure why it thinks factory is not defined.
Traceback (most recent call last):
  File "C:/Automation/Python/Write to file practice/csv_write_test.py", line 18, in 
    fake = Factory.create()
NameError: name 'Factory' is not defined
My code snippet is:
from faker import factory
import csv

def create_fake_stuff(fake):
""""""
stuff = ["email", "bs", "address", "city", "state", "paragraph"]
for item in stuff:
    print "%s = %s" % (item, getattr(fake, item)())

with open('test.csv', 'wb') as csvfile:
write_to_csv = csv.writer(csvfile, delimiter=' ',
                        quotechar='|', quoting=csv.QUOTE_MINIMAL)
write_to_csv.writerow(['id,' 'TITLE,' 'FNAME,' 'SNAME,' 'GENDER,' 'ADD1,'])

if __name__ == "__main__":
fake = Factory.create()
create_fake_stuff(fake)

Thanks for help!

A:

You are importing a factory module, but need to import a Factory class. Replace:
from faker import factory

with:
from faker import Factory  # or from faker.factory import Factory

