[Tutor] Can I use def without ( ) at the end?
Nathan Pinno
falcon3166 at hotmail.com
Sun Jul 10 03:13:06 CEST 2005
Brian,
I'll do one better and post the code after I'm done writing it. Then you
can decide for yourself what I'm trying to do.
Nathan P.
----- Original Message -----
From: "Brian van den Broek" <bvande at po-box.mcgill.ca>
To: "Nathan Pinno" <falcon3166 at hotmail.com>
Cc: <tutor at python.org>
Sent: Saturday, July 09, 2005 6:54 PM
Subject: Re: [Tutor] Can I use def without ( ) at the end?
> Nathan Pinno said unto the world upon 09/07/2005 20:36:
>
> <top post corrected>
>
>> ----- Original Message ----- From: "Brian van den Broek"
>>
>> > Nathan Pinno said unto the world upon 09/07/2005 19:03:
>> >> Hi all,
>> >>
>> >> Is the subject possible without getting an error?
>> >>
>> >> Nathan Pinno
>> >> Crew, McDonalds Restaurant, Camrose, AB Canada
>> >> http://www.npinnowebsite.ca/
>> >
>> > No. Why do you want to do this? If it is to have a function with no
>> > arguments:
>> >
>> > >>> def no_args():
>> > ... print "I've no arguments"
>> > ...
>> > >>> no_args()
>> > I've no arguments
>> > >>>
>> >
>> > Brian vdB
>>
>>
>>
>> Also, I just wanted to know because I'm using it in my Giant Computer
>> program for the menus, so I don't have to keep re-typing them.
>>
>> Nathan Pinno
>
>
> Nathan,
>
> I'm afraid I don't know what you meant in your other post by "get a
> def". I'm also unclear on what it is you feel that you are having to
> retype.
>
> The usual way to have some functions and 'drive' them through a text
> menu is either a dictionary dispatch (don't worry about that right
> now) or something simpler like:
>
>
> >>> def function_1():
> ... print "I am function 1!"
> ...
> >>> def function_2():
> ... print "I am function 2!"
> ...
> >>> def menu():
> ... print "I'm a simple menu system."
> ... print "Enter 1 for function 1"
> ... print "Enter 2 for function 2"
> ... choice = raw_input("Your selection please?\n")
> ... if choice == '1':
> ... function_1()
> ... elif choice == '2':
> ... function_2()
> ... else:
> ... print "Please read more carefully"
>
> Try that at the prompt, and then call the menu function -- on a line,
> type:
>
> menu()
>
> If that isn't helping, you are going to have to explain more clearly
> what problem it is that you are trying to avoid.
>
> Brian vdB
>
>
More information about the Tutor
mailing list