python gripes survey

Ryan Lowe ryanlowe0 at msn.com
Tue Aug 26 00:37:48 CEST 2003


"Josh" <joshway_without_spam at myway.com> wrote in message
news:bidr0d$p9g$1 at fred.mathworks.com...
> sismex01 at hebmex.com wrote:
> > [Afanasiy]
> >>  Returning a struct in C is
> >>  easier to deal with than returning a near-mystery tuple in Python.
> >>
>
> > You *really* *must* *be* *kidding*.
>
> > -gustavo
>
> It's really pretty easy:
>
>   typedef struct {
>     int x;
>     int y;
>   } T;
>
>   T f() {
>     T t = { 1, 2 };
>     return t;
>   }
>
>   int main() {
>     T t = f();
>     return 0;
>   }
>
> And arguably easier to deal with than Python in that the fields are
> named.  I think that's all Afanasiy was getting at.

is it that hard to send a dictionary? i dont know how that compares to a
tuple in terms of speed/memory usage, but its not a whole lot harder to use
than a tuple.

def fruit() :
    return {'apple' : 'A', 'orange' : 'B'}

>>> food = fruit()
>>> food['apple']
... 'A'


anyone have any more things they dont like or, better yet, feel are missing
from python? ive got a pretty big list going. ill post a link when i get it
uploaded.


"Andrew Dalke" <adalke at mindspring.com> wrote in message
news:P372b.1862$Jh2.521 at newsread4.news.pas.earthlink.net
[...]
> > >   code blocks (like Smalltalk)
> >
> > is this what it sounds like? do you name a block of code and call it
like
> an
> > inline function with no parameters?
>
> Consider the following Ruby code
>
>  [ 1, 3, 5 ].each { |i| puts i }
>
> The
>   |i| puts i
>  is an *unnamed* code block which does take parameters.
> The [] is a container, and [].each sends the code block to
> each of the elements in the container.  See
>   http://www.rubycentral.com/book/tut_containers.html
>

i looked into code blocks. they still seem a bit confusing, but from what i
learned i dont see any advantage over python's generators. for example take
these two versions of code that produces the fibonacci series:

RUBY
def fibUpTo(max)
  a, b = 1, 1        # parallel assignment
  while a <= max
    yield i1
    a, b = b, a+b
  end
end

fibUpTo(1000) { |f| print f, " " }

PYTHON
def fibUpTo(max) :
    a, b = 1, 1
    while a <= max :
        yield a
        a, b = b, a+b

>>> for f in fibUpTo(1000) :
            print f,

i think the python version is much more intuitive. are there more
complicated uses of code blocks that would make them more powerful than
python's generators? i think i read a PEP or something about adding the
ability to pass info into a generator. if this doesnt exist yet or ever,
that would probably be a good difference, but i cant think of a good example
to illustrate this...








More information about the Python-list mailing list