0

Is there any way to open an active, interactive python terminal that will automatically run my initial ~10 lines of code?

My specific use (which will probably be needed to clarify the question) is that I have a Microsoft SQL Server that it takes just a little too long to bother opening SSMS when I just want to quickly find the ID for a record or something.

What I've found myself doing is opening a python terminal (just have python pinned to the start menu), and copy-pasting in ~10 lines of code from a text file I leave open (import sqlalchemy, import pandas, set driver and connection string). Then I'll actually type in whatever I'm looking for (pd.read_sql('Select * from table where x = y') and getting the name of my record.

I've no doubt that there are plenty of completely better solutions to viewing data in a database effectively, but I'm hoping that I can easily improve my current (albeit janky) worthflow until I get around to a real solution. Plus, just seems like a useful thing to do.

2
  • I think you can use crontab, or make a exec and add it to you windows scheduler, the latter I don't think can be scheduled for every 10 mins but you can try it out. Commented Jan 20, 2022 at 20:56
  • @LakshyaSrivastava, did you mean to comment on another question? Commented Jan 20, 2022 at 20:56

1 Answer 1

1

You could use python -i script_with_first_10_lines.py:

When a script file is used, it is sometimes useful to be able to run the script and enter interactive mode afterwards. This can be done by passing -i before the script.

This will run your script, then stay in interactive mode so you can run more code by typing it in.

Sign up to request clarification or add additional context in comments.

1 Comment

as a little addition for myself, I created a shortcut that runs python -i script.py and then pinned that shortcut to my start menu. so now i just have that start-menu button and boom, ready to go. based it off of this article, but changed the command to be python instead of cmd: winaero.com/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.