Seite 1 von 1
AttributeError: 'module' object has no attribute 'thread'
Verfasst: Donnerstag 7. Juni 2007, 10:03
von eztam
Hallo,
wenn ich folgenden Code ausführe, dann bekomme ich immer eine Fehlermeldung:
Code: Alles auswählen
#!/usr/bin/python
import threading
class MyThread ( threading.thread ):
def run ( self ):
print 'You called my start method, yeah.'
print 'Were you expecting something amazing?'
MyThread().start()
#./threading.py
Traceback (most recent call last):
File "./threading.py", line 2, in <module>
import threading
File "/Users/matze/python/threading.py", line 4, in <module>
class MyThread ( threading.thread ):
AttributeError: 'module' object has no attribute 'thread'
Diese Fehlermeldung bekomme ich scheinbar bei allen Programmen, die threading benutzen.
Kann mir jemand weiterhelfen?
Verfasst: Donnerstag 7. Juni 2007, 10:43
von george
Hey eztam,
Probiere mal "threading.thread" mit "threading.Thread" zu ersetzen.
gruss george
Verfasst: Donnerstag 7. Juni 2007, 10:47
von eztam
Mit "threading.Thread" funktioniert es leider auch nicht

Verfasst: Donnerstag 7. Juni 2007, 10:50
von george
Hey,
Code: Alles auswählen
#!/usr/bin/python
import threading
class MyThread ( threading.Thread ):
def run ( self ):
print 'You called my start method, yeah.'
print 'Were you expecting something amazing?'
MyThread().start()
Ausgabe
Code: Alles auswählen
>>> You called my start method, yeah.
Were you expecting something amazing?
Bei mir läufts sauber. Schau mal, ob du noch einen Syntaxfehler hast
gruss george
Verfasst: Donnerstag 7. Juni 2007, 10:59
von eztam
Ich habe nochmal alles überprüft. Aber es geht immer noch nicht.
Ich habe es mit python2.3 und python2.5 ausprobiert (unter Mac OS X).
Bei beiden kam der gleiche Fehler.
Kann es sein, dass das Modul "threading" irgendwie falsch installiert ist?
Verfasst: Donnerstag 7. Juni 2007, 11:34
von Masaru
Mac OS ... hmm ... dachte immer, "threading" würde auf dem Modul
thread aufbauen.
Und "thread" nach zur Folge, funktiert dies nur unter:
- Windows
- Linux
- SGI IRIX
- Solaris 2.x
- sowie Systemen, die eine bestimmte Implementierung von 'threads' integriert haben
Ich kenne mich mit Mac so leider gar nicht aus, aber vielleicht liegt es dadran, dass eben thread->threading auf dem Betriebssystem vom Python Interpreter gar nicht angeboten wird.
Re: AttributeError: 'module' object has no attribute 'thread
Verfasst: Donnerstag 7. Juni 2007, 11:38
von gerold
eztam hat geschrieben:Code: Alles auswählen
File "/Users/matze/python/threading.py", line 4, in <module>
class MyThread ( threading.thread ):
AttributeError: 'module' object has no attribute 'thread'
Hallo eztam!
Willkommen im Python-Forum!
Nenne dein Programm **nicht** "threading.py". Damit überschreibst du das "threading"-Modul von Python.
mfg
Gerold

Verfasst: Donnerstag 7. Juni 2007, 11:59
von Masaru
*an den Kopf fass* ... aye, stimmt ja .. manchmal sind es die einfachsten Dinge, daran könnte es wirklich liegen.
Verfasst: Donnerstag 7. Juni 2007, 12:02
von eztam
Das mit dem Dateinamen hat leider auch nichts gebracht.
Vermutlich wird threading für python unter OS X tatsächlich nicht angeboten.
Nicht einmal der folgende Code funktioniert:
Fehlermeldung:
Code: Alles auswählen
Traceback (most recent call last):
File "./t.py", line 3, in ?
import threading
File "/Users/matze/python/threading.py", line 5, in ?
class MyThread ( threading.Thread ):
AttributeError: 'module' object has no attribute 'Thread'
Verfasst: Donnerstag 7. Juni 2007, 12:05
von eztam
Oh wie dumm von mir. Ich habe die Datei nur unter einem anderen Namen gespeichert und die alte threading.py nicht gelöscht.
Jetzt Geht es !
Danke für Eure Hilfe