newbie

U. N. Owen electricity at uymail.com
Wed Aug 27 12:48:20 EDT 2003


First of all, install Python ;-)

Let's rewrite some parts of the doc...

Launch the interpreter, and try to
load some modules:

>>> import math
>>> import time

You may have some problems in Windows if
you installed Python in a folder with
spaces (like "Program Files").


>>> a=1
>>> b=1.0e-1
>>> math.sin(b)
>>> str(a)
>>> int('10')
>>> print a

The preceeding are very useful ;-)

Next, you will need to write whole
functions, so you need a folder to
put your files (not inside the Python
library !). You must add this folder
to the PYTHONPATH variable.
On linux, it's just another "setenv" or "export".
On Mac, you need to run something like
"ConfigurePythonPref" in the main Python folder,
and on Windows, I can't remember; maybe you
add PYTHONPATH in autoexec.bat or (another
place in NT and XP).

Then open your preferred text editor.
A python file is similar to what is
typed in the interpreter, but it's
much simpler to type.

To define a function :

def fibonacci(n):
  if n<2: return n
  a,b=0,1
  for i in range(n):
    a,b=b,a+b
  return a

First note indentation is *very* important.
It's the only way to distinguish "block",
like in the for loop. The colon is also important.

You should use space for indentation, and
no tabs.

You can save this new file as fib.py,
in the folder you add to PYTHONPATH.
Then

>>> import fib
>>> fib.fibonacci(10)

or

>>> from fib import fibonacci
>>> fibonacci(10)



It certainly isn't enough, but I tried to
explain some points where I had some problems
when I learnt... You should definitively
read the documentation.




I hope this helps. If you have any question,
you can use jeanclaude.arbaut at free.fr.



-- 
_______________________________________________
Get your free email from http://www.uymail.com

Powered by Outblaze





More information about the Python-list mailing list