Hướng dẫn python locale list - danh sách ngôn ngữ python
Mã nguồn: lib/locale.py Lib/locale.py Show Mô -đun Mô -đun Mô -đun Ngoại lệ được nâng lên khi địa phương được chuyển đến Nếu Locale được đưa ra và khô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 locale1, setlocale() sẽ sửa đổi cài đặt Locale cho danh mục. Các danh mục có sẵn được liệt kê trong mô tả dữ liệu dưới đây. Locale 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 nó có một sự khác biệt, thì nó đã chuyển đổi thành một tên địa phương bằng cách sử dụng động cơ bí danh địa phương. Một chuỗi trống chỉ định cài đặt mặc định của người dùng. Nếu việc sửa đổi địa phương thất bại, 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 locale3 sẽ được nâng lên. Nếu thành công, cài đặt địa phương mới được trả về. Nếu Locale 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 locale1, cài đặt hiện tại cho danh mục được trả về.
import locale locale.setlocale(locale.LC_ALL, '') Điều này đặt locale 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 locale6). Nếu địa điểm không thay đổi sau đó, việc sử dụng đa luồng sẽ không gây ra vấ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 locale6 environment variable). If the locale is not changed thereafter, using multithreading should not cause problems. ________ 6 ________ 18 ()()¶ Trả về cơ sở dữ liệu của các quy ước địa phương như một từ điển. Từ điển này có các chuỗi sau làm khóa:
Tất cả các giá trị số có thể được đặt thành Các giá trị có thể cho
Hàm đặt tạm thời đị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 locale9 hoặc địa phương locale 6 nếu các địa phương là khác nhau và các chuỗi tiền tệ hoặc tiền tệ là không 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 tạm thời đị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 locale9 locale in some cases. ________ 6 ________ 55 (Tùy chọn) ¶(option)¶ Trả về một số thông tin cụ thể địa phương dưới dạng chuỗi. Hàm này không có sẵn trên tất cả các hệ thống và tập hợp các tùy chọn có thể cũng có thể thay đổi giữa các nền tảng. Các giá trị đối số có thể là các số, trong đó các hằng số biểu tượng có sẵn trong mô -đun địa phương. Hàm Nhận một chuỗi có tên của mã hóa ký tự được sử dụng trong ngôn ngữ đã chọn. ________ 6 ________ 60¶Nhận một chuỗi có thể được sử dụng làm chuỗi định dạng cho Nhận một chuỗi có thể được sử dụng làm chuỗi định dạng cho Nhận một chuỗi có thể được sử dụng làm chuỗi định dạng cho Nhận một chuỗi định dạng cho Error 1Lấy tên của ngày thứ n trong tuần. Ghi chú Điều này theo Công ước Hoa Kỳ về Error 3Nhận tên viết tắt của ngày thứ n trong tuần. Error 4Lấy tên của tháng n. Error 5Nhận tên viết tắt của tháng n. ________ 6 ________ 77¶Nhận ký tự radix (dấu chấm thập phân, dấu phẩy thập phân, v.v.). ________ 6 ________ 79¶Nhận ký tự phân tách cho hàng ngàn (nhóm ba chữ số). ________ 6 ________ 81¶Nhận một biểu thức thông thường có thể được sử dụng với hàm regex để nhận ra phản hồi tích cực cho câu hỏi có/không. Ghi chú Điều này theo Công ước Hoa Kỳ về Error 3Nhận tên viết tắt của ngày thứ n trong tuần. Error 4Lấy tên của tháng n. Error 5Nhận tên viết tắt của tháng n. ________ 6 ________ 77¶ Nhận ký tự radix (dấu chấm thập phân, dấu phẩy thập phân, v.v.). ________ 6 ________ 79¶Nhận ký tự phân tách cho hàng ngàn (nhóm ba chữ số). ________ 6 ________ 81¶Nhận một biểu thức thông thường có thể được sử dụng với hàm regex để nhận ra phản hồi tích cực cho câu hỏi có/không. Biểu thức nằm trong cú pháp phù hợp với hàmsetlocale() 2 từ thư viện C, có thể khác với cú pháp được sử dụng trong setlocale() 3.________ 6 ________ 85¶ Nhận một biểu thức thông thường có thể được sử dụng với hàm regex (3) để nhận ra phản hồi tiêu cực đối với câu hỏi có/không.________ 6 ________ 87¶ Nhận biểu tượng tiền tệ, trước đó là--Nếu biểu tượng sẽ xuất hiện trước giá trị, thì++nếu biểu tượng sẽ xuất hiện sau giá trị, hoặc. Nếu biểu tượng nên thay thế ký tự radix.([envvars])¶________ 6 ________ 89¶ Nhận một chuỗi đại diện cho ERA được sử dụng trong ngôn ngữ hiện tạ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 locale6 variable. Since we do not want to interfere with the current locale setting we thus emulate the behavior in the way described above. Hầu hết các địa phương không xác định giá trị này. Một ví dụ về một địa điểm xác định giá trị này là giá trị Nhật Bản. Tại Nhật Bản, đại diện truyền thống của ngày bao gồm tên của thời đại tương ứng với triều đại của hoà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 locale6 variable is tested, but a list of variables given as envvars parameter. The first found to be defined will be used. envvars defaults to the search path used in GNU gettext; it must always contain the variable name >>> 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 locale11. The GNU gettext search path contains >>> 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 locale12, >>> 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 locale13, >>> 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 locale11 and >>> 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 locale15, in that order. Thông thường không cần thiết phải sử dụng giá trị này trực tiếp. 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 locale1 if their values cannot be determined. ________ 6 ________ 93¶(category=LC_CTYPE)¶ Nhận một chuỗi định dạng cho Thông thường không cần thiết phải sử dụng giá trị này trực tiếp. 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 locale1 if their values cannot be determined. ________ 6 ________ 93¶(do_setlocale=True)¶ Nhận một chuỗi định dạng cho ________ 6 ________ 96¶ 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 locale29, the locale encoding and the do_setlocale argument are ignored. Các tiền đề Python định cấu hình địa phương LC_CTYPE. Xem thêm mã hóa hệ thống tập tin và xử lý lỗi.Python preinitialization configures the LC_CTYPE locale. See also the filesystem encoding and error handler. Đã thay đổi trong phiên bản 3.7: Hàm bây giờ 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 locale30 on Android or if the Python UTF-8 Mode is enabled. ________ 6 ________ 132 (LocalEname) ¶(localename)¶ Trả về một mã địa phương được chuẩn hóa cho tên địa phương đã cho. Mã địa phương được trả về được định dạng để sử dụng với Nếu mã hóa đã cho không được biết, hàm mặc định là mã hóa mặc định cho mã locale giống như Đặt Locale 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 locale37. 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 locale21. 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 locale41 hiện tại. Như bất kỳ hàm so sánh nào khác, trả về một giá trị âm hoặc giá trị dương hoặc locale 4, tùy thuộc vào việc String1 đối chiếu trước hay sau chuỗi2 hay bằng với nó. ________ 6 ________ 144 (Chuỗi) ¶(string)¶Chuyển đổi một chuỗi thành một chuỗi có thể được sử dụng trong các so sánh nhận biết địa phươ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 locale45 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 locale46. Hàm này có thể được sử dụng khi cùng một chuỗi được so sánh nhiều lần, ví dụ: Khi đối chiếu một chuỗi các chuỗi. ________ 6 ________ 148 (định dạng, val, nhóm = false, tiền tệ = sai) ¶(format, val, grouping=False, monetary=False)¶ Đị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 locale9 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 locale50. Đối với các giá trị điểm nổi, điểm thập phân được sửa đổi nếu thích hợp. Nếu nhóm là đúng, cũng tính đến nhóm. Nếu tiền tệ là đúng, việc chuyển đổi sử dụng các chuỗi hàng ngàn tiền tệ và chuỗi nhóm. Các quy trình định dạng các nhà xác định 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 locale51, nhưng tính đến các cài đặt địa phươ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.The monetary keyword parameter was added. ________ 6 ________ 153 (định dạng, val, nhóm = false, tiền tệ = sai) ¶(format, val, grouping=False, monetary=False)¶Xin lưu ý rằng chức năng này hoạt độ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 locale54 nhưng sẽ chỉ hoạt động cho chính xác một trình 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 locale55. 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 locale56 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 locale57 đều là các nhà 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 locale58 thì không. Đối với toàn bộ chuỗi định dạng, 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 locale54. ________ 6 ________ 161 (val, symbol = true, nhóm = false, quốc tế = false)(val, symbol=True, grouping=False, international=False)¶ Định dạng một số Val theo cài đặt Chuỗi được trả về bao gồm ký hiệu tiền tệ nếu biểu tượng là đúng, đó là mặc định. Nếu nhóm là đúng (không phải là mặc định), nhóm được thực hiện với giá trị. Nếu quốc tế là đúng (không phải là mặc định), biểu tượng tiền tệ quốc tế được sử dụng. Lưu ý rằng chức năng này sẽ không hoạt động với ngôn ngữ ‘C, vì vậy bạn phải đặt một ngôn ngữ qua Các định dạng một số điểm nổi sử dụng cùng định dạng với hàm tích hợ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 locale66, nhưng tính đến điểm thập phân. ________ 6 ________ 168 (Chuỗi) ¶(string)¶ Chuyển đổi một chuỗi thành một chuỗi số được chuẩn hóa, 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 locale9. Mới trong phiên bản 3.5. ________ 6 ________ 171 (chuỗi, nhóm = false, tiền tệ = sai) ¶(string, grouping=False, monetary=False)¶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 locale9. Mới trong phiên bản 3.10. ________ 6 ________ 174 (Chuỗi, func = float) ¶(string, func=float)¶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 locale9, bằng cách gọi func theo 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 locale76 trên chuỗi. ________ 6 ________ 178 (Chuỗi) ¶(string)¶ Chuyển đổi một chuỗi thành một số nguyên, theo các quy ướ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 locale9. ________ 6 ________ 181¶ Danh mục địa phương cho các hàm 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 locale82 xử lý trường hợp thay đổi hành vi của chúng. ________ 6 ________ 184¶ Thể loại địa phương để phân loại 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 locale85 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 locale86 của mô -đun locale bị ảnh hưởng. ________ 6 ________ 189¶Thể loại địa phương cho định dạng thời gian. Hàm Thể loại địa phương để định dạng các giá trị tiền tệ. Các tùy chọn có sẵn 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 locale93. ________ 6 ________ 195¶ Danh mục địa phương cho hiển thị tin nhắn. Python hiện không hỗ trợ các tin nhắn nhận biết địa phương cụ thể của ứng dụng. Các tin nhắn được hiển thị bởi hệ điều hành, giống như các tin nhắn đượ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 locale96 có thể bị ảnh hưởng bởi danh mục này. ________ 6 ________ 198¶ Danh mục địa phươ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 locale99, locale 00, locale 01 và locale 02 của mô -đun locale 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.________ 6 ________ 205¶Kết hợp tất cả các cài đặt địa phương. Nếu cờ này được sử dụng khi địa điểm được thay đổi, hãy đặt địa điểm cho tất cả các danh mục được thử. Nếu điều đó thất bại cho bất kỳ danh mục nào, 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 chỉ ra cài đặt cho tất cả các danh mục được trả về. Chuỗi này sau đó có thể được sử dụng để khôi phục cài đặt. ________ 6 ________ 207¶Đây là một 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 locale93. Example: >>> 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 ý, lời khuyên và cảnh báoTiêu chuẩn C định nghĩa Locale là một 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ị phá vỡ theo cách mà các thay đổi địa phương thường xuyên có thể gây ra các bãi rác lõi. Điều này làm cho địa điểm hơi đau đớn khi sử dụng chính xác. Ban đầu, khi một chương trình được bắt đầu, ngôn ngữ là đị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 locale06. Nói chung là một ý tưởng tồi để gọi Nếu, khi mã hóa một mô -đun để sử dụng chung, bạn cần một phiên bản độc lập địa phương của một hoạt động bị ảnh hưởng bởi locale (chẳng hạn như các định dạng nhất định được sử dụng với Cách duy nhất để thực hiện các hoạt động số theo ngôn ngữ là sử dụng các hàm đặ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 locale99, locale 02.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 địa phương. Đối với các chuỗi văn bản (unicode), chúng chỉ được thực hiện theo giá trị ký tự, trong khi đối với chuỗi byte, các chuyển đổi và phân loại được thực hiện theo giá trị ASCII của byte và byte có bit cao được đặt (tức là, không ) không bao giờ được chuyển đổi hoặc được coi là một phần của một lớp ký tự như chữ cái hoặc khoảng trắng. Cho các nhà văn và chương trình mở rộng nhúng Python¶Các mô -đun mở rộng không bao giờ nên gọi Khi mã Python sử dụng mô -đun Truy cập vào Danh mục Tin nhắn________ 6 ________ 226 (MSG) ________ 6 ________ 228 (Tên miền, MSG)(msg)¶locale. locale 28(domain, msg)¶ locale. locale 30(domain, msg, category)¶ locale. locale 32(domain)¶ locale. locale 34(domain, dir)¶Mô -đun Locale hiển thị giao diện GetText 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 Các ứng dụng Python thường không cần phải gọi các chức năng này và nên sử dụng |