Is there a way to store commands in Python?
For example, to store a bash command I can put:
# in .bash_profile
alias myproject="cd /path/to/my/project"
$ project
Is there a way to store a command, for example something like this:
'store' profile="from userprofile.models import Profile"
>>> profile
which will work in the Python command prompt whenever/wherever it is opened? Thank you.
In Bash, I’m assuming you are defining this aliases in
.profile,.bash_rcor a similar file. In that file, add the lineThis will allow you to create a
.python_rc.pyfile that is included whenever you start a session in the Python prompt/REPL. (It will not be included when running Python scripts, becasue it could be disruptive to do so.)Inside that file, you could define a function for the command you want to save. In your case what you’re doing is actually a touch more complicated than it seems, so you’d need to use a few more lines:
After doing this, you’ll be able to call
profile()to importProfilein the Python prompt.