To initialize some variables in a program written in Python (in a structured way, without the use of object-oriented programming), I want to use a function called home()which is invoked from a function to main(). The problem is the scope of these variables, because if I give the initial value in the function home(), when you try to use them in the function main() will generate an error because there does not exist. For example:
import serial def inicializacion(): puerto = '/dev/ttyACM0' baudRate = 115200 buffer = '' ser = serial.Serial(puerto, baudRate, timeout=1) def main(): inicializacion() buffer = buffer + leerDatos(ser)
What are alternatives to avoid the use of "global" in the initialization function? Is it possible to implement any solution without having to pass the variables as arguments and without having to send them back in the "return"?