Seite 1 von 1

Mein Python kennt die next()-Methode nicht mehr

Verfasst: Samstag 2. Mai 2009, 17:03
von Thuught
Hallo zusammen,
wenn ich bei mir die next() Methode auf einen Containertyp anwende, kommt
bei mir der Fehler:
AttributeError: 'list' object has no attribute 'next'

Das kann ich mir nicht erklären, weil ich seit eh und je diese Methode
benutzt habe. Wie kann ich das Problem beheben?

edit: die for-Schleife funktioniert wie gehabt

Verfasst: Samstag 2. Mai 2009, 17:10
von BlackJack
@Thuught: Das ist nicht zufällig Python 3.x? Da gibt's keine `next()`-Methode mehr auf Iteratoren, sondern eine `next()`-Funktion.

Verfasst: Samstag 2. Mai 2009, 17:17
von Thuught
Daran hab ich auch schon gedacht, aber es scheint Python 2.6.2 zu sein
[Vorgestern von der Webseite geladen]

hier mal das komplette shell:

Code: Alles auswählen

Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

    ****************************************************************
    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer's internal loopback
    interface.  This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
    ****************************************************************
    
IDLE 2.6.2      
>>> Zahlen=[1,2,3]
>>> Zahl=Zahlen.next()

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    Zahl=Zahlen.next()
AttributeError: 'list' object has no attribute 'next'
>>> 

Verfasst: Samstag 2. Mai 2009, 17:24
von hendrikS
Also ich finde, Du solltest Statements wie "es scheint" nicht benutzen, wenn es doch einfach klarzustellen ist.

>python -V

Edit: OK. Info schon nachgeliefert.

Verfasst: Samstag 2. Mai 2009, 17:30
von b.esser-wisser
list() -objecte haben auch keine next()-Methode - Aber du kannst ja einen Iterator benutzen:

Code: Alles auswählen

In [3]: l=[1,2,3,4,7]

In [4]: it = iter(l)

In [5]: it.next()
Out[5]: 1

In [6]: it.next()
Out[6]: 2

In [7]: it.next()
Out[7]: 3
(Python 2.5.4, WinXP)
rtfm, Jörg