Global name not working in python -
I am coding a program where I am using the curve to create a UI and I am using the terminal Has earned the width and height from a different command and I want to make those two variables universal so that I can pass them through parameters in every program (unless I have to do this?) I have a simple layout of:
Def three (): print width, height def two (): three () def one (): two () global width global height width, height = console.getTerminalSize () one () < P> So I'm getting a global name not defined error, but I'm sure why I have defined it globally, first it's called a series of functions, where did I go wrong?
You do not need to define global in the main code; Any variables declared are global by default, you must put the global width and global height in that function where you call them the dragon Instead of using the global version of the variable instead of the local one (which is the default behavior). But to answer your second question: The use of global is generally undesirable, and it is better to pass in the parameters when you can. This is less risky.
Comments
Post a Comment