[Tutor] empty delimiters, and None
spir
denis.spir at gmail.com
Sat Nov 30 10:28:19 CET 2013
On 11/29/2013 02:19 PM, ugajin at talktalk.net wrote:
> I have also looked at locale.py Line 494 of which is the last line of a def (def function?) I include this below, hopefully this may save you searching for locale.py (Pyhon 2.6) should you need it and wish to answer the above questions, it may help.
>
> def setlocale(category, locale=None):
>
> """ Set the locale for the given category. The locale can be
> a string, a locale tuple (language code, encoding), or None.
>
> Locale tuples are converted to strings the locale aliasing
> engine. Locale strings are passed directly to the C lib.
>
> category may be given as one of the LC_* values.
>
> """
> if locale and type(locale) is not type(""):
> # convert to string
> locale = normalize(_build_localename(locale))
> return _setlocale(category, locale)
As a side-note, in addition to what other have said, the headline of the
function def
def setlocale(category, locale=None)
says that None is the default (standard) value for the parameter 'locale'. This
means that, if ever you provide no value for it when calling setlocale, then the
value None is used in standard. So, you could as well call it like:
locale.setlocale(locale.LC_ALL) # no value at all for param 'locale'
instead of you correction
locale.setlocale(locale.LC_ALL, None)
for the initial version
locale.setlocale(locale.LC_ALL, '')
This is actually good coding practice (in all language which have default values).
Denis
More information about the Tutor
mailing list