[Tutor] Need help appending data to a logfile

Jim Mooney cybervigilante at gmail.com
Mon Jun 17 23:17:24 CEST 2013


On 17 June 2013 11:30, Peter Otten <__peter__ at web.de> wrote:

> The help() function in the interactive interpreter is a good tool hunt for
> help on features of functions and classes. For example:

I tripped on Python help a couple of times, since I'm used to
easy-living GUI help, so here is a bit of help on help. From the
Python command line it may be help(open), for instance, but only for
builtins -- things that don't need dot syntax. For methods, like
str.find(), that need dot syntax, it's help(str.find) not help(find);
or you can use your own defined string name, such as
help(your_big_string.find). Basically, Python help must be fed an
object. It's not like a GUI searchable help file.

And for a method you don't use the method call, so it's help(str.find)
not help(str.find())  I'm embarrassed to say that tripped me up a
couple of times, due to habit.

For instance, you get help for open but not for close. Since you open
with a file handle such as fh = open('yourfile'), you must use
fh.close(), since close is a method of fh, and not a builtin. Since
python follows your lead and see the object fh, you can get help with
help(fh.close) as you named it, but not for help(close). I'm not sure
of the generic name Python wants for file, that would work like
help(str.find). I'll have to go find that. I tried 'file' but that
ain't it.

And if you want to be obtuse, just to see that python help Always
wants an object, even if you don't see it:

import builtins
help(builtins.open)  works to get the
supercalifragilisticexpialidocoius genormous help file for open, which
tells you more things about open than you could possibly want to know
unless you are really Hardcore ;')

But it is not recommended as your primary  method.

-- 
Jim
After indictment the bacon smuggler was put on the no-fry list


More information about the Tutor mailing list