New to Python - block grouping (spaces)

Chris Angelico rosuav at gmail.com
Mon Apr 20 05:44:08 CEST 2015


On Mon, Apr 20, 2015 at 1:28 PM, Rustom Mody <rustompmody at gmail.com> wrote:
>> If you have a ten-file project that's identifying a key function
>> globally as 'f', then you already have a problem. If your names are
>> more useful and informative, a global search-and-replace will do the
>> job.
>
> Are you sure your global search-and-replace will do a proper job inside
> strings and comments?

Yep! Any occurrence inside a string literal or comment is generally
going to be referring to the same function, and thus should be
renamed. Can your system handle _that_? Example:

def add_grab(widget):
    """Add a widget to the grabbed widgets"""

def remove_grab(widget):
    """Undo the effect of add_grab() on a given widget"""
    # Note that multiple add_grab() calls will add multiple instances,
    # so we remove only the first.

Every occurrence of add_grab here is referring to the function. If you
do a global search-and-replace, they'll be caught automatically. With
your non-text magic, you'd need to explicitly implement this as a
feature. Text files make life easier!

>> What's your point, though?
>
> Point?
>
> Nnotions like identifier (and dozens of others) are straightforwardly
> present and available inside the python implementation.
> However the language implementation is a hard-n-high silo
> For the programmer accessing the language through an editor these notions are
> not available unless hi-power explosives are used to punch holes in the silo
> -- eg open Cpython sources.

Would it help if Python grew a function like Pike's
Function.defined(), which tells you exactly where, even in C source,
something was defined? I don't honestly see that looking in the
CPython source is such a common need that it begs for assistance, and
I definitely don't see how a non-text source code format would improve
on it. Feel like elaborating?

ChrisA



More information about the Python-list mailing list