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


Groups > comp.lang.python > #28957

Re: avoid the redefinition of a function

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <maniandram01@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'function,': 0.07; 'python': 0.09; 'c/c++': 0.09; 'called.': 0.09; 'to:addr:comp.lang.python': 0.09; 'url:github': 0.09; 'cc:addr :python-list': 0.10; 'def': 0.10; ':-)': 0.13; '(like': 0.15; '18:26:36': 0.16; 'idea:': 0.16; 'occur.': 0.16; 'package).': 0.16; 'redefinition': 0.16; 'ubuntu.': 0.16; 'wrote:': 0.17; 'thanks,': 0.18; 'wednesday,': 0.22; 'cc:2**0': 0.23; 'script': 0.24; 'allows': 0.25; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '---': 0.26; 'looks': 0.26; 'skip:# 10': 0.27; 'functions.': 0.27; 'url:code': 0.29; 'function': 0.30; 'code': 0.31; 'print': 0.32; 'function.': 0.33; 'problem': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'project': 0.34; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'add': 0.36; 'but': 0.36; 'url:org': 0.36; 'should': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'interested.': 0.38; 'called': 0.39; 'little': 0.39; 'your': 0.60; 'url:p': 0.63; 'here': 0.65; 'account': 0.67; 'checker': 0.84; 'descriptive': 0.84; 'p.s.:': 0.84; 'grew': 0.91; 'received:209.85.220.184': 0.91; 'suspended': 0.91
Newsgroups comp.lang.python
Date Wed, 12 Sep 2012 06:15:21 -0700 (PDT)
In-Reply-To <mailman.554.1347454594.27098.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=122.178.208.59; posting-account=uPFZNQoAAAAm9w7z13q1SjWNKNjztdcD
References <mailman.554.1347454594.27098.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-IP 122.178.208.59
MIME-Version 1.0
Subject Re: avoid the redefinition of a function
From Ramchandra Apte <maniandram01@gmail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Cc Python mailing list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.555.1347455731.27098.python-list@python.org> (permalink)
Lines 65
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1347455731 news.xs4all.nl 6895 [2001:888:2000:d::a6]:59815
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:28957

Show key headers only | View raw


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/

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

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

csiph-web