[Pywikipedia-l] [Pywikipedia-svn] SVN: [6653] trunk/pywikipedia/wikipedia.py

Nicolas Dumazet nicdumz at gmail.com
Wed Apr 22 02:45:35 UTC 2009


2009/4/22  <nicdumz at svn.wikimedia.org>:
> @@ -4145,6 +4145,14 @@
>         # search for family module in the 'families' subdirectory
>         sys.path.append(config.datafilepath('families'))
>         exec "import %s_family as myfamily" % fam
> +    except SyntaxError:
> +        if '-' in fam:
> +            # A python module cannot include an hyphen
> +            output(u"""\
> +A family name cannot include an hyphen (-). Please consider renaming your
> +'%s' family to '%s' or '%s' instead."""
> +                    % (fam, fam.replace('-', ''), fam.replace('-', '_')))
> +            sys.exit(1)
>     except ImportError:
>         if fatal:
>             output(u"""\


On the other hand using the builtin __import__ would allow us to load
families with hyphens:


     try:
         # search for family module in the 'families' subdirectory
         sys.path.append(config.datafilepath('families'))
-        exec "import %s_family as myfamily" % fam
+        myfamily = __import__('%s_family' % fam)
    except SyntaxError:
        if '-' in fam:
            # A python module cannot include an hyphen
            output(u"""\


__import__ is also cleaner than exec, obviously.

Should we allow family names with hyphens?

-- 
Nicolas Dumazet — NicDumZ [ nɪk.d̪ymz ]



More information about the Pywikipedia-l mailing list