I run Inkscape (an Open Source vector drawing application) on OSX (Snow
leopard) installed via .dmg pkg. The application ships with a collection of
Python extensions, one of which Measure Path, failed to execute.
I could not find a reference for this issue in the Inkscape archives, and I
tried and worked with other workarounds including a javascript (outside
Inkscape) to find the length of Bézier paths, but eventually I raised the issue
and contacted launchpad/inkscape (question #239599) but to limited avail. After
much continued searching I then found this Bug #803791 report which describes
(as an aside) the exact same issue together with a solution.
I know next to nothing about Python and I shall be glad if any Python guru can
make clear (in layman's terms where possible) what the problem is/was and how
the fix works.
I remembered an alternative posting that I had read, which reported that Python
dislikes empty delimiters. So I took a slightly different approach to the one
mentioned in the above bug report. Instead of removing line 35 from the Measure
Path script I replaced the empty delimiters with the Python constant None. To
my great delight as well as my own amazement the 'fix' worked.
The problem may or may not be limited to OSX.
On trying to run the script (before the fix) I had the following traceback
message:
File "measure.py", line 35, in <module>
locale.setlocale(locale.LC_ALL, '')
File
"/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/locale.py",
line 494, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
If I booted from the Unix file I received the following feedback:
Setting Language: .UTF-8
(process:82224): Gtk-WARNING **: Locale not supported by C library.
Using the
fallback 'C' locale.
Line 35 (above) shows the empty delimiter. The fix that I applied was to
replace line 35 in the Measure.py script with:
locale.setlocale(locale.LC_ALL, None). The Measure Path script then executes
correctly. No other action is/was required.
I note also the Python 2 library entry for Built-in Constants as:
None
The sole value of types.NoneType. None is frequently used to represent the
absence of a value, as when default arguments are not passed to a function.
Changed in version 2.4: Assignments to None are illegal and raise a SyntaxError.
And under standard type hierarchy as:
None
This type has a single value. There is a single object with this value. This
object is accessed through the built-in name None. It is used to signify the
absence of a value in many situations, e.g., it is returned from functions that
don’t explicitly return anything. Its truth value is false.
I have run the various scripts in a Python Validator, and line 35 (both
versions) pass unremarked, although there are a few other code errors and
warnings and many pep8 warnings.
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)
Many, many thanks for your interest and considering matters.
-A
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor