gpython icon indicating copy to clipboard operation
gpython copied to clipboard

Implement string format method

Open DoDaek opened this issue 6 years ago • 4 comments

python

>>> a = 'alpha'
>>> b = 'bravo'
>>> d = 'delta'
>>> origin = '{} {} charlie {}'
>>> new = origin.format(a, b, d)
>>> print(new)
alpha bravo charlie delta
>>> print(origin)
{} {} charlie {}
>>>

gpython

>>> a = 'alpha'
>>> b = 'bravo'
>>> d = 'delta'
>>> origin = '{} {} charlie {}'
>>> new = origin.format(a, b, d)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    FIXME line of source goes here
AttributeError: "'str' has no attribute 'format'"
>>> print(new)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    FIXME line of source goes here
NameError: "name 'new' is not defined"
>>> print(origin)
{} {} charlie {}
>>>

Attribute error occured using string.

DoDaek avatar Oct 07 '19 09:10 DoDaek

Yes gpython needs this :-)

The specification of the format language is here so it is reasonably complicated to do completely.

ncw avatar Oct 08 '19 15:10 ncw

It may take some time, but I'll work it out. Thanks for your information :+1:

DoDaek avatar Oct 11 '19 13:10 DoDaek

@DoDaek You can have a look (or use it?) here. The function should be callable using "".format and str.format

ghost avatar Oct 11 '19 17:10 ghost

Waiting on response from @slongfield

https://github.com/slongfield/pyfmt/issues/15

drew-512 avatar Feb 16 '22 19:02 drew-512