简体   繁体   English

Python向后运行程序

[英]Python running program backwards

I was wondering if a console-based program in python can run backwards. 我想知道python中基于控制台的程序是否可以向后运行。 More specifically, while the program runs, if there is a possibility to undo an action from the user input (eg a user accidentally typed sth incorrect and he wants to go back without restarting the program, like tapping Ctrl+Z to undo) Is that possible? 更具体地说,在程序运行时,是否有可能从用户输入中撤消某项操作(例如,用户意外键入某项错误,并且他想在不重新启动程序的情况下返回,例如点击Ctrl + Z撤消)可能? If yes how? 如果是,怎么办? :) :)

No. 没有。

Unfortunately Python doesn't provide this feature. 不幸的是,Python没有提供此功能。

Python is an imperative language with mutable state and implementing an "undo" feature would require a quite heavy refactoring of the language internals (after the user types in the wrong input a lot of things can happen in memory... and all of them would have to be in a "transaction" to allow going back to the previous state). Python是一种具有可变状态的命令式语言,实现“撤消”功能将需要对语言内部进行大量的重构(在用户键入错误的输入后,很多事情可能会在内存中发生……而所有这些事情都会必须处于“交易”状态才能返回到之前的状态)。

Consider also that when processing the wrong input a program could for example change a file on disk or send a network message to another computer... how do you "undo" these actions? 还要考虑一下,当处理错误的输入时,程序可能会更改磁盘上的文件或将网络消息发送到另一台计算机……您如何“撤消”这些操作?

I doubt that any language has built in support for rolling back arbitrarily in a program. 我怀疑任何语言都内置了对程序中任意回滚的支持。 When you see a program with an undo feature it's because that was implemented manually in terms of the specific state that the program manages. 当您看到具有撤消功能的程序时,是因为它是根据程序管理的特定状态手动实现的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM