ssf package¶
Submodules¶
ssf.ssf module¶
-
class
ssf.ssf.SSF(tzinfo=None, date1904=False, dateNF=None, table=None, color_pre=None, color_post=None, locale_support=True, locale=None, default_width=None, decimal_separator=None, thousands_separator=None, errors='warn')[source]¶ Bases:
objectSpreadsheet Formatter (number format). Formats values according to spreadsheet-style format codes. If
date1904is True, then the base date is January 1, 1904, which was used on some spreadsheet programs for Mac. The default (False), means that the base date is December 31, 1899 (which spreadsheet programs call the 1900 date system). ThedateNFif not None, replaces the default Short Date format of m/dd/yyyy. Thetableif not None, replaces the entire translation from ints to formats table.The
color_preandcolor_postspecify formats for values that are provided before and after the results that have a[ColorN]or color name e.g.[Red]specifier in the formats. Any{}in the specified format are replaced by the specified color (in Title Case). Any{rgb}in the formats are replaced with the hex color number (without a#).If
locale_supportis True, then handle the international decimal point and thousands separator changes, and the language-based month names. To use this, you can pass thelocalehere, or when you callssf.format(). Iflocaleis None, then the default local locale is used. Thedefault_width, if not None, gives the width to use on every ssf.format() call, if not otherwise specified. Thedecimal_separatorandthousands_separatorare used to override the defaults as specified by the locale. Theerrorsparameter specifies what to do on locale (and other) errors. The default is to warn using the warnings module, then ignore the error. The other choices are ‘ignore’, which completely ignores the error, ‘pounds’, which fills the result with ‘#’ characters, and ‘raise’, which will raise a ValueError exception.-
SSF_js_version= '0.11.2'¶
-
autocorrect_format(fmt)[source]¶ Run some automatic corrections on the given format, and return the corrected format
-
format(fmt, v, width=None, align=None, locale=None, decimal_separator=None, thousands_separator=None)[source]¶ Format a value
vaccording to the spreadsheet format infmtwith fieldwidthwith alignmentalign. Ifwidthis not specified, then the default_width from the ssf object is used. Thealigncan be specified as ‘left’, ‘right’, ‘center’ or None. Ifalignis None, the alignment is defaulted by the type of the value and the format. Text is left aligned, numbers and dates are right aligned, and bool’s are centered. If the format is a text format (@), then the default is left aligned for all types of values. Iflocaleis not None and thessfobject supports locale, then this locale is used as the default locale if none is otherwise specified in the format. Thedecimal_separatorandthousands_separatorcome from the specified locale, or the locale of the ssf object if None. If specified, they override the default. If they are specified as inherit, then the corresponding values of the ssf object are used even if alocaleis specified here. Note that any locale specified in the format itself does not change these separator values, to be consistent with spreadsheet implementations.
-
get_day_names()[source]¶ Returns a 7-tuple containing 2-tuples of the abbreviation and full-day name, with Monday first
-
get_format(type='General', places=None, use_thousands_separator=None, negative_numbers=None, fraction_denominator=-1, positive_sign_exponent=True, locale=None)[source]¶ Get an appropriate format for the
localeeither specified here or the locale of thessfobject. Thetypeis one of General, Number, Currency, Accounting, Date, Short Date, Long Date, Time, Percentage, Fraction, Scientific, or Text (in any case). Ifplacesis not None and this is a number format, then this specifies the number of decimal places, else a default is used. Also for number formats,use_thousands_separatordetermines if the locale-specified thousands separator is used. For currency and accounting formats,use_thousands_separatordefaults to True. In addition,negative_numbersspecifies how to format negative numbers. It can be None, which uses a default format depending on the type (normally ‘-‘), or -, which always uses a minus sign, Red, which formats in red without a minus sign, parens which formats in parenthesis, or Redparens, which does both red and parenthesis. You can also specify () as a synonym for parens.For currencies, these additional
negative_numbersformats are supported:<<-The sign should precede the value and currency symbol (-does this too)>>-The sign should follow the value and currency symbol<-The sign should immediately precede the value>-The sign should immediately follow the value
For Fraction formats, the
fraction_denominatorspecifies the denominator to be used for the fraction. If it is negative, then it instead specifies how many digits to use in the numerator. If it is zero, then a ValueError is raised.For Scientific formats,
positive_sign_exponentdetermines if a positive sign is displayed for positive exponents. The default is True.
-
get_month_names()[source]¶ Returns a 13-tuple containing 3-tuples of the single-letter abbreviation, the abbreviation, and the full-month name. The entry at index 0 is None.
-
static
is_date(fmt)¶ Returns True iff this
fmta date format
-
load(fmt, idx=None)¶ Loads a single format entry specified by
fmtinto the mapping table. Ifidxis specified, then that is used as the table index, else the first free entry is used. The index used is returned.
-
load_entry(fmt, idx=None)[source]¶ Loads a single format entry specified by
fmtinto the mapping table. Ifidxis specified, then that is used as the table index, else the first free entry is used. The index used is returned.
-
load_table(tbl)[source]¶ Given a dict of table indexes and values in
tbl, load it for use by the formatter
-
static
round(number, places=0)[source]¶ JavaScript style: Round 0.5 always up - not to even like python 3
-
set_day_names(days)[source]¶ Given an iterable of length 7 as
days, each of which containing a tuple of the abbreviation and full-day name, with Monday first, set this as the values to be returned for ddd and dddd formats, respectfully.
-
set_month_names(months)[source]¶ Given an iterable of length 13 as
months, each of which containing a 3-tuple of the single-letter abbreviation, the abbreviation, and the full-month name, set this as the values to be returned for mmmmm, mmm, and mmmm formats, respectfully. The first element is not used, so that the first month has index = 1.
-
-
class
ssf.ssf.SSF_CALENDAR(calendar=0)[source]¶ Bases:
objectHandle alternative calendars for ssf. This shouldn’t be used directly.
-
CHINESE_LUNAR= 19¶
-
GREGORIAN_ARABIC= 10¶
-
GREGORIAN_LOCAL= 1¶
-
GREGORIAN_MIDDLE_EASTERN_FRENCH= 9¶
-
GREGORIAN_TRANSLITERATED_ENGLISH= 11¶
-
GREGORIAN_TRANSLITERATED_FRENCH= 12¶
-
GREGORIAN_US= 2¶
-
HIJRI= 6¶
-
JAPANESE= 3¶
-
JEWISH= 8¶
-
KOREAN= 5¶
-
LUNAR_x0E= 14¶
-
LUNAR_x11= 17¶
-
LUNAR_x12= 18¶
-
SYSTEM_DEFAULT= 0¶
-
TAIWAN= 4¶
-
THAI_BUDDHIST= 7¶
-
UM_AL_QURA= 23¶
-
day_month_map= {}¶
-
day_names(locale_name)[source]¶ Return the day names for this calendar in the given
locale_name. The result is an array of day names, starting with Sunday in index 0, or None if we have no day names for this locale
-
ecclesiastical_leap_to_civil= {1: 8, 2: 9, 3: 10, 4: 11, 5: 12, 6: 13, 7: 1, 8: 2, 9: 3, 10: 4, 11: 5, 12: 6, 13: 7}¶
-
ecclesiastical_to_civil= {1: 7, 2: 8, 3: 9, 4: 10, 5: 11, 6: 12, 7: 1, 8: 2, 9: 3, 10: 4, 11: 5, 12: 6}¶
-
era_list= None¶
-
property
has_leap_month¶ Could this calendar have a leap month?
-
lunar_bin= None¶
-
month_names(locale_name, isleap=False)[source]¶ Return the month names for this calendar in the given
locale_name. The result is an array of month names, starting with January in index 0, or None if we have no month names for this locale. If isleap is True and this calendar has a leap month, then the result contains 13 entries, else it has the normal 12.
-
to_local(ymd)[source]¶ Convert a tuple containing (year, month, day) to a SimpleNamespace containing (year, month, day, isleap, era)
-
um_bin= None¶
-
x0D= 13¶
-
x0F= 15¶
-
x10= 16¶
-
x14= 20¶
-
x15= 21¶
-
x16= 22¶
-
x18= 24¶
-
x19= 25¶
-
x1A= 26¶
-
x1B= 27¶
-
x1C= 28¶
-
x1D= 29¶
-
x1E= 30¶
-
x1F= 31¶
-
-
class
ssf.ssf.SSF_LOCALE(locale=None, locale_support=True, locale_currency=True, decimal_separator=None, thousands_separator=None, calendar_code=None)[source]¶ Bases:
objectHandle locale support for SSF. This shouldn’t be used directly.
-
GANNEN= '元'¶
-
MAX_AMPM= 6¶
-
am_pm_map= None¶
-
currency_map= None¶
-
dbnum_map= None¶
-
era_map= None¶
-
lc_all_map= None¶
-
lcid_map= None¶
-
lcid_max= 0¶
-
lcid_reverse_map= None¶
-
numbers_map= None¶
-
table_map= None¶
-
Module contents¶
Top-level package for ssf.