Page 1 of 1

how to see module contents?

Posted: Mon Apr 18, 2022 1:23 am
by KJM
upythons builtin onewire module is throwing an error

Code: Select all

File "ds18x20.py", line 20, in convert_temp
TypeError: function takes 1 positional arguments but 2 were given
This module is either frozen or baked-in not in lib

Code: Select all

>>> os.listdir('lib')
['urequests.py']
I'd like to have a peek at ds18x20.py to try to figure out the problem but I can't work out how to do it in the repl? Can't seem to get past

Code: Select all

>>> dir(onewire)
['__class__', '__name__', '__file__', 'machine', 'time', 'OneWire', 'DS18X20']
>>> inspect.getsource(onewire)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'inspect' isn't defined
Thoughts on how to see what's in ds18x20.py anybody?

Re: how to see module contents?

Posted: Mon Apr 18, 2022 2:35 am
by sweetcandysp
Do you see them in a scan? I would have thought you would (as adv_type = 3). (If you see them in bluetoothctl then you should see them from MicroPython).
slope 2

Re: how to see module contents?

Posted: Mon Apr 18, 2022 5:48 am
by Roberthh
No need to guess, since the source code is available: https://github.com/micropython/micropyt ... ds18x20.py

Re: how to see module contents?

Posted: Mon Apr 18, 2022 12:18 pm
by KJM
Turns out Robert that old 2016 module ['__class__', '__name__', '__file__', 'machine', 'time', 'OneWire', 'DS18X20'] was in the ESP32 flash & was taking import precedence over the baked-in ['__class__', '__name__', '__file__', '_ow', 'OneWireError', 'OneWire'] version of onewire. Once I deleted it my temperature calling routine worked.

Interestingly (to me anyway) if the old 2016 module is in lib it doesn't take import precedence over the baked-in version.

So there is no way to catch a glimpse of baked in module code? Trawling google for examples of how to call something like onewire is tough going when there are multiple versions of onewire floating around, each requiring it's own matching calling routine.