Re: python gripes survey

Discussion in 'Python' started by Gonçalo Rodrigues, Aug 27, 2003.

  1. On Sat, 23 Aug 2003 15:39:27 GMT, "Ryan Lowe" <>
    wrote:

    >python is a big improvement on most languages that came before it, but no
    >language is perfect. id like to make a list of some of the aspects people
    >find most annoying, regardless of their feasibility of implementation. for
    >instance, i discussed putting if clauses in for loops, and i noticed another
    >thread about allowing {} and [] to be added and subtracted. if its something
    >from another language (especially an obscure one), please explain how it
    >works in case people like myself dont know the language.
    >


    Major gripes: names bound in nested scopes are read-only, not
    rebindable. Related with this is the global declaration -- the only
    declaration in Python! There should be another way to handle this:
    something like scopes becoming objects where the names bound in it are
    it's attributes and then you would have two functions global() and
    enclosing() returning the global and the enclosing scope. Or something
    to this effect :)

    Minor gripes:
    - trimming down the builtins, e.g. move enumerate to itertools, get
    rid of map and filter, etc.

    - Get rid of lambda or find a way for lambda to accept statements.

    - Some of the more advanced Python stuff (super, metaclasses) has some
    dark corners (check the bugs tracker). Bring on the light.

    Things that I still haven't decided if they are gripes or not:

    - __slots__. Dangerous hack, makes generic code much more difficult.

    - names in for loops/list comprehensions leak out.

    With my best regards,
    G. Rodrigues
    Gonçalo Rodrigues, Aug 27, 2003
    #1
    1. Advertising

  2. Gonçalo Rodrigues

    Sean Ross Guest

    "Gonçalo Rodrigues" <> wrote in message
    news:...
    [snip]
    > Related with this is the global declaration -- the only
    > declaration in Python! There should be another way to handle this:
    > something like scopes becoming objects where the names bound in it are
    > it's attributes and then you would have two functions global() and
    > enclosing() returning the global and the enclosing scope. Or something
    > to this effect :)
    >


    This is probably not what you want, and it's probably worse than just using
    a global declaration, but it *is* "another way to handle this":

    >>> # put this at the top of your module,
    >>> # to grab hold of this module's namespace
    >>> import __main__ as main
    >>> g = "global variable"
    >>> def f():

    .... main.g = "re-bound global"
    ....
    >>> f()
    >>> g

    're-bound global'
    >>>



    If you want a global() function that returns the namespace, you can do this:

    #
    # your_utils.py
    #

    # I'll use the name 'main' rather than shadow the global keyword
    def main():
    import __main__
    return __main__


    # other_module.py
    from your_utils import main
    foo = "foo"
    def bar():
    print main().foo

    # output
    foo


    I have no idea what issues this raises, but that is not my concern here -
    I'm just seeing whether there is "another way to handle this". It looks like
    there is. Usual disclaimers apply: "Don't do that", "Use at your own risk",
    "Yada, Yada"

    I can't help you with "names bound in nested scopes are read-only, not
    rebindable". I tried to implement your enclosing() idea. I made a
    'namespace' class to use as follows:

    def foo():
    x = 1
    def bar():
    # context is the number of frames to go back
    outer = namespace(context=1)
    # outer keeps a reference to foo's frame
    outer.x = 2
    # so, I tried to re-bind the x in foo using something like
    # self.frame.f_locals['x'] = 2, but f_locals is not writable!
    # I made several attempts to circumvent this, but no success.
    bar()
    print x

    foo()

    # output
    1

    Oh well...


    "just seeing if it can be done-ly yours"
    Sean
    Sean Ross, Aug 27, 2003
    #2
    1. Advertising

  3. Gonçalo Rodrigues

    Ryan Lowe Guest

    [smarter_than_you]
    >How about this for a symmetrical, Pythonesque syntax:
    >
    >def sumdif(a, b):
    > sum = a + b
    > dif = a - b
    > return sum, dif
    >
    >#normal syntax:
    >s, d = sumdif(5,7)
    >
    >#additional syntax with named returns:
    >
    >(s=sum, d=dif)=sumdif(5, 7)
    >
    >#eqivalent to:
    >
    >(d=dif, s=sum)=sumdif(5, 7)
    >
    >#I call it 'symmetrical' because we can do this:
    >
    >(s=sum, d=dif)=sumdif(a=5, b=7)
    >
    >Not sure how easy to implement this would be, or how it affects the
    >scope of locals and such, but it looks nice on paper.



    not bad. heres an alternative:

    s, d = (sum, dif) from sumdif(5, 7)
    d, s = (dif, sum) from sumdif(5, 7)

    uses the from keyword. makes it look like a parallel assignment.
    Ryan Lowe, Aug 28, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Geoff Howland

    Re: python gripes survey

    Geoff Howland, Aug 24, 2003, in forum: Python
    Replies:
    7
    Views:
    343
    Colin J. Williams
    Aug 25, 2003
  2. Ryan Lowe

    Re: python gripes survey

    Ryan Lowe, Aug 24, 2003, in forum: Python
    Replies:
    1
    Views:
    316
    John Roth
    Aug 25, 2003
  3. Patrick Lioi

    Re: python gripes survey

    Patrick Lioi, Aug 25, 2003, in forum: Python
    Replies:
    3
    Views:
    311
    Jacek Generowicz
    Aug 25, 2003
  4. Dave Brueck

    Re: python gripes survey

    Dave Brueck, Aug 25, 2003, in forum: Python
    Replies:
    13
    Views:
    509
    Gonçalo Rodrigues
    Aug 28, 2003
  5. Replies:
    6
    Views:
    347
    Skip Montanaro
    Aug 25, 2003
Loading...

Share This Page