Re: avoid the redefinition of a function

Thanks for the answers. I decided to use numbers in the name of the
functions to facilitate function calls. Now if you have this menu
option for instance:

(5) install mc

You can type just "5" as user input and step_5() is called
automatically. If I use descriptive names like install_java() then
selecting a menu point would be more difficult. And I don't want users
to type "java", I want to stick to simple numbers.

Advertisements

On 12/09/2012 19:04, Alister wrote:
> On Wed, 12 Sep 2012 18:56:46 +0200, Jabba Laci wrote:
>
>>> For example:
>>>
>>> def install_java():
>>> pass
>>>
>>> def install_tomcat():
>>> pass
>>
>> Thanks for the answers. I decided to use numbers in the name of the
>> functions to facilitate function calls. Now if you have this menu option
>> for instance:
>>
>> (5) install mc
>>
>> You can type just "5" as user input and step_5() is called
>> automatically. If I use descriptive names like install_java() then
>> selecting a menu point would be more difficult. And I don't want users
>> to type "java", I want to stick to simple numbers.
>>
>> Laszlo
>
> No No NO!
> you cant just pass user input to system calls without validating it first
> (google sql injection for examples of the damage unsanitised input can
> cause, it is not just as SQL problem)
>
> it is just as easy so select a reasonably named function as a bad one
>
> option=raw_input('select your option :')
>
> if option =="1": install_java()
> if option =="2": install_other()
>
> alternatively you cold add your functions into a dictionary an call them
> from that
>
> opts={'1':install java,'2':install_other}
>
> option=raw_input('select your option :')
> opts[option]
>
> Poorly named functions are a major example of poor programming style.
>
> one of the fundamental pillars for python is readability!
>
Or you could do this:

Advertisements

On Wed, 12 Sep 2012 18:04:51 GMT
Alister <> wrote:
> No No NO!
> you cant just pass user input to system calls without validating it first
> (google sql injection for examples of the damage unsanitised input can
> cause, it is not just as SQL problem)

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!