r/pythonhelp • • 2d ago

Test code very broken with os lib

https://github.com/jacobrinaldi/mkcmd/blob/main/tests/testMain.py

I making a tool and i wanted to make it much more lightweight while still being coded in python but this just breaks i was told be some to remove global in my if statements but that didnt help.

0 Upvotes

7 comments sorted by

View all comments

Show parent comment

1

u/LNXByte 1d ago

Sorry for asking but can you dumb it down a little bit? I'm still very new programming

1

u/Educational-Paper-75 1d ago

In Python all variables you use inside a function for the first time are local to that function that means they're unknown inside other functions. Whereas variables used outside functions are global and (thus) can be used inside functions. However, you cannot change global variables inside functions unless you declare them inside that function with the global statement (that starts with the global keyword). In your case it's easiest to simply assign an arbitrary value (like an empty string i.e. "") to shebang and exetension outside all functions just like you do with the other variables and declare them as global using the statement (global shebang, exetension) inside you main function where you ask for them.

1

u/LNXByte 1d ago

oh i think i get it! I did use global but in 2 diffrint statements so i just one?