[colug-432] Python inline help or library exploration tips

Tom Hanlon tom at functionalmedia.com
Mon Aug 1 15:51:14 EDT 2016


Colug,

I am playing with the faker tool from python to generate fake data to use
in some database and noSQL examples.

I think I am missing the easy way to use the docs or to use some inline or
online tips to get things done efficiently.

I will share my code but understand I am not so much looking for a solution
to this SPECIFIC problem as I am looking for how to enable myself to
discover these solutions on my own going forward.

I have this code, and it works, I like it.

>>>>>>>>>>>>>>>>>>>>>>>
from faker import Factory
import csv
import sys
with open('data.csv','w') as f:
    for i in range(100):
        fake = Factory.create()
        name = fake.profile()['name']
        address_raw = fake.profile()['address']
        address = address_raw.replace('\n', ', ')
        birthdate = fake.profile()['birthdate']
        phone = fake.phone_number()
        writer = csv.writer(f)
        writer.writerow((name,address,birthdate,phone))

>>>>>>>>>>>>>>>>

Here is todays challenge.

The name generated will include firstname lastname and also prefix, like
Dr. William Smith.

I want a few thousand rows of just firstname,lastname

So I copy that code and begin.

How would I see all the options in fake.profile() so I can see if there is
a firstname, lastname.

I assume fake.profile returns an array of name value pairs, I want to see
all of them so I can pick and choose.

If I did not want to just write the code, where would I find the docs on
this.

Thanks in advance..

As usual wording the question has probably lead me to an answer on my own,
but please still reply.

Thanks

Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.colug.net/pipermail/colug-432/attachments/20160801/7bc192fa/attachment.html 


More information about the colug-432 mailing list