Re: [libgpiod v2][PATCH v3 2/4] bindings: python: add examples

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Oct 17, 2022 at 07:24:40PM +0300, Andy Shevchenko wrote:
> On Mon, Oct 17, 2022 at 05:53:52PM +0200, Bartosz Golaszewski wrote:
> > On Mon, Oct 17, 2022 at 4:19 PM Andy Shevchenko
> > <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
> 
> ...
> 
> > How about this?
> > 
> >     lvs = list(
> >         map(
> >             lambda val: [val[0], Value(int(val[1]))],
> >             [arg.split("=") for arg in sys.argv[2:]],
> >         )
> >     )
> 
> Yeah, this looks ugly... So initial variant with two lines looks to me
> like this:
> 
>   lvs = [arg.split("=") for arg in sys.argv[2:]] # btw, needs handling 2 exceptions
>   values = dict((x, Value(int(y))) for (x,y) in lvs) # needs to handle an exception
>   # Perhaps you need ordered dict?
>   lines = values.keys()
> 

Indeed, an OrderedDict keys would provide the lines in argv order, so values.keys()
could be used in place of lines.

And if you use a parser function then it can deal with the parsing exceptions.

   values = OrderedDict([ parse(arg) for args in sys.argv[2:] ])

Cheers,
Kent.

> >     lines = [x[0] for x in lvs]
> >     values = dict(lvs)
> 
> > It's so much less readable but at least it's pythonic, look at those
> > lambdas and comprehension lists and even a map! :)
> 
> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
> 



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux