On 09/26/2011 06:53 AM, Sajjad wrote:
Hello forum,


It has been two days that i have started with python and i am stuck with the
following simple issue:

i have created a python file and inside the file i have defined a function
as follows:

////////////////////////////////////////////////////////////
def greeting():
       print "Welcome to python"

///////////////////////////////////////////////////////////

I am following the Book named - "Rapid GUI programming with Python and Qt"

In the book they mentioned that  in the command line if i type

greeting() i should get the output "Welcome to python"

But i get nothing.


Any hint on this?


Regards
Sajjad

A little more precision would be helpful. You never told us what you called that source file. And there are several possible "command line" you might be referring to. The most likely are the shell, and the interpreter prompt. if you had shown us your session (via cut 'n paste), we might have been able to guess.

If you get nothing, then you must be somewhere else, since each of those will give you some response, depending on which shell you're running. So for example, if you're running Python 2.7 on Linux 10.04, with Bash as your shell, you might get

davea@think:~$ greeting()
>


That > prompt means you haven't finished the command line, and bash is waiting for the rest. Use Ctrl-C to get out of that one. Greeting is not a program from bash's point of view.

or if I'm running in the interpreter, I might get:

Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> greeting()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'greeting' is not defined
>>>

And this would be because two errors have occurred. In the above session I didn't import the source file, and I didn't qualify the name greeting so the interpreter could look in that module.

I would normally just add the greeting() call to the bottom of the source file firstprogram.py, and then run the whole thing with

davea@think:~$ python firstprogram.py

But your tutorial may have other ideas, so you'd best tell us what you've tried, and exactly what happened.




--

DaveA

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to