Re: [Tutor] How does len() compute length of a string in UTF-8, 16, and 32?

2017-08-07 Thread eryk sun
On Tue, Aug 8, 2017 at 3:20 AM, Cameron Simpson wrote: > > As you note, the 16 and 32 forms are (6 + 1) times 2 or 4 respectively. This > is because each encoding has a leading byte order marker to indicate the big > endianness or little endianness. For big endian data that is \xff\xfe; for > litt

Re: [Tutor] How does len() compute length of a string in UTF-8, 16, and 32?

2017-08-07 Thread Cameron Simpson
On 07Aug2017 21:44, boB Stepp wrote: py3: s = 'Hello!' py3: len(s.encode("UTF-8")) 6 py3: len(s.encode("UTF-16")) 14 py3: len(s.encode("UTF-32")) 28 How is len() getting these values? And I am sure it will turn out not to be a coincidence that 2 * (6 + 1) = 14 and 4 * (6 + 1) = 28. Hmm The

Re: [Tutor] How does len() compute length of a string in UTF-8, 16, and 32?

2017-08-07 Thread Zachary Ware
On Mon, Aug 7, 2017 at 9:44 PM, boB Stepp wrote: > py3: s = 'Hello!' > py3: len(s.encode("UTF-8")) > 6 > py3: len(s.encode("UTF-16")) > 14 > py3: len(s.encode("UTF-32")) > 28 > > How is len() getting these values? And I am sure it will turn out not > to be a coincidence that 2 * (6 + 1) = 14 and

Re: [Tutor] How does len() compute length of a string in UTF-8, 16, and 32?

2017-08-07 Thread Ben Finney
boB Stepp writes: > How is len() getting these values? By asking the objects themselves to report their length. You are creating different objects with different content:: >>> s = 'Hello!' >>> s_utf8 = s.encode("UTF-8") >>> s == s_utf8 False >>> s_utf16 = s.encode("UTF-16")

[Tutor] How does len() compute length of a string in UTF-8, 16, and 32?

2017-08-07 Thread boB Stepp
py3: s = 'Hello!' py3: len(s.encode("UTF-8")) 6 py3: len(s.encode("UTF-16")) 14 py3: len(s.encode("UTF-32")) 28 How is len() getting these values? And I am sure it will turn out not to be a coincidence that 2 * (6 + 1) = 14 and 4 * (6 + 1) = 28. Hmm ... -- boB _

Re: [Tutor] setup.py "script" vs "console_scripts" Was: if __name__=='main' vs entry points: What to teach new comers?

2017-08-07 Thread Ben Finney
Thomas Güttler writes: > Why is "the sane default is 'use console_scripts entry-point in > setup.py'" not a good answer? Because third-party Setuptools is required for entry points, which means entry points cannot be a default choice. It may well be a good choice for many cases. But that's a di

Re: [Tutor] Difference(s) betweenPython 3 static methods with and without @staticmethod?

2017-08-07 Thread boB Stepp
I feel like I have gazed into a crystal clear pool, apparently shallow, with many interesting objects (Pun intended!) on the pool floor. Interested in these beautiful things, I jump in to grab one for close-up study only to find that the pool is much, ... , much deeper (> 1 boB-height) than it app

Re: [Tutor] Difference(s) betweenPython 3 static methods with and without @staticmethod?

2017-08-07 Thread Steven D'Aprano
On Sun, Aug 06, 2017 at 06:35:10PM -0500, boB Stepp wrote: > py3: class MyClass: > ... def my_method(): > ... print('This is my_method in MyClass!') > ... > py3: class MyOtherClass: > ... @staticmethod > ... def my_other_method(): > ... print('This is my_other_m

Re: [Tutor] setup.py "script" vs "console_scripts" Was: if __name__=='main' vs entry points: What to teach new comers?

2017-08-07 Thread Thomas Güttler
Am 05.08.2017 um 06:14 schrieb Ben Finney: Thomas Güttler writes: The underlaying question is: Imangine you are a newcomer. A newcomer is in a tough position when it comes to packaging and distributing Python code, especially the command-line programs. There has been significant progress