我写了这样的东西来将逗号分隔的列表转换为字典。
def list_to_dict( rlist ) :
rdict = {}
i = len (rlist)
while i:
i = i - 1
try :
rdict[rlist[i].split(":")[0].strip()] = rlist[i].split(":")[1].strip()
except :
print rlist[i] + ' Not a key value pair'
continue
return rdict
Run Code Online (Sandbox Code Playgroud)
有没有办法
for i, row = enumerate rlist
rdict = tuple ( row )
Run Code Online (Sandbox Code Playgroud)
或者其他的东西?
我有多个(1000 多个)客户端连接到单个服务器并发送一些日志数据。
服务器分析数据并在必要时做出响应。
PUB/SUB是一个方向(监视器示例)。
REQ/REP无法识别对等方并专门回复对等方(仅用于 ACK 等)。
我需要注册这些客户,识别他们并在分析他们的日志后能够做出回应。
使用套接字,我有客户端套接字,在接受之后我可以使用该套接字进行响应,并且客户端可以在我连接到的同一个套接字上接收。
我在 0mq 的第一周没有在 ZeroMQ 中找到这样的东西。
ROUTER socket 可以打印对等方的 id,但是如何使用该 id 回复该对等方?
有没有更好的方法来处理这个问题?
我有一个程序,需要输入数字列表(逗号分隔),我应该运行以这些数字开头的文件
myprogram.py 1,6,8
Run Code Online (Sandbox Code Playgroud)
必须检查文件1001_filename, 1004_filename, 6001_filename, 8003_filename, 8004_filename等,
一种方法是迭代 3 次(一次为 1*, 6*, 8* )并执行 if
for file_type in file_types:
file.startswith(file_type):
Run Code Online (Sandbox Code Playgroud)
但我怎样才能匹配列表中的任何一个呢?
是否有一个正则表达式可以执行以下操作:
file.startswith(any of file_types): file_types 这里是1,6,8 或有什么效果?
我/bin/sh: -c: line 1: syntax error: unexpected end of file在下面的makefile中获得if语句-怎么了?(我的提示是/tmp >。)
/tmp > make test
set -e
if [[ -f /tmp/device ]] ; then
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** [test] Error 2
/tmp > cat Makefile
.ONESHELL:
test:
set -e
if [[ -f /tmp/device ]] ; then
echo 'Do something'
fi
Run Code Online (Sandbox Code Playgroud)
我正在使用GNU Make 3.81。
我正在运行一个吐出 IP 的命令,我需要将其提供给位于特定位置的另一个程序,我该怎么做?
$ command1 | command2 -c configfile -i "$1" status
Run Code Online (Sandbox Code Playgroud)
“$1”是我想要 command1 结果所在的位置。
谢谢。
我有格式xxxxxxxx-abcdxxxxx的主机名x不是一个设定的数字所以不能使用打印,text[10:14]因为我没有设置位置,唯一的模式是4个字符后-.