0

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

1 Answer 1

1

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))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.