diff options
author | pohmelie <multisosnooley@gmail.com> | 2016-01-29 12:09:10 +0300 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-02-02 16:25:24 +0000 |
commit | e3a29de1dc7649656228460caf72e7841440a373 (patch) | |
tree | c3b4f936989c7888300b7e2198dcec05a01c7379 /tests/basics | |
parent | 2bd758fe96e2913f48c1a0fdccafddc3dfb31cf9 (diff) | |
download | micropython-e3a29de1dc7649656228460caf72e7841440a373.tar.gz micropython-e3a29de1dc7649656228460caf72e7841440a373.zip |
py/objstr: For str.format, add nested/computed fields support.
Eg: '{:{}}'.format(123, '>20')
@pohmelie was the original author of this patch, but @dpgeorge made
significant changes to reduce code size and improve efficiency.
Diffstat (limited to 'tests/basics')
-rw-r--r-- | tests/basics/string_format.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/tests/basics/string_format.py b/tests/basics/string_format.py index 7fb53cb491..e07f0d9533 100644 --- a/tests/basics/string_format.py +++ b/tests/basics/string_format.py @@ -66,6 +66,14 @@ test("{:>20}", "foo") test("{:^20}", "foo") test("{:<20}", "foo") +# nested format specifiers +print("{:{}}".format(123, '#>10')) +print("{:{}{}{}}".format(123, '#', '>', '10')) +print("{0:{1}{2}}".format(123, '#>', '10')) +print("{text:{align}{width}}".format(text="foo", align="<", width=20)) +print("{text:{align}{width}}".format(text="foo", align="^", width=10)) +print("{text:{align}{width}}".format(text="foo", align=">", width=30)) + print("{foo}/foo".format(foo="bar")) print("{}".format(123, foo="bar")) print("{}-{foo}".format(123, foo="bar")) |