Skip to content

auto vs. ev3 #196

Closed
Closed

Description

@ndward

I see many programs that include either or both of these lines:
import ev3dev.ev3 as ev3
from ev3dev.auto import *

When is each one needed?

Activity

  1. ddemidov commented on Sep 4, 2016

    @ddemidov
    Member

    If you have an EV3 brick, those two are interchangeable. ev3dev, however, supports a couple of other systems (like raspberry pi based brick pi). Those may have slightly different hardware configuration, and each of the supported systems have a dedicated submodule in ev3dev (now there are just ev3 and brickpi). auto, when imported, just tries to detect your system and imports the correct module. It mostly is needed to keep the scripts as generic as possible.

  2. ndward commented on Sep 4, 2016

    @ndward
    Author

    Wow, that was quick. So you're saying I should usually use auto, which should always work. When would it ever be preferable to use ev3? Also auto means I don't have to precede everything with ev3 e.g. ts=ev3.TouchSensor() , right, so more legible code?

  3. ddemidov commented on Sep 4, 2016

    @ddemidov
    Member

    So you're saying I should usually use auto, which should always work.

    Yes

    Also auto means I don't have to precede everything with ev3 e.g. ts=ev3.TouchSensor() , right, so more legible code?

    Not exactly. If you do it like

    from ev3dev.auto import *

    or

    from ev3dev.ev3 import *

    then yes, you can drop the ev3 preffix from your code. But you can also do it like

    import ev3dev.auto as ev3

    which may be preferred in some cases. For example, it does not pollute global namespace (which is not that important for small scripts I guess).

  4. WasabiFan commented on Sep 4, 2016

    @WasabiFan
    Member

    @ndward the difference hat you are seeing is a result of the fact that there are multiple ways to import modules in Python, and the examples use both ways. import foo as bar makes it so that all the items inside foo can be accessed by the name bar. from foo import *, meanwhile, just makes everything within foo accessible everywhere, as if you had declared them in your code yourself.

  5. ndward commented on Sep 4, 2016

    @ndward
    Author

    I'm making ev3python.com for beginners, so I'll happily pollute my global namespace in the name of legibility!

  6. dlech commented on Sep 4, 2016

    @dlech
    Member

    ev3dev.auto doesn't really work like it is supposed to unless you have certain combinations of hardware, so I would avoid it. Also, code introspection in PyCharm doesn't work with ev3dev.auto - another reason to not use it.

  7. ndward commented on Sep 22, 2016

    @ndward
    Author

    With ddemidov encouraging me to use auto rather than ev3 and dlech encouraging me to avoid auto I'm a bit lost at the moment...

  8. dlech commented on Sep 22, 2016

    @dlech
    Member

    We have stated the pros and cons so it is up to you to make an informed decision. Here they are again, in case it was not clear...

    from ev3dev.auto import *
    Pro:

    • The same program should work an all hardware (EV3, BrickPi, PiStorms, EVB)

    Cons:

    • This is actually broken and only works for EV3 and BrickPi on Raspberry Pi model 1. It will not work on any other combination of devices. (See PiStorms support #170).
    • Code completion does not work in PyCharm (and probably other IDEs)

    from ev3dev.ev3 import *
    Pro:

    • Code completion will work in PyCharm

    Con:

    • Users of non-EV3 hardware (PiStorms, BrickPi, EVB) will have to change the import line or else the program won't work.
  9. ndward commented on Sep 23, 2016

    @ndward
    Author

    Based on your comments I opt for ev3 rather than auto and have just modified all the sample programs on ev3python.com (there are about twenty so far). I understand that users of non-EV3 hardware (PiStorms, BrickPi, EVB) (I imagine there are not many people in this situation) will have to change the import line but it's not obvious exactly what change they have they to make - it this documented somewhere?

  10. ddemidov commented on Sep 23, 2016

    @ddemidov
    Member

    There are currently just two options: ev3 and brickpi. EV3 users have to

    from ev3dev.ev3 import *

    and BrickPI users will

    from ev3dev.brickpi import *

    I guess the rest of the users will be restricted to core (universal) functionality and should

    from ev3dev.core import *
  11. ndward commented on Sep 23, 2016

    @ndward
    Author

    I'm sure you mean for BrickPi users
    from ev3dev.brickpi import *

  12. ddemidov commented on Sep 23, 2016

    @ddemidov
    Member

    I've edited the comma away already :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions