How can I run a script inside the Python shell effectively?

20 Replies, 1155 Views

I feel you on the clunky copy-paste thing. What I do is use `exec()` but wrap it in a function to keep things tidy. Like:

```python
def run_script():
with open('script.py') as f:
exec(f.read())
```

For debugging, I’d say start with `assert` statements to catch issues early.

Also, if you’re running scripts inside Python shell a lot, maybe look into using `ptpython`—it’s a nicer REPL with autocomplete and stuff.

Messages In This Thread



Users browsing this thread: 1 Guest(s)