Re: [Tutor] When is and isn't "__file__" set?

2018-01-12 Thread Steven D'Aprano
On Fri, Jan 12, 2018 at 05:22:05PM +, Albert-Jan Roskam wrote: > > On Jan 11, 2018 03:47, Steven D'Aprano wrote: [...] > > Modules which are loaded from a .py or .pyc file on disk should always > > have __file__ set. If they don't, that's a bug in the interpreter. > > >

Re: [Tutor] When is and isn't "__file__" set?

2018-01-12 Thread eryk sun
On Fri, Jan 12, 2018 at 5:22 PM, Albert-Jan Roskam wrote: > On Jan 11, 2018 03:47, Steven D'Aprano wrote: >> >> Modules which are loaded from a .dll or .so binary file also should have >> __file__ set. > > And .pyd? I would hope so A .pyd is a

Re: [Tutor] When is and isn't "__file__" set?

2018-01-12 Thread Albert-Jan Roskam
On Jan 11, 2018 03:47, Steven D'Aprano wrote: > > On Wed, Jan 10, 2018 at 08:02:24PM -0600, boB Stepp wrote: > > > I am still puzzling over things from the thread, "Why does > > os.path.realpath('test_main.py') give different results for unittest > > than for testing

Re: [Tutor] When is and isn't "__file__" set?

2018-01-10 Thread Steven D'Aprano
On Wed, Jan 10, 2018 at 08:02:24PM -0600, boB Stepp wrote: > I am still puzzling over things from the thread, "Why does > os.path.realpath('test_main.py') give different results for unittest > than for testing statement in interpreter?" The basic question I am > trying to answer is how to

[Tutor] When is and isn't "__file__" set?

2018-01-10 Thread boB Stepp
I am actually interested in the answer to this question for Python versions 2.4, 2.6 and 3.x. At https://docs.python.org/3/reference/import.html?highlight=__file__#__file__ it says: __file__ is optional. If set, this attribute’s value must be a string. The import system may opt to leave