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

Doc: inputoutput tutorial improvements #16251

Merged
merged 3 commits into from
May 28, 2020

Conversation

adorilson
Copy link
Contributor

Just two little improvements: typo and make clear that sprintf is a C function.

Copy link
Contributor

@aeros aeros left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @adorilson.

@@ -172,7 +172,7 @@ Positional and keyword arguments can be arbitrarily combined::
If you have a really long format string that you don't want to split up, it
would be nice if you could reference the variables to be formatted by name
instead of by position. This can be done by simply passing the dict and using
square brackets ``'[]'`` to access the keys ::
square brackets ``'[]'`` to access the keys. ::
Copy link
Contributor

Choose a reason for hiding this comment

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

Within this context, the sentence is correct with or without the period since it's referring to an example, but I think your change is okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

More or less. Periods before an example always ends with a "." or with a ":". Right?
I chose the first one for no special reason.

Copy link
Contributor

@aeros aeros Sep 20, 2019

Choose a reason for hiding this comment

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

@adorilson:

More or less. Periods before an example always ends with a "." or with a ":". Right?

Here are all of the correct ways to use examples within the Python docs (as far as I'm aware):

This can be done by simply passing the dict and using square brackets ``'[]'``
to access the keys::
This can be done by simply passing the dict and using square brackets ``'[]'``
to access the keys. For example::
This can be done by simply passing the dict and using square brackets ``'[]'``
to access the keys. ::

Those types of formatting corrections aren't worth their own PR, but it can be useful to touch up on them if you're working on a nearby area for something more significant (such as with this PR). The quote used in PEP 8, "A foolish consistency is the hobgoblin of little minds", would be applicable to changing a section exclusively to use the correct formatting conventions.

left argument much like a :c:func:`sprintf`\ -style format string to be applied
to the right argument, and returns the string resulting from this formatting
operation. For example::
left argument much like to C's :c:func:`sprintf`\ -style format string to be
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on making this section more specific, any reader not familiar with C may not recognize that sprintf() is a C function. Particularly since this is in the tutorial, this should aim to be a new-user friendly as possible and not expect prior knowledge.

As a minor grammar correction, the "to" is not needed and the "a" should remain. However, I noticed that the sentence seems to run on a bit excessively. The ", and" part should be split into a second sentence.

Additionally, the Sphinx role does not accomplish anything here. This can be seen by referring to the documentation (https://docs.python.org/3.9/tutorial/inputoutput.html#old-string-formatting), it provides no link. Therefore, it should be converted into inline code blocks.

Here are the full changes that I would recommend:

It interprets the left argument much like a C ``sprintf()``-style format string
to be applied to the right argument. Then, the string resulting from the
formatting operation is returned.

Note: I did not include the word wrapping since I was just focusing on that individual sentence.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm accord this a lot

this should aim to be a new-user friendly as possible and not expect prior knowledge.

What if we removed the sprintf mention? Something like this:

The % operator (modulo) can also be used for string formatting. Given ``string % values``, % conversion specifications in ``string`` are replaced with zero or more elements of ``values``. This is also known as interpolation operator. For example:

Additionally, this section already has a link to https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting.

Copy link
Contributor

@aeros aeros Sep 20, 2019

Choose a reason for hiding this comment

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

@adorilson:

What if we removed the sprintf mention? Something like this:

Hmm, this is an interesting idea. String interpolation is a far more universal concept across several languages, and is likely to be more relatable to users of other languages without requiring the prior knowledge.

My suggestion would be to change:

This is also known as interpolation operator.

To this:

This operation is commonly known as string interpolation.

While "interpolation operator" is not incorrect, I've seen "string interpolation" mentioned far more commonly. See https://en.wikipedia.org/wiki/String_interpolation and https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated. In any search engine, using the query string interpolation <language> is pretty much guaranteed to find the correct results for any widely used programming language.

Also as a more minor suggestion, I would recommend changing:

Given ``string % values``, % conversion specifications in ``string`` are replaced with zero or more elements of ``values``.

To this:

Given ``'string' % values``, instances of ``%`` in ``string`` are replaced with zero or more elements of ``values``.

I think this phrasing will make a bit more sense to readers and adds a bit of clarity with the formatting.

Good idea overall though, I'm definitely on board with it myself. +1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great. I will do this. But, I have a question. In my local branch, Do I must revert this commit or just add a new?

Copy link
Contributor

Choose a reason for hiding this comment

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

@adorilson:

In my local branch, Do I must revert this commit or just add a new?

Either way works. Since this will all get squashed into a single commit when/if the PR is merged, the actual commit log within the PR branch doesn't matter much. I usually prefer to add commits so that I can revert back to it at a later point in time if needed, but it's up to personal preference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aeros167 It's done. Thanks for suggestions.

@aeros
Copy link
Contributor

aeros commented Sep 19, 2019

Since this section also exists in the 3.8 and 3.7 docs, these changes should be able to automatically backport without any merge conflicts.

@csabella
Copy link
Contributor

@aeros, would you like to merge this? Thanks!

@aeros
Copy link
Contributor

aeros commented May 28, 2020

Sure! Thanks for reminding me about this PR @csabella, it's a bit easy for me to lose track of the ones I approved prior to getting commit privileges. :-)

@aeros aeros merged commit eaca2aa into python:master May 28, 2020
@miss-islington
Copy link
Contributor

Thanks @adorilson for the PR, and @aeros for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-20475 is a backport of this pull request to the 3.8 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 28, 2020
* Use a more universal explanation of string interpolation rather than specifically referencing sprintf(), which depends on the reader having a C background.

Co-authored-by: Kyle Stanley <aeros167@gmail.com>
(cherry picked from commit eaca2aa)

Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
@miss-islington
Copy link
Contributor

Thanks @adorilson for the PR, and @aeros for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington
Copy link
Contributor

Thanks @adorilson for the PR, and @aeros for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-20476 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 28, 2020
* Use a more universal explanation of string interpolation rather than specifically referencing sprintf(), which depends on the reader having a C background.

Co-authored-by: Kyle Stanley <aeros167@gmail.com>
(cherry picked from commit eaca2aa)

Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
@bedevere-bot
Copy link

GH-20477 is a backport of this pull request to the 3.9 branch.

miss-islington added a commit that referenced this pull request May 28, 2020
* Use a more universal explanation of string interpolation rather than specifically referencing sprintf(), which depends on the reader having a C background.

Co-authored-by: Kyle Stanley <aeros167@gmail.com>
(cherry picked from commit eaca2aa)

Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
miss-islington added a commit that referenced this pull request May 28, 2020
* Use a more universal explanation of string interpolation rather than specifically referencing sprintf(), which depends on the reader having a C background.

Co-authored-by: Kyle Stanley <aeros167@gmail.com>
(cherry picked from commit eaca2aa)

Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
miss-islington added a commit that referenced this pull request May 28, 2020
* Use a more universal explanation of string interpolation rather than specifically referencing sprintf(), which depends on the reader having a C background.

Co-authored-by: Kyle Stanley <aeros167@gmail.com>
(cherry picked from commit eaca2aa)

Co-authored-by: Adorilson Bezerra <adorilson@gmail.com>
@adorilson adorilson deleted the inputoutupt_improvements branch March 31, 2024 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip issue skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants