[issue26506] hex() documentation: mention "%x" % int

2017-06-27 Thread STINNER Victor
STINNER Victor added the comment: Can someone pick the last patch and convert it to a pull request? CPython moved to GitHub in the meanwhile! See http://docs.python.org/devguide/ ;-) -- ___ Python tracker

[issue26506] hex() documentation: mention "%x" % int

2016-03-22 Thread Manvi B
Manvi B added the comment: Considered the reviews from STINNER Victor (haypo) and comments, the patch is modified. -- Added file: http://bugs.python.org/file42242/issue26506.diff ___ Python tracker ___

[issue26506] hex() documentation: mention "%x" % int

2016-03-21 Thread Ezio Melotti
Ezio Melotti added the comment: > Note: Ezio, do you prefer format(value, 'x') for '{:x}'.format(value)? While formatting a single value the former is better/shorter, but the latter is perhaps more common since you usually have something else in the string too. The latter can also be used to d

[issue26506] hex() documentation: mention "%x" % int

2016-03-21 Thread STINNER Victor
STINNER Victor added the comment: Ezio Melotti added the comment: > I can think of 3 possible solutions: > > 1) keep the examples but condense them so that they don't take so much space: n = 255 f'{n:#x}', format(n, '#x'), '%#x' % n > ('0xff', '0xff', '0xff') f'{n:x}', format(n, 'x

[issue26506] hex() documentation: mention "%x" % int

2016-03-21 Thread Ezio Melotti
Ezio Melotti added the comment: > The documentation for hex() doesn't look the bests place for examples > of using string formatting. I think it is enough to add short > references to corresponding formatting codes. I think those examples take too much space compared to the actual docs of the f

[issue26506] hex() documentation: mention "%x" % int

2016-03-21 Thread STINNER Victor
STINNER Victor added the comment: Serhiy Storchaka: > The documentation for hex() doesn't look the bests place for examples of > using string formatting. I think it is enough to add short references to > corresponding formatting codes. I like Manvi B's patch with many examples. It's hard to re

[issue26506] hex() documentation: mention "%x" % int

2016-03-21 Thread Manvi B
Manvi B added the comment: Modified the patch with '%x' % value. -- Added file: http://bugs.python.org/file42228/issue26506.diff ___ Python tracker ___ __

[issue26506] hex() documentation: mention "%x" % int

2016-03-21 Thread Manvi B
Manvi B added the comment: Removed hex()[:2] from the patch. -- Added file: http://bugs.python.org/file42227/issue26506.diff ___ Python tracker ___ __

[issue26506] hex() documentation: mention "%x" % int

2016-03-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The documentation for hex() doesn't look the bests place for examples of using string formatting. I think it is enough to add short references to corresponding formatting codes. -- ___ Python tracker

[issue26506] hex() documentation: mention "%x" % int

2016-03-20 Thread STINNER Victor
STINNER Victor added the comment: You misunderstood the whole purpose of my issue! You must not write hex()[:2] (it's inefficent)! Please remove it from your patch. -- ___ Python tracker ___

[issue26506] hex() documentation: mention "%x" % int

2016-03-20 Thread Manvi B
Manvi B added the comment: Modified documentation for the functions bin(), hex() and oct() as mentioned in the comments. Submitted the patch. -- keywords: +patch nosy: +Manvi B Added file: http://bugs.python.org/file42221/issue26506.diff ___ Python t

[issue26506] hex() documentation: mention "%x" % int

2016-03-11 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I agree with you and always prefer formatting strings. Your example shows that at least an alternative to str.zfill() should be mentioned in the educational purposes. With C-style formatting your example can be written more laconically: return "%0*x" %

[issue26506] hex() documentation: mention "%x" % int

2016-03-11 Thread STINNER Victor
STINNER Victor added the comment: I opened the issue when I read this change: https://review.openstack.org/#/c/288224/2/neutron/common/utils.py rndstr = hex(...)[2:] # Whether there is a trailing 'L' is a py2/3 incompatibility rndstr = rndstr.rstrip('L') return rndstr.zfill(lengt

[issue26506] hex() documentation: mention "%x" % int

2016-03-10 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: There is no harm if use hex(value)[2:]. It's a matter of taste. We can mention "%x" % value for the case if the user just doesn't know about this alternative. The same is for value.ljust(5) and '%-5s' % value. --

[issue26506] hex() documentation: mention "%x" % int

2016-03-10 Thread STINNER Victor
STINNER Victor added the comment: Serhiy Storchaka added the comment: > If document alternatives for hex(), we should also document formatting alternatives for bin(), oct(), Ok for these two since they also add a prefix. But I don't see the point of documenting alternatives for the other listed

[issue26506] hex() documentation: mention "%x" % int

2016-03-10 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: > That's why I ran the micro-benchmark and, in fact, I was expecting > %-interpolation to be faster exactly because it is less flexible. Actually %-interpolation is more flexible. >>> '%x' % 123 '7b' >>> '%0X' % 123 '7B' >>> '%#x' % 123 '0x7b' >>> '%04x' % 1

[issue26506] hex() documentation: mention "%x" % int

2016-03-10 Thread Wolfgang Maier
Wolfgang Maier added the comment: > Hum, python3 looks faster on this dummy microbenchmark yeah. Who said that > Python 3 is slower? :-) If you're alluding to that seemingly endless thread over on python-list, let me say that it is not my motivation to start anything like that here. Sorry also

[issue26506] hex() documentation: mention "%x" % int

2016-03-10 Thread STINNER Victor
STINNER Victor added the comment: > I regulary see Python code using hex(value)[2:] In fact, it's even worse, I also saw Python 2 code stripping trailing "L", since hex(long) adds a L suffix... $ python2 Python 2.7.10 (default, Sep 8 2015, 17:20:17) [GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on

[issue26506] hex() documentation: mention "%x" % int

2016-03-09 Thread STINNER Victor
STINNER Victor added the comment: > Ah, but it's not that format() is slower in 3.5, but that %-formatting got > faster. Hum, python3 looks faster on this dummy microbenchmark yeah. Who said that Python 3 is slower? :-) $ python2 -m timeit -s 'import random; nums = [random.randint(0, 255) for

[issue26506] hex() documentation: mention "%x" % int

2016-03-09 Thread Wolfgang Maier
Wolfgang Maier added the comment: Ah, but it's not that format() is slower in 3.5, but that %-formatting got faster. It looks as if it got optimized and I was wondering whether the same optimization could be applied to format(). -- ___ Python tracke

[issue26506] hex() documentation: mention "%x" % int

2016-03-09 Thread Eric V. Smith
Eric V. Smith added the comment: Without lots of analysis (and disassembly), I can't speak to how valid your tests are, but they don't seem unreasonable. format() will always be slower, because it's more general (primarily in that it can be extended to new types). Plus, it involves at least a

[issue26506] hex() documentation: mention "%x" % int

2016-03-09 Thread Wolfgang Maier
Wolfgang Maier added the comment: Your two suggestions prompted me to do a speed comparison between them and the result surprised me. I tried: import random nums = [random.randint(0, 255) for n in range(1000)] then timed the simple: for n in nums: hx = '%X' % n # or hx = format(n, '

[issue26506] hex() documentation: mention "%x" % int

2016-03-07 Thread Eric V. Smith
Eric V. Smith added the comment: For 3.5 and 2.7, I'd suggest: format(value, 'x') or: format(value, 'X') Although you might disagree because of the verbosity. But at least you're not parsing a string at runtime. And for 3.6 with PEP-498: f'{value:x}' There are of course options for padding a

[issue26506] hex() documentation: mention "%x" % int

2016-03-07 Thread STINNER Victor
New submission from STINNER Victor: I regulary see Python code using hex(value)[2:], whereas "%x" % value does the same thing. We should mention "%x" % value in the hex() doc. Maybe also mention "%#X" % value to format in upper case? -- assignee: docs@python components: Documentation m