Bläddra i källkod

Python 交互模式查看整个命令历史

#  如何在交互式python中看到整个命令历史?
import readline
def history():
    for i in range(readline.get_current_history_length()):
        print(readline.get_history_item(i + 1))
    print( Yellow   + ':: Clear_History:  readline.clear_history() ')
蘭雅sRGB 3 år sedan
förälder
incheckning
f6b18c1dee
1 ändrade filer med 7 tillägg och 4 borttagningar
  1. 7 4
      python/me.py

+ 7 - 4
python/me.py

@@ -1,6 +1,6 @@
 #-*- coding: UTF-8 -*- 
 
-import sys , os
+import sys, os, readline
 
 # define Color
 Green = '\033[32m'
@@ -36,11 +36,14 @@ def cat(file = 'me.py'):
 def bash():
     os.system('bash')
 
+def history():
+    for i in range(readline.get_current_history_length()):
+        print(readline.get_history_item(i + 1))
+    print( Yellow   + ':: Clear_History:  readline.clear_history() ')
+
 def info():
     print( SkyBlue + ':: Usage:  ' + Green + 'python -i me.py' + Yellow + '     or [import me] , import the module me.py')
-    print( Green   + ':: Function:  cls()  ls()  cd(path)  cat(file)  pwd()  bash()  info() ')
+    print( Green   + ':: Function:  cls()  ls()  cd(path)  cat(file)  pwd()  bash()  info()  history()')
     pwd()
 
-cls()
 info()
-