[Mesa-dev] [PATCH 22/26] python: Use open(), not file()
The latter is a constructor for file objects, but when actually opening a file, using the former is more idiomatic. In addition, file() is not a builtin any more in Python 3, so this makes the script compatible with both Python 2 and Python 3. Signed-off-by: Mathieu Bridon --- src/util/xmlpool/gen_xmlpool.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/xmlpool/gen_xmlpool.py b/src/util/xmlpool/gen_xmlpool.py index 886c1854f3..b0db183854 100644 --- a/src/util/xmlpool/gen_xmlpool.py +++ b/src/util/xmlpool/gen_xmlpool.py @@ -168,7 +168,7 @@ print("/***\ # Process the options template and generate options.h with all # translations. -template = file (template_header_path, "r") +template = open (template_header_path, "r") descMatches = [] for line in template: if len(descMatches) > 0: @@ -199,6 +199,8 @@ for line in template: else: print(line, end='') +template.close() + if len(descMatches) > 0: sys.stderr.write ("Warning: unterminated description at end of file.\n") expandMatches (descMatches, translations) -- 2.17.1 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 22/26] python: Use open(), not file()
Reviewed-by: Dylan Baker Quoting Mathieu Bridon (2018-07-05 06:17:53) > The latter is a constructor for file objects, but when actually opening > a file, using the former is more idiomatic. > > In addition, file() is not a builtin any more in Python 3, so this makes > the script compatible with both Python 2 and Python 3. > > Signed-off-by: Mathieu Bridon > --- > src/util/xmlpool/gen_xmlpool.py | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/src/util/xmlpool/gen_xmlpool.py b/src/util/xmlpool/gen_xmlpool.py > index 886c1854f3..b0db183854 100644 > --- a/src/util/xmlpool/gen_xmlpool.py > +++ b/src/util/xmlpool/gen_xmlpool.py > @@ -168,7 +168,7 @@ > print("/***\ > > # Process the options template and generate options.h with all > # translations. > -template = file (template_header_path, "r") > +template = open (template_header_path, "r") > descMatches = [] > for line in template: > if len(descMatches) > 0: > @@ -199,6 +199,8 @@ for line in template: > else: > print(line, end='') > > +template.close() > + > if len(descMatches) > 0: > sys.stderr.write ("Warning: unterminated description at end of file.\n") > expandMatches (descMatches, translations) > -- > 2.17.1 > > ___ > mesa-dev mailing list > mesa-dev@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/mesa-dev signature.asc Description: signature ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 22/26] python: Use open(), not file()
On Thursday, 2018-07-05 15:17:53 +0200, Mathieu Bridon wrote: > The latter is a constructor for file objects, but when actually opening > a file, using the former is more idiomatic. > > In addition, file() is not a builtin any more in Python 3, so this makes > the script compatible with both Python 2 and Python 3. > > Signed-off-by: Mathieu Bridon Reviewed-by: Eric Engestrom > --- > src/util/xmlpool/gen_xmlpool.py | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/src/util/xmlpool/gen_xmlpool.py b/src/util/xmlpool/gen_xmlpool.py > index 886c1854f3..b0db183854 100644 > --- a/src/util/xmlpool/gen_xmlpool.py > +++ b/src/util/xmlpool/gen_xmlpool.py > @@ -168,7 +168,7 @@ > print("/***\ > > # Process the options template and generate options.h with all > # translations. > -template = file (template_header_path, "r") > +template = open (template_header_path, "r") > descMatches = [] > for line in template: > if len(descMatches) > 0: > @@ -199,6 +199,8 @@ for line in template: > else: > print(line, end='') > > +template.close() > + > if len(descMatches) > 0: > sys.stderr.write ("Warning: unterminated description at end of file.\n") > expandMatches (descMatches, translations) > -- > 2.17.1 > > ___ > mesa-dev mailing list > mesa-dev@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/mesa-dev ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev