代码很简单:
import locale
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8') # I tried de_DE and de_DE.utf8 too
locale.currency(0)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.7/locale.py", line 267, in currency
raise ValueError("Currency formatting is not possible using "
ValueError: Currency formatting is not possible using the 'C' locale.
Run Code Online (Sandbox Code Playgroud)
当我在 ubuntu 上运行它时它有效。然而,在高山上,会弹出此错误。我尝试了此评论中的解决方法,但没有成功。我还添加/usr/glibc-compat/bin
到PATH
该脚本之上,但没有帮助。
有什么办法可以让语言环境在高山上工作吗?
自己尝试一下:
docker run --rm alpine sh -c "apk add python3; python3 -c 'import locale; locale.setlocale(locale.LC_ALL, \"de_DE.UTF-8\"); locale.currency(0)'"
Run Code Online (Sandbox Code Playgroud)
更新:这个仓库也不起作用。
更新:我也尝试过这个 …
我希望 kubernetes 中的部署有权从集群内自行重启。
我知道我可以创建一个 serviceaccount 并将其绑定到 pod,但我缺少允许'*'
该命令的最具体权限的名称(即不仅仅是允许)
kubectl rollout restart deploy <deployment>
Run Code Online (Sandbox Code Playgroud)
这就是我所拥有的,并且???是我所缺少的
apiVersion: v1
kind: ServiceAccount
metadata:
name: restart-sa
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: default
name: restarter
rules:
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["list", "???"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: testrolebinding
namespace: default
subjects:
- kind: ServiceAccount
name: restart-sa
namespace: default
roleRef:
kind: Role
name: restarter
apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
kind: Pod
metadata:
name: example
spec:
containers:
- image: nginx
name: …
Run Code Online (Sandbox Code Playgroud) 我想输入提示以下函数:
def get_obj_class(self) -> *class*:
return self.o.__class__
Run Code Online (Sandbox Code Playgroud)
self.o
可以是任何类型,它是在运行时确定的.
*class*
显然不是这里的答案,因为它是无效的语法.但是,什么是正确的答案?我找不到任何关于此的文档,任何帮助表示赞赏.
在类似的说明中,如果我有一个f(cls: *class*)
返回实例的函数cls
,有没有办法键入提示返回值?
这是设置:
\n\n program [root]\n \xe2\x94\x9c\xe2\x94\x80 main.py\n \xe2\x94\x9c\xe2\x94\x80 utils\n | |\n | \xe2\x94\x94\xe2\x94\x80 util1.py\n \xe2\x94\x94\xe2\x94\x80 plugins\n |\n \xe2\x94\x94\xe2\x94\x80 plugin1.py\n
Run Code Online (Sandbox Code Playgroud)\n\n现在我想动态加载所有插件,使用pkgutil.iter_modules()
,效果很好。直到我放入from ..utils import util1
plugin1。然后我得到
ValueError: attempted relative import beyond top-level package\n
Run Code Online (Sandbox Code Playgroud)\n\n我尝试了两件事。首先,我用了importer.find_module().load_module()
这样使用:
for importer, module_name, ispkg in pkgutil.iter_modules(plugins.__path__):\n importer.find_module(module_name).load_module(module_name)\n
Run Code Online (Sandbox Code Playgroud)\n\n由于__package__
plugin1中为空,我也尝试过importlib.import_module()
这样:
module = importlib.import_module(package + "." + module_name, package=package)\n
Run Code Online (Sandbox Code Playgroud)\n\n以package
as 开头"plugins"
并将每个子文件夹添加plugins
到字符串中,并用 a 分隔.
我有什么想法可以让这项工作成功吗?
\n标题基本上说明了一切,对于存储cronjob所需的密码,有什么好习惯?
例如,如果您想定期运行cron到另一台计算机上,您不仅会将用户名和密码简单地放在bash脚本中,是吗?
ssh当然是一个不好的例子,因为您可以使用密钥对,但是也许您就可以达到我想要的目的。将密码存储在使用openssl加密的文件中吗?但是,当您查看用于加密文件的脚本时,您显然拥有仅解密文件的所有信息。
我已经想了好一阵子了,我永远无法想出答案,任何想法都值得赞赏。
这似乎是一个如此简单的任务,但我现在在这上面花了太多时间,没有解决方案。这是设置:
class A(object):
def __init__(self, x=0):
print("A.__init__(x=%d)" % x)
class B(object):
def __init__(self, y=1):
print("B.__init__(y=%d)" % y)
class C(A, B):
def __init__(self, x=2, y=3, z=4):
super().__init__(x=x, y=y)
print("C.__init__(z=%d)" % z)
Run Code Online (Sandbox Code Playgroud)
这就是想法,但这当然会导致
TypeError: __init__() got an unexpected keyword argument 'y'
Run Code Online (Sandbox Code Playgroud)
其他所有尝试都失败了类似的方式,我可以找到没有用正确的解决方案在互联网上的资源。唯一的解决方案包括将所有 init 参数替换为*args, **kwargs
. 这不太适合我的需求。
根据请求,一个真实世界的例子:(
这使用了一种不同的方法,它具有有效的语法,但会产生不需要的结果。)
from PyQt5.QtCore import QObject
class Settings(object):
def __init__(self, file):
self.file = file
class SettingsObject(object):
def __init__(self, settings=None):
print("Super Init", settings is None)
self.settings = settings
class MyObject(QObject, SettingsObject):
def __init__(self, …
Run Code Online (Sandbox Code Playgroud) 我想删除bytes
函数中参数的元素。我希望更改参数,而不是返回新对象。
def f(b: bytes):
b.pop(0) # does not work on bytes
del b[0] # deleting not supported by _bytes_
b = b[1:] # creates a copy of b and saves it as a local variable
io.BytesIO(b).read(1) # same as b[1:]
Run Code Online (Sandbox Code Playgroud)
这里的解决方案是什么?
python ×5
python-3.x ×4
alpine-linux ×1
byte ×1
cron ×1
docker ×1
kubernetes ×1
locale ×1
passwords ×1
python-3.7 ×1
rbac ×1
type-hinting ×1
types ×1