1.000,1234我正在Windows操作系统下的Python中寻找德语数字格式(例如)的正确方法。
我尝试过locale.setlocale但没有成功。
相反,我编写了一个函数来提供所需的输出。
有没有更好的办法?
def ger_num(number, precision=3):
"""
returns german formatted number as string or an empty string
"""
if number is not None:
try:
my_number = "{:,f}".format(number)
except ValueError:
return ""
decimals, fraction = my_number.split(".")[0], my_number.split(".")[1]
decimals = decimals.replace(",", ".")
if precision:
return decimals + "," + fraction[:precision]
else:
return decimals
else:
return ""
Run Code Online (Sandbox Code Playgroud)
我想仅使用 Python 3.9 中的标准库构建 DST 有效时间戳,并希望在此版本中可以实现这一点。
在我的时区“欧洲/柏林”中,2020 年的 DST 交叉点为:
2020-03-29 02:00 时钟切换到 03:00(没有 2 点!)
2020-10-25 03:00时钟切换回 02:00(小时 2 存在两次!)
我的脚本产生以下输出:
MARCH
2020-03-29 01:59:00+01:00 CET plus 1 h: 2020-03-29 02: 59:00+01:00 CET
(应该是 03:59:00 CEST,因为没有小时 2!) 2020 年
10 月 25 日 10 月
02:00:00+02:00 CEST 加 1 小时:2020-10-25 03:00:00+01:00 CET
(看起来不错-编辑:应该是 02:00 CET!!!)
下面提供了示例代码。Windows 用户可能需要“pip install tzdata”才能使其工作。
任何建议将不胜感激!
'''
Should work out of the box with Python 3.9
Got a fallback import statement.
BACKPORT (3.6+)
pip install backports.zoneinfo …Run Code Online (Sandbox Code Playgroud) 我将Qt Designer用于GUI布局,并在QUILoader的帮助下将.ui文件加载到python中。
我设法将“退出”按钮连接到我的“ quit_app”方法。
我的问题是在用户尝试使用“ X”关闭窗口的情况下如何连接此方法。
提前致谢!
---> PYTHON CODE <---
import sys
from PySide2.QtUiTools import QUiLoader
from PySide2.QtWidgets import QApplication
from PySide2.QtCore import QFile
class main_w(object):
def __init__(self):
# load ui; create w
self.file = QFile("simple_quit.ui")
self.file.open(QFile.ReadOnly)
self.loader = QUiLoader()
self.w = self.loader.load(self.file)
# connections
# Quit Button
self.w.QUITButton.clicked.connect(self.quit_app)
# ??? Window's X Button ???
# THROWS ERROR:
self.w.closeEvent.connect(self.quit_app)
def quit_app(self):
# some actions to perform before actually quitting:
print('CLEAN EXIT')
app.exit()
def show(self):
self.w.show()
app = QApplication(sys.argv)
w …Run Code Online (Sandbox Code Playgroud) python ×2
python-3.x ×2
dst ×1
locale ×1
localization ×1
pyside2 ×1
timedelta ×1
timezone ×1
zoneinfo ×1