This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!
Project Description

Simple way to have partially applied formatted strings.

This python package provides a wrapper around the ‘str.format’ functionality in order to skip unresolved formatting parts. All arguments are applied lazily.

Install

Enter the following command:

$ pip install lazy_format

Examples

More examples you can find in the tests.

Common use case:

>>> from lazy_format import LazyFormat
>>>
>>> lazy = LazyFormat('{0} {1} {0} {msg} {var1} {var2} {obj!r} {x:.2f}', 'fist arg', msg='Hello')
>>> lazy
<lazy_format.format.LazyFormat at 0x22a2590>
>>> print lazy
fist arg {1} fist arg Hello {var1} {var2} {obj!r} {x:.2f}
>>>
>>> lazy.format('second arg', obj=LazyFormat, x=22/7.)
"fist arg second arg fist arg Hello {var1} {var2} <class 'lazy_format.format.LazyFormat'> 3.14"
>>>
>>> lazy.format('second arg', obj=LazyFormat, x=22/7., var1='1', var2=2)
"fist arg second arg fist arg Hello 1 2 <class 'lazy_format.format.LazyFormat'> 3.14"
>>>
>>> lazy.format('second arg', obj=LazyFormat, x=22/7., var1='1', var2=2, msg='Bye')
"fist arg second arg fist arg Bye 1 2 <class 'lazy_format.format.LazyFormat'> 3.14"

Global context:

>>> LazyFormat.global_context.update_context_with({'global_var1': 'GV1', 'global_var2': 'GV2'})
>>> lazy2 = LazyFormat('{global_var1}, {global_var2}')
>>> print lazy2
GV1, GV2
>>> print lazy2.format(global_var1='my var1')
my var1, GV2

Extra features:

>>> from lazy_format import Aliases
>>> from lazy_format import LazyAliasFormat
>>>
>>> Aliases.add_alias('project_name', 'LazyFormat')
>>> lazy3 = LazyAliasFormat('{alias.project_name}')
>>> print lazy3
LazyFormat
>>>
>>>
>>> def func(alias, context):
>>>     return 'dyn value for ' + alias
>>>
>>> Aliases.add_alias('val', func)
>>> lazy4 = LazyAliasFormat('{alias.val}')
>>> print lazy4
dyn value for val
>>>
>>>
>>> LazyAliasFormat('{project_dir}', alias='dir')
<lazy_format.format.LazyAliasFormat at 0x22a2a50>
>>> templates = LazyAliasFormat('{alias.dir}/{template_dir_name}',
>>>                             template_dir_name='templates',
>>>                             alias='template_dir')
>>>
>>> my_prj_templates = LazyAliasFormat('{alias.template_dir}',
>>>                                    project_dir='/code/lazy_format',
>>>                                    template_dir_name='tmps')
>>> print templates
{project_dir}/templates
>>> print my_prj_templates
/code/lazy_format/tmps
>>> print my_prj_templates.format(project_dir='/code2')
/code2/tmps
Release History

Release History

0.0.2

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
lazy_format-0.0.2.linux-x86_64.exe (64.9 kB) Copy SHA256 Checksum SHA256 any Windows Installer Jun 19, 2013
lazy_format-0.0.2.tar.gz (2.2 kB) Copy SHA256 Checksum SHA256 Source Jun 19, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting