r/pythonhelp • • 12h 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

6 comments sorted by

•

u/AutoModerator 12h ago

To give us the best chance to help you, please include any relevant code.
Note. Please do not submit images of your code. Instead, for shorter code you can use Reddit markdown (4 spaces or backticks, see this Formatting Guide). If you have formatting issues or want to post longer sections of code, please use Privatebin, GitHub or Compiler Explorer.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/atarivcs 12h ago

"this just breaks" is not a good description of the problem.

Please show us the exact error or incorrect result you are getting.

1

u/LNXByte 12h ago

to make sure this works add usr/local/bin to your paths

if you're on a non-intel based mac you may have to run:

sudo mkdir -p /usr/local/bin

this program will run in 5 seconds

name WITHOUT file extension testMain

What language did you code your program in? python

What is the path to your project? .

What do you want to name your command testMkcmd

Do you have a shebang line at the top? (if not thats fine theres no need to add it) yes

it freezes here and then i was getting some error messages (which i cant find due to the freezing) about my shebang and extension vars

1

u/Educational-Paper-75 9h ago

shebang and extension are local variables and thus unknown in the install function. Either declare them globally as well or pass them in the install function calls as function arguments (to added function parameters).

1

u/LNXByte 3h ago

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

1

u/Educational-Paper-75 1h 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.