newbie questions

M

meeper34

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?

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

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

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

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

Thanks,
John
 
K

keirr

meeper34 said:
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?

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

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

epydoc: http://epydoc.sourceforge.net/ is used by a bunch of people -
including me.
The documentation it produces is far from a header file, typically it
is in HTML
(although other output formats are available) but I find it does.
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().

There is some idiom for this.

def main(*args, **kw):
# do stuff
pass
if __name__ == '__main__':
# call main, perhaps with sys.argv
main()

You put this at the bottom of the file you want to run.
The __name__ property will be '__main__' iff you have executed the file

from the command line.
In particular the code in the if __name__... block won't be run if you
just import the file.

All the best,

Keir.
 
L

Luigi

Hi!

1. Documentation... sorry...
2. There are no standars, it depends on the apidoc tool you want to use
3. I don't know, but when you extract the api documentation (using
tools as epydoc or happydoc) you have all the information you need (I
think)....

4. As your python code is a script code, you don't need a main()
function (like C): all the lines you write are directly executed. For
example a code:

---
#!/usr/bin/python
a=5
b=a+3
print b
---

is directly executed.

If you are writing a class:

---
#!/usr/bin/python
class Test:
_init__(self):
self.name="My test"

t = Test()
print t.name
----

This code instances a class Test and prints the name attribute.

Note that if you import a file containing the code above as a python
module, the last 2 lines are executed. In order to avoid it you must
write:

---
#!/usr/bin/python
class Test:
_init__(self):
self.name="My test"

if __name__ == "__main__":
t = Test()
print t.name
----

Like this you execute the last two lines only if you execute directly
your file with the python interpreter.

I hope this can help you.

Luigi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,290
Messages
2,571,452
Members
48,129
Latest member
DianneCarn

Latest Threads

Top