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.

classification
Title: Edit with IDLE 3.6 don´t work if Name of File "code.py"
Type: behavior Stage: resolved
Components: IDLE Versions: Python 3.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: IDLE: Remove '', user_dir, and idlelib from sys.path when added
View: 25488
Assigned To: terry.reedy Nosy List: steve.dower, terry.reedy, wueste87
Priority: normal Keywords:

Created on 2017-01-31 09:03 by wueste87, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg286518 - (view) Author: Christian Wüste (wueste87) Date: 2017-01-31 09:03
As soon as I specify a file "code.py", it can not be opened via the right click > Edit with IDLE 3.6 (64-Bit).
The content of the file is completely irrelevant.
All other Python files located in the same folder as "code.py" can not be opened.
If I rename the file in for example coder.py everything works.
Previously, Python version 3.5.3 was installed.
It is also possible that it is attached to my system.
msg286883 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2017-02-03 18:49
I assume this is because Idle is doing "import code" somewhere and picking up your file instead of the real one.

Renaming the file to not conflict with the standard library is an immediate workaround, but perhaps Idle should do some sys.path protection around wherever it's importing that module.
msg286893 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-02-03 21:50
Steve is correct.  lib/code.py is used for IDLE's Shell.

One should generally avoid naming files the same as stdlib files.  To do so, one can either look in the module index of the docs or try 'import somename'.

When Python starts, it imports the modules it uses *before* it adds '' or <userdir> to the front of sys.path.  Applications that both import modules and run user code need to at least temporarily remove the addition to do imports.  Having IDLE fix sys.path is #25488.

Duplicate names can also sabotage user code.  More than one person has written, for instance, a random.py, forgotten about it, and later written a mystuff.py in the same directory.  If mystuff has 'import random' with the intent to use the stdlib module, mystuff usually fails, often mysteriously.

When IDLE fails, make sure you run it from a console with 'python -m idlelib' (python3 on some systems, idlelib.idle on 2.7).  There will usually be an error message, which may or may not help.
History
Date User Action Args
2022-04-11 14:58:42adminsetgithub: 73581
2017-02-03 21:50:05terry.reedysetstatus: open -> closed
superseder: IDLE: Remove '', user_dir, and idlelib from sys.path when added
messages: + msg286893

resolution: duplicate
stage: resolved
2017-02-03 18:49:30steve.dowersetnosy: + steve.dower
messages: + msg286883
2017-01-31 09:03:23wueste87create