On Lists and Iterables
Xen
list at xenhideout.nl
Sun Dec 17 10:23:27 UTC 2017
Neal McBurnett schreef op 16-12-2017 18:16:
> For example here I port your one-line Python 2 script that uses zip.
>
> $ cat porting_example.py
> print zip(["a","b"], ["c","d"])
>
> $ python porting_example.py
> [('a', 'c'), ('b', 'd')]
>
> $ 2to3 porting_example.py > porting_example.patch
>
> $ cat porting_example.patch
> --- porting_example.py (original)
> +++ porting_example.py (refactored)
> @@ -1 +1 @@
> -print zip(["a","b"], ["c","d"])
> +print(list(zip(["a","b"], ["c","d"])))
>
> $ patch -b < porting_example.patch # -b saves original as
> porting_example.py.orig
>
> $ cat porting_example.py
> print(list(zip(["a","b"], ["c","d"])))
>
> $ python3 porting_example.py
> [('a', 'c'), ('b', 'd')]
Well that's sweet, but I hope you realize how much more ugly that line
of code has become.
My topic is that none of you, or almost none of you, opposes this, and
then goes on to say that they "have no choice" but to "follow along with
upstream".
That is a basic lie and that's all that is and that's all I wanted to
say.
It does mean my 30 minutes of porting just went down to 5 ;-). Or well,
it would still be 30, but I would have to check everything out after the
fact.
Here, I will do it for you, since you go to this effort anyway.
In my one file the only changes are these:
+ for vg in list(self.vgs.values()):
Verbosity has gone up in all of the 5 instances of this, but strangely,
it isn't required in 3 of them, because they are for loops.
In the other file likewise. Though I am not sure my data object will
work.
And it works! Or almost, I need to change to an integer division:
keys = Gdk.Keymap.get_entries_for_keyval(Gdk.Keymap.get_default(),
keyvals[ (direction + 1) / 2 ])
TypeError: list indices must be integers or slices, not float
And works perfectly now :p.
The point is that I don't like this "language", I do not want this
"language" and I would probably sooner switch to Ruby than have to write
it in this language.
This is a small file, but all of the changes resulted in increased
verbosity, while gaining zero benefits; how is this to my benefit?
Performance? Don't make me laugh.
More information about the Ubuntu-devel-discuss
mailing list