classification
Title: mimetypes.guess_extension returns different values when init() is called several times
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: mimetypes.guess_extension result changes after mimetypes.init()
View: 4963
Assigned To: Nosy List: egamby, r.david.murray
Priority: normal Keywords:

Created on 2015-05-20 12:26 by egamby, last changed 2015-05-20 13:37 by r.david.murray. This issue is now closed.

Messages (2)
msg243655 - (view) Author: Emmanuel Gamby (egamby) Date: 2015-05-20 12:26
Hi,

Following the principle of least astonishment, I would expect the function to return the same value.

Python 2.7.3 (default, Mar 13 2014, 11:03:55) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mimetypes
>>> mimetypes.init()
>>> mimetypes.guess_extension('text/plain') 
'.ksh'
>>> mimetypes.init()
>>> mimetypes.guess_extension('text/plain') 
'.asc'
>>> mimetypes.init()
>>> mimetypes.guess_extension('text/plain') 
'.txt'

It seems that each call overrides the global dictionnary, which changes the iteration order of the next call.

Best Regards,
Emmanuel
msg243662 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-05-20 13:37
This is a duplicate of issue 4963.
History
Date User Action Args
2015-05-20 13:37:29r.david.murraysetstatus: open -> closed

superseder: mimetypes.guess_extension result changes after mimetypes.init()

nosy: + r.david.murray
messages: + msg243662
resolution: duplicate
stage: resolved
2015-05-20 12:28:52egambysettype: behavior
2015-05-20 12:26:21egambycreate