[Tutor] Running Python from UNIX

Anand Ramakrishna anandrs@hexaware.com
Tue, 6 Aug 2002 16:30:15 +0530


Hi Valdas,
               Thanks a lot. It was an indentation problem as you =
correctly guessed. Thanks a lot. I have some confusing questions.

1. From my UNIX command prompt (I am using bash shell), if I type =
python, I go to python shell, then when I type=20
print 'Hello World'  --> This prints Hello World.

When I type
print 'Hello World' in a file (say newfile.p), then give execute =
permissions for the file and if I type in my UNIX command prompt
python newfile.p  --> This prints Hello World.

When I type
python print 'Hello World' in a file and then execute the file. It gives =
out an error saying python not found.

When I type
#! python print 'Hello World' in a file and then execute the file, it =
gives out an error saying python not found.

When I type from my UNIX command prompt
python print 'Hello World'  --> This gives an error message saying print =
command not found.

I am not able to understand this observation. Hope an expert like you =
can help me through.

Thanks and regards,
Anand~

[p.s] - I just visited your website www.if.lt. What is that language.




-----Original Message-----
From: Valdas Jonikas [mailto:valdas.jonikas@if.lt]
Sent: Tuesday, August 06, 2002 4:38 AM
To: Anand Ramakrishna
Subject: RE: [Tutor] Running Python from UNIX


> Hi,
>     The code is as follows
>=20
> def fibonacci (n):
>   "This function generates fibonacci series"
>   fib =3D []
>   a, b =3D 0, 1
>   while b < n:
>      print b
>      a, b =3D b, a+b
>=20
>   fibonacci(100)
>=20
> If I execute this code from the command line, the fibonacci=20
> series gets generated but when I put the same as a script=20
> file it does not print the result. But if I dont code it as a=20
> function and just code it as a program like
>=20
> n =3D 100
> a, b =3D 0, 1
> while b < n:
>    print b
>    a, b =3D b, a+b
>=20
> This program as a script prints out the result but the same=20
> program as a function did not print the result. Why is this happening.

Hmm..., strange :-\
Do you put an indent before function call? I mean that line
fibonacci(100)
should be without indents in the beginning, otherwise
Python understands this line as a part of function fibonacci.

Regards,
Valdas