2

I am using the Command Prompt in Windows 8 to perform some analytical tasks with Python.

I'm using a few external libraries, some .py files with functions I need, and some set up commands (like setting certain variables based on databases I need to load).

In all there are about 20 statements. The problem is, that each time I want to work on it, I have to manually enter (copy/paste) all of these commands into the Shell, which adds a few minutes each time.

Is there any way I can save all of these commands somewhere and automatically load them into the prompt when needed?

1 Answer 1

3

Yes,

Save your commands in any file in your home directory. Then set your PYSTARTUP environment variable to point to that file. Every time you start the python interpreter it will run the commands from the startup file

Here is the link to example of such file and more detailed explanation

If you need to have different start up files for different projects. Make a set of shell scripts one per project. The scripts should look like this:

#!/bin/bash
export PYTHONSTARTUP=~/proj1Settings.py
python

And so on. Or you can simply change the value of PYTHONSTARTUP variable before you start working on a particular project. Personally, I use MacOS with Iterm2, so I set-up multiple profiles for different projects. When I need to work on a particular project I simply launch a tab with the profile configured for the project.

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

2 Comments

But I don't want it to ALWAYS start up with Python. I only want it when I'm working on a specific project. Are there ways to set multiple startup files that can be used separately?
I edited my answer to explain how to work with multiple startup files.

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.