Python cục bộ

Mô-đun

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
7 mở quyền truy cập vào chức năng và cơ sở dữ liệu ngôn ngữ POSIX. Cơ chế bản địa POSIX cho phép lập trình viên giải quyết các vấn đề văn hóa nhất định trong một ứng dụng mà không yêu cầu lập trình viên biết tất cả các chi tiết cụ thể của từng quốc gia nơi phần mềm được thực thi

Mô-đun

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
7 được triển khai trên đầu mô-đun
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
9, do đó sử dụng triển khai ngôn ngữ ANSI C nếu có

Mô-đun

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
7 xác định các chức năng và ngoại lệ sau

ngoại lệ ngôn ngữ. Lỗi

Ngoại lệ được đưa ra khi ngôn ngữ được chuyển đến

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
1 không được nhận dạng

ngôn ngữ. setlocale[danh mục , ngôn ngữ=Không có]

Nếu ngôn ngữ được cung cấp và không phải là

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
2, thì
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
1 sẽ sửa đổi cài đặt ngôn ngữ cho danh mục. Các danh mục có sẵn được liệt kê trong phần mô tả dữ liệu bên dưới. ngôn ngữ có thể là một chuỗi hoặc có thể lặp lại hai chuỗi [mã ngôn ngữ và mã hóa]. Nếu đó là một lần lặp, nó sẽ được chuyển đổi thành tên ngôn ngữ bằng cách sử dụng công cụ đặt bí danh ngôn ngữ. Một chuỗi trống chỉ định cài đặt mặc định của người dùng. Nếu sửa đổi ngôn ngữ không thành công, ngoại lệ
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
0 sẽ được nâng lên. Nếu thành công, cài đặt ngôn ngữ mới được trả về

Nếu ngôn ngữ bị bỏ qua hoặc

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
2, cài đặt hiện tại cho danh mục được trả về

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
1 không an toàn cho luồng trên hầu hết các hệ thống. Các ứng dụng thường bắt đầu bằng lệnh gọi

import locale
locale.setlocale[locale.LC_ALL, '']

Điều này đặt ngôn ngữ cho tất cả các danh mục thành cài đặt mặc định của người dùng [thường được chỉ định trong biến môi trường

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
3]. Nếu ngôn ngữ không bị thay đổi sau đó, việc sử dụng đa luồng sẽ không gây ra sự cố

ngôn ngữ. localeconv[]

Trả về cơ sở dữ liệu của các quy ước cục bộ dưới dạng từ điển. Từ điển này có các chuỗi sau đây làm khóa

Loại

Chìa khóa

Nghĩa

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
4

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
5

Ký tự dấu thập phân

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
6

Dãy số xác định vị trí tương đối mà

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
7 được mong đợi. Nếu chuỗi được kết thúc bằng
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
8, thì không có nhóm nào được thực hiện nữa. Nếu chuỗi kết thúc bằng
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
9, kích thước nhóm cuối cùng được sử dụng lặp lại

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
7

Ký tự được sử dụng giữa các nhóm

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
71

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
72

Ký hiệu tiền tệ quốc tế

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
73

Biểu tượng tiền tệ địa phương

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
74

Liệu ký hiệu tiền tệ có đứng trước giá trị hay không [đối với phản hồi tích cực. giá trị âm]

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
75

Ký hiệu tiền tệ có được phân tách khỏi giá trị bằng dấu cách hay không [đối với phản hồi tích cực. giá trị âm]

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
76

Dấu thập phân được sử dụng cho các giá trị tiền tệ

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
77

Số chữ số phân số được sử dụng trong định dạng cục bộ của các giá trị tiền tệ

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
78

Số chữ số phân số được sử dụng trong định dạng quốc tế của các giá trị tiền tệ

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
79

Dấu tách nhóm được sử dụng cho các giá trị tiền tệ

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
70

Tương đương với

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
6, được sử dụng cho các giá trị tiền tệ

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
72

Biểu tượng được sử dụng để chú thích một giá trị tiền tệ dương

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
73

Biểu tượng được sử dụng để chú thích giá trị tiền tệ âm

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
74

Vị trí của dấu hiệu [đối với phản ứng tích cực. giá trị âm], xem bên dưới

Tất cả các giá trị số có thể được đặt thành

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
8 để cho biết rằng không có giá trị nào được chỉ định trong ngôn ngữ này

Các giá trị có thể có cho

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
76 và
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
77 được đưa ra bên dưới

Giá trị

Giải trình

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
9

Tiền tệ và giá trị được bao quanh bởi dấu ngoặc đơn

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
79

Dấu hiệu phải đứng trước giá trị và ký hiệu tiền tệ

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
70

Dấu hiệu phải tuân theo giá trị và ký hiệu tiền tệ

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
71

Dấu hiệu phải ngay trước giá trị

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
72

Dấu hiệu phải ngay lập tức theo sau giá trị

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
8

Không có gì được chỉ định trong ngôn ngữ này

Hàm tạm thời đặt ngôn ngữ

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
74 thành ngôn ngữ
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
4 hoặc ngôn ngữ
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
71 nếu ngôn ngữ khác và chuỗi số hoặc tiền tệ không phải ASCII. Thay đổi tạm thời này ảnh hưởng đến các chủ đề khác

Đã thay đổi trong phiên bản 3. 7. Hàm hiện tạm thời đặt ngôn ngữ

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
74 thành ngôn ngữ
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
4 trong một số trường hợp.

ngôn ngữ. nl_langinfo[tùy chọn]

Trả lại một số thông tin cụ thể về ngôn ngữ dưới dạng chuỗi. Chức năng này không khả dụng trên tất cả các hệ thống và tập hợp các tùy chọn khả thi cũng có thể khác nhau giữa các nền tảng. Các giá trị đối số có thể có là các số, trong đó các hằng số tượng trưng có sẵn trong mô-đun ngôn ngữ

Hàm

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
79 chấp nhận một trong các khóa sau. Hầu hết các mô tả được lấy từ mô tả tương ứng trong thư viện GNU C

ngôn ngữ. CODESET

Nhận một chuỗi có tên mã hóa ký tự được sử dụng trong ngôn ngữ đã chọn

ngôn ngữ. D_T_FMT

Nhận một chuỗi có thể được sử dụng làm chuỗi định dạng cho

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
90 để biểu thị ngày và giờ theo cách dành riêng cho ngôn ngữ

ngôn ngữ. D_FMT

Nhận một chuỗi có thể được sử dụng làm chuỗi định dạng cho

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
90 để biểu thị một ngày theo cách dành riêng cho ngôn ngữ

ngôn ngữ. T_FMT

Nhận một chuỗi có thể được sử dụng làm chuỗi định dạng cho

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
90 để biểu thị thời gian theo cách dành riêng cho ngôn ngữ

ngôn ngữ. T_FMT_AMPM

Nhận chuỗi định dạng cho

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
90 để biểu thị thời gian ở định dạng sáng/chiều

DAY_1 . DAY_7

Lấy tên của ngày thứ n trong tuần

Ghi chú

Điều này tuân theo quy ước của Hoa Kỳ về

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
94 là Chủ nhật, không phải quy ước quốc tế [ISO 8601] rằng Thứ Hai là ngày đầu tuần

ABDAY_1 . ABDAY_7

Lấy tên viết tắt của ngày thứ n trong tuần

MON_1 . MON_12

Lấy tên của tháng thứ n

ABMON_1 . ABMON_12

Lấy tên viết tắt của tháng thứ n

ngôn ngữ. RADIXCHAR

Nhận ký tự cơ số [dấu chấm thập phân, dấu phẩy thập phân, v.v. ]

ngôn ngữ. NHÀ NHÀ

Lấy ký tự phân cách cho hàng nghìn [nhóm ba chữ số]

ngôn ngữ. YESEXPR

Nhận biểu thức chính quy có thể được sử dụng với hàm regex để nhận dạng phản hồi tích cực cho câu hỏi có/không

ngôn ngữ. NOEXPR

Nhận biểu thức chính quy có thể được sử dụng với hàm regex[3] để nhận dạng phản hồi phủ định cho câu hỏi có/không

Ghi chú

Các biểu thức chính quy cho

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
95 và
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
96 sử dụng cú pháp phù hợp với hàm
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
97 từ thư viện C, cú pháp này có thể khác với cú pháp được sử dụng trong
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
98

ngôn ngữ. CRNCYSTR

Lấy ký hiệu tiền tệ, trước dấu “-” nếu ký hiệu xuất hiện trước giá trị, “+” nếu ký hiệu xuất hiện sau giá trị hoặc “. ” nếu biểu tượng nên thay thế ký tự cơ số

ngôn ngữ. Kỷ nguyên

Nhận một chuỗi đại diện cho thời đại được sử dụng trong ngôn ngữ hiện tại

Hầu hết các địa phương không xác định giá trị này. Một ví dụ về ngôn ngữ xác định giá trị này là ngôn ngữ Nhật Bản. Ở Nhật Bản, cách biểu thị ngày truyền thống bao gồm tên của thời đại tương ứng với triều đại của hoàng đế khi đó

Thông thường không cần thiết phải sử dụng trực tiếp giá trị này. Việc chỉ định công cụ sửa đổi

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
99 trong chuỗi định dạng của chúng sẽ khiến hàm
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
90 sử dụng thông tin này. Định dạng của chuỗi trả về không được chỉ định và do đó bạn không nên cho rằng mình đã biết về nó trên các hệ thống khác nhau

ngôn ngữ. ERA_D_T_FMT

Nhận chuỗi định dạng cho

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
90 để biểu thị ngày và giờ theo cách dựa trên thời đại dành riêng cho ngôn ngữ

ngôn ngữ. ERA_D_FMT

Nhận một chuỗi định dạng cho

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
90 để biểu thị một ngày theo cách dựa trên thời đại cụ thể của miền địa phương

ngôn ngữ. ERA_T_FMT

Nhận một chuỗi định dạng cho

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
90 để biểu thị thời gian theo cách dựa trên thời đại cụ thể của miền địa phương

ngôn ngữ. ALT_DIGITS

Nhận đại diện cho tối đa 100 giá trị được sử dụng để đại diện cho các giá trị từ 0 đến 99

ngôn ngữ. getdefaultlocale[[envvars]]

Cố gắng xác định cài đặt ngôn ngữ mặc định và trả về chúng dưới dạng một bộ có dạng

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
74

Theo POSIX, một chương trình không được gọi là

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
75 chạy bằng ngôn ngữ
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
76 di động. Gọi
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
75 cho phép nó sử dụng ngôn ngữ mặc định như được xác định bởi biến
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
3. Vì chúng tôi không muốn can thiệp vào cài đặt ngôn ngữ hiện tại, do đó, chúng tôi mô phỏng hành vi theo cách được mô tả ở trên

Để duy trì khả năng tương thích với các nền tảng khác, không chỉ biến

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
3 được kiểm tra mà cả danh sách các biến được cung cấp dưới dạng tham số envvars. Cái đầu tiên được tìm thấy được xác định sẽ được sử dụng. envvars mặc định cho đường dẫn tìm kiếm được sử dụng trong GNU gettext; . Đường dẫn tìm kiếm văn bản GNU chứa
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
11,
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
12,
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
10 và
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
14, theo thứ tự đó

Ngoại trừ mã

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
76, mã ngôn ngữ tương ứng với RFC 1766. mã ngôn ngữ và mã hóa có thể là
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
2 nếu không xác định được giá trị của chúng

Không dùng nữa kể từ phiên bản 3. 11, sẽ bị xóa trong phiên bản 3. 13

ngôn ngữ. getlocale[danh mục=LC_CTYPE]

Trả về cài đặt hiện tại cho danh mục ngôn ngữ đã cho dưới dạng chuỗi chứa mã ngôn ngữ, mã hóa. danh mục có thể là một trong các giá trị

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
17 ngoại trừ
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
18. Nó mặc định là
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
74

Ngoại trừ mã

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
76, mã ngôn ngữ tương ứng với RFC 1766. mã ngôn ngữ và mã hóa có thể là
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
2 nếu không xác định được giá trị của chúng

ngôn ngữ. getpreferredencoding[do_setlocale=Đúng]

Trả về mã hóa ngôn ngữ được sử dụng cho dữ liệu văn bản, theo tùy chọn của người dùng. Các tùy chọn của người dùng được thể hiện khác nhau trên các hệ thống khác nhau và có thể không có sẵn theo chương trình trên một số hệ thống, vì vậy chức năng này chỉ trả về kết quả đoán.

Trên một số hệ thống, cần phải gọi

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
1 để có được tùy chọn người dùng, vì vậy chức năng này không an toàn cho luồng. Nếu gọi setlocale là không cần thiết hoặc không mong muốn, do_setlocale nên được đặt thành
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
23

Trên Android hoặc nếu Chế độ Python UTF-8 được bật, hãy luôn trả về

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
24, . and the do_setlocale argument are ignored.

Việc Khởi tạo trước Python định cấu hình ngôn ngữ LC_CTYPE. Xem thêm mã hóa hệ thống tệp và trình xử lý lỗi .

Đã thay đổi trong phiên bản 3. 7. Chức năng hiện luôn trả về

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
25 trên Android hoặc nếu Chế độ Python UTF-8 được bật.

ngôn ngữ. getencoding[]

Nhận mã hóa ngôn ngữ hiện tại.

  • Trên Android và VxWorks, trả về

    >>> import locale
    >>> loc = locale.getlocale[]  # get current locale
    # use German locale; name might vary with platform
    >>> locale.setlocale[locale.LC_ALL, 'de_DE']
    >>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
    >>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
    >>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
    >>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
    
    25

  • Trên Unix, trả lại mã hóa của ngôn ngữ

    >>> import locale
    >>> loc = locale.getlocale[]  # get current locale
    # use German locale; name might vary with platform
    >>> locale.setlocale[locale.LC_ALL, 'de_DE']
    >>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
    >>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
    >>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
    >>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
    
    74 hiện tại. Trả về
    >>> import locale
    >>> loc = locale.getlocale[]  # get current locale
    # use German locale; name might vary with platform
    >>> locale.setlocale[locale.LC_ALL, 'de_DE']
    >>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
    >>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
    >>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
    >>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
    
    25 nếu
    >>> import locale
    >>> loc = locale.getlocale[]  # get current locale
    # use German locale; name might vary with platform
    >>> locale.setlocale[locale.LC_ALL, 'de_DE']
    >>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
    >>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
    >>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
    >>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
    
    29 trả về một chuỗi rỗng. ví dụ: nếu ngôn ngữ LC_CTYPE hiện tại không được hỗ trợ

  • Trên Windows, trả về trang mã ANSI

Việc Khởi tạo trước Python định cấu hình ngôn ngữ LC_CTYPE. Xem thêm mã hóa hệ thống tệp và trình xử lý lỗi .

Hàm này tương tự như

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
10 ngoại trừ chức năng này bỏ qua Chế độ Python UTF-8 .

Mới trong phiên bản 3. 11

ngôn ngữ. chuẩn hóa[tên ngôn ngữ]

Trả về mã ngôn ngữ được chuẩn hóa cho tên ngôn ngữ đã cho. Mã ngôn ngữ được trả về được định dạng để sử dụng với

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
1. Nếu quá trình chuẩn hóa không thành công, tên ban đầu được trả về không thay đổi

Nếu không biết mã hóa đã cho, hàm sẽ mặc định là mã hóa mặc định cho mã ngôn ngữ giống như

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
1

ngôn ngữ. resetlocale[danh mục=LC_ALL]

Đặt ngôn ngữ cho danh mục thành cài đặt mặc định

Cài đặt mặc định được xác định bằng cách gọi

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
13. danh mục mặc định là
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
18

Không dùng nữa kể từ phiên bản 3. 11, sẽ bị xóa trong phiên bản 3. 13

ngôn ngữ. strcoll[string1 , string2]

So sánh hai chuỗi theo cài đặt

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
15 hiện tại. Như bất kỳ hàm so sánh nào khác, trả về giá trị âm hoặc dương hoặc
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
9, tùy thuộc vào việc chuỗi1 đối chiếu trước hay sau chuỗi2 hoặc bằng với nó

ngôn ngữ. strxfrm[chuỗi]

Chuyển đổi một chuỗi thành một chuỗi có thể được sử dụng trong so sánh nhận biết ngôn ngữ. Ví dụ,

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
17 tương đương với
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
18. Chức năng này có thể được sử dụng khi cùng một chuỗi được so sánh lặp đi lặp lại, e. g. khi đối chiếu một chuỗi các chuỗi

ngôn ngữ. format_string[định dạng , val , nhóm=Sai , tiền tệ=Sai]

Định dạng một số val theo cài đặt

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
4 hiện tại. Định dạng tuân theo các quy ước của toán tử
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
00. Đối với các giá trị dấu phẩy động, dấu thập phân được sửa đổi nếu thích hợp. Nếu nhóm là
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
01, cũng sẽ tính đến nhóm

Nếu tiền tệ là đúng, chuyển đổi sử dụng dấu tách hàng nghìn tiền tệ và chuỗi nhóm

Xử lý thông số định dạng như trong

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
02, nhưng tính đến cài đặt ngôn ngữ hiện tại

Đã thay đổi trong phiên bản 3. 7. Tham số từ khóa tiền tệ đã được thêm vào.

ngôn ngữ. định dạng[định dạng , val , nhóm=Sai , tiền tệ=Sai]

Xin lưu ý rằng chức năng này hoạt động giống như

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
03 nhưng sẽ chỉ hoạt động cho chính xác một mã xác định
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
04. Ví dụ:
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
05 và
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
06 đều là các từ xác định hợp lệ, nhưng
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
07 thì không

Đối với toàn bộ chuỗi định dạng, hãy sử dụng

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
03

Không dùng nữa kể từ phiên bản 3. 7. Sử dụng

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
03 thay thế.

ngôn ngữ. tiền tệ[val , ký hiệu=Đúng , nhóm=Sai , quốc tế=Sai]

Định dạng một số val theo cài đặt

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
71 hiện tại

Chuỗi trả về bao gồm ký hiệu tiền tệ nếu ký hiệu là đúng, đây là ký hiệu mặc định. Nếu nhóm là

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
01 [không phải là mặc định], việc nhóm được thực hiện với giá trị. Nếu quốc tế là
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
01 [không phải là mặc định], ký hiệu tiền tệ quốc tế được sử dụng

Ghi chú

Chức năng này sẽ không hoạt động với ngôn ngữ 'C', vì vậy trước tiên bạn phải đặt ngôn ngữ qua

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
1

ngôn ngữ. str[phao]

Định dạng một số dấu phẩy động bằng cách sử dụng cùng định dạng với hàm tích hợp sẵn

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
14, nhưng tính đến dấu thập phân

ngôn ngữ. delocalize[chuỗi]

Chuyển đổi một chuỗi thành một chuỗi số được chuẩn hóa, tuân theo cài đặt

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
4

Mới trong phiên bản 3. 5

ngôn ngữ. bản địa hóa[chuỗi , nhóm=Sai , tiền tệ=Sai]

Chuyển đổi một chuỗi số được chuẩn hóa thành một chuỗi được định dạng theo cài đặt

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
4

Mới trong phiên bản 3. 10

ngôn ngữ. atof[chuỗi , func=phao]

Chuyển đổi một chuỗi thành một số, theo cài đặt

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
4, bằng cách gọi func trên kết quả của việc gọi
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
18 trên chuỗi

ngôn ngữ. atoi[chuỗi]

Chuyển đổi một chuỗi thành một số nguyên, tuân theo các quy ước của

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
4

ngôn ngữ. LC_CTYPE

Thể loại ngôn ngữ cho các chức năng loại ký tự. Tùy thuộc vào cài đặt của danh mục này, các chức năng của mô-đun

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
20 xử lý trường hợp thay đổi hành vi của chúng

ngôn ngữ. LC_COLLATE

Danh mục ngôn ngữ để sắp xếp chuỗi. Các chức năng

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
21 và
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
22 của mô-đun
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
7 bị ảnh hưởng

ngôn ngữ. LC_TIME

Thể loại ngôn ngữ để định dạng thời gian. Hàm

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
90 tuân theo các quy ước này

ngôn ngữ. LC_MONETARY

Thể loại địa phương để định dạng các giá trị tiền tệ. Các tùy chọn khả dụng có sẵn từ chức năng

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
25

ngôn ngữ. LC_MESSAGES

Danh mục ngôn ngữ để hiển thị tin nhắn. Python hiện không hỗ trợ các thông báo nhận biết ngôn ngữ cụ thể của ứng dụng. Các thông báo được hiển thị bởi hệ điều hành, chẳng hạn như các thông báo được trả về bởi

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
26 có thể bị ảnh hưởng bởi danh mục này

Giá trị này có thể không khả dụng trên các hệ điều hành không phù hợp với tiêu chuẩn POSIX, đặc biệt là Windows

ngôn ngữ. LC_NUMERIC

Thể loại ngôn ngữ để định dạng số. Các chức năng

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
27,
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
28,
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
29 và
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
30 của mô-đun
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
7 bị ảnh hưởng bởi danh mục đó. Tất cả các hoạt động định dạng số khác không bị ảnh hưởng

ngôn ngữ. LC_ALL

Kết hợp tất cả các cài đặt ngôn ngữ. Nếu cờ này được sử dụng khi thay đổi ngôn ngữ, thì việc đặt ngôn ngữ cho tất cả các danh mục sẽ được thử. Nếu điều đó không thành công đối với bất kỳ danh mục nào, thì không có danh mục nào được thay đổi. Khi ngôn ngữ được truy xuất bằng cờ này, một chuỗi cho biết cài đặt cho tất cả các danh mục sẽ được trả về. Chuỗi này sau này có thể được sử dụng để khôi phục cài đặt

ngôn ngữ. CHAR_MAX

Đây là hằng số tượng trưng được sử dụng cho các giá trị khác nhau được trả về bởi

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
25

Thí dụ

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale

Bối cảnh, chi tiết, gợi ý, mẹo và lưu ý¶

Tiêu chuẩn C xác định ngôn ngữ là thuộc tính toàn chương trình có thể tương đối tốn kém để thay đổi. Trên hết, một số triển khai bị hỏng theo cách mà các thay đổi ngôn ngữ thường xuyên có thể gây ra các kết xuất lõi. Điều này làm cho ngôn ngữ hơi khó sử dụng một cách chính xác

Ban đầu, khi một chương trình được bắt đầu, ngôn ngữ là ngôn ngữ

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
33, bất kể ngôn ngữ ưa thích của người dùng là gì. Có một ngoại lệ. danh mục
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
74 được thay đổi khi khởi động để đặt mã hóa ngôn ngữ hiện tại thành mã hóa ngôn ngữ ưa thích của người dùng. Chương trình phải nói rõ ràng rằng nó muốn cài đặt ngôn ngữ ưa thích của người dùng cho các danh mục khác bằng cách gọi
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
75

Nói chung, gọi

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
1 trong một số thói quen của thư viện là một ý tưởng tồi, vì như một tác dụng phụ, nó ảnh hưởng đến toàn bộ chương trình. Lưu và khôi phục nó gần như tệ. nó đắt tiền và ảnh hưởng đến các luồng khác chạy trước khi cài đặt được khôi phục

Nếu khi mã hóa một mô-đun để sử dụng chung, bạn cần một phiên bản hoạt động độc lập với ngôn ngữ bị ảnh hưởng bởi ngôn ngữ đó [chẳng hạn như một số định dạng nhất định được sử dụng với

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
90], bạn sẽ phải tìm cách thực hiện điều đó mà không cần sử dụng thư viện tiêu chuẩn . Tốt hơn nữa là tự thuyết phục bản thân rằng sử dụng cài đặt ngôn ngữ là được. Chỉ là phương sách cuối cùng, bạn nên ghi lại rằng mô-đun của bạn không tương thích với cài đặt ngôn ngữ không phải ____033

Cách duy nhất để thực hiện các phép toán số theo ngôn ngữ là sử dụng các chức năng đặc biệt được xác định bởi mô-đun này.

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
29,
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
28,
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
27,
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
30

Không có cách nào để thực hiện chuyển đổi trường hợp và phân loại ký tự theo ngôn ngữ. Đối với các chuỗi văn bản [Unicode], những điều này chỉ được thực hiện theo giá trị ký tự, trong khi đối với các chuỗi byte, việc chuyển đổi và phân loại được thực hiện theo giá trị ASCII của byte và các byte có bit cao được đặt [i. e. , byte không phải ASCII] không bao giờ được chuyển đổi hoặc được coi là một phần của lớp ký tự, chẳng hạn như chữ cái hoặc khoảng trắng

Dành cho người viết tiện ích mở rộng và chương trình nhúng Python¶

Các mô-đun mở rộng không bao giờ được gọi

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
1, ngoại trừ để tìm hiểu ngôn ngữ hiện tại là gì. Nhưng vì giá trị trả về chỉ có thể được sử dụng hợp lý để khôi phục nó, nên điều đó không hữu ích lắm [ngoại trừ có lẽ để tìm hiểu xem ngôn ngữ đó có phải là
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
33 hay không]

Khi mã Python sử dụng mô-đun

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
7 để thay đổi ngôn ngữ, điều này cũng ảnh hưởng đến ứng dụng nhúng. Nếu ứng dụng nhúng không muốn điều này xảy ra, ứng dụng đó nên xóa mô-đun mở rộng
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
9 [thực hiện tất cả công việc] khỏi bảng các mô-đun tích hợp trong tệp
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
47 và đảm bảo rằng mô-đun
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
9 không thể truy cập được như

Truy cập vào danh mục tin nhắn¶

ngôn ngữ. nhận văn bản[tin nhắn] ¶ . locale.dgettext[tên miền , tin nhắn . ]locale.dcgettext[tên miền , tin nhắn . , category]locale.miền văn bản[miền] ¶ . locale.miền liên kết văn bản[miền , dir]

Mô-đun ngôn ngữ hiển thị giao diện gettext của thư viện C trên các hệ thống cung cấp giao diện này. Nó bao gồm các chức năng

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
49,
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
50,
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
51,
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
52,
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
53, và
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
54. Các chức năng này tương tự như các chức năng tương tự trong mô-đun
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
55, nhưng sử dụng định dạng nhị phân của thư viện C cho danh mục thư và thuật toán tìm kiếm của thư viện C để định vị danh mục thư

Các ứng dụng Python thường thấy không cần gọi các hàm này và thay vào đó nên sử dụng

>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
55. Một ngoại lệ đã biết đối với quy tắc này là các ứng dụng liên kết với các thư viện C bổ sung gọi nội bộ
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
49 hoặc
>>> import locale
>>> loc = locale.getlocale[]  # get current locale
# use German locale; name might vary with platform
>>> locale.setlocale[locale.LC_ALL, 'de_DE']
>>> locale.strcoll['f\xe4n', 'foo']  # compare a string containing an umlaut
>>> locale.setlocale[locale.LC_ALL, '']   # use user's preferred locale
>>> locale.setlocale[locale.LC_ALL, 'C']  # use default [C] locale
>>> locale.setlocale[locale.LC_ALL, loc]  # restore saved locale
51. Đối với những ứng dụng này, có thể cần phải liên kết miền văn bản để các thư viện có thể định vị chính xác danh mục thư của họ

Cục bộ [] trong Python là gì?

Hàm Python local[] . Một bảng ký hiệu chứa thông tin cần thiết về chương trình hiện tại. returns the local symbol table as a dictionary. A symbol table contains necessary information about the current program.

Địa phương và toàn cầu trong Python là gì?

Biến cục bộ được khai báo bên trong khối chức năng còn Biến toàn cục là loại biến được khai báo bên ngoài mọi chức năng của chương trình .

Sự khác biệt giữa globals[] locals[] và vars[] là gì?

globals[] luôn trả về từ điển của không gian tên mô-đun. locals[] luôn trả về một từ điển của không gian tên hiện tại. vars[] trả về từ điển của không gian tên hiện tại [nếu được gọi mà không có đối số] hoặc từ điển của đối số

Chức năng địa phương Python hoạt động như thế nào?

Hàm locals[] của Python trả về tất cả thông tin được lưu trữ trong bảng ký hiệu cục bộ dưới dạng từ điển . Do đó, khi được sử dụng trong một chương trình, phương thức sẽ trả về một từ điển chứa tất cả các biến phạm vi cục bộ.

Chủ Đề