105 print("Error: ", e)
106 try:
107 os.system("xdg-open " + os.path.join(os.getcwd(), "Resources/Images/Saved_fractals/"))
108 except Exception as e:109 print("Error: ", e)
110 checked_ez_button.create_button()
111
135 print("Error: ", e)
136 try:
137 os.system("xdg-open " + "CONFIG.ini")
138 except Exception as e:139 print("Error: ", e)
140 if any(
141 complex_button.check_hover(mouse_x, mouse_y)
75 try:
76 subprocess.Popen(
77 ["xdg-open", os.path.join(os.getcwd(), "Resources/Images/Saved_fractals/")])
78 except Exception as e: 79 print("Error:", e)
80
81 if checked_ez_button.name == "btnExport":
105 print("Error: ", e)
106 try:
107 os.system("xdg-open " + os.path.join(os.getcwd(), "Resources/Images/Saved_fractals/"))
108 except Exception as e:109 print("Error: ", e)
110 checked_ez_button.create_button()
111
135 print("Error: ", e)
136 try:
137 os.system("xdg-open " + "CONFIG.ini")
138 except Exception as e:139 print("Error: ", e)
140 if any(
141 complex_button.check_hover(mouse_x, mouse_y)
The local variable name hides the variable defined in the outer scope, making it inaccessible and might confuse.
filename = 'myfile.txt'
def read_file(filename): # This shadows the global `filename`
with open(filename) as file:
return file.readlines()
FILENAME = 'myfile.txt' # renamed global to UPPER_CASE as convention
def read_file(filename):
with open(filename) as file:
return file.readlines()
Another usual suspect of this is when you use the same parameter name inside a function as the global variable you are using. For example:
def run_app(app):
# This `app` shadows the global app...
app.run()
if __name__ == '__main__':
app = MyApp() # This is a global variable!
run_app(app)
To avoid this re-defining of a global, consider not defining app
as a global, but inside a main()
function instead:
def run_app(app):
# There is no longer a global `app` variable.
app.run()
def main():
app = MyApp()
run_app(app)
if __name__ == '__main__':
main()