newbie questions

bruno at modulix onurb at xiludom.gro
Wed Mar 15 18:10:36 CET 2006


meeper34 wrote:
> Hi,
> 
> I'm just starting out with Python, and so far I am thoroughly impressed
> with what you can do very easily with the language.
>
>  I'm coming from a
> C++ background here.  A couple of questions came up as I was thinking
> about dynamically typed languages:
> 
> 1.  If someone releases an interface in Python, how does the user know
> what parameters the function takes/returns?

They read the doc !-)

The minimal documentation effort is to put docstrings in the source:
http://www.python.org/doc/peps/pep-0257/

Then there are many ways to get at the doc, the most useful being the
help() command in the interactive python shell.

> 2.  If documentation is the answer to 1, then are there any Python
> documentation standards?

cf above

> 3.  Are there any tools out there that can extract the interface
> information from Python files and release it as documentation like
> header (.h) files?  I know there are tools like this for languages like
> C#.

cf above

> 4.  Really basic question, and I'm sure I will learn this very quickly
> with more reading, but I'm confused by the lack of an entry point in a
> Python app, i.e. int main().

When the python interpreter is feed a python source file, it executes
all that is at the top-level. So for the simplest cases, there's no need
for an "entry point". Now there's a common idiom which is:

# myfile.py
... imports, defs etc here ...

def main(argv):
  ... code for main here ...
  return 0 # ok

if __name__ == "__main__" :
  import sys
  sys.exit(main(sys.argv))

A quick explanation: a source file can be either passed to the
interpreter, in which case it's considered as the program itself, or
imported by another source file, in which case it's considered as a
module. In the first case, the magic variable __name__ will be set to
"__main__", in the second it will be set to ne name of the module. The
idiom above allow to use the file both as a program or as a module.
Another use for it is to put some tests in the main() if the file is not
meant to be used as a program.

> Btw, I was turned on to Python from Bruce Eckel's article "Strong
> Typing vs Strong Testing."

Hope you'll enjoy it - but even if the language itself is quite easy to
learn, it may takes some time getting used to the pythonic way of doing
things.

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list