Package jazzparser :: Package utils :: Module strings
[hide private]
[frames] | no frames]

Module strings

source code

String processing utilities.


Author: Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>

Functions [hide private]
 
strs(list, sep=', ')
I'm fed up of typing this every time I want to print a list!
source code
 
fmt_prob(prob, prec=4)
Format a float as a string in a style suitable for displaying probabilities.
source code
 
group_numerical_suffixes(inlist, open_brace='{', close_brace='}')
Handy utility for concise readable output of a list of name that includes many that differ only by a numerical suffix.
source code
 
make_unique(strings, separator='')
Ensures that there are no duplicate strings in a list of strings.
source code
 
strip_accents(string)
Given a unicode string, which may contain accented characters, returns a string with no accented characters.
source code
 
str_to_bool(string) source code
 
slugify(value)
Normalizes string, converts to lowercase, removes non-alpha characters, and converts spaces to hyphens.
source code
Variables [hide private]
  TRUE_STRINGS = ['true', 't', '1', 'yes', 'on', 'hellyeah']
  __package__ = None
hash(x)
Function Details [hide private]

strs(list, sep=', ')

source code 

I'm fed up of typing this every time I want to print a list!

This is nothing more than:

 return sep.join(["%s" % item for item in list])

fmt_prob(prob, prec=4)

source code 

Format a float as a string in a style suitable for displaying probabilities. This is not a particularly quick procedure. If you need to format lots of probabilities, it's probably best to do something cruder.

group_numerical_suffixes(inlist, open_brace='{', close_brace='}')

source code 

Handy utility for concise readable output of a list of name that includes many that differ only by a numerical suffix. For example, ['model0','model1','model2'] is better represented as 'model{0-2}'.

Given a list of items, return a potentially smaller list, with all names differing only by a numerical suffix condensed into a single item, using {} to denote the suffix and using ranges where possible, otherwise comma-separated lists.

make_unique(strings, separator='')

source code 

Ensures that there are no duplicate strings in a list of strings. Wherever a duplicate is found, it is distinguished by appending an integer.

slugify(value)

source code 

Normalizes string, converts to lowercase, removes non-alpha characters, and converts spaces to hyphens.

Lifted straight from Django's slugify function.