保护工作区变量

发布于 2024-10-03 06:27:56 字数 167 浏览 3 评论 0原文

也许你曾经经历过以下的情况。您正在工作,开始运行一个又一个脚本,然后突然意识到您已经更改了您感兴趣的变量的值。除了对工作区进行备份之外,是否没有其他方法来保护变量?

有没有办法在工作区中选择要保护的单个变量?

除了查看命令历史寄存器之外,是否还存在已赋予某个特定变量的不同值的历史寄存器?

Maybe you have come past the following situation. You're working and you start to run one script after another and then suddenly realize you've changed the value of a variable you are interested in. Apart from making a backup of the workspace, is there no other way to protect the variables?

Is there a way to select individual variables in the workspace that you're going to protect?

Apart from seeing the command history register, is there a history register of the different values that have been given to one particular variable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

看海 2024-10-10 06:27:56

按顺序运行脚本会导致灾难。如果可能的话,尝试将这些脚本转换为函数。这自然会消除您遇到的覆盖变量的问题,因为函数内部的变量对于这些函数来说是本地的,而脚本中的变量对于工作区来说是本地的——因此很容易被单独的脚本访问/覆盖(通常是无意的,尤其是如果您使用“结果”等变量名称)。

Running scripts in sequence is a recipe for disaster. If possible, try turning those scripts into functions. This will naturally do away with the problems of overwriting variables you are running into, since variables inside functions are local to those functions whereas variables in scripts are local to the workspace -- and thus easily accessed/overwritten by separate scripts (often unintentionally, especially if you use variable names like "result").

峩卟喜欢 2024-10-10 06:27:56

我也同意在这种情况下编写函数会很有帮助。但是,如果您正在操作非常大的数据集,那么您需要小心地以不会在函数中创建变量的多个副本的形式编写代码,否则您可能会遇到内存短缺问题。

I also agree that writing functions can be helpful in this situation. If however you are manipulating very large data sets then you need to be careful to write your code in a form which doesn't make multiple copies of variables within your functions or you may run into memory shortage problems.

揪着可爱 2024-10-10 06:27:56

不,没有工作区历史记录。我想说,如果您遇到您所描述的问题,您应该考虑改变您的编程风格。

我建议您:

  1. 将那么多代码或信息放入脚本中,这样您就可以从空工作区开始完成任务。因此,我总是将 clear all 放在主文件的开头。

  2. 如果它变得太复杂,请考虑调用函数。如果您需要由另一个脚本或函数生成的值,请将该脚本重写为函数并在主文件中调用它或保存变量。加载变量是绝对没问题的。但按顺序运行脚本会导致灾难,正如 marciovm 提到的marciovm。< /p>

No, there is no workspace history. I would say, if you run into that problem that you described, you should consider changing your programming style.

I would suggest you:

  1. put that much code or information in your script, so you can start from an empty workspace to fulfill a task. For that reason I always put clear all at the start of my main file.

  2. If it's getting too complex, consider calling functions. If you need values that are generated by another script or function, rewrite that script to become a function and call it in your main file or save the variables. Loading variables is absolutely okay. But running scripts in sequence leads to disaster as mentioned by marciovm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文