[sugar] [PATCH controlpanel] Use os.path.splitext() to remove file extensions, not str.strip().

Marco Pesenti Gritti mpgritti
Thu Jun 26 03:54:46 EDT 2008


r+

On Thu, Jun 26, 2008 at 5:41 AM, Chris Ball <cjb at laptop.org> wrote:
> Hi,
>
> Calling string.strip(".py") has two problems:  strip() looks for the
> chars you pass separately rather than consecutively, and it works at
> both the start and end of string:
>
>  >>> a = "power.py"
>  >>> a.strip(".py")
>  'ower'
>
> Thanks,
>
> - Chris.
>
> From: Chris Ball <cjb at laptop.org>
> Date: Wed, 25 Jun 2008 23:22:41 -0400
> Subject: [PATCH] Use os.path.splitext() to remove file extensions, not str.strip().
>
> ---
>  src/controlpanel/gui.py |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/controlpanel/gui.py b/src/controlpanel/gui.py
> index b07687f..a1e8876 100644
> --- a/src/controlpanel/gui.py
> +++ b/src/controlpanel/gui.py
> @@ -197,7 +197,7 @@ class ControlPanel(gtk.Window):
>
>         for name in names:
>             if name.endswith('.py') and name != '__init__.py':
> -                tmp = name.strip('.py')
> +                tmp = os.path.splitext(name)[0]
>                 mod = __import__('.'.join(subpath) + '.' + tmp, globals(),
>                                  locals(), [tmp])
>                 view_class_str = getattr(mod, 'CLASS', None)
> @@ -224,7 +224,7 @@ class ControlPanel(gtk.Window):
>
>         for name in names:
>             if name.endswith('.py') and name != '__init__.py':
> -                tmp = name.strip('.py')
> +                tmp = os.path.splitext(name)[0]
>                 if tmp in options:
>                     mod = __import__('.'.join(subpath) + '.' + tmp,
>                                      globals(), locals(), [tmp])
> --
> 1.5.4.3
> _______________________________________________
> Sugar mailing list
> Sugar at lists.laptop.org
> http://lists.laptop.org/listinfo/sugar
>



More information about the Sugar-devel mailing list