Re: newbie

Discussion in 'Python' started by U. N. Owen, Aug 27, 2003.

  1. U. N. Owen

    U. N. Owen Guest

    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 .



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

    Powered by Outblaze
     
    U. N. Owen, Aug 27, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Id0x
    Replies:
    4
    Views:
    1,210
    Erik Max Francis
    Jul 21, 2003
  2. JohnE

    newbie with newbie questions

    JohnE, Aug 17, 2009, in forum: ASP .Net
    Replies:
    3
    Views:
    525
    Gregory A. Beamer
    Aug 17, 2009
  3. Jerry C.
    Replies:
    8
    Views:
    264
    Uri Guttman
    Nov 23, 2003
  4. Kruno Saho
    Replies:
    0
    Views:
    157
    Kruno Saho
    Apr 7, 2013
  5. Dave Angel
    Replies:
    0
    Views:
    137
    Dave Angel
    Apr 7, 2013
Loading...

Share This Page