Where is console input history stored on Python for Windows?

2024/9/20 0:27:10

Good afternoon,

The Question

Is there a particular spot that the entries are stored, or is it just a local set of stored variables, for the windows version of Python?

The Context

I am curious about where Python.exe stores the entries typed out from the command line, not the Tkinter GUI. I'm particularly interested in this because I've noticed you can resort to previous entries if you are typing in raw_input(). There have been many discussions in regards to raw_input() and input() receiving some sort of default argument that is editable.

See. This link to a related SO question

Obviously this is very doable with Linux / GNU with modules that will allow you to take advantage of Bash's format. Windows users are unlucky in that regard.

Notes on these modules:

readline is GNU based and does not work properly in Windows.

pyreadline does not benefit the command line interpreter.

curses is GNU based and does not work at all in Windows.

A Follow up

The conclusion I'm arriving to is that if the user is given a pre-defined set of entries, you can limit what is entered into the command space.


P.S. - I understand it is much easier to just create a PySide, Tkinter or "other"-based GUIs to get around what I'm asking.

Sir James

Answer

On Windows 7, using the standard Python 3.7 command interpreter (not IPython or IDLE), the command history is stored in the file %USERPROFILE%\.python_history. This location is not used for Python 2.7.x, as the Python command history feature was introduced starting with Python 3.4.

https://en.xdnf.cn/q/72397.html

Related Q&A

Matplotlib Animation: how to dynamically extend x limits?

I have a simple animation plot like so: import numpy as np from matplotlib import pyplot as plt from matplotlib import animation# First set up the figure, the axis, and the plot element we want to anim…

How to get round the HTTP Error 403: Forbidden with urllib.request using Python 3

Hi not every time but sometimes when trying to gain access to the LSE code I am thrown the every annoying HTTP Error 403: Forbidden message.Anyone know how I can overcome this issue only using standard…

Installing lxml in virtualenv for windows

Ive recently started using virtualenv, and would like to install lxml in this isolated environment.Normally I would use the windows binary installer, but I want to use lxml in this virtualenv (not glob…

Saving a model in Django gives me Warning: Field id doesnt have a default value

I have a very basic model in Django:class Case(models.Model):name = models.CharField(max_length=255)created_at = models.DateTimeField(default=datetime.now)updated_at = models.DateTimeField(default=date…

Authorization architecture in microservice cluster

I have a project with microservice architecture (on Docker and Kubernetes), and 2 main apps are written in Python using AIOHTTP and Django (also there are and Ingress proxy, static files server, a coup…

fastest way to load images in python for processing

I want to load more than 10000 images in my 8gb ram in the form of numpy arrays.So far I have tried cv2.imread,keras.preprocessing.image.load_image,pil,imageio,scipy.I want to do it the fastest way pos…

How to access server response when Python requests library encounters the retry limit

I am using the Python requests library to implement retry logic. Here is a simple script I made to reproduce the problem that I am having. In the case where we run out of retries, I would like to be ab…

Matplotlib patch with holes

The following code works. The problem is I dont know exactly why it works. The code draws a circle patch (using PathPatch) with a triangle cutout from the centre. My guess is that the inner triangle is…

Convert sha256 digest to UUID in python

Given a sha256 hash of a str in python: import hashlibhash = hashlib.sha256(foobar.encode(utf-8))How can the hash be converted to a UUID? Note: there will obviously be a many-to-one mapping of hexdige…

Drag and Drop QLabels with PyQt5

Im trying to drag and drop a Qlabel on another Qlabel with PyQt5:from PyQt5.QtWidgets import QApplication, QWidget, QToolTip, QPushButton, QMessageBox, QHBoxLayout, QVBoxLayout, QGridLayout,QFrame, QCo…