I'm looking for functionality like this in C:
// driver.h
void some_func(struct _struct* prod);
// driver_thisproduct.c
void some_func(struct _struct* prod) {
// do some stuff
}
// driver_thatproduct.c
void some_func(struct _struct* prod) {
//do some stuff
}
//Makefile(sorry I don't know much about Make)
if model == 'thisproduct'
obj += driver_thisproduct.o
elif model == 'thatproduct'
obj += driver_thatproduct.o
by this, I can link different function by linking different object file.
I thought I could do like this in python:
#this_product.py
def some_func(self):
# do some stuff
# that_product.py
def some_func(self):
# do some stuff
# driver.py
class Driver:
def __init__(self):
product = input()
if product == 'thisproduct':
importlib.import_module('thisproduct')
elif product == 'thatproduct':
importlib.import_module('thatproduct')
by this, I thought I could do dynamic linking, but I couldn't do it.
I've read How can I separate the functions of a class into multiple files?, but I couldn't get what I expected. What did I do wrong? is using importlib.import_module
and import ...
different?