Skip to content

[Lang] Support very basic python string.format() now#2552

Merged
ljcc0930 merged 7 commits intotaichi-dev:masterfrom
Leonz5288:print
Jul 20, 2021
Merged

[Lang] Support very basic python string.format() now#2552
ljcc0930 merged 7 commits intotaichi-dev:masterfrom
Leonz5288:print

Conversation

@Leonz5288
Copy link
Contributor

Related issue = #2396

@Leonz5288
Copy link
Contributor Author

/format

@Leonz5288 Leonz5288 requested review from k-ye and ljcc0930 July 20, 2021 03:41
@Leonz5288
Copy link
Contributor Author

Leonz5288 commented Jul 20, 2021

We support basic string format in print now. For example, code below:

import taichi as ti
ti.init()
ops = ti.field(ti.float32, shape=(1, ))
yes = ti.field(ti.int32, shape=(1, ))

@ti.kernel
def test():
    ops[0] = 3.14
    yes[0] = 3
    print('Two numbers:', ' {} and {} '.format(ops[0], yes[0]), 'and a list: ', ['q', 'w', 'e', 'r'], sep='|')
    print('round{}square{}what?{}'.format(ops[0], 123, ' wellwellwell'))

test()

Would print the result:

Two numbers:| 3.140000 and 3 |and a list: |[q, w, e, r]
round3.140000square123what? wellwellwell

@Leonz5288
Copy link
Contributor Author

/format

1 similar comment
@ljcc0930
Copy link
Contributor

/format

Copy link
Contributor

@ljcc0930 ljcc0930 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@CLAassistant
Copy link

CLAassistant commented Jul 20, 2021

CLA assistant check
All committers have signed the CLA.

@ljcc0930 ljcc0930 merged commit 688f926 into taichi-dev:master Jul 20, 2021
@Leonz5288 Leonz5288 deleted the print branch July 20, 2021 09:32
@Leonz5288 Leonz5288 mentioned this pull request Jul 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants