Article View: pl.comp.lang.python
Article #13641Re: NameError: name '__file__' is not defined
From: Tupteq
Date: Wed, 25 Jan 2006 11:54
Date: Wed, 25 Jan 2006 11:54
15 lines
1500 bytes
1500 bytes
Mateusz Łoskot wrote: > Nie rozumiem albo coś na przestrzeni wersji Pythona mi umknęło. > Dlaczego Python 2.3 protestuje gdy w skrypcie używam __file__? > > Czy to coś niepoprawnego: > path = os.path.dirname(__file__) Hmm, w dokumentacji stoi, że __file__ to atrybut modułu, tak więc pewnie używa się go moduł.__file__ Uruchamiany plik nie jest modułem, ale jeśli ten sam plik wczytasz z innego używając import, to się nim stanie i możesz w nim użyć __file__ bez podania obiektu (takie są wnioski z mojego 3 minutowego śledztwa). -- Pozdro... Tupteq
Technical Details
Message-ID:
<dr7p4d$bst$1@nemesis.news.tpi.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!mat.uni.torun.pl!news.man.torun.pl!newsfeed.pionier.net.pl!news.nask.pl!news.nask.org.pl!newsfeed.tpinternet.pl!atlantis.news.tpi.pl!news.tpi.pl!not-for-mailReferences:
<dr7m8h$36t$2@inews.gazeta.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!mat.uni.torun.pl!news.man.torun.pl!newsfeed.pionier.net.pl!news.nask.pl!news.nask.org.pl!newsfeed.tpinternet.pl!atlantis.news.tpi.pl!news.tpi.pl!not-for-mail From: Tupteq <tupteqCIACH@CIACHtlen.pl> Newsgroups: pl.comp.lang.python Subject: Re: NameError: name '__file__' is not defined Date: Wed, 25 Jan 2006 12:54:30 +0100 Organization: tp.internet - http://www.tpi.pl/ Lines: 15 Message-ID: <dr7p4d$bst$1@nemesis.news.tpi.pl> References: <dr7m8h$36t$2@inews.gazeta.pl> NNTP-Posting-Host: usbmis.pl Mime-Version: 1.0 X-Trace: nemesis.news.tpi.pl 1138190286 12189 195.116.168.36 (25 Jan 2006 11:58:06 GMT) X-Complaints-To: usenet@tpi.pl NNTP-Posting-Date: Wed, 25 Jan 2006 11:58:06 +0000 (UTC) User-Agent: Thunderbird 1.5 (Windows/20051201) In-Reply-To: <dr7m8h$36t$2@inews.gazeta.pl> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit