Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: python gripes survey

Reply
Thread Tools

Re: python gripes survey

 
 
Gonšalo Rodrigues
Guest
Posts: n/a
 
      08-27-2003
On Sat, 23 Aug 2003 15:39:27 GMT, "Ryan Lowe" <(E-Mail Removed)>
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
 
Reply With Quote
 
 
 
 
Sean Ross
Guest
Posts: n/a
 
      08-27-2003
"Gonšalo Rodrigues" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
[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


 
Reply With Quote
 
 
 
 
Ryan Lowe
Guest
Posts: n/a
 
      08-28-2003

[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.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: python gripes survey Dave Brueck Python 13 08-28-2003 02:15 PM
RE: python gripes survey sismex01@hebmex.com Python 6 08-25-2003 09:01 PM
Re: python gripes survey Geoff Howland Python 7 08-25-2003 02:22 PM
Re: python gripes survey Patrick Lioi Python 3 08-25-2003 11:39 AM
Re: python gripes survey Ryan Lowe Python 1 08-25-2003 12:31 AM



Advertisments