Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: newbie

Thread Tools

Re: newbie

U. N. Owen
Posts: n/a

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
for i in range(n):
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,
in the folder you add to PYTHONPATH.

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


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

Get your free email from

Powered by Outblaze

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie with newbie questions JohnE ASP .Net 3 08-17-2009 10:10 PM
VONAGE Newbie w/newbie question VOIP 0 08-11-2007 01:40 PM
another newbie question from another newbie.... Lee UK VOIP 4 05-17-2005 04:10 PM
newbie: cisco vlan newbie question No Spam Cisco 3 06-07-2004 10:02 AM
Newbie! I'm a newbie! What's wrong with this program? Id0x Python 4 07-20-2003 11:40 PM