A strange and annoying restriction, possibly a bug. A glance by amore experienced would be nice.

Discussion in 'Python' started by =?ISO-8859-1?Q?Elmo_M=E4ntynen?=, Jun 25, 2005.

  1. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    This is the case:

    >>> n=(100,) tuple(*n)


    Traceback (most recent call last):
    File "<pyshell#31>", line 1, in -toplevel-
    tuple(*n)
    TypeError: iteration over non-sequence

    To be sure I searched for ways to check if something is a sequence:

    >>> n.__iter__().next()

    100
    >>> n.__getitem__(0)

    100
    >>> iter(n).next()

    100

    So as you see, as far as I can see, I gave a sequence, but the
    Traceback says the opposite.
    To me it seems like a bug, but I haven't filed any bugs before, so a
    little help wouldn't be bad. I haven't checked if there is bug for
    this, but I don't consider me finding a bug as obvious as this very
    propable and something like this not to be fixed a long time ago.

    I tried this with python 2.3 and 2.4.

    If possible, could you send any anwsers to my own address also. Thanks
    in advance.
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.1 (GNU/Linux)
    Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

    iD8DBQFCvdUActNFyQJObrsRAha+AJ9oEyL7sufkXCcsQxuMDvyxNqvGGACglBrF
    le8HmOgXAyRqAY3DASArjM4=
    =F9NR
    -----END PGP SIGNATURE-----
    =?ISO-8859-1?Q?Elmo_M=E4ntynen?=, Jun 25, 2005
    #1
    1. Advertising

  2. =?ISO-8859-1?Q?Elmo_M=E4ntynen?=

    D H Guest

    Re: A strange and annoying restriction, possibly a bug. A glanceby a more experienced would be nice.

    Elmo Mäntynen wrote:
    > -----BEGIN PGP SIGNED MESSAGE-----
    > Hash: SHA1
    >
    > This is the case:
    >
    >
    >>>>n=(100,) tuple(*n)

    >
    >
    > Traceback (most recent call last):
    > File "<pyshell#31>", line 1, in -toplevel-
    > tuple(*n)
    > TypeError: iteration over non-sequence


    The star (*n) means you are essentially calling tuple(100). And 100
    alone isn't a sequence. The star explodes or expands the sequence, like
    in this example:

    def doit(x, y, z):
    print x, y, z

    vals = (1,2,3)

    doit(*vals) #see the star symbol
    D H, Jun 25, 2005
    #2
    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. Pavils Jurjans
    Replies:
    0
    Views:
    375
    Pavils Jurjans
    Apr 1, 2004
  2. Dan Perl

    would be nice: import from archive

    Dan Perl, Aug 27, 2004, in forum: Python
    Replies:
    43
    Views:
    998
    Steve Christensen
    Sep 1, 2004
  3. Thomas G. Marshall
    Replies:
    2
    Views:
    828
    Thomas G. Marshall
    Oct 16, 2006
  4. Greg Curie

    First glance at Design Patterns

    Greg Curie, Jan 20, 2007, in forum: C Programming
    Replies:
    1
    Views:
    406
    Nick Keighley
    Jan 22, 2007
  5. nguillot
    Replies:
    0
    Views:
    244
    nguillot
    Jan 17, 2011
Loading...

Share This Page