关于Perl中字符串比较的接受答案 与"eq"vs"=="
它说 First, eq is for comparing strings; == is for comparing numbers.
"==进行数字比较:它将两个参数都转换为数字然后进行比较."
"eq进行字符串比较:两个参数必须在词汇上匹配(区分大小写)"
您只能使用eq来比较字符串,但
eq AND == 都可用于比较数字
数字是字符串的子集,所以我只是不明白为什么你会使用==
有没有理由为什么你想使用==来比较数值而不仅仅是使用eq?
我正在看上面的问题/答案,让自己很困惑
53 class First(object):
54 def __init__(self):
55 print "first"
56
57 class Second(First):
58 def __init__(self):
59 super(Second, self).__init__()
60 print "second"
61
62 class Third(First):
63 def __init__(self):
64 print "third"
65
66 class Fourth(Second, Third):
67 def __init__(self):
68 super(Fourth, self).__init__()
69 print "thats it"
Run Code Online (Sandbox Code Playgroud)
第四()
第三
秒
就是这样
53 class First(object):
54 def __init__(self):
55 print "first"
56
57 class Second(First):
58 def __init__(self):
59 #super(Second, self).__init__() <---- commented out
60 print "second"
61
62 …Run Code Online (Sandbox Code Playgroud) try:
#statement 1
#statement 2
except Exception, err:
print err
pass
Run Code Online (Sandbox Code Playgroud)
这可能是非常微不足道的,但直到现在我才真正想过它,我发现自己无法回答以下问题:
如果在语句1中引发错误,是否会执行语句2?
在语句1和语句2都引发错误的情况下,Exception如何处理?在上面的代码中打印出哪个错误?都?
7 foreach (@crons) {
8 unless (index($_, "cks") != -1) {
9 unless (index($_, "aab") != -1) {
10 unless (index($_, "lam") != -1) {
11 push (@found, $_);
12 }
13 }
14 }
15 }
Run Code Online (Sandbox Code Playgroud)
为什么以上不能提供与以下相同的输出:
7 foreach (@crons) {
8 unless (index($_, "cks") != -1 && index($_, "aab") != -1 && index($_, "lam") != -1) {
9 push (@found, $_);
10 }
11 }
Run Code Online (Sandbox Code Playgroud)
@crons有字符串列表,我试图得到所有没有"cks","aab"和"lam"的字符串
代码的第一部分做我想要的但是第二部分没有,在我看来,它应该......
任何人都可以解释为什么它们不一样,也不能给出相同的输出?
我有一个守护进程,它记录其操作:
LOG_FILE = '%s/%s.log' % (LOG_DIR, machine_name)
logging.basicConfig(filename=LOG_FILE,
level=logging.DEBUG,
format='%(asctime)s,%(msecs)05.1f '
'(%(funcName)s) %(message)s',
datefmt='%H:%M:%S')
Run Code Online (Sandbox Code Playgroud)
过了一会儿,日志大小变得非常大,设备上没有剩余空间。
所以我不得不手动删除日志,这很好。
保持日志大小不超过特定限制的最佳方法是什么?可以通过日志记录模块完成还是我需要编写外部脚本来每隔一段时间删除一次日志?
我有一个由10个Swarm节点组成的集群,通过docker swarm join命令启动
如果我想将docker实例扩展为15
docker service create --replicas 15
Run Code Online (Sandbox Code Playgroud)
docker swarm如何知道启动容器的位置?
它是循环还是考虑到计算资源(使用了多少cpu/mem)?
https://docs.docker.com/storage/#more-details-about-mount-types
卷的良好用例
- 当您想将容器的数据存储在远程主机或云提供商上,而不是本地时。
这是如何通过 docker volume 实现的?主机的/var/lib/docker下不是docker卷吗?
你能给我一个“docker volume create”的例子以及如何利用它吗?
现在,我在群集集群中有两个节点
$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
yey1njv9uz8adf33m7oz0h80f * redis2 Ready Active Leader
lbo91v2l15h24isfd5jegoxu1 redis3 Ready Active
Run Code Online (Sandbox Code Playgroud)
这是docker-compose.yml文件
version: "3"
services:
daggr:
# replace username/repo:tag with your name and image details
image: daggr
hostname: examplehostname
deploy:
replicas: 1
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "4000:80"
networks:
- webnet
visualizer:
image: dockersamples/visualizer:stable
ports:
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
deploy:
placement:
constraints: [node.role == manager]
networks:
- webnet
redis:
image: redis
networks:
- …Run Code Online (Sandbox Code Playgroud) 根据https://hub.docker.com/_/centos/ Centos7 容器必须使用 init 进程运行才能正确让 systemd 工作
Dockerfile
FROM centos:7
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
CMD ["/usr/sbin/init"]
Run Code Online (Sandbox Code Playgroud)
我希望在调用“docker run”时能够自动运行脚本,因此我将 CMD 行更改为
COPY startup.sh /usr/local/bin/startup.sh
CMD ["/usr/sbin/init", "/usr/local/bin/startup.sh"]
Run Code Online (Sandbox Code Playgroud)
当我 docker exec'd 进入容器时,我看到了该进程
root 1 …Run Code Online (Sandbox Code Playgroud) import java.util.*;
import static java.lang.String.format;
public class Dumpground {
private static final String[] fruits = new String[]{"apples", "bananas", "grapes", "oranges", "watermelons", "kiwis"};
static Map<String, Long> expirationMap;
public static void main(String[] args) {
long expiration = 1L;
expirationMap = new HashMap<>();
for (String fruit : values()){
expirationMap.put(fruit, expiration);
expiration++;
}
for (Map.Entry<String, Long> item : expirationMap.entrySet()) {
String key = item.getKey();
Long value = item.getValue();
System.out.println(format("key: %s, value: %s", key, value));
}
}
public static String[] values() {return fruits;}
}
Run Code Online (Sandbox Code Playgroud)
OUTPUT …
docker ×4
python ×3
docker-swarm ×2
perl ×2
centos7 ×1
hashmap ×1
java ×1
java-8 ×1
java-stream ×1
logging ×1