Jak dodać dopełnienie kart do powłoki Pythona?
Uruchamiając aplikację django używając python manage.py shell
, otrzymuję interaktywną powłokę - mogę użyć uzupełniania tabulatorów, itp.
Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
Podczas uruchamiania interpretera Pythona za pomocą python
, nie oferuje on uzupełniania tabulatorów.
Czy ktoś może mi powiedzieć, co django robi, aby dać mi interaktywną konsolę, lub co muszę zrobić, aby uruchomić interaktywną konsolę bez aplikacji django?
9 answers
Chyba znalazłem na to sposób.
Utwórz plik .pythonrc
# ~/.pythonrc
# enable syntax completion
try:
import readline
except ImportError:
print("Module readline not available.")
else:
import rlcompleter
readline.parse_and_bind("tab: complete")
Potem w Twoim .plik bashrc, dodaj
export PYTHONSTARTUP=~/.pythonrc
To chyba działa.Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-03-21 12:15:37
Myślę, że django robi coś takiego https://docs.python.org/library/rlcompleter.html
Jeśli chcesz mieć naprawdę dobrego interaktywnego tłumacza, zajrzyj na IPython .
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-01-24 08:59:07
Dla przypomnienia, jest to omówione w samouczku: http://docs.python.org/tutorial/interactive.html
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2008-10-29 16:39:03
Używam ptpython - jest to wspaniałe narzędzie autocomplete Shell cmd.
Instalacja ptpython jest bardzo łatwa, użyj narzędzia pip
pip install ptpython
A dla powłoki django, powinieneś zaimportować django env, jak to
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testweb.settings")
Zaufaj mi, to najlepszy sposób dla Ciebie!!!Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-11-21 14:27:58
Poprawka dla powłoki Windows 10:
pip install pyreadline
-
pip install ipython
[shell]
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-11-21 14:28:56
Wygląda na to, że python3 ma to po wyjęciu z pudełka!
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-03-23 21:50:33
W Python3 ta funkcja jest domyślnie włączona. Mój system nie miał zainstalowanego modułu readline
. Jestem na Manjaro. Nie spotkałem się z tym problemem w innych dystrybucjach Linuksa (elementary, ubuntu, mint).
Po zainstalowaniu pip
modułu, podczas importowania, wystąpił następujący błąd -
ImportError: libncursesw.so.5: cannot open shared object file: No such file or directory
Aby to rozwiązać, pobiegłem -
cd /usr/lib
ln -s libncursesw.so libncursesw.so.5
To rozwiązało błąd importu. I, to również przyniósł tab completion w Pythonie repl bez żadnych tworzenie / zmiany .pythonrc
i .bashrc
.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-07-02 19:44:48
Tak. Jest wbudowany do 3,6.
fernanr@gnuruwi ~ $ python3.6
Python 3.6.3 (default, Apr 10 2019, 14:37:36)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.
Display all 318 possibilities? (y or n)
os.CLD_CONTINUED os.O_RDONLY os.ST_NOEXEC os.environ os.getpid( os.readlink( os.spawnvpe(
os.CLD_DUMPED os.O_RDWR os.ST_NOSUID os.environb os.getppid( os.readv( os.st
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-11-21 14:30:45
Dla starszych wersji (2.x) powyższy skrypt działa jak czar:)
fernanr@crsatx4 ~ $ cat .bashrc | grep -i python
#Tab completion for python shell
export PYTHONSTARTUP=~/.pythonrc
fernanr@crsatx4 ~ $ . ~/.bashrc
fernanr@crsatx4 ~ $ echo $?
0
fernanr@crsatx4 ~ $ python2
Python 2.7.5 (default, Jun 11 2019, 14:33:56)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.
Display all 249 possibilities? (y or n)
os.EX_CANTCREAT os.O_WRONLY
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-02-11 10:04:09