Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #28953 > unrolled thread

avoid the redefinition of a function

Started byJabba Laci <jabba.laci@gmail.com>
First post2012-09-12 14:56 +0200
Last post2012-09-12 06:15 -0700
Articles 4 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  avoid the redefinition of a function Jabba Laci <jabba.laci@gmail.com> - 2012-09-12 14:56 +0200
    Re: avoid the redefinition of a function Ramchandra Apte <maniandram01@gmail.com> - 2012-09-12 06:15 -0700
      Re: avoid the redefinition of a function Alister <alister.ware@ntlworld.com> - 2012-09-12 14:04 +0000
    Re: avoid the redefinition of a function Ramchandra Apte <maniandram01@gmail.com> - 2012-09-12 06:15 -0700

#28953 — avoid the redefinition of a function

FromJabba Laci <jabba.laci@gmail.com>
Date2012-09-12 14:56 +0200
Subjectavoid the redefinition of a function
Message-ID<mailman.554.1347454594.27098.python-list@python.org>
Hi,

I have an installer script that contains lots of little functions. It
has an interactive menu and the corresponding function is called. Over
time it grew long and when I want to add a new function, I should give
a unique name to that function. However, Python allows the
redefinition of functions:

#!/usr/bin/env python

def step_1():
    print 1

def step_1():
    print 2

step_1()

This will call the 2nd function. Now my functions are called step_ID
(like step_27(), step_28(), etc.). How to avoid the danger of
redefinition? Now, when I write a new function, I search for its name
to see if it's unique but there must be a better way.

Thanks,

Laszlo
P.S.: the script is here ( https://github.com/jabbalaci/jabbatron ) if
you are interested. It's made for Ubuntu.

[toc] | [next] | [standalone]


#28956

FromRamchandra Apte <maniandram01@gmail.com>
Date2012-09-12 06:15 -0700
Message-ID<97ae2677-ef7c-424d-9c40-eaf47a50d475@googlegroups.com>
In reply to#28953
On Wednesday, 12 September 2012 18:26:36 UTC+5:30, Jabba Laci  wrote:
> Hi,
> 
> 
> 
> I have an installer script that contains lots of little functions. It
> 
> has an interactive menu and the corresponding function is called. Over
> 
> time it grew long and when I want to add a new function, I should give
> 
> a unique name to that function. However, Python allows the
> 
> redefinition of functions:
> 
> 
> 
> #!/usr/bin/env python
> 
> 
> 
> def step_1():
> 
>     print 1
> 
> 
> 
> def step_1():
> 
>     print 2
> 
> 
> 
> step_1()
> 
> 
> 
> This will call the 2nd function. Now my functions are called step_ID
> 
> (like step_27(), step_28(), etc.). How to avoid the danger of
> 
> redefinition? Now, when I write a new function, I search for its name
> 
> to see if it's unique but there must be a better way.
> 
> 
> 
> Thanks,
> 
> 
> 
> Laszlo
> 
> P.S.: the script is here ( https://github.com/jabbalaci/jabbatron ) if
> 
> you are interested. It's made for Ubuntu.

Use a code checker such as PyLint (http://www.logilab.org/857 or pylint package).
Better idea:
I *strongly* recommend to never use names such as step_12. Use descriptive names and the problem will not occur.
Your project looks interesting. I can contribute. :-)
---
Bragging rights:SO account suspended
py2c, a Python to *pure* C/C++ translator, is my project (I am the author)
http://code.google.com/p/py2c/

[toc] | [prev] | [next] | [standalone]


#28966

FromAlister <alister.ware@ntlworld.com>
Date2012-09-12 14:04 +0000
Message-ID<xD04s.136155$5o4.45198@fx23.am4>
In reply to#28956
On Wed, 12 Sep 2012 06:15:21 -0700, Ramchandra Apte wrote:

> On Wednesday, 12 September 2012 18:26:36 UTC+5:30, Jabba Laci  wrote:
>> Hi,
>> 
>> 
>> 
>> I have an installer script that contains lots of little functions. It
>> 
>> has an interactive menu and the corresponding function is called. Over
>> 
>> time it grew long and when I want to add a new function, I should give
>> 
>> a unique name to that function. However, Python allows the
>> 
>> redefinition of functions:
>> 
>> 
>> 
>> #!/usr/bin/env python
>> 
>> 
>> 
>> def step_1():
>> 
>>     print 1
>> 
>> 
>> 
>> def step_1():
>> 
>>     print 2
>> 
>> 
>> 
>> step_1()
>> 
>> 
>> 
>> This will call the 2nd function. Now my functions are called step_ID
>> 
>> (like step_27(), step_28(), etc.). How to avoid the danger of
>> 
>> redefinition? Now, when I write a new function, I search for its name
>> 
>> to see if it's unique but there must be a better way.
>> 
>> 
>> 
>> Thanks,
>> 
>> 
>> 
>> Laszlo
>> 
>> P.S.: the script is here ( https://github.com/jabbalaci/jabbatron ) if
>> 
>> you are interested. It's made for Ubuntu.
> 
> Use a code checker such as PyLint (http://www.logilab.org/857 or pylint
> package).
> Better idea:
> I *strongly* recommend to never use names such as step_12. Use
> descriptive names and the problem will not occur.
> Your project looks interesting. I can contribute. :-)
> ---
> Bragging rights:SO account suspended py2c, a Python to *pure* C/C++
> translator, is my project (I am the author)
> http://code.google.com/p/py2c/

+1 Regards the Naming of your functions it makes it harder for new users 
to read & understand the code (and yourself in 6 months!)



-- 
Overload -- core meltdown sequence initiated.

[toc] | [prev] | [next] | [standalone]


#28957

FromRamchandra Apte <maniandram01@gmail.com>
Date2012-09-12 06:15 -0700
Message-ID<mailman.555.1347455731.27098.python-list@python.org>
In reply to#28953
On Wednesday, 12 September 2012 18:26:36 UTC+5:30, Jabba Laci  wrote:
> Hi,
> 
> 
> 
> I have an installer script that contains lots of little functions. It
> 
> has an interactive menu and the corresponding function is called. Over
> 
> time it grew long and when I want to add a new function, I should give
> 
> a unique name to that function. However, Python allows the
> 
> redefinition of functions:
> 
> 
> 
> #!/usr/bin/env python
> 
> 
> 
> def step_1():
> 
>     print 1
> 
> 
> 
> def step_1():
> 
>     print 2
> 
> 
> 
> step_1()
> 
> 
> 
> This will call the 2nd function. Now my functions are called step_ID
> 
> (like step_27(), step_28(), etc.). How to avoid the danger of
> 
> redefinition? Now, when I write a new function, I search for its name
> 
> to see if it's unique but there must be a better way.
> 
> 
> 
> Thanks,
> 
> 
> 
> Laszlo
> 
> P.S.: the script is here ( https://github.com/jabbalaci/jabbatron ) if
> 
> you are interested. It's made for Ubuntu.

Use a code checker such as PyLint (http://www.logilab.org/857 or pylint package).
Better idea:
I *strongly* recommend to never use names such as step_12. Use descriptive names and the problem will not occur.
Your project looks interesting. I can contribute. :-)
---
Bragging rights:SO account suspended
py2c, a Python to *pure* C/C++ translator, is my project (I am the author)
http://code.google.com/p/py2c/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web