Good evening, I'm Wagner Herculano from Brazil. I was trying to do a table exercise with number 5 and tried formatting spaces and did not find it in PEP 498 documentation. Finally I found a way, if possible, include this example in the documentation please. Below is my script with the desired formatting about table of 5. n = 5 for i in range(1,11): print(f'{n} x {i:>2} = {n*i:>2}') Result 5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25 5 x 6 = 30 5 x 7 = 35 5 x 8 = 40 5 x 9 = 45 5 x 10 = 50 ----------- Sorry my English, I needed to use Google Translate Best Regards, Wagner Herculano
That's covered under "format specifiers" I think. The PEP mentions this: https://www.python.org/dev/peps/pep-0498/#format-specifiers That specific example is not mentioned in the docs, but there other examples of using format specifiers with f-strings. https://docs.python.org/3/reference/lexical_analysis.html#formatted-string-l... On Dec 15, 2017 7:39 AM, "Wagner Herculano" <wagherculano@hotmail.com> wrote:
Good evening, I'm Wagner Herculano from Brazil. I was trying to do a table exercise with number 5 and tried formatting spaces and did not find it in PEP 498 documentation. Finally I found a way, if possible, include this example in the documentation please.
Below is my script with the desired formatting about table of 5.
*n = 5*
*for i in range(1,11): print(f'{n} x {i:>2} = {n*i:>2}') Result 5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25 5 x 6 = 30 5 x 7 = 35 5 x 8 = 40 5 x 9 = 45 5 x 10 = 50* *-----------* *Sorry my English, I needed to use Google Translate*
Best Regards, Wagner Herculano
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/mariatta. wijaya%40gmail.com
That's covered under "format specifiers" I think. The PEP mentions this: https://www.python.org/dev/peps/pep-0498/#format-specifiers I can see how a newbie might not realize that that means that f-strings use the same formatting language as the .format() method, and or where to find documentation for it. So somewhere in the docs making that really clear, with a link to the formatting spec documentation would be good. Not sure where though — a PEP is not designed to be user documentation. -CHB That specific example is not mentioned in the docs, but there other examples of using format specifiers with f-strings. https://docs.python.org/3/reference/lexical_analysis.html#formatted-string-l... On Dec 15, 2017 7:39 AM, "Wagner Herculano" <wagherculano@hotmail.com> wrote:
Good evening, I'm Wagner Herculano from Brazil. I was trying to do a table exercise with number 5 and tried formatting spaces and did not find it in PEP 498 documentation. Finally I found a way, if possible, include this example in the documentation please.
Below is my script with the desired formatting about table of 5.
*n = 5*
*for i in range(1,11): print(f'{n} x {i:>2} = {n*i:>2}') Result 5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25 5 x 6 = 30 5 x 7 = 35 5 x 8 = 40 5 x 9 = 45 5 x 10 = 50* *-----------* *Sorry my English, I needed to use Google Translate*
Best Regards, Wagner Herculano
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/mariatta. wijaya%40gmail.com
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/chris.barker%40noaa.gov
I agree it's useful info :) I went ahead and made a PR [1]. In my PR, I simply linked to the Format Specification Mini Language[2] from f-strings documentation[3]. Not sure about updating PEP 498 at this point.. [1] https://github.com/python/cpython/pull/4888 [2] https://docs.python.org/3.6/library/string.html#format-s pecification-mini-language [3] https://docs.python.org/3/reference/lexical_analysis.html#f-strings
On Fri, Dec 15, 2017 at 9:39 AM, Mariatta Wijaya <mariatta.wijaya@gmail.com> wrote:
I agree it's useful info :)
I went ahead and made a PR [1].
Thanks! I added a couple comments to that PR.
Not sure about updating PEP 498 at this point..
A little clarification text would be nice. I made a PR for that: https://github.com/python/peps/pull/514 -CHB -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
Mariatta Wijaya writes:
I agree it's useful info :)
I went ahead and made a PR [1]. In my PR, I simply linked to the Format Specification Mini Language[2] from f-strings documentation[3].
Not sure about updating PEP 498 at this point..
I don't see any reason not to document tips and tricks with f-strings, and this is a nice and useful example. But it looks like TOOWTDI to me. The syntax is documented (6.1.3.1 in the Library Reference), along with a specific relevant example ("Aligning the text and specifying a width" in 6.1.3.2). So -1 on putting the recipe in the reference docs. I really don't think this kind of information belongs in a PEP for sure, and probably not even in the Library Reference. The Tutorial might be a good place for it, though. If I were Bach, I'd compose a more-itertools-like module to be named Variations_on_the_F_String. :-) Steve
On Tue, Dec 19, 2017 at 8:47 AM, Stephen J. Turnbull < turnbull.stephen.fw@u.tsukuba.ac.jp> wrote:
I don't see any reason not to document tips and tricks with f-strings, and this is a nice and useful example. But it looks like TOOWTDI to me. The syntax is documented (6.1.3.1 in the Library Reference), along with a specific relevant example ("Aligning the text and specifying a width" in 6.1.3.2).
So -1 on putting the recipe in the reference docs. I really don't think this kind of information belongs in a PEP for sure, and probably not even in the Library Reference.
The docs (and I think PEP) have been updated to clearly state that f-strings use the same formatting specifiers as .format(), and have links to those docs. So I think we're good.
The Tutorial might be a good place for it, though.
yup. -CHB -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov
Eric Fahlgren writes:
On Tue, Dec 19, 2017 at 8:47 AM, Stephen J. Turnbull < turnbull.stephen.fw@u.tsukuba.ac.jp> wrote:
If I were Bach, I'd compose a more-itertools-like module to be named Variations_on_the_F_String. :-)
Would that be P.D.Q. Bach to whom you are referring?
It's a curried function, supply your own arguments. "No, I won't!" Steve
Hi, Thank you all for your time. In fact I'm really a newbie and I need to study so hard (including English) to become someone like you all. I don't know if is possible, but I need to try. Once again, thank you all for your time and I'm sorry if I'm bother both of you. Kind regards, Wagner Herculano. ________________________________ From: Chris Barker - NOAA Federal <chris.barker@noaa.gov> Sent: Friday, December 15, 2017 2:49:08 PM To: Mariatta Wijaya Cc: Wagner Herculano; Python Dev Subject: Re: [Python-Dev] f-strings That's covered under "format specifiers" I think. The PEP mentions this: https://www.python.org/dev/peps/pep-0498/#format-specifiers I can see how a newbie might not realize that that means that f-strings use the same formatting language as the .format() method, and or where to find documentation for it. So somewhere in the docs making that really clear, with a link to the formatting spec documentation would be good. Not sure where though — a PEP is not designed to be user documentation. -CHB That specific example is not mentioned in the docs, but there other examples of using format specifiers with f-strings. https://docs.python.org/3/reference/lexical_analysis.html#formatted-string-l... On Dec 15, 2017 7:39 AM, "Wagner Herculano" <wagherculano@hotmail.com<mailto:wagherculano@hotmail.com>> wrote: Good evening, I'm Wagner Herculano from Brazil. I was trying to do a table exercise with number 5 and tried formatting spaces and did not find it in PEP 498 documentation. Finally I found a way, if possible, include this example in the documentation please. Below is my script with the desired formatting about table of 5. n = 5 for i in range(1,11): print(f'{n} x {i:>2} = {n*i:>2}') Result 5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25 5 x 6 = 30 5 x 7 = 35 5 x 8 = 40 5 x 9 = 45 5 x 10 = 50 ----------- Sorry my English, I needed to use Google Translate Best Regards, Wagner Herculano _______________________________________________ Python-Dev mailing list Python-Dev@python.org<mailto:Python-Dev@python.org> https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/mariatta.wijaya%40gmail.c... _______________________________________________ Python-Dev mailing list Python-Dev@python.org<mailto:Python-Dev@python.org> https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/chris.barker%40noaa.gov
participants (6)
-
Chris Barker -
Chris Barker - NOAA Federal -
Eric Fahlgren -
Mariatta Wijaya -
Stephen J. Turnbull -
Wagner Herculano