Question

I have the code below and I would like to feel the parameters of the function map at runtime. It should be like

#devices = map(InputDevice, ('/dev/input/event15','/dev/input/event16'))

But when I try to do it at runtime, it does not work. Here is my attempt:

readers = ""
devices = map(InputDevice, list_devices())
for dev in devices:
   if "深" in dev.name or "Barcode" in dev.name:
      if readers == "":
         readers = "'" + dev.fn + "'"
      else:
         readers = readers + ", '" + dev.fn + "'"

devices = map(InputDevice, (readers))

Where readers shows exactly '/dev/input/event15','/dev/input/event16', but this string does not work as parameter. I guess it does not work because of the comma. Does anyone know how can I do it?

This function is part of the evdev.

Thanks since now! Best regards, Erik

Was it helpful?

Solution

It looks to me like you want readers to be a non-string iterable. Maybe try:

devices = map(InputDevice, readers.split(','))

This will split readers into a list, rather than keeping it as a string.

This still isn't particularly clean code. Better would be to build a list in the first place:

readers = []
devices = map(InputDevice, list_devices())
for dev in devices:
   if "深" in dev.name or "Barcode" in dev.name:
      readers.append(dev.fn)

devices = map(InputDevice, (readers))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top