NameError: name 'ultrasonicRead' is not defined

Hi,

it’s my second day on GrovePi and i love it. I have a Raspberry Pi B+ with GrovePi+ with latest firmware 1.2.2 and library updated as suggested, by attaching the Ultrasonic Ranger to D4 and running sudo python grove_ultrasonic.py i get:
Traceback (most recent call last):
File “grove_ultrasonic.py”, line 13, in <module>
print ultrasonicRead(ultrasonic_ranger)
NameError: name ‘ultrasonicRead’ is not defined

I have no clue on why it doesn’t work. Any suggestion please?
Thanks

Okay, i got it.
changed “import grovepi” to “from grovepi import *” as seen in (working) Project file. Is this an issue i can open on github or are there specific reason why it behaves this way? Useful in case i find similar bugs.

“import grovepi” means you can use method grovepi.foo()

“from grovepi import” means you can use foo() instead of grovepi.foo().

Stack overflow discussion about it:

There is a bug in here:

To match the other examples, it should be:
print grovepi.ultrasonicRead()

If you want to contribute the fix, create a fork, commit your fix and create a pull request.

Otherwise, if this all sounds too hard, I can do it.

Thanks for the clarification mcauser. By your suggestion i created my first pull request on github. Have a nice day

Excellent! And thank you for the contribution! Just approved the pull, great work!