PowerShellStandard.Library+ System.Text.Json.我的csproj文件包含这个块:
<ItemGroup>
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" />
<PackageReference Include="System.Text.Json" Version="4.7.0" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
我的.cs文件使用System.Text.Json和System.Management.Automation.
当我使用JsonSerializer.Serialize(...). 它在运行时也没有错误或警告地编译dotnet build。我可以导入它,但最后,当我运行代码时,我收到以下错误:
Get-JsonString : Could not load file or assembly 'System.Text.Json, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
At line:1 char:1
+ Get-JsonString -input s
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-JsonString], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,UrlCSharpPowerShell.CreateJson
Run Code Online (Sandbox Code Playgroud)
我在这里缺少什么?
所有文件都在'venv'目录中
我将代码分成五个单独的文件.一个'主'文件,收集所有其他文件并最终创建GUI.文件的前缀是"注意",后面是适当的描述.
我现在的问题是将'NoteTopMenu'导入主文件'NoteMainApp'.代码是:
import NoteStatusbar as SB
import NoteTopMenu as TM
import NoteWidgets as NW
import tkinter as tk
class MainApp(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self,parent)
super().__init__(parent)
self.topbar = TM.TopMenu(parent)
self.widget = NW.FrontFrames(parent)
self.statusbar = SB.StatusBar(parent)
root = tk.Tk()
MainApp(root).pack(side="top", fill="both")
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
我收到错误消息:
Traceback (most recent call last):
File "C:/Users/PycharmProjects/MindNotez/NoteMainApp.py", line 2, in <module>
import NoteTopMenu as TM
File "C:\Users\PycharmProjects\MindNotez\NoteTopMenu.py", line 2, in <module>
import NoteMainApp as Main
File "C:\Users\PycharmProjects\MindNotez\NoteMainApp.py", line 29, in <module>
MainApp(root).pack(side="top", fill="both") …Run Code Online (Sandbox Code Playgroud) my_string = "wolfofwalstreet(2012)is a movie"
Run Code Online (Sandbox Code Playgroud)
需要运行python脚本来检查它是否包含字符:括号
“(”
在 PowerShell 中,您可以创建一个哈希表,并使用 将这个哈希表添加到您的函数中@,这在 PowerShell中是splatting。
$dict = @{param1 = 'test'; param2 = 12}
Get-Info @dict
Run Code Online (Sandbox Code Playgroud)
可以将字典作为参数集合传递给构造函数或方法吗?
我正在构建一个应用程序,它接受输入,将其保存到 CSV 文件,现在最后一个基本部分是显示列内容的饼图。输入应该是关于书籍的。因此,饼图应该显示列表中所有书籍的类型。
我在创建饼图时没有问题,我在单独的脚本中管理它,我也没有收到错误消息,但只有一个白色字段。
import csv
import tkinter as tk
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from tkinter import ttk
from collections import Counter
class FrontFrames:
def __init__(self, master):
super().__init__()
#Split the screen horizontally in two parts
top_frame = tk.Frame(master, bg="green")
bottom_frame = tk.Frame(master, bg="yellow")
top_frame.pack(side="top", fill="both", expand=True)
bottom_frame.pack(side="top", fill="both", expand=True)
#Creating the three top widgets
self.tree = Label(top_frame)
column = ("Title", "author", "year", "others")
self.treeview = ttk.Treeview(top_frame, columns=column, show='headings')
self.treeview.heading("Title", text="Title") …Run Code Online (Sandbox Code Playgroud) I got the tuple -
Result = [('80407', 'about power supply of opertional amplifier', '11 hours ago'), ('80405', '5V Regulator Power Dissipation', '11 hours ago')]`
Run Code Online (Sandbox Code Playgroud)
I want to iterate over the tuples and separate the items in the tuples by ;.
The output should be as follows -
80407;about power supply of opertional amplifier;11 hours ago
Run Code Online (Sandbox Code Playgroud)
I tried the following:
for item in zip(*Result):
print(*item[0], end=';')
Run Code Online (Sandbox Code Playgroud)
Which gave me the result -
8 0 4 0 7;a b o …Run Code Online (Sandbox Code Playgroud) 我想用 C# 编写 PowerShell。red-gate.com 提供了一个有用的链接,其中描述了该过程的步骤。作者使用 .Net Framework 作为 Class 库项目。我对此没有任何问题,但是,我想也为 .Net Core 编写我的函数,以使它们也具有跨平台功能。我用目标框架创建了一个新项目netcoreapp3.1。当我安装时,System.Management.Automation 7.1.2我收到错误:
Error NU1202 Package System.Management.Automation 7.1.2 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package System.Management.Automation 7.1.2 supports: net5.0 (.NETCoreApp,Version=v5.0)
Run Code Online (Sandbox Code Playgroud)
我对受支持的.NETCoreApp v5.0. 通过此链接https://dotnet.microsoft.com/download有 .NET v5.0 和 .NET Core 3.1。当我定位时,net5.0我收到错误,提示未找到参考程序集,但我安装了 .NET 5.0 SDK。
C:\Users\Alex_P>dotnet --list-sdks
3.1.403 [C:\Program Files\dotnet\sdk]
5.0.201 [C:\Program Files\dotnet\sdk]
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何System.Management.Automation在 .NET Core(跨平台项目)中使用来编写 PowerShell 函数?
创建功能时,我的家用笔记本电脑出现异常行为。参数不会传递到函数中。
例:
function Get-Info {
param (
$input
)
$input | gm
}
Run Code Online (Sandbox Code Playgroud)
使用此代码(Get-Info -input 'test'),我收到以下错误:
gm : You must specify an object for the Get-Member cmdlet.
At line:5 char:14
+ $input | gm
+ ~~
+ CategoryInfo : CloseError: (:) [Get-Member], InvalidOperationException
+ FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand
Run Code Online (Sandbox Code Playgroud)
我也只是尝试打印带有参数的详细语句,但我只得到一个空行。
为什么参数没有传递到函数中?
我正在尝试为机器人模拟编写代码。对于方向,我有一个 DU:
type Direction = North | East | South | West
Run Code Online (Sandbox Code Playgroud)
当类型为South且您给出向右转两次的指令时,是否有一个选项使该值实际上再次从 开始North?
我试图在我的字符串列表中添加一个额外的项目。我首先想到将项目添加到我的列表中::。
let test = ["hello"];;
let newtest = test :: ["world"];;
Run Code Online (Sandbox Code Playgroud)
这给我带来了错误:
let newtest = test :: ["world"];;
-----------------------^^^^^^^
stdin(36,24): error FS0001: This expression was expected to have type
'string list'
but here has type
'string'
Run Code Online (Sandbox Code Playgroud)
它才开始与@. 但是,在创建新列表的几个 SO 问题上,使用了该::方法。为了使用::,我最终创建了一个列表列表,这绝对不是我想要的。
let newtest01 = test :: [["world"]];;
val newtest01 : string list list = [["hello"]; ["world"]]
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下它们之间的区别吗?
python-3.x ×4
c# ×3
powershell ×3
python ×3
f# ×2
dictionary ×1
find ×1
function ×1
iteration ×1
list ×1
pie-chart ×1
tkinter ×1
tuples ×1
types ×1