Message330880
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__'. |
|
Date |
User |
Action |
Args |
2018-12-02 11:27:56 | ksriram | set | recipients:
+ ksriram, pmpp, xtreak |
2018-12-02 11:27:56 | ksriram | set | messageid: <1543750076.57.0.788709270274.issue35375@psf.upfronthosting.co.za> |
2018-12-02 11:27:56 | ksriram | link | issue35375 messages |
2018-12-02 11:27:56 | ksriram | create | |
|