python语言环境货币转换为0小数 - python

我不知道如何将货币设置为0个小数。目前,它总是使我的货币落后.00。

locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
damn = locale.currency(self.damn, grouping=True).replace('$','') + " Dmn"

self.damn始终是整数。

python大神给出的解决方案

看来您只是对分组感兴趣。您不需要为此使用货币功能。使用locale.format()

import locale
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
damn = '{0} Dmn'.format(locale.format('%d', self.damn, True))

如果您不依赖locale东西,也可以将数字与string.format()分组:

# Comma as separator
damn = '{:,} Dmn'.format(self.damn)
# Locale aware separator
damn = '{:n} Dmn'.format(self.damn)

Python sqlite3数据库已锁定 - python

我在Windows上使用Python 3和sqlite3。我正在开发一个使用数据库存储联系人的小型应用程序。我注意到,如果应用程序被强制关闭(通过错误或通过任务管理器结束),则会收到sqlite3错误(sqlite3.OperationalError:数据库已锁定)。我想这是因为在应用程序关闭之前,我没有正确关闭数据库连接。我已经试过了: connectio…

Python pytz时区函数返回的时区为9分钟 - python

由于某些原因,我无法从以下代码中找出原因:>>> from pytz import timezone >>> timezone('America/Chicago') 我得到:<DstTzInfo 'America/Chicago' LMT-1 day, 18:09:00 STD…

用大写字母拆分字符串,但忽略AAA Python Regex - python

我的正则表达式:vendor = "MyNameIsJoe. I'mWorkerInAAAinc." ven = re.split(r'(?<=[a-z])[A-Z]|[A-Z](?=[a-z])', vendor) 以大写字母分割字符串,例如:'我的名字是乔。 I'mWorkerInAAAinc”变成…

Python:同时在for循环中添加到列表列表 - python

我想用for循环外的0索引值创建一个新列表,然后使用for循环添加到相同的列表。我的玩具示例是:import random data = ['t1', 't2', 't3'] masterlist = [['col1', 'animal1', 'an…

如何获取Python中所有内置函数的列表 - python

当我们从中获取关键字列表时,如何从Python提示符中获取Python中所有内置函数的列表? python大神给出的解决方案 更新:关于__builtins__或__builtin__可能会有一些混淆。What’s New In Python 3.0建议使用builtins 将模块__builtin__重命名为builtins(删除下划线, 添加一个“ s”…