嘿,我是 python 脚本新手,我想知道是否有人可以帮助我理解我如何使用 python 或任何方便的脚本语言来挑选特定的数据值(只是 Excel 表上的几个任意列),并获取数据和输入到 chrome 等网络浏览器。只是一个关于它应该如何运作的一般想法会非常有帮助,如果有一个可用的 API 会很高兴知道。
任何建议表示赞赏。谢谢。
我制作了一个简单的 powershell 脚本,它有两个参数。如果我尝试不带参数执行脚本,它工作正常。如果我尝试使用两个参数之一执行它,它工作正常。当我尝试使用两个参数运行脚本时,出现以下错误:
Parameter set cannot be resolved using the specified named parameters.
Run Code Online (Sandbox Code Playgroud)
它还有一个关于 AmbiguousParameterSet 的花絮。
我的脚本的参数部分如下所示:
[CmdletBinding(DefaultParameterSetName="None")]
param(
[Parameter(Mandatory=$False, ParameterSetName="BuildExclude")]
[ValidateSet('proj1','proj2', 'proj3', 'proj4')]
[string[]]$BuildExclude,
[Parameter(Mandatory=$False, ParameterSetName="SkipDbRestore")]
[switch]$SkipDbRestore
)
Run Code Online (Sandbox Code Playgroud)
这些用法有效:
.\RunScript.ps1 -BuildExclude proj1, proj2
.\RunScript.ps1 -SkipDbRestore
.\RunScript.ps1
Run Code Online (Sandbox Code Playgroud)
由于上述原因,此用法不起作用:
.RunScript.ps1 -BuildExclude proj1, proj2 -SkipDbRestore
Run Code Online (Sandbox Code Playgroud)
即使我颠倒了参数的顺序,它也不起作用。我尝试添加参数位置,使 BuildExclude=0 和 SkipDbRestore=1 ,希望如果我至少保持它们的顺序,我就能让它们一起工作。但这给了我同样的歧义错误。我错过了什么?理想情况下,我希望能够以任何顺序调用带有参数的脚本并让它做正确的事情。
parameters powershell scripting parameter-passing optional-parameters
我之前问过这个问题,但是我更新了我的代码并且出现了同样的问题。当pathToLoad(Application.persistentDataPath+[save name]). 这是我的代码:
这是保存/加载代码:
public void GetDatesFromFile(string pathToLoad)
{
Debug.Log("It is here!");
if (File.Exists(pathToLoad))
{
Debug.Log("Exists");
using (StreamReader reader = File.OpenText(pathToLoad))
{
string currentLine = "";
string[] currentElements;
string[] separatorString = new string[] { "," };
currentLine = reader.ReadLine();
currentElements = currentLine.Split(separatorString, StringSplitOptions.RemoveEmptyEntries);
MainMenuBasicBehaviour.theTime = currentElements[0];
MainMenuBasicBehaviour.theDate = currentElements[1];
reader.Close();
}
}
else
{
Debug.Log("No Exists");
using (File.CreateText(pathToLoad))
{
using (TextWriter writer = new StreamWriter(pathToLoad, false))
{
writer.WriteLine("00:00:00,00/00/0000,1,1,500,20000,1500,50,20,10,5,2,1,1,0,10,50,50");
writer.Close();
}
MainMenuBasicBehaviour.theTime = "00:00:00";
MainMenuBasicBehaviour.theDate = "00 / 00 …Run Code Online (Sandbox Code Playgroud) 问题是:显示每行文本中的 和 字符。
这是我的代码:
while read line
do
a=`echo $line | cut -c 2`
b=`echo $line | cut -c 7`
echo -n $a
echo $b
done
Run Code Online (Sandbox Code Playgroud)
问题是当第一个字符是空格时,它不会打印空格。例如,
Input:
A big elephant
Expected output:
e
My output:
e
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
我是构建 Makefile 的新手,并且正在尝试确定如果变量为空,构建目标将如何失败。我希望能够将变量作为环境变量或 make 参数传入。
假设我有一个这样的 makefile:
VER ?=
step0:
echo "step0 should work"
step1:
echo "step1 should enforce variable"
ifeq($(VER), "")
$(error VER is not set)
endif
echo "Success: Value of Ver ${VER}"
step2:
echo "step2 should work"
Run Code Online (Sandbox Code Playgroud)
我希望能够运行以下测试用例:
VER="foo" make step1
# should result in printing the "Success:" line
Run Code Online (Sandbox Code Playgroud)
或者
export VER=foo
make step1
# should result in printing the "Success:" line
Run Code Online (Sandbox Code Playgroud)
或者
make step1 VER=foo
# should result in printing the "Success:" line
Run Code Online (Sandbox Code Playgroud)
或者
make step1
# …Run Code Online (Sandbox Code Playgroud) 我有三个文件。我需要根据一列加入它们并执行一些转换。
file1.dat(第1列用于加入)
123,is1,ric1,col1,smbc1
123,is2,ric1,col1,smbc1
234,is3,ric3,col3,smbc2
345,is4,ric4,,smbc2
345,is4,,col5,smbc2
Run Code Online (Sandbox Code Playgroud)
file2.dat(第1列用于加入)
123,abc
234,bcd
Run Code Online (Sandbox Code Playgroud)
file3.dat(第4列用于加入)
r0c1,r0c2,r0c3,123,r0c5,r0c6,r0c7,r0c8
r2c1,r2c2,r2c3,123,r2c5,r2c6,r2c7,r2c8
r3c1,r3c2,r3c3,234,r3c5,r3c6,r3c7,r3c8
r4c1,r4c2,r4c3,345,r4c5,r4c6,r4c7,r4c8
Run Code Online (Sandbox Code Playgroud)
预期输出 (output.dat)
123,r0c5,is1,ric1,smbc1,abc,r0c8,r0c6,col1,r0c7,r0c1,r0c2,r0c3
123,r0c5,is2,ric1,smbc1,abc,r0c8,r0c6,col1,r0c7,r0c1,r0c2,r0c3
123,r2c5,is1,ric1,smbc1,abc,r2c8,r2c6,col1,r2c7,r2c1,r2c2,r2c3
123,r2c5,is2,ric1,smbc1,abc,r2c8,r2c6,col1,r2c7,r2c1,r2c2,r2c3
234,r3c5,is3,ric3,smbc2,bcd,r3c8,r3c6,col3,r3c7,r3c1,r3c2,r3c3
345,r4c5,is4,ric4,smbc2,N/A,r4c8,r4c6,N/A,r4c7,r4c1,r4c2,r4c3
345,r4c5,is4,N/A,smbc2,N/A,r4c8,r4c6,col5,r4c7,r4c1,r4c2,r4c3
Run Code Online (Sandbox Code Playgroud)
我写了以下 awk 命令。
awk '
BEGIN {FS=OFS=","}
FILENAME == ARGV[1] { temp_join_one[$1] = $2"|"$3"|"$4"|"$5; next}
FILENAME == ARGV[2] { exchtbunload[$1] = $2; next}
FILENAME == ARGV[3] { s_temp_join_one = temp_join_one[$4];
split(s_temp_join_one, array_temp_join_one,"|");
v3=(array_temp_join_one[1]==""?"N/A":array_temp_join_one[1]);
v4=(array_temp_join_one[2]==""?"N/A":array_temp_join_one[2]);
v5=(array_temp_join_one[4]==""?"N/A":array_temp_join_one[4]);
v6=(exchtbunload[$4]==""?"N/A":exchtbunload[$4]);
v9=(array_temp_join_one[3]==""?"N/A":array_temp_join_one[3]);
v11=($2=""?"N/A":$2);
print $4, $5, v3, v4, v5, v6, $8, $6, v9, $7, $1, v11, $3 > …Run Code Online (Sandbox Code Playgroud) 我试图将主硬盘序列号作为echo稍后要编辑的变量。
我已经使用了它并且它有效:
for /f "tokens=2 delims== " %%k in ('WMIC path win32_physicalmedia get serialnumber /value') do (for /f "delims=" %%l in ("%%k") do set "SerialNumber=%%l")
Run Code Online (Sandbox Code Playgroud)
但是,它只执行最后一个序列号,我想获取主要序列号。
如果我使用这个命令,
"wmic path win32_physicalmedia where tag='\\\\.\\PHYSICALDRIVE0' get serialnumber /value"
Run Code Online (Sandbox Code Playgroud)
然后我只得到所需的序列号。
问题是当我尝试修改工作代码时,运行 bat 时出现错误:
无效动词。
努力上班:
for /f "tokens=2 delims== " %%k in ('wmic path win32_physicalmedia where tag='\\\\.\\PHYSICALDRIVE0' get serialnumber /value') do (for /f "delims=" %%l in ("%%k") do set SerialNumber=%%l)
Run Code Online (Sandbox Code Playgroud)
错误:
无效动词
如果我只运行:
wmic path win32_physicalmedia where tag='\\\\.\\PHYSICALDRIVE0' get serialnumber /value in …Run Code Online (Sandbox Code Playgroud) sub Solution{
$matchflag=0;
$occurence=0;
#OUPTUT [uncomment & modify if required]
my $ind=index($m,$p);
if ($ind!=-1){
$matchflag=1;
}
$occurence= () = $m =~ /$q/g;
print("$matchflag\n");
print($occurence);
}
#INPUT [uncomment & modify if required]
$n=<STDIN>;
$m=<STDIN>;
$p=<STDIN>;
$q=<STDIN>;
Solution();
Run Code Online (Sandbox Code Playgroud)
你好,有人可以告诉我这段代码有什么问题吗?它给了我以下输出。
6
naman
nam
n
0
1
Run Code Online (Sandbox Code Playgroud)
显然 0 应该是 1,因为 nam 存在于 naman 字符串中。并且 1 也应该是 2 因为 n 在字符串中出现两次。
这段代码有什么问题?
我正在寻找一种自动化脚本执行的方法,它有 5 个提示:4xYES和1*NO. 提示总是位于同一个地方:
是 | 是 | 是 | 没有| 是的
类似于下面的示例(基于 3 个提示):
#!/bin/bash
read -r -p "Ready to proceed? [yes/no]: " input
if [[ "$input" = "yes" ]]
then
read -r -p "Or maybe abort? [yes/no]: " answer
if [[ "$answer" = "no" ]]
then
read -r -p "So... proceed? [yes/no]: " response
if [[ "$response" = "yes" ]]
then echo "NICE JOB!!!"
fi
fi
fi
Run Code Online (Sandbox Code Playgroud)
显然,通过管道向这个脚本传递一个“是”或“否”是行不通的,因为预期的响应是不同的。不知道是否有办法通过管道传递多个参数。
我想创建一个数组PROMPT=(yes no yes),并$i …
我希望能够在运行时以十六进制看到我的程序的输出,但是如果我将输出通过管道传输到 xxd 它只会在程序停止运行后打印。
这些是我尝试过的事情:
./a.out | while read LINE; do echo "$LINE" | xxd; done
./a.out | xxd
Run Code Online (Sandbox Code Playgroud)
这是我的控制台的样子:(箭头是我的评论)
1 <-- input
2 <-- input
3 <-- input
4 <-- input
a <-- input (program ends after this input)
00000000: 6465 6667 0a defg.. <-- output
00000000: 6465 6667 0a defg.. <-- output
00000000: 6465 6667 0a defg.. <-- output
00000000: 6465 6667 0a defg.. <-- output
Run Code Online (Sandbox Code Playgroud)
但这就是我想要的
1 <-- input
00000000: 6465 6667 0a defg.. <-- output
2 <-- …Run Code Online (Sandbox Code Playgroud)