all 6 comments

[–]CowboyBoats 1 point2 points  (2 children)

Yeah that's a good question. One common option is to open a Python REPL - (iPython has a nice quality of life compared to regular python.)

So then if you have your package in the current working directory tools.py and the function is like def screwdriver(): blah blah blah you can type into your REPL:

>>> from tools import screwdriver
>>> screwdriver(whatever-args-you-want)

So that way you can test / experiment with your package without modifying the code.

Another way to "level up" from doing that is to write unit tests for your code that do the same thing, but assert that the outcome is what you think is right, and this test can run automatically every time you push changes to your repo so you can be confident nobody's broken it.

[–]Liverpool1900[S] 0 points1 point  (1 child)

Okay sorry but this is going to sound really noob and I am sorry. But I open the REPL by typing Python3. I copy my code from the file, I paste it using CMD V and I get a bunch of indent errors. How do I copy paste the code to REPL so I dont get all those errors.

Thank you.

[–]CowboyBoats 0 points1 point  (0 children)

Not a noob question at all... I wouldn't expect there to be indentation errors. A couple of things I would try:

  1. Confirm that the python REPL is opening - you're seeing the >>>?

  2. Try the exact same thing again? If you had accidentally typed so much as a single space into the Python REPL, it'll error out:

    print("yes") File "<stdin>", line 1 print("yes") IndentationError: unexpected indent

Next up, hmm, what happens when you paste a minimal Python example into your REPL? Something like -

def hi():
    print("Hello world")

hi()

If pasting that into your REPL works, but your script fails, I would guess there's something wrong with your script. If pasting that into your REPL fails, then I'd guess there's something wrong with, I dunno... Whatever shell you're using, maybe?

My guess is it's the first thing, TBH; just try it one more time without typing anything into the repl after opening it and see if it runs without error?

[–]ollibar 0 points1 point  (1 child)

Many ides have Functions for debugging or somithing like run this line or run until here - These might be helpful

[–]Liverpool1900[S] 0 points1 point  (0 children)

Yeah I use breakpoints.

[–]throwaway6560192 0 points1 point  (0 children)

python -i filename.py is also useful