Created
January 23, 2014 18:52
-
-
Save GabLeRoux/8584525 to your computer and use it in GitHub Desktop.
pythonrc with autocompletion! :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import atexit | |
import os | |
import sys | |
try: | |
import readline | |
except ImportError: | |
print "Module readline not available." | |
else: | |
import rlcompleter | |
readline.parse_and_bind('tab:complete') | |
print(".pythonrc :: AutoCompletion Loaded") | |
# History | |
historyPath = os.path.expanduser("~/.pyhistory") | |
def save_history(historyPath=historyPath): | |
import readline | |
readline.write_history_file(historyPath) | |
print(".pythonrc :: history saved to " + historyPath) | |
if os.path.exists(historyPath): | |
readline.read_history_file(historyPath) | |
atexit.register(save_history) | |
# anything not deleted (sys and os) will remain in the interpreter session | |
del atexit, readline, rlcompleter, save_history, historyPath |
Hi Gabriel,
It is working with python3 in my system. Only with the python3.8 it is not
working.
Will try to fix it. Thanks a lot for all your help.
Bhavin Moriya <https://sites.google.com/site/bhavinmoriya/>
Assistant Professor
The Federal University of Viçosa - Brazil.
Departamento de Matemática <http://www.dma.ufv.br/>
Av. P.H. Rolfs, s/n
36570-000 – Viçosa.
Minas Gerais
Brasil.
My Blog
https://livelifemaverick.blogspot.com/
"Only the gentle are ever really strong."
- James Dean
…On Mon, Mar 30, 2020 at 4:01 PM Gabriel Le Breton ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Well, there's probably something wrong with your system, I just tried on a
fresh ubuntu:18.04 docker image on https://labs.play-with-docker.com/ (a
bit different from an actual clean os, but still)
docker pull ubuntu:18.04
docker run --rm -it ubuntu:18.04 bash
apt-get update && apt-get install -y python3 vim
touch ~/.pythonrc
vim ~/.pythonrc# paste content of file from blog post and write file
vim ~/.bashrc# paste 'export PYTHONSTARTUP=~/.pythonrc' and write filesource ~/.bashrc
python3
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
.pythonrc :: AutoCompletion Loaded
.pythonrc :: history file: /root/.pyhistory>>> print('example')
example>>>
.pythonrc :: history saved to /root/.pyhistory
cat /root/.pyhistory
print('example')
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://gist.github.com/8584525#gistcomment-3233591>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADX5EV5ZDGY2VX637NCD5O3RKDUBFANCNFSM4LVMD3TA>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Well, there's probably something wrong with your system, I just tried on a fresh ubuntu:18.04 docker image on https://labs.play-with-docker.com/ (a bit different from an actual clean os, but still)