473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Module documentation

Just getting to grips with Python, a great language BUT
With something like Java I can find the syntax of a method call with no
problems, how do I do the same with Python?

For example, using MySQLdb or SGMLParser I can see what the available
methods are with dir, but how do I find out what parameters are needed and
what they represent?

Tony
Mar 26 '06 #1
6 1352
Tony Burrows:
With something like Java I can find the syntax of a method call with no
problems, how do I do the same with Python?
The basic syntax is just the name, with parameters in brakcets:

object.method(par1, par2, ...)

This is explained in the documentation, of course.
how do I find out what parameters are needed and what they represent?


This is documented in the library reference:
http://docs.python.org/modindex.html

You can also query the module for its docstrings:
import os
help(os) ....help(os.utime)

Help on built-in function utime in module nt:
....
Mar 26 '06 #2
Tony Burrows wrote:
Just getting to grips with Python, a great language BUT
With something like Java I can find the syntax of a method call with no
problems, how do I do the same with Python?

For example, using MySQLdb or SGMLParser I can see what the available
methods are with dir, but how do I find out what parameters are needed and
what they represent?


You can use the help function to get documentation on modules,
functions, classes and objects. For example:

import sgmllib
help(sgmllib) # gives lots of information on the entire module
help(sgmllib.SGMLParser) # gives information on the class
help(sgmllib.SGMLParser.__init__) # gives initialisation information

Unfortunately, because of the discrepancies between "old-style" and
"new-style" classes, you can't always get decent help on objects.
Consider this contrived example:

parser = sgmllib.SGMLParser() # you'd usually be using a subclass
help(parser) # gives information about "class instance(object)"

Compare this to what happens when you get help on a file object:

f = open("/etc/hosts")
help(f) # gives information about "class file(object)"

Personally, I feel that the whole "new-style" thing - making a class
which inherits from something called "object" (of all the names that
could have been chosen) - introduces a fair number of
implementation-level issues that should have been hidden at the level
of the language. I know that various other object-oriented languages
have "object" or "Object" as a root class, but it's a dubious
convention, unnecessary for the first seven or more years of Python's
public life, and perhaps a prime candidate for elimination in the
much-discussed-of-late Python 3000.

Paul

Mar 26 '06 #3
On Sun, 26 Mar 2006 17:19:35 +0200, Rene Pijlman wrote:
Tony Burrows:
With something like Java I can find the syntax of a method call with no
problems, how do I do the same with Python?


The basic syntax is just the name, with parameters in brakcets:

object.method(par1, par2, ...)

This is explained in the documentation, of course.
how do I find out what parameters are needed and what they represent?


This is documented in the library reference:
http://docs.python.org/modindex.html

You can also query the module for its docstrings:
import os
help(os) ...help(os.utime)

Help on built-in function utime in module nt:
...

Wow! Thanks for that, I didn't know about the help command. The problem
was that things like MySQLdb wasn't in the link you give (or at least, I
couldn't find it - though poking around did take me to the database
section and there it was).

Tony
Mar 26 '06 #4
Tony Burrows a écrit :
Just getting to grips with Python, a great language BUT
With something like Java I can find the syntax of a method call with no
problems, how do I do the same with Python?

For example, using MySQLdb or SGMLParser I can see what the available
methods are with dir, but how do I find out what parameters are needed and
what they represent?


In the python shell, typing 'help(<symbol>)' should get you started most
of the time.

Mar 26 '06 #5
Tony Burrows wrote:
Just getting to grips with Python, a great language BUT
With something like Java I can find the syntax of a method call with no
problems, how do I do the same with Python?

For example, using MySQLdb or SGMLParser I can see what the available
methods are with dir, but how do I find out what parameters are needed and
what they represent?


In case of extension modules and libraries not in the Python standard library,
they should have a documentation somewhere too.

And if they are implemented in Python, just look at the source to understand
how the methods work.

Georg
Mar 27 '06 #6
Bruno Desthuilliers wrote:
In the python shell, typing 'help(<symbol>)' should get you started most
of the time.


And honestly, it should work all of the time. If it doesn't, file a bug
report. I can't stand it when that doesn't work. Some of us don't do
all of our work with a browser handy, and a net connection.

Mike

Mar 27 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Bart Nessux | last post by:
How can one view the contents of a queue? I'd like to verify that the queue has the same number of objects as the list that has been put into it. Also, should one think of a queue as static or...
0
by: Josiah Carlson | last post by:
Good day everyone, I have produced a patch against the latest CVS to add support for two new formatting characters in the struct module. It is currently an RFE, which I include a link to at the...
12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
17
by: Jacob Page | last post by:
I have created what I think may be a useful Python module, but I'd like to share it with the Python community to get feedback, i.e. if it's Pythonic. If it's considered useful by Pythonistas, I'll...
25
by: Xah Lee | last post by:
Python Doc Problem Example: gzip Xah Lee, 20050831 Today i need to use Python to compress/decompress gzip files. Since i've read the official Python tutorial 8 months ago, have spent 30...
3
by: Chris Smith | last post by:
Hola, pythonisas: The documentation for the logging module is good, but a bit obscure. In particular, there seems to be a lot of action at a distance. The fact that getLogger() can actually be a...
1
by: alain MONTMORY | last post by:
Hello everybody, I am a newbie to python so I hope I am at the right place to expose my problem..... :-http://www.python.org/doc/2.4.2/ext/pure-embedding.html 5.3 Pure Embedding I download the...
2
by: Gabriele *darkbard* Farina | last post by:
Hi, I'm using Python 2.5 to develop a simple MVC framework based on mod_python. To load my controllers, I create new modules using the "new" module like this: # .... my_module =...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
4
by: dj | last post by:
Hello again, Does anyone know which method in the time module will generate and am or pm ? If none of the method will do this for me. Can I produce the value on my own ? Any suggestions ?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.