当hash()在Python 3中调用method时,我注意到在使用int数据类型但使用stringtype 时,它不会返回长整数。
这应该这样工作吗?如果确实是这种情况,那么int对于具有短哈希值的类型,由于它太短会不会引起冲突?
for i in [i for i in range(5)]:
print(hash(i))
print(hash("abc"))
Run Code Online (Sandbox Code Playgroud)
结果:
0
1
2
3
4
4714025963994714141
Run Code Online (Sandbox Code Playgroud) 我有以下目录结构,我正在尝试创建一个简单的bash脚本,用模式foo*/scripts/*A.txt打印出所有文件(即foo1/scripts/fileA.txt和foo2/scripts/fileA.txt)
$ tree
.
??? bar
? ??? scripts
? ??? fileA.txt
? ??? fileB.txt
??? bash_scrap.sh
??? foo1
? ??? scripts
? ??? fileA.txt
? ??? fileB.txt
??? foo2
??? scripts
??? fileA.txt
??? fileB.txt
Run Code Online (Sandbox Code Playgroud)
我现在创建一个脚本bash_scrap.sh,我想用第一个命令行参数给出的模式打印所有文件名.
$ cat bash_scrap.sh
#!/bin/bash
FILES=$1
for f in $FILES
do
echo "Processing $f file..."
printf "\n\n"
done
Run Code Online (Sandbox Code Playgroud)
当我直接定义FILES并在终端中运行脚本时,我得到了预期的输出
$ FILES=foo*/scripts/*A.txt
$ for f in $FILES; do echo "Processing $f file..."; printf "\n\n"; done
Processing foo1/scripts/fileA.txt file...
Processing foo2/scripts/fileA.txt file...
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试将此作为带有输入模式的脚本运行,它只打印出第一个文件名.
$ ./bash_scrap.sh foo*/scripts/*A.txt …Run Code Online (Sandbox Code Playgroud) 给定两个字符串:
a="hello h"
b=""
Run Code Online (Sandbox Code Playgroud)
在bash 4.2版中,其regex比较结果为true
[[ "${a}" =~ "${b}" ]]
echo $? # 0
Run Code Online (Sandbox Code Playgroud)
在bash 3.2版中,正则表达式的比较结果为false
[[ "${a}" =~ "${b}" ]]
echo $? # 2
Run Code Online (Sandbox Code Playgroud)
编辑:第一个结果在带有4.2.46(2)-发行版bash的linux操作系统上运行,而第二个结果在运行3.2.57(1)-发行版bash的OS Mojave上运行。
由于我对 json 术语不太了解,我举一个例子:
假设我有一个 json:
{
"var1": "foo",
"var2": "bar",
...
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能jq将其转换为:
{
"Variables":
{
"var1": "foo",
"var2": "bar",
...
}
}
Run Code Online (Sandbox Code Playgroud) 我尝试使用以下内容bash来访问文件夹的内容;
test_dir="/some_dir/dir_test"
ssh -t -t user@remote-host "
if [ -d '$test_dir' ]; then
sudo chown -R user:admin '$test_dir'
echo '$test_dir'/*
if [ '$(ls -A $test_dir)' ]; then
sudo rm -rf '$test_dir'/*
echo '$test_dir'/*
fi"
Run Code Online (Sandbox Code Playgroud)
该脚本尝试检查是否/some_dir/dir_test为空,如果不是,则删除该文件夹中的所有文件;但我收到以下错误;
ls: cannot access '/some_dir/dir_test': No such file or directory
/some_dir/dir_test
drwxr-xr-x. 3 sys admin 16 Sep 23 15:03 dir_test
Run Code Online (Sandbox Code Playgroud)
不过,我ssh可以remote-host和ls -A /some_dir/dir_test。
我想知道如何解决它。
我在 SSH 配置中有这个设置( /etc/ssh/sshd_config)
AllowUsers root john
Run Code Online (Sandbox Code Playgroud)
我想添加jane到行尾
AllowUsers root john jane
Run Code Online (Sandbox Code Playgroud)
我试过了
sed -i -e '/AllowUsers/{s/:/ /g;s/.*=//;s/$/ jane/p}' /etc/ssh/sshd_config && cat /etc/ssh/sshd_config
Run Code Online (Sandbox Code Playgroud)
我一直得到这个结果
AllowUsers root john jane
AllowUsers root john jane
Run Code Online (Sandbox Code Playgroud)
为什么会有多余的线?
如果我以某种方式运行该命令两次
我会得到这些结果
AllowUsers root john jane
AllowUsers root john jane
AllowUsers root john jane
AllowUsers root john jane
Run Code Online (Sandbox Code Playgroud)
再次运行 x3 次,将得到这个
AllowUsers root john jane
AllowUsers root john jane
AllowUsers root john jane
AllowUsers root john jane
AllowUsers root john jane …Run Code Online (Sandbox Code Playgroud) 2>3是假的。对于and,如果整个表达式中有一个 false,则应该返回 false。
print(3>2 and 2>3 and 7>5 or 1>0)
Run Code Online (Sandbox Code Playgroud)
谢谢你,
我的shell脚本如下:
#!/bin/bash
account0=0xf2de2e86b9b634f655e441a4e8353c9bf59352d7
passwd=123456
data={"jsonrpc":"2.0","method":"personal_unlockAccount","id":1,"params":[$account0,$passwd]}
echo $data
Run Code Online (Sandbox Code Playgroud)
我的期望是(通知"):
{"jsonrpc":"2.0","method":"personal_unlockAccount","id":1,"params":[0xf2de2e86b9b634f655e441a4e8353c9bf59352d7,123456]}
Run Code Online (Sandbox Code Playgroud)
不
{jsonrpc:2.0,method:personal_unlockAccount,id:1,params:[0xf2de2e86b9b634f655e441a4e8353c9bf59352d7,123456]}
Run Code Online (Sandbox Code Playgroud)
:我不希望使用转义字符,怎么样?像内容插入到xml标签" <![CDATA[..."..]]>"
我正在尝试从网站复制字符串并将其粘贴到另一个程序中。但是我首先必须删除“。” 和字符串中的“-”。例如 它是“ 123.345.322.22-00”,但我需要它是“ 1233453222200”。
我试过使用replace()以及replace和join()。是python 3.7.2
#copy number
pg.moveTo(238,419)
pg.click(238,419,clicks=3)
pg.hotkey('ctrl','c')
cep = pyperclip.paste()
print(cep)
cepnovo= [cep.split(".").join("")]
print(cepnovo)
Run Code Online (Sandbox Code Playgroud)
我懂了 AttributeError: 'list' object has no attribute 'join'
实际结果 AttributeError: 'list' object has no attribute 'join'
期望的是输出不带"."和的字符串"-"。