Seite 1 von 1
Wie kann ich den Ort des importierten Moduls einfach finden?
Verfasst: Mittwoch 5. Oktober 2005, 12:50
von Gast
Hallo Zusammen,
ich möchte gerne das absolute Verzeichnis von bestimmt importieren Modulen haben. Das muss gehen!
Z.B. help(einmodul) zeigt das Verzeichnis, wo das Modul namens einmodul liegt. aber wie kann man einfach den String bekommen, besser nicht durch help(einmodul)
Danke im voraus!
MfG
Re: Wie kann ich den Ort des importierten Moduls einfach fin
Verfasst: Mittwoch 5. Oktober 2005, 13:21
von Francesco
Anonymous hat geschrieben:Hallo Zusammen,
ich möchte gerne das absolute Verzeichnis von bestimmt importieren Modulen haben. Das muss gehen!
Z.B. help(einmodul) zeigt das Verzeichnis, wo das Modul namens einmodul liegt. aber wie kann man einfach den String bekommen, besser nicht durch help(einmodul)
Danke im voraus!
MfG
Habe jetzt ein bisschen rumprobiert
>>> import os
>>> os
<module 'os' from 'C:\Python24\lib\os.pyc'>
das gleiche ohne importieren:
>>> inspect.getmodule(os)
<module 'os' from 'C:\Python24\lib\os.pyc'>
muesste man nurmehr path+filename heraussuchen.
Verfasst: Mittwoch 5. Oktober 2005, 13:25
von Gast
hi Francesco,
danke dir.
Zusammenfassung:
import inspect
import os
inspect(os)
====><module 'os' from 'C:\Programme\Python241\lib\os.pyc'>
MfG
Verfasst: Mittwoch 5. Oktober 2005, 13:45
von Francesco
Anonymous hat geschrieben:hi Francesco,
danke dir.
Zusammenfassung:
import inspect
import os
inspect(os)
====><module 'os' from 'C:\Programme\Python241\lib\os.pyc'>
MfG
Bitte,
muesste noch einfacher gehen:
import re
inspect.getfile(re)
'C:\\Python24\\lib\\re.pyc'
aber:
da muesste man die exception abfangen, da sys ein internes
module ist:
inspect.getfile(sys)
Traceback (most recent call last):
File "<input>", line 1, in ?
File "C:\Python24\lib\inspect.py", line 312, in getfile
raise TypeError('arg is a built-in module')
TypeError: arg is a built-in module
Verfasst: Mittwoch 5. Oktober 2005, 14:20
von jens
Verfasst: Mittwoch 5. Oktober 2005, 14:31
von Francesco
jens hat geschrieben:Warum nicht einfach so:
Ui, ja
Warum einfach, wenn es auch kompliziert geht?
