Hướng dẫn locale python currency - tiền tệ python địa phương
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 phải Nếu Locale bị bỏ qua hoặc
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 locale2). 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 locale2 environment variable). If the locale is not changed thereafter, using multithreading should not cause problems. Locale.localeconv () ¶localeconv()¶ 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 >>> 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 locale7 để chỉ ra rằng không có giá trị được chỉ định trong ngôn ngữ này. Các giá trị có thể cho
Hàm tạm thời đặ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 locale3 hoặc địa phương locale 0 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ạm thời đặt locale >>> 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 locale in some cases. Locale.nl_langinfo (tùy chọn) ¶nl_langinfo(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. Locale.D_T_FMT¶D_T_FMT¶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 Lấ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ề Nhận tên viết tắt của ngày thứ n trong tuần. MON_1...MON_12 ... MON_12Lấy tên của tháng n. ABMON_1...ABMON_12 ... ABMON_12Nhận tên viết tắt của tháng n. Nhận ký tự radix (dấu chấm thập phân, dấu phẩy thập phân, v.v.). Locale.ThouseP¶THOUSEP¶Nhận ký tự phân tách cho hàng ngàn (nhóm ba chữ số). Locale.yesexpr¶YESEXPR¶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. Locale.NoExpr¶NOEXPR¶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. Ghi chú Điều này theo Công ước Hoa Kỳ về Lấy tên của tháng n. Nhận tên viết tắt của tháng n.ERA¶Locale.Radixchar¶ Nhận ký tự radix (dấu chấm thập phân, dấu phẩy thập phân, v.v.). Locale.ThouseP¶ Nhận ký tự phân tách cho hàng ngàn (nhóm ba chữ số).ERA_D_T_FMT¶Locale.yesexpr¶ 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.ERA_D_FMT¶Locale.NoExpr¶ 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.ERA_T_FMT¶Các biểu thức chính quy cho cú pháp 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. Locale.era¶getdefaultlocale([envvars])¶Nhận một chuỗi đại diện cho ERA đượ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ề 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 locale2 variable. Since we do not want to interfere with the current locale setting we thus emulate the behavior in the way described above. 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 locale2 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 setlocale() 9. The GNU gettext search path contains None 0, None 1, setlocale() 9 and None 3, in that order.Locale.era_d_t_fmt¶RFC 1766. language code and encoding may be Nhận một chuỗi định dạng cho Nhận một chuỗi định dạng cho Locale.era_d_t_fmt¶RFC 1766. language code and encoding may be _locale 9 để biểu diễn ngày và thời gian theo cách dựa trên thời đại địa phương.getpreferredencoding(do_setlocale=True)¶Locale.era_d_fmt¶locale encoding used for text data, according to user preferences. User preferences are expressed differently on different systems, and might not be available programmatically on some systems, so this function only returns a guess. Nhận một chuỗi định dạng cho Locale.era_t_fmt¶Python UTF-8 Mode is enabled, always return 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ề Nhận mã hóa ngôn ngữ hiện tại:locale encoding:
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. Hàm này tương tự như Mới trong phiên bản 3.11. Locale.Normalize (LocalEname) ¶normalize(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 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. 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 locale8, tùy thuộc vào việc String1 đối chiếu trước hay sau chuỗi2 hay bằng với nó. Locale.strxfrm (Chuỗi) ¶strxfrm(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ụ, Đị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 locale3 hiện tại. Định dạng tuân theo các quy ước của toán tử Error 9. Đố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à >>> 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 locale00, cũng sẽ tính đến việc 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 locale01, 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. locale.format (định dạng, val, nhóm = false, tiền tệ = false) ¶format(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 locale02 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 locale03. 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 locale04 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 locale05 đề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 locale06 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 locale02. Locale.Currency (Val, Symbol = true, nhóm = false, international = false) ¶currency(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à >>> 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 locale00 (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à >>> 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 locale00 (không phải là mặc định), biểu tượng 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 bạn phải đặt một locale 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 locale12, nhưng tính đến điểm thập phân. locale.delocalize (chuỗi) ¶delocalize(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 locale3. Mới trong phiên bản 3.5. locale.locize (chuỗi, nhóm = false, tiền tệ = false) ¶localize(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 locale3. Mới trong phiên bản 3.10. Locale.atof (String, func = float) ¶atof(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 locale3, bằng cách gọi func về kết quả 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 locale16 trên chuỗi. Locale.atoi (Chuỗi) ¶atoi(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 locale3. Locale.lc_ctype¶LC_CTYPE¶ 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 locale18 xử lý trường hợp thay đổi hành vi của chúng. Locale.lc_collate¶LC_COLLATE¶ 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 locale19 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 locale20 của mô -đun locale bị ảnh hưởng.
Locale.lc_time¶LC_TIME¶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 locale23. Locale.LC_Messages¶LC_MESSAGES¶ 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 locale24 có thể bị ảnh hưởng bởi danh mục này. Locale.lc_numeric¶LC_NUMERIC¶ Danh mục địa phương để định dạng số. Các 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 locale25, >>> 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 locale26, >>> 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 locale27 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 locale28 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. Locale.lc_all¶LC_ALL¶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. Locale.char_max¶CHAR_MAX¶Đâ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 locale23. 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 locale31, bất kể người dùng ưa thích là địa phương là gì. Có một ngoại lệ: danh mục _locale 3 được thay đổi khi khởi động để đặt mã hóa ngôn ngữ hiện tại cho 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 địa phương ưa thích của người dùng cho các danh mục khác bằng cách gọi setlocale() 4.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 locale27, >>> 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 locale26, >>> 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 locale25, >>> 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 locale28. 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 >>> 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 locale31). 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 locale45 và đảm bảo rằng mô-đun _locale không thể truy cập được một thư viện được chia sẻ.Truy cập vào Danh mục Tin nhắnlocale.gettext (msg) ¶ Locale.DgetText (tên miền, tin nhắn) ¶ Locale.DcgetText (tên miền, tin nhắn, danh mục) ¶ Locale.TextDomain (miền)gettext(msg)¶ locale.dgettext(domain, msg)¶ locale.dcgettext(domain, msg, category)¶ locale.textdomain(domain)¶ locale.bindtextdomain(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 >>> 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 locale47, >>> 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 locale48, >>> 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 locale49, >>> 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, >>> 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 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 locale52. Chúng 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 locale53, nhưng sử dụng định dạng nhị phân của thư viện C cho các danh mục tin nhắn và các thuật toán tìm kiếm thư viện C để định vị các danh mục tin nhắn. 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 >>> 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 locale53 thay thế. 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 locale47 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 locale49. Đối với các ứ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ị đúng danh mục tin nhắn của họ. |