[U-Boot] [PATCH 6/9] patman: Use items() to iterate over dictionaries in python 3.x

Simon Glass sjg at chromium.org
Tue Sep 27 02:33:06 CEST 2016


Hi Paul,

On 26 September 2016 at 08:30, Paul Burton <paul.burton at imgtec.com> wrote:
> In python 3.x the iteritems() method has been removed from dictionaries,
> and the items() method does effectively the same thing. Convert the code
> to attempt to use iteritems() to be efficient on python 2.x, but use
> items() when that fails on python 3.x.
>
> Signed-off-by: Paul Burton <paul.burton at imgtec.com>
> ---
>
>  tools/patman/settings.py | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

I'd be happy with just using items(), since efficiency is not a
concern here, and I'm not keen on the try..except approach for
handling Python 2/3 differences.

>
> diff --git a/tools/patman/settings.py b/tools/patman/settings.py
> index 3caf379..8b10630 100644
> --- a/tools/patman/settings.py
> +++ b/tools/patman/settings.py
> @@ -94,7 +94,11 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser):
>          if not self.has_section(project_settings):
>              self.add_section(project_settings)
>          project_defaults = _default_settings.get(project_name, {})
> -        for setting_name, setting_value in project_defaults.iteritems():
> +        try:
> +            iterator = project_defaults.iteritems()
> +        except:
> +            iterator = project_defaults.items()
> +        for setting_name, setting_value in iterator:
>              self.set(project_settings, setting_name, setting_value)
>
>      def get(self, section, option, *args, **kwargs):
> --
> 2.10.0
>

Regards,
Simon


More information about the U-Boot mailing list