Python question

José Matos jaomatos at gmail.com
Thu Dec 29 11:07:18 UTC 2022


On Thu, 2022-12-29 at 10:39 +0100, Jürgen Spitzmüller wrote:
> makeupdatetests (runtests.py, for that matter) currently outputs
> rather
> unpleasant messages, since it just prints stderr.read() in encoded
> form.
> 
> The following change works for me, but is this the right thing to do?
> 
> diff --git a/src/tex2lyx/test/runtests.py
> b/src/tex2lyx/test/runtests.py
> index 103c74e307..4c5f969f34 100755
> --- a/src/tex2lyx/test/runtests.py
> +++ b/src/tex2lyx/test/runtests.py
> @@ -109,7 +109,7 @@ def main(argv):
>          err = proc.returncode
>          errorstring = proc.stderr.read()
>          if not errorstring is None:
> -            print(errorstring)
> +            print(errorstring.decode(sys.getfilesystemencoding()))
>          if err != 0:
>              errors.append(f)
> 
> 
> Thanks,
> -- 
> Jürgen

That seems a reasonable thing to do, and it works for python 2 and 3.


Incidentally I had a hard time (it took me a couple of seconds) to read
the test above, I suggest to change it to

if errorstring is not None:
...

changing the order of the *not* operator keeps the test and it becomes
a lot easier to read. It is also a lot more idiomatic than the current
version

I suspect that in this case an even simpler version would be:

if errorstring:
...

The difference from the above is that we would not print the empty
string... not that anyone would notice the difference. :-)

If a tree falls in a forest and no one is listening does it make a
sound? :-D

-- 
José Abílio


More information about the lyx-devel mailing list