This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ksriram
Recipients ksriram, pmpp, xtreak
Date 2018-12-02.11:27:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1543750076.57.0.788709270274.issue35375@psf.upfronthosting.co.za>
In-reply-to
Content
My contention is that this behaviour breaks the Principle of Least Astonishment.

In the particular example I gave, the user doesn't know (and can't be expected to know) the existence of a module called profile in the standard library. Here the user is not explicitly importing profile. The user can't be expected to know which submodules are imported by the modules they use. Hence they wouldn't expect another file sitting in the same directory to get imported when they are not explicitly importing it.

on 2018-12-02 10:35, pmpp said:
> you can avoid that with

> import sys,os
> sys.path.remove( os.getcwd() )

> at the start of your program. 

completely removing cwd from sys.path would disable the option of importing user modules.

Any method of fixing this would be backwards incompatible, and will break some (most likely badly written) code.

My hack solution was to have cwd in sys.path only if __name__ is '__main__'.
History
Date User Action Args
2018-12-02 11:27:56ksriramsetrecipients: + ksriram, pmpp, xtreak
2018-12-02 11:27:56ksriramsetmessageid: <1543750076.57.0.788709270274.issue35375@psf.upfronthosting.co.za>
2018-12-02 11:27:56ksriramlinkissue35375 messages
2018-12-02 11:27:56ksriramcreate