To initialize some variables in a Python program (in a structured way, without using OOP), I want to use a function called initialization() , which is called from a main() function . The problem is the scope of these variables, since if I give them their initial value in the initialization() function , trying to use them in the main() function will generate an error because they do not exist there. 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 alternatives are there to avoid using "global" in the initialization function? Is it possible to implement any solution without having to pass the variables as arguments and without having to return them on the "return"?