Search code examples
pythonreturn-value

Calling up a return value from another module


I have 'main.py' and 'newcanmonitor.py' I want to call up the return value "string" from newcanmonitor.py inside main.py

-----main.py----

import newcanmonitor
xy=newcanmonitor.read_bus('vcan0')
print(xy)

-----newcanmonitor.py------

def read_bus(bus_device):
    """Read data from `bus_device` until the next newline character."""
    message = bus.recv(0.2)
    while True:
        if message:
            break
        message = bus.recv(0.2)

    try:
        string = "{}:ID={}:LEN={}".format("RX", message.arbitration_id, message.dlc)
        for x in range(message.dlc):
            string += ":{:02x}".format(message.data[x])

    except Exception as e:
        print(e)
    return string

Obviously this is not working Can you help me?


Solution

  • There is no reason that calling a function from another module wouldn't work. You never use "bus_device" in your code. Could that be an omission and the source of your woes?