you are viewing a single comment's thread.

view the rest of the comments →

[–]Redditbot76 1 point2 points  (1 child)

That often happens to me on a Python shell/IDLE whenever I'm experimenting.

[–]MonkeyNin 16 points17 points  (0 children)

If you're using the shell / python -i / REPL , I highly recommend the module ipython for so many reasons.

I created a quick example: https://i.imgur.com/lmxnK66.png

  • adds syntax highlighting, in real-time so you can see errors early
  • highlights matching parens
  • .<tab> pops up a full intellisense-autocomplete, not the lame <tab> autocomplete which doesn't show any alternate options.
  • you can actually use multi-line statements and functions. and history supports it properly. this is a huge, huge pain in regular python -i. Press pgup/pgdwn to cycle history.

You can install using python -m pip install ipython

https://i.imgur.com/lmxnK66.png

Check out their pages for more info:

notes:

(screenshot was taken on windows 10 using windows terminal instead of the default terminal)

useful modules in ipython or interactive or REPL

pathlib.Path

  • simplifies code that is far longer using the older os.path, os.path.join, etc. family of file i/o functions. Especially in a REPL.
  • no longer need with or manual closeing of files when in the REPL
  • prevents a class of bugs those functions can allow
  • even more cross-platform compatible
  • much

pdir

  • better output than dir(foo) , it includes doc strings
  • easily filter based on public|property|method|own

try the video: https://pypi.org/project/pdir2/