[Tutor] Need help appending data to a logfile

Dave Angel davea at davea.name
Mon Jun 17 23:43:27 CEST 2013


On 06/17/2013 05:17 PM, Jim Mooney wrote:
> 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.

You can use the call version, if you want help on the return type.  Of 
course, you want to watch out for side effects;  don't do this unless 
you really want the method to be called.

>
> 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.







In Python 2.x
  help(file.close)
In Python 3.x,
  help(_io.TextIOWrapper.close)
    or
  help(sys.stdin.close)

But that 3.3 help text isn't right.

In 2.x, it starts:

Help on method_descriptor:

close(...)
     close() -> None or (perhaps) an integer.  Close the file.

     Sets data attribute .closed to....

But in 3.3, it says:
Help on built-in function close:

close(...)

with no more explanation.

>
> 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.
>


-- 
DaveA


More information about the Tutor mailing list