Python的deepcopy()的Decimal()对象(Python deepcopy() of a Decimal() object)
我努力深度拷贝()一个包含Decimal值的类。 所以我尝试了深度复制一个Decimal对象,并且失败了。 我在这里误解了什么?
from copy import deepcopy from decimal import Decimal ## Deepcopy an array ## a = [1,2,3,4] b = deepcopy(a) a is b # False ## Deep copy a Decimal ## a = Decimal('0.123') b = deepcopy(a) a is b # True ## Deepcopy a class containing a Decimal ## class A(object): def __init__(self, dec): self.myDecimal = Decimal(dec) a = A('0.123') b = deepcopy(a) a is b # False a.myDecimal is b.myDecimal # True
该类复制但小数引用保持不变。
I'm struggling to deepcopy() a class containing a Decimal value. So I tried deep copying a Decimal object on its own and that failed too. What am I misunderstanding here?
from copy import deepcopy from decimal import Decimal ## Deepcopy an array ## a = [1,2,3,4] b = deepcopy(a) a is b # False ## Deep copy a Decimal ## a = Decimal('0.123') b = deepcopy(a) a is b # True ## Deepcopy a class containing a Decimal ## class A(object): def __init__(self, dec): self.myDecimal = Decimal(dec) a = A('0.123') b = deepcopy(a) a is b # False a.myDecimal is b.myDecimal # True
The class copies but the decimal reference remains the same.
原文:https://stackoverflow.com/questions/43369382
最满意答案
Powershell希望在脚本文件运行之前有一个合适的脚本文件路径。 所以你需要使用
powershell.exe .\myscript.ps1
如果它位于当前工作目录中(不太可能并且容易中断此用例)或使用脚本的完整路径:
powershell.exe C:\Users\Foo\Scripts\myscript.ps1
或类似的。
Powershell wants to have a qualified path to script files before it will run them. So you need to either use
powershell.exe .\myscript.ps1
if it lies in the current working directory (unlikely and prone to break for this use case) or use the full path to the script:
powershell.exe C:\Users\Foo\Scripts\myscript.ps1
or similar.
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
你在运行32位cmd.exe吗? 如果是这样,那么Import-Module应该可以工作。 如果您运行的是64位cmd.exe,则会启动64位PowerShell.exe,除非您完全限定了32位版本PowerShell.exe的路径(c:\ windows \ syswow64 \ windowspowershell \ v1。 0 \ powershell.exe)。 Are you running a 32-bit cmd.exe? If so then the Import-Module should ...
-
C ++ CLI Wrapper(C++ CLI Wrapper)[2022-05-20]
如果其他包装类位于同一个程序集中,请将访问权限设置为internal而不是public。 - 罗杰罗兰于2013年4月25日9:47 。 如果他们不在同一个集会? ... 看看朋友们的集会 - 塞巴斯蒂安卡博特2月1日15:43 If the other wrapper classes are in the same assembly, make the access internal instead of public. – Roger Rowland Apr 25 '13 at 9:47 . if th ... -
这个答案可能会帮助您解决问题,但如果您提供有关问题和NativeScript版本的更多信息,这将有所帮助。 关于这种情况,如果你想使用旧项目,最好用tns platform remove ios并再次tns platform add ios 。 This answer might help you to solve your problem, however it would help if you give some more info about the problem and NativeScript ...
-
Powershell希望在脚本文件运行之前有一个合适的脚本文件路径。 所以你需要使用 powershell.exe .\myscript.ps1 如果它位于当前工作目录中(不太可能并且容易中断此用例)或使用脚本的完整路径: powershell.exe C:\Users\Foo\Scripts\myscript.ps1 或类似的。 Powershell wants to have a qualified path to script files before it will run them. So y ...
-
只需使用powershell exit命令将结果作为参数。 例如: C:\>powershell -command "exit [int]$true;" C:\>echo %errorlevel% 1 C:\>powershell -command "exit [int]$false;" C:\>echo %errorlevel% 0 或者你的情况: powershell.exe -command "exit [int]((get-service wsearch).status -eq 'Runni ...
-
我认为有一些事情可以防止这种情况发生。 首先,当你使用单引号时, '你指示PowerShell按字面意思操作。 这意味着它不会扩展变量。 不是你想要的。 更好的方法是使用这样的子表达式。 $Global:commandBlock={ 'ham' >> C:\temp\test.txt } $cmdProc=start-process powershell -ArgumentList ("-command $($Global:commandBlock)") -PassThru -NoNewWindow:$N ...
-
您也可以在Windows中从命令行运行PHP脚本。 鉴于你有一个文件namned main.php,你可以在这种情况下通过编写php%filename%(所以php main.php)来运行这个文件。 写入标准输出流的任何内容都将显示在控制台中。 php二进制文件默认情况下不存在于环境路径变量中,因此应该添加。 You can run PHP scripts from the commandline in Windows as well. Given you have a file namned main. ...
-
您可以指定多个重定向。 防爆。 powershell.exe -file Sample.ps1 2>errors.txt 1>output.txt Sample.ps1 Write-Error "This is a critial error" Write-Output "This is output" "This is also output" ERRORS.TXT C:\Users\frode\Desktop\Sample.ps1 : This is a critial error + Ca ...
-
从Heroku CLI运行脚本(Running script from Heroku CLI)[2021-10-10]
您忘记在命令中指定node ,因此我怀疑Heroku正在尝试运行createUser.js ,就像它是一个shell脚本一样。 您可能需要安装node.js buildpack才能在Heroku上运行该程序,但请尝试: heroku run node bin/createUser.js --username admin --password admin --clientId -1 You forgot to specify node in the command, so I suspect that He ...