gpt4 book ai didi

wolfram-mathematica - 为什么我会在此构造中收到安全警告消息 "This file contains potentially unsafe dynamic content"

转载 作者:行者123 更新时间:2023-12-04 00:14:08 28 4
gpt4 key购买 nike

我终于能够重现我偶尔收到的这条消息。

这在 V8.04 上,在 Windows 7 上。

在尝试时,我发现了当我打开一个带有 Manipulate 的笔记本时,如何让 Mathematica 生成上述消息。

首先是错误消息屏幕:

enter image description here

我现在点击“启用动态”,一切似乎都很好。但是每次我重新打开笔记本时,我都会再次收到消息。 (必须关闭M,重新启动,然后打开笔记本才能看到消息)。

所以我不明白这个警告消息,为什么会出现,以及我需要在代码中更改什么才能删除它。

生成它的代码是:

Manipulate[

DynamicModule[{p},
p["x"] = 0;
Row[{Dynamic[
Refresh[p["x"]++; Row[{"p[x]=", p["x"]}],
TrackedSymbols -> {n}]]}]
],

Button["update counter", n++],
{{n,0}, None}
]

以上是在自己的笔记本上,笔记本中没有其他内容。

我关闭M,然后启动它,然后打开笔记本,我看到了上面的消息。

现在,我最初认为要删除消息,我需要将 p["x"] 更改为 p[x] 所以我关闭了上面的笔记本,并使用以下代码制作了一个新笔记本:
Manipulate[

DynamicModule[{p},
p = 0;
Row[{Dynamic[Refresh[p++; Row[{"p=", p}], TrackedSymbols -> {n}]]}]
],

Button["update counter", n++],
{{n, 0}, None}
]

然后关闭M,重新启动,打开上面的笔记本,
现在我没有看到警告信息。但是当我重复这个过程时,我看到同样的错误又回来了。

(我将此问题发布到数学组,但这很慢,我的帖子甚至没有出现在那里,但在那篇帖子中我说当我将 p["x"] 更改为 p[x] 时错误消失了,因为一开始确实是这样,但是后来我试了一下,消息又回来了,不明白为什么)

p["x"] 是一个索引对象,如本页所述:

http://reference.wolfram.com/mathematica/tutorial/MakingDefinitionsForIndexedObjects.html

问题是:上面的代码是什么让这个警告出现?我在上面的例子中写错了吗?

启用动态后,代码运行正常。顺便说一句,我从打开我所有其他笔记本的同一个文件夹中打开这个笔记本,没有任何改变,这是在家用 PC 上,没有网络共享文件夹,也没有任何异常。

这是笔记本安全的相关链接

http://reference.wolfram.com/mathematica/tutorial/NotebookSecurity.html

我在上面没有看到与我正在做的事情相关的任何事情。我只能说,它与 Manipulate 内部使用 DynamicModule[] 有关,它本身就是一个 DynamicModule。但我不太明白这一点,无法弄清楚为什么这是一个问题。

更新 1

我不明白这与路径有什么关系。我可以通过像这样简单地注释掉内部 Dynamic 来消除错误:
Manipulate[


(*
DynamicModule[{p},
p["x"]=0;
Row[{Dynamic[Refresh[p["x"]++;Row[{"p[x]=",p["x"]}],TrackedSymbols-> \
{n}]]}]
],
*)

n,
Button["update counter", n++],
{{n, 0}, None}
]

保存笔记本,关闭M,启动M,打开笔记本。错误消失了。

所以,它在代码中。

更新 2

试图重现尤达在他的回答中报告的内容,我无法做到。
  • 制作新笔记本,输入 Dynamic@DateString[]
  • 输入进行评估。
  • 保存
  • 关闭 M
  • 开M
  • 打开笔记本
  • 没有错误

  • enter image description here

    2001 年 12 月 21 日更新

    在数学组,John Fultz 很友好地回复了我的帖子,我认为他不会介意我在这里发布他的答案以供其他人看到
    > > So, why is using p["x"] causing the security warning message?

    That is a bug, which has already been fixed in development sources.
    John Fultz
    User Interface Group
    Wolfram Research, Inc.

    抱歉,我没有包含他回复的链接,我现在在 google 上找不到链接。我使用雷鸟来阅读新闻组。

    现在这个问题应该保持开放吗?还是应该关闭?如果我需要关闭它,我可以接受其中一个答案,因此它已关闭。

    最佳答案

    这不是因为特定的代码示例,而是因为 Mathematica 的安全功能。来自 tutorial/NotebookSecurity ,

    When the user opens a notebook containing dynamic content, Mathematica will first determine whether the notebook's directory is trusted, untrusted, or neither.

    • If the notebook's directory is trusted, the notebook will be allowed to automatically perform dynamic evaluations without alerting the user.
    • If the notebook's directory is untrusted, the user will be alerted upon any attempt by the notebook to perform dynamic evaluations.
      enter image description here


    默认情况下,只有 $InstallationDirectory , $BaseDirectory , 和 $UserBaseDirectory被“信任”。此外,还有一组始终不受信任(可以更改)的目录。这些是您的下载
    现在的解决方案是将您当前的工作目录添加到受信任文件夹列表中。

    转至 Preferences > Advanced > Open Options Inspector及以下 Global Preferences ,开始搜索 trusted您应该会看到弹出的三个选项。您可以在此处添加它们。

    enter image description here

    关于wolfram-mathematica - 为什么我会在此构造中收到安全警告消息 "This file contains potentially unsafe dynamic content",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8583521/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com