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
TextCalendar.prweek/month/year outputs an extra whitespace character #72442
Comments
Currently TextCalendar.prweek/month/year outputs an extra whitespace which makes the output weird: >>> calendar.TextCalendar().prweek([(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7)], 2)
1 2 3 4 5 6 7 >>> calendar.TextCalendar().prmonth(2016,9)
September 2016
Mo Tu We Th Fr Sa Su
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
>>> |
The patch LGTM. Could you please add tests? I suppose this is a consequence of porting from Python 2 to Python 3 (maybe with 2to3). Usually "print x," in Python 2 corresponds to "print(x, end=' ')" in Python 3. But if x ends with \n, print with a comma in Python 2 don't add a space, this corresponds to "print(x, end='')". Similar issue was fixed not long ago. Maybe there are other similar issues in the stdlib or scripts. |
prweek() in Python 2 adds a final space. Python 3 version looks correct. |
A single >>> print 'a',
a
>>>
>>> print('a', end='')
a>>> |
Actually the behavior of the print statement in Python 2 is more complex. "print x," doesn't output a space after x, but sets the softspace attribute of the file to true (unless x is a string ending with non-space whitespace character like \n or \t). print tests this flag before outputting a value and outputs a space if it is true. Any output to a file resets this flag. This behavior can't be exactly reproduced in Python 3. |
It looks to me that only prmonth() should be changed. prweek() and pryear() either match the behavior of PYthon 2 or are the good approximation of it. |
New changeset 8d54c2a1c796 by Serhiy Storchaka in branch '3.5': New changeset ebe5bd33f86f by Serhiy Storchaka in branch '3.6': New changeset 049e58f74272 by Serhiy Storchaka in branch 'default': |
New changeset 4a3892f49e1a by Serhiy Storchaka in branch 'default': |
prweek() and pryear() are changed only in 3.7. If this breaks somebody's code, there is enough time to update this code or rollback changes. |
Misc/NEWS
so that it is managed by towncrier #552Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: