我是 Kubernetes 新手,尝试访问时遇到代码错误 403。
kubectl cluster info
Kubernetes master is running at https://x.x.x.x:6443
KubeDNS is running at https://x.x.x.x:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
"status": "Failure",
"message": "namespaces is forbidden: User \"system:anonymous\" cannot list namespaces at the cluster scope",
"reason": "Forbidden",
"details": {
"kind": "namespaces"
},
"code": 403
kubectl get pods --all-namespaces
kube-system calico-etcd-6629s 1/1 Running 0 10h
kube-system calico-kube-controllers-675684d4bb-5h28d 1/1 Running 0 10h
kube-system calico-node-r75wv 2/2 Running 0 10h
kube-system etcd-sp2013a.... 1/1 Running 0 10h
kube-system kube-apiserver-sp2013a ... 1/1 Running 0 10h
kube-system kube-controller-manager-sp2013a.... 1/1 …Run Code Online (Sandbox Code Playgroud) 所以我有可以用不同方式比较的对象。我有一个类层次结构,其中基础对象必须定义如何以各种可能的方式进行比较,而对于一些要比较的子类,有一种标准方法,因此可以为这些方法提供默认值。
这很难用语言解释,所以这里有一些代码
// This is akin to how `Comparable<in T>` is defined
interface AllComparisons<in T> {
// this interface has all the possible comparison methods
fun cmp1(other: T): Int
fun cmp2(other: T): Int
}
interface SomeComparisons<in T>: AllComparisons<T> {
// this interface has a default for some comparison methods
override fun cmp2(other: T) = -this.cmp1(other) // eg
}
// This is akin to how a comparable object `Obj: Comparable<Obj>` is defined
abstract class BaseClass: AllComparisons<BaseClass> // must define both cmp1 …Run Code Online (Sandbox Code Playgroud) 我有一个如下所示的字符串,我想从 Python 中的字符串中删除所有 \\x06 字符。
\n\n前任:
\n\ns = \'test\\x06\\x06\\x06\\x06\'\ns1 = \'test2\\x04\\x04\\x04\\x04\'\nprint(literal_eval("\'%s\'" % s))\nRun Code Online (Sandbox Code Playgroud)\n\n输出:\n 测试\xe2\x99\xa0\xe2\x99\xa0\xe2\x99\xa0\xe2\x99\xa0
\n\n我只需要字符串测试并删除所有 \\xXX。
\n如何使用lambda函数搜索精确的字符串?数据框如下:
A B
10 Mini
20 Mini Van
15 Mini
13 Mini Bus
Run Code Online (Sandbox Code Playgroud)
期望的结果
A B
10 Mini
15 Mini
Run Code Online (Sandbox Code Playgroud)
我尝试了以下,但都失败了:
df_temp = df_temp[df_temp['B'].apply(lambda x: 'mini' in x)] and
df_temp = df_temp[df_temp['B'].apply(lambda x: 'mini' in x.str.match())]
Run Code Online (Sandbox Code Playgroud)
谢谢
无法弄清楚为什么结果中的第一个键是"abc"而不是"c",正如我所期望的那样.(我使用的是Python 3.6.4)
数据结构很奇怪,因为我删除了不相关的键和值.
f = { 'replace' : { 'ab' : ''} }
r = {}
data = { 'abc' : 1, 'def' : 2, 'ghi' : 3, 'jkf' : 4, 'lmn' : 5 }
for d in data:
replaced = 'hello'
for x in f['replace']:
if x in d:
replaced = d.replace(x, f['replace'][x])
print(replaced)
else:
replaced = d
r.update( { replaced : data[d] } )
print(r)
Run Code Online (Sandbox Code Playgroud) 我有一个小问题.
我有以下功能:
def getCommands():
for file in os.listdir(com_dir):
if file.endswith(com_ext):
z = string.strip(file, '.gcom')
print z
Run Code Online (Sandbox Code Playgroud)
在目录(定义方com_dir)中有三个文件.
a.gcom
b.gcom
c.gcom
跑步的时候 getCommands()
输出如下:
a
b
显示文件a和b,但是,未显示c,所有文件都在目录中,并且所有文件都使用相同的文件扩展名:.gcom这也是com_ext可变的.
有没有人有任何提示,为什么文件c没有显示?
旁注:输出中似乎应该有一个空白区域c但是我不确定这是否在手头的问题中有任何部分并且不仅仅是脚本中其他位置的意外空间.
这里有点新的Python.
我目前有一个嵌套列表列表.我试图从0-25开始标记每个子列表.但是,如果两个子列表相同,则它们应具有相同的标签.
例如:
label_list = [['AH0'], ['AA1', 'K', 'S'], ['AH0', 'N', 'T'], ['AA1', 'K', 'S'], ['IH0', 'N'], ['AA1', 'K', 'S']]
Run Code Online (Sandbox Code Playgroud)
输出应该是 [0, 1, 2, 1, 4, 1]
因为第二,第四和第六个子列表是相同的.其余的子列表应该以连续的数字顺序标记.我知道我需要使用一个循环,但我很困惑,任何人都有任何建议如何处理这个?谢谢.
我有一个小问题。我在 ubuntu 16.04 机器上,在 python 脚本中我想启动一个子进程,该子进程应在用户的主目录中启动。我尝试过:
subprocess.Popen('echo "Test"', cwd="~", shell=True,universal_newlines=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, executable="/bin/bash")
Run Code Online (Sandbox Code Playgroud)
但是当我这样做时,我收到以下错误:
proc = subprocess.Popen('echo "test"', cwd="~", shell=True,universal_newlines=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, executable="/bin/bash")
File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: '~'
Run Code Online (Sandbox Code Playgroud)
我不确定我做错了什么,因为当您在 cd 命令中输入 ~ 时,它会将您切换到主目录。我希望有人能找到解决方案,解释为什么它不能以这种方式工作,以及在主目录中启动它的正确方法是什么。
python ×6
python-3.x ×2
interface ×1
jvm ×1
kotlin ×1
kubernetes ×1
linux ×1
list ×1
loops ×1
nested ×1
oop ×1
pandas ×1
popen ×1
python-2.7 ×1
subprocess ×1