classification
Title: idle filename extension
Type: enhancement Stage:
Components: IDLE Versions: Python 3.3
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ajaksu2, amaury.forgeotdarc, brian.curtin, geon, gpolo, serwy, taleinat, terry.reedy
Priority: normal Keywords: patch

Created on 2009-01-04 15:16 by geon, last changed 2011-12-14 18:49 by serwy.

Files
File name Uploaded Description Edit
defaultextension.patch amaury.forgeotdarc, 2009-05-13 17:00 review
fix_defaultextension.diff gpolo, 2009-08-01 20:45 review
issue4832.diff serwy, 2011-12-14 18:49 review
Messages (13)
msg79062 - (view) Author: Pavel Kosina (geon) Date: 2009-01-04 15:16
There should not be necessity to write filename *with extension* at the
saving dialog. It should be enough, at least on Windows, to put there
just "hello" and get "hello.py". It is really complication especially
for beginners. If they, as they are used to from another programs, put
there just "hello", it is saved without extension ".py" what have 2
result: they cannot see any icons at that file and they are not able to
run in, cause python.exe is bind with ".py".

Hoping its not duplicate I haven't found anything like this here.
msg86620 - (view) Author: Daniel Diniz (ajaksu2) Date: 2009-04-26 22:17
I get the .py automatically on Linux, is this an intended behavior
difference or should this issue be considered a bug instead?
msg87695 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-05-13 17:00
I think I found the relevant documentation:
http://wiki.tcl.tk/1842
"""
On Unix, when typing a filename without extension, the first extension
belonging to the currently selected filetype will be appended to the
filename. On Windows, this is not the case, but one can define a fixed
extension with the -defaultextension option. To get the same behaviour
on Unix, use -defaultextension {}.
"""

I tried to add "defaultextension=.py", (see attached patch) the problem
is that now it seems impossible to create a file without an extension...
msg87702 - (view) Author: Daniel Diniz (ajaksu2) Date: 2009-05-13 19:07
Amaury,
Your patch also forces '.py' to any saved file on Linux, but using
'defaultextension = ""' it works correctly here. Does if fix things on
Windows?
msg87703 - (view) Author: Pavel Kosina (geon) Date: 2009-05-13 19:46
Trying to patch the latest revision 72608 and it didnt work, here on winxp. 

C:\prg\Python30\Lib\idlelib>svn update
Restored 'IOBinding.py'
At revision 72608.

C:\prg\Python30\Lib\idlelib>patch IOBinding.py defaultextension.patch
--verbose
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|Index: Lib/idlelib/IOBinding.py
|===================================================================
|--- Lib/idlelib/IOBinding.py   (revision 72282)
|+++ Lib/idlelib/IOBinding.py   (working copy)
--------------------------
Patching file IOBinding.py using Plan A...
Hunk #1 succeeded at 480 (offset -45 lines).
Hmm...  Ignoring the trailing garbage.
done


If I do the patch by hand, it works. All files are saved with ext. .py.
When set 'defaultextension = ""', it is save well too, but then IDLE
crashed immediately.
msg91168 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2009-08-01 20:45
I'm attaching a very similar patch that I tested on Linux and Windows.
It just combines the default behaviour with the details required for
Windows, that is, the default extension is set to '.py' for Windows and
'' elsewhere (the default).
msg91260 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-08-04 17:47
With this new patch, is it possible to create a file without extension
on Windows?
msg91262 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2009-08-04 18:05
> With this new patch, is it possible to create a file without extension
> on Windows?

It is tricky but, answering your question, you could enter a name
ending with a period to save without an extension.

It seems this isn't going anywhere then. The default behaviour on
Linux is to get the .py already, so this patch changes nothing there.
On Windows no extension is set by default, and with this patch it is
always .py if no extension is specified.
msg110962 - (view) Author: Tal Einat (taleinat) (Python committer) Date: 2010-07-20 20:13
On Windows, I can't think of any common reason to want to save a file edited in IDLE without the .py extension. On the other hand, accidentally forgetting the .py extension is annoying, and users have come to expect a default extension being added by applications (e.g. MS Office).

Guilherme's patch (applied manually) works fine here on Windows7. I'm +1 for committing this if it has been tested to work as expected on Linux and OSX.

(minor nit-pick: could use sys.platform.startswith('win') instead of slicing)
msg110964 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-07-20 20:23
I would forget about slicing or using startswith. "win32" is the platform name for Python on Windows whether or not it's 64-bit (see PC/pyconfig.h), so I'd just check """sys.platform == 'win32'"""
msg110966 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2010-07-20 20:31
Sorry but this is just bikeshedding, whoever commits can make this change or if it had been committed without this "improvement" then anyone could adjust without needing a new issue.
msg130399 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-03-09 02:23
The behavior (for Windows) I expect and would like is that the default extension would be .py, .txt, or nothing, depending on the selection in the 'save as type' box in the SaveAS dialog. (.pyw, being rare, would have to be explicitly typed.) Of course, doubled extensions like .py.py should be avoided. I believe other apps on Windows do something like this, but I should check.

I have no idea how the other systems differ.
msg149466 - (view) Author: Roger Serwy (serwy) * Date: 2011-12-14 18:49
I was unable to produce the crash that Pavel described in msg87703.  

Just adding "defaultextension=''" solves this issue for Windows and still preserves the correct behavior on Linux. Amaury's quote of tcl/tk documentation in msg87695 mentions this as well.

I tested this on Linux with 2.7.1 and 3.2 and on Windows Vista using 2.7.1 and 3.2.2. 

Attached is a diff against 3.3a0.
History
Date User Action Args
2011-12-14 18:49:55serwysetfiles: + issue4832.diff
nosy: + serwy
messages: + msg149466

2011-12-10 03:52:09terry.reedylinkissue10364 superseder
2011-03-09 02:23:07terry.reedysetnosy: terry.reedy, amaury.forgeotdarc, taleinat, ajaksu2, gpolo, geon, brian.curtin
messages: + msg130399
2011-03-09 02:16:22terry.reedysetnosy: + terry.reedy

versions: + Python 3.3, - Python 3.1, Python 2.7
2010-07-20 20:31:43gpolosetmessages: + msg110966
2010-07-20 20:23:40brian.curtinsetnosy: + brian.curtin
messages: + msg110964
2010-07-20 20:13:29taleinatsetnosy: + taleinat
messages: + msg110962
2009-08-04 18:05:51gpolosetmessages: + msg91262
2009-08-04 17:47:49amaury.forgeotdarcsetmessages: + msg91260
2009-08-01 20:45:07gpolosetfiles: + fix_defaultextension.diff

messages: + msg91168
2009-05-13 19:46:43geonsetmessages: + msg87703
2009-05-13 19:07:02ajaksu2setmessages: + msg87702
2009-05-13 17:00:16amaury.forgeotdarcsetfiles: + defaultextension.patch

nosy: + amaury.forgeotdarc
messages: + msg87695

keywords: + patch
2009-04-26 22:17:11ajaksu2setpriority: normal
versions: - Python 2.6, Python 2.5, Python 3.0
nosy: + ajaksu2, gpolo

messages: + msg86620

type: behavior -> enhancement
2009-01-04 15:16:01geoncreate