python 本地化 local
locale 模块提供了 C 本地化( localization )函数的接口, 如 Example 8-1 所示. 同时提供相关函数, 实现基于当前 locale 设置的数字, 字符串转换. (而 int , float , 以及 string 模块中的相关转换函数不受 locale 设置的影 响.)
#! /usr/bin/env python
# encoding=utf8
import locale
print("locale", "=>", locale.setlocale(locale.LC_ALL, ""))
# integer formatting
value = 4711
print(locale.format_string("%d", value, 1), "==",)
print(locale.atoi(locale.format_string("%d", value, 1)))
# floating point
value = 47.11
print(locale.format_string("%f", value, 1), "==",)
print(locale.atof(locale.format_string("%f", value, 1)))
info = locale.localeconv()
print(info["int_curr_symbol"])
输出:
locale => Chinese (Simplified)_China.936
4,711 ==
4711
47.110000 ==
47.11
CNY
python 本地化 local的更多相关文章
- TLS 与 python thread local
TLS 先说TLS( Thread Local Storage),wiki上是这么解释的: Thread-local storage (TLS) is a computer programming m ...
- Python本地化例子 - gettext 模块
关键字:Python 3.4,gettext,本地化,Localization OS:Windows 7,Mac 1. 创建一个locsample.py文件,文件内容如下,把所有需要本地化的字符串放到 ...
- Python thread local
由于GIL的原因,笔者在日常开发中几乎没有用到python的多线程.如果需要并发,一般使用多进程,对于IO Bound这种情况,使用协程也是不错的注意.但是在python很多的网络库中,都支持多线程, ...
- python: local variable 'xxx' referenced before assignment
问题发现 xxx = 23 def PrintFileName(strFileName): if xxx == 23: print strFileName xxx = 24 PrintFileName ...
- [Python]threading local 线程局部变量小測试
概念 有个概念叫做线程局部变量.一般我们对多线程中的全局变量都会加锁处理,这样的变量是共享变量,每一个线程都能够读写变量,为了保持同步我们会做枷锁处理.可是有些变量初始化以后.我们仅仅想让他们在每一个 ...
- Python LEGB (Local, Enclosing, Global, Build in) 规则
Local 一个函数定义了一个 local 作用域; PyFrameObject 中的 f_local 属性 Global 一个 module 定义了一个 global 作用域; PyFrameObj ...
- python:UnboundLocalError: local variable 'xxx' referenced before assignment
近来一直都在学习python语言,偶然在伯乐在线看到2017年京东C/C++的面试题.就打算用python+ST3 IDE顺便敲下面试题代码. 原题 C语言: #include <stdio.h ...
- python 局部local和全局global变量
global和local变量 虽然简单,但是还是记录一下,主要是转载 转载自:http://blog.sina.com.cn/s/blog_436992740102ux8z.html 先看一段代码 ...
- python - threading.local
import time import threading try: # 线程和协程都可处理 import greenlet get_ident = greenlet.getcurrent except ...
随机推荐
- Fisher精确检验【转载】
转自:https://en.wikipedia.org/wiki/Fisher%27s_exact_test https://www.cnblogs.com/Dzhouqi/p/3440575.htm ...
- PAT 1040 Longest Symmetric String[dp][难]
1040 Longest Symmetric String (25)(25 分) Given a string, you are supposed to output the length of th ...
- 安卓手机上微信无法打开Https网址的完美解决方案
1,第三方网站检测网站的SSL证书是否正确的安装 https://www.geocerts.com/ssl-checker,大概率你会看到下边的场景,一个证书链完整的警告,如果想知道我的基础配置是什么 ...
- testng入门教程2用TestNG编写测试及执行测试
编写TestNG测试基本上包括以下步骤: 测试和编写业务逻辑,在代码中插入TestNG的注解.. 添加一个testng.xml文件或build.xml中在测试信息(例如类名,您想要运行的组,等..) ...
- nginx安装,反向代理配置
1.centos 版本 下载最新稳定版 https://www.nginx.com/resources/wiki/start/topics/tutorials/install/# 2.执行语句: ./ ...
- Object-C-selector
Shape *shape=[[Shape alloc]init]; //[shape draw] SEL selDraw=@selector(draw); [shape performSelector ...
- java多线程----Semaphore信号量
import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util ...
- RPC框架原理剖析(含实例)(转)
转自:http://blog.csdn.net/rulon147/article/details/53814589 一.什么是RPC RPC(Remote Procedure Call Protoco ...
- python之路----hashlib模块
在平时生活中,有很多情况下,你在不知不觉中,就用到了hashlib模块,比如:注册和登录认证注册和登录认真过程,就是把注册用的账户密码进行:加密 --> 解密 的过程,在加密.解密过程中,用的了 ...
- keepalived+lvs高可用集群
LVS+Keepalived 介绍 LVS LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国 ...