Strings

flutils offers the following string utility functions.

flutils.camel_to_underscore(text)[source]

Convert a camel-cased string to a string containing words separated with underscores.

Parameters:text (str) – The camel-cased string to convert.
Returns:An underscore separated string.
Return type:str

Example

>>> from flutils import camel_to_underscore
>>> camel_to_underscore('FooBar')
'foo_bar'
flutils.underscore_to_camel(text, lower_first=True)[source]

Convert a string with words separated by underscores to a camel-cased string.

Parameters:
  • text (str) – The camel-cased string to convert.
  • lower_first (bool, optional) – Lowercase the first character. Defaults to True
Returns:

A camel-cased string.

Return type:

str

Examples

>>> from flutils import underscore_to_camel
>>> underscore_to_camel('foo_bar')
'fooBar'
>>> underscore_to_camel('_one__two___',lower_first=False)
'OneTwo'