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


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

Re: avoid the redefinition of a function

Started byKen Seehart <ken@seehart.com>
First post2012-09-12 06:32 -0700
Last post2012-09-12 06:32 -0700
Articles 1 — 1 participant

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: avoid the redefinition of a function Ken Seehart <ken@seehart.com> - 2012-09-12 06:32 -0700

#28962 — Re: avoid the redefinition of a function

FromKen Seehart <ken@seehart.com>
Date2012-09-12 06:32 -0700
SubjectRe: avoid the redefinition of a function
Message-ID<mailman.557.1347456866.27098.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

Use lambda expressions to define some constraints:


gt = lambda x: lambda y: x>y
eq = lambda x: lambda y: x==y

constraints = [gt(2), eq(1)]
data = [3,1]

for i,c in enumerate(constraints):
    print c(data[i])
   
   

On 9/12/2012 5:56 AM, 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.


[toc] | [standalone]


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


csiph-web