我是 Powershell 的新手,据我所知,它没有像 Python 中的 PEP8/PEP484 这样的东西。我从 Microsoft找到了这份文档,并从 Posh Code 找到了这份第三方指南。我写了以下函数:
function Invoke-Authenticate {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]
# IP address of the OME server
$Ip,
[Parameter(Mandatory)]
# Credentials for the OME server
[pscredential] $Credentials
)
$SessionUrl = "https://$($IpAddress)/api/SessionService/Sessions"
$Type = "application/json"
$UserDetails = @{"UserName"=$Credentials.username;"Password"=$Credentials.GetNetworkCredential().password;
"SessionType"="API"} | ConvertTo-Json
$Headers = @{}
try {
$SessResponse = Invoke-WebRequest -Uri $SessionUrl -Method Post -Body $UserDetails -ContentType $Type `
-SkipCertificateCheck
if ($SessResponse.StatusCode -eq 200 -or $SessResponse.StatusCode -eq 201) {
# …Run Code Online (Sandbox Code Playgroud) 我已经浏览了这里的文档。奇怪的是,我找不到任何提及如何使用 PowerShell 简单连接(而不是挂载)SMB 共享的内容。我正在寻找Python中的等价物:
with smbclient.open_file(args.share, username=args.smbuser, password=args.smbpass, mode='w', encoding='utf-8-sig', newline='') as file:
file.write("stuff")
Run Code Online (Sandbox Code Playgroud) 我看到很多措辞相似的问题,但是我很难想出这个语法。
给定一个单词列表,我想打印所有没有特殊字符的单词。
我有一个正则表达式,可以识别带有特殊字符的单词\w*[\u00C0-\u01DA']\w*。我已经看到很多答案都带有相当简单的场景,比如一个简单的 word。但是,我无法找到否定组的任何内容 - 我已经看到了几组不同的语法来包含否定前瞻?!,但我一直无法想出一种适用于它的语法。
在我的情况下,给出一个字符串,如:“应该打印 n?t thìs”
应打印should和print而不是其他两个词。re.findall("(\w*[\u00C0-\u01DA']\w*)", paragraph.text)给你特殊字符 - 我只是想反转它。
标题说明了一切.我知道pickle可以做到,但我真的不想打开一个文件只是为了转换一个数字.我想采用浮点数('nan')并以二进制格式通过网络发送.
试图找出 Kibana 的 ELASTICSEARCH_HOSTS 语法,但我收到:
kib01 | FATAL Error: [config validation of [elasticsearch].hosts]: types that failed validation:
kib01 | - [config validation of [elasticsearch].hosts.0]: expected URI with scheme [http|https].
kib01 | - [config validation of [elasticsearch].hosts.1]: could not parse array value from json input
Run Code Online (Sandbox Code Playgroud)
来自 Kibana 本身或:
ERROR: The Compose file './docker-compose.yml' is invalid because:
services.kibana.environment.ELASTICSEARCH_HOSTS contains ["http://es01:9200", "http://es02:9200", "http://es03:9200", "http://es04:9200"], which is an invalid type, it should be a string, number, or a null
Run Code Online (Sandbox Code Playgroud)
来自 Docker 撰写。
我的最新迭代是:
environment: …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 PowerShell 中复制以下 Python 代码段的功能:
allowed_mac_separators = [':', '-', '.']
for sep in allowed_mac_separators:
if sep in mac_address:
test = codecs.decode(mac_address.replace(sep, ''), 'hex')
b64_mac_address = codecs.encode(test, 'base64')
address = codecs.decode(b64_mac_address, 'utf-8').rstrip()
Run Code Online (Sandbox Code Playgroud)
它需要一个 MAC 地址,删除分隔符,将其转换为十六进制,然后是 base64。(我没有编写 Python 函数,也无法控制它或它是如何工作的。)
例如,MAC 地址AA:BB:CC:DD:E2:00将转换为AABBCCDDE200,然后转换为,b'\xaa\xbb\xcc\xdd\xe2\x00'最后作为输出b'qrvM3eIA'。我尝试做类似的事情:
$bytes = 'AABBCCDDE200' | Format-Hex
[System.BitConverter]::ToString($bytes);
Run Code Online (Sandbox Code Playgroud)
但这会产生MethodException: Cannot find an overload for "ToString" and the argument count: "1".,我不确定它在寻找什么。我发现的所有使用该调用的示例都只有一个参数。这有效:
[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes('AABBCCDDE200'))
但显然不会先将其转换为十六进制,从而产生不正确的结果。任何帮助表示赞赏。
因此,这些年来如何使用 MASM 似乎发生了大约 50 次变化,因为我找到了大量答案,但没有一个有效。
我想知道的是你如何在 MASM 上调用类似 exitprocess 的东西?我包含哪些文件/它们在哪里?我正在使用 VS2015 社区版中内置的 ml.exe。我的根驱动器或 VS 上都没有 MASM 文件夹。VS 没有附带任何 .inc 文件(我在驱动器上进行了详尽的搜索)。我只想做一些简单的事情:
.386
.model flat, stdcall
option casemap:none
includelib ?????????????
include ?????????????
.data
.code
start:
invoke ExitProcess,0
end start
Run Code Online (Sandbox Code Playgroud)
我试过只包含 msvcrt.lib 但这也不起作用。
我正在尝试从<v:imagedata r:id="rId7" o:title="1-REN"/>带有命名空间的 Word 文档中查找所有内容xmlns:v="urn:schemas-microsoft-com:vml",但我无法弄清楚语法到底是什么。
这些文档只涵盖了非常直接的情况,并且在加入了 URN 和 VML 组合后,我似乎无法让我在网上看到的任何示例都可以工作。有人碰巧知道它是什么吗?
我正在尝试做这样的事情:
namespace = {'v': "urn:schemas-microsoft-com:vml"}
results = ET.fromstring(xml).findall("imagedata", namespace)
for image_id in results:
print(image_id)
Run Code Online (Sandbox Code Playgroud)
编辑:@aneroid 所写的是 1000% 正确的答案并且非常有帮助。你应该点赞。也就是说,在理解了所有这些之后 - 我选择了 BS4 答案,因为它在两行中完成了我需要的全部工作。如果您实际上并不关心命名空间,那似乎更容易。
在 Python 中,有一些简单的衬垫可以采用类似 的路径C:\somefolder\somesubfolder\file.csv,抓取C:\somefolder\somesubfolder\零件(如果存在),并告诉您它是否有效。我必须考虑用户可能传递绝对路径、相对路径或根本不传递路径并且文件仅写入同一目录。一些潜在的用户输入:
..\an_invalid_folder\something.csvC:\an invalid folder\something.csvsomething.csvsome_absolute_path\something.csv在 PowerShell 中,我发现这非常麻烦。我发现像 Split-Path 这样的东西有奇怪的行为 - 例如:如果你只通过C:\然后使用 leaf 选项运行 split path ,它会告诉你C:\是叶子。现在,我明白他们为什么这样做,但这使得解决上述问题变得有点难看。下面是我的想法 - PowerShell 没有类似os.path库的东西可以更干净地处理所有这些情况吗?
$ParentPath = $(Split-Path -Path $OutputFilePath -Parent)
if ($ParentPath -ne "") {
if (-not $(Test-Path -PathType Container $ParentPath)) {
Write-Error "The path you provided for $($OutputFilePath) is not valid." -ErrorAction Stop
}
}
if (Test-Path $(Split-Path -Path $OutputFilePath -Leaf) -PathType Container) {
Write-Error "You must …Run Code Online (Sandbox Code Playgroud) 我正在关注英雄示例的 Angular 之旅,并以相同的方式构建了(我认为)我的代码版本,但没有收到我期望的行为。
import { Injectable } from '@angular/core';
import { PORTS } from './mock-ports'
import { Port } from './port'
import { Observable, of } from 'rxjs';
import { HttpClient, HttpHeaders } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class UpdateportsService {
private controller_url = '/gelante/getports/150013889525632'
private controller_ip = 'http://localhost:8080'
getPorts(): Observable<Port[]> {
return this.http.get<Port[]>(this.controller_ip + this.controller_url)
}
constructor(private http: HttpClient) { }
}
Run Code Online (Sandbox Code Playgroud)
const myObserver = {
next: x => console.log('Observer got a next value: ' …Run Code Online (Sandbox Code Playgroud)