[colug-432] Python inline help or library exploration tips
jep200404 at columbus.rr.com
jep200404 at columbus.rr.com
Wed Aug 17 13:12:43 EDT 2016
On Mon, 1 Aug 2016 15:51:14 -0400, Tom Hanlon <tom at functionalmedia.com> wrote:
> I am playing with the faker tool from python ...
Are you using the fake-factory module, not the faker module?
> 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.
You are missing good docs.
Python has a standard way of providing docs called "docstrings".
Unfortunately, fake-factory has few docstrings and the ones it
does have are not very helpful.
> 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.
For Python, use the help() and dir() functions.
Also explore __doc__ property of things of interest.
For example, from the Python command line,
play with the following commands
to explore the range function.
help(range)
dir(range)
range.__doc__
> How would I see all the options in fake.profile()
> so I can see if there is a firstname, lastname[?]
You _should_ be able to ask for docs with the following:
help(fake.profile)
or
help(Factory.create().profile)
or
Factory.create().profile.__doc__
or
print(Factory.create().profile.__doc__)
More empirically:
fake = Factory.create().profile()
print(repr(fake))
print(repr(fake.keys()))
> If I did not want to just write the code,
> where would I find the docs on this.
Read the source on github, add the missing docs,
and submit pull requests. In this case, lines 37-40 of
faker/providers/profile/__init__.py offaker project.
See
https://github.com/joke2k/faker/blob/master/faker/providers/profile/__init__.py
python.org/dev/peps/pep-0257
python.org/dev/peps/pep-0258
python.org/dev/peps/pep-0287
Chapter 15 of "Learning Python" 5th ed. by Mark Lutz
Also watch Brandon Rhodes' PyOhio 2011 presentation
"Squinting at Python Objects".
To misparaphrase ESR, more snake eyes make all Python bugs
shallow. cohpy.org has a technical mailing list that might
have more snake eyes than this list.
cohpy.org
https://mail.python.org/mailman/listinfo/centraloh
More information about the colug-432
mailing list