我以表格形式输出命令.我正在从结果文件中解析此输出并将其存储在字符串中.一行中的每个元素由一个或多个空格字符分隔,因此我使用正则表达式匹配1个或多个空格并将其拆分.但是,在每个元素之间插入一个空格:
>>> str1="a b c d" # spaces are irregular
>>> str1
'a b c d'
>>> str2=re.split("( )+", str1)
>>> str2
['a', ' ', 'b', ' ', 'c', ' ', 'd'] # 1 space element between!!!
Run Code Online (Sandbox Code Playgroud)
有一个更好的方法吗?
将每个拆分str2附加到列表后.
我希望foo()不要修改数组.所以我把数组声明foo()为const
如果我编译这段代码,编译器就会抱怨:
#include <stdio.h>
void foo(const int arr[5][5])
{
int i,j;
for( i = 0; i < 5; i++)
{
for( j = 0; j < 5; j++)
{
printf("%d\n", arr[i][j]);
}
}
}
int main()
{
int val = 0;
int i,j;
int arr[5][5];
for( i = 0; i < 5; i++)
{
for( j = 0; j < 5; j++)
{
arr[i][j] = val++;
}
}
foo(arr);
}
Run Code Online (Sandbox Code Playgroud)
警告是:
allocate.c: In function 'main':
allocate.c:26:9: warning: …Run Code Online (Sandbox Code Playgroud) 我想从源服务器 S 连接到我的目标服务器 T。但是,与 T 的连接仅限于中间服务器 I。由于 S 无法连接到 T,我使用以下方法创建了从 S 到 T 的 ssh 隧道:
ssh -N -f -L port:T:22 I
现在我可以使用以下方法连接到 T:
ssh -p port user@localhost
但我的问题是我必须 ping 到目标 T。我如何使用隧道进行 ping。