0

I am new to python, I would like to import a folder containing a .py file and dll files to another python script.

USB_Relay
  __init__.py
  USB_relay.dll
  test.py

In my other python file, I would like to run a function inside test.py which needs to use source from the dll file. May I know what is the correct way of importing?

I have tried a few but it didn't work.

#import USB_Relay
#import USB_Relay.test
from USB_Relay import test

test.turnoff1()

test.py

L = ctypes.CDLL( "./USB_relay.dll/" )
def turnoff1():
    ret = L.usb_relay_device_close_one_relay_channel(hdev,1)

I will get an error

type object 'L' has no attribute 'usb_relay_device_open_one_relay_channel'

Alex T
  • 9
  • 4
  • Let's break down your question. First, you want to import a folder with all its files, correct? Then, you want to know how to call a DLL function from a python script? – Oren_C Dec 04 '18 at 10:26
  • already answered [here](https://stackoverflow.com/q/4383571/5783608) – Adithya Dec 04 '18 at 10:27
  • Hi Alex. Welcome to SO. I noticed that `from USB_Relay import test` is misspelled. Don't know if that could be causing it or is just a typo. – amanb Dec 04 '18 at 10:27
  • His imports are working, otherwise he'd get a Traceback with ImportError. That error comes from the DLL. @AlexT, can you share test.py turnoff1() definition? – Alexandre Juma Dec 04 '18 at 10:37
  • @Oren_C I dont have to call the DLL function again, all i need to do is to call the python function directly – Alex T Dec 04 '18 at 10:40
  • @AlextT I'm not following. You tested the function on test.py directly (like you added a main block to locally test the function?) Only in the original script that imports test.py the error is present? You need to edit your original post and put more detail so we can help you better. – Alexandre Juma Dec 04 '18 at 11:02

0 Answers0