Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README #3

Merged
merged 1 commit into from
Sep 28, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ Usages
def scope():
l_foo = 'local-foo'
l_bar = 'local-bar'
print( f('{l_foo}, {l_bar}') ) # 'local-foo, local-bar'
print( f('{l_foo}, {l_bar}') ) # 'local-foo, local-bar'
print( f('{g_foo}, {g_bar!r}') ) # "global-foo, 'global-bar'"

scope()
print( f('{{ }}') ) # '{ }'
print( f('hex: {g_num:#x}') ) # '0x17'
print( f('{os.EX_OK}') ) # '0'
print( f('{{ }}') ) # '{ }'
print( f('hex: {g_num:#x}') ) # '0x17'
print( f('{os.EX_OK}') ) # '0'
print( f('{g_ls[0]}, {g_ls[1]}, {g_ls[2]}') ) # '1, 2, 3'


Expand Down Expand Up @@ -70,16 +70,16 @@ Usages
def __format__(self, fmt):
return 'abcdefg'[int(fmt)]

print( f('{1234567890:,}') ) # '1,234,567,890'
print( f('{1 + 2}') ) # '3'
print( f('{str(1 + 2)!r}') ) # "'3'"
print( f('{[i for i in range(5)]}') ) # '[0, 1, 2, 3, 4]'
print( f('{1234567890:,}') ) # '1,234,567,890'
print( f('{1 + 2}') ) # '3'
print( f('{str(1 + 2)!r}') ) # "'3'"
print( f('{[i for i in range(5)]}') ) # '[0, 1, 2, 3, 4]'
ls = range(5)
print( f('{{i for i in ls}}') ) # 'set([0, 1, 2, 3, 4])' or '{0, 1, 2, 3, 4}'
print( f('{{i for i in ls}}') ) # 'set([0, 1, 2, 3, 4])' or '{0, 1, 2, 3, 4}'
print( f('{{k:v for k,v in zip(range(3), range(3, 6))}}') ) # '{0: 3, 1: 4, 2: 5}'
print( f('{datetime(1994, 11, 6):%Y-%m-%d}') ) # '1994-11-06'
print( f('{list(map(lambda x: x+1, range(3)))}') ) # '[1, 2, 3]'
print( f('{S()!r} {S()!s} {S():1}') ) # 'hello hi b'
print( f('{datetime(1994, 11, 6):%Y-%m-%d}') ) # '1994-11-06'
print( f('{list(map(lambda x: x+1, range(3)))}') ) # '[1, 2, 3]'
print( f('{S()!r} {S()!s} {S():1}') ) # 'hello hi b'


- Also, you can register some namespaces for convenience.
Expand All @@ -90,14 +90,14 @@ Usages
import fmt as f

f.mregister({'x': 1, 'y': 2}) # register multiple
f.register('z', 3) # register only one
f.register('z', 3) # register only one

def func(x, y):
return x + y

print( f('{func(x, y)}') ) # '3'
print( f('{func(x, z)}') ) # '4'
print( f('{func(y, z)}') ) # '5'
print( f('{func(x, y)}') ) # '6'


Installation
Expand Down