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

2017-08-08 Thread Cameron Simpson
On 07Aug2017 20:22, boB Stepp wrote: On Mon, Aug 7, 2017 at 8:36 AM, Steven D'Aprano wrote: [...] It is hard to see the distinction between an ordinary method and a static method from this example. What you are seeing is, by accident, the equivalent of just writing: def my_method(): prin

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

2017-08-08 Thread Alan Gauld via Tutor
On 08/08/17 02:22, boB Stepp wrote: > "@staticmethod" then there are two ways of calling the method, using > objects or using the class. Is there some reason not to use the > "ClassName.a_static_method()" syntax? Are there intended uses for > doing this? classes are objects too... You could ha

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

2017-08-08 Thread Peter Otten
Alan Gauld via Tutor wrote: > classes are objects too... Also, classes are instances. Given >>> class Foo: ... pass ... >>> foo = Foo() >>> type(foo) >>> type(Foo) what is the type of the type of the type ... of foo? The answer is a circular definition that you cannot spell in Python its

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

2017-08-08 Thread Cameron Simpson
On 08Aug2017 08:39, Alan Gauld wrote: (1) There are very, very few good uses for static methods in Python. If you think you need a static method, you probably could just use a regular module-level function. Amen to that, I try to avoid staticmethods... and so far have never found a valid use f

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

2017-08-08 Thread Chris Warrick
On 8 August 2017 at 03:30, Ben Finney wrote: > 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. > > I

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

2017-08-08 Thread boB Stepp
On Mon, Aug 7, 2017 at 10:01 PM, Ben Finney wrote: > 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") >

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

2017-08-08 Thread boB Stepp
On Mon, Aug 7, 2017 at 10:04 PM, Zachary Ware wrote: > Next, take a dive into the wonderful* world of Unicode: > > https://nedbatchelder.com/text/unipain.html > https://www.youtube.com/watch?v=7m5JA3XaZ4k > > Hope this helps, Thanks, Zach, this actually clarifies things considerably. I just fin

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

2017-08-08 Thread Mats Wichmann
eh? the bytes are ff fe h 0 0xff is not literally four bytes, its the hex repr of an 8bit quantity with all bits on On August 8, 2017 9:17:49 PM MDT, boB Stepp wrote: >On Mon, Aug 7, 2017 at 10:01 PM, Ben Finney > wrote: >> boB Stepp writes: >> >>> How is len() getting these values? >> >> By

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

2017-08-08 Thread boB Stepp
On Mon, Aug 7, 2017 at 10:20 PM, Cameron Simpson wrote: > 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 tu

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

2017-08-08 Thread boB Stepp
On Mon, Aug 7, 2017 at 11:30 PM, eryk sun wrote: > 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 endi

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

2017-08-08 Thread boB Stepp
On Tue, Aug 8, 2017 at 10:29 PM, Mats Wichmann wrote: > eh? the bytes are ff fe h 0 > 0xff is not literally four bytes, its the hex repr of an 8bit quantity with > all bits on ARG! (space inserted for visual clarity) truly is ff in hex. Again ARGH!!! All I can say is that I have

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

2017-08-08 Thread boB Stepp
On Tue, Aug 8, 2017 at 10:17 PM, boB Stepp wrote: > On Mon, Aug 7, 2017 at 10:01 PM, Ben Finney > wrote: >> boB Stepp writes: >> >>> How is len() getting these values? >> > > It is translating the Unicode code points into bits patterned by the > encoding specified. I know this. I was reading

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

2017-08-08 Thread boB Stepp
On Tue, Aug 8, 2017 at 2:39 AM, Alan Gauld via Tutor wrote: > On 08/08/17 02:22, boB Stepp wrote: [snip lots of good stuff] I am coming to the conclusion I need to code a substantial, challenging project using OOP techniques, instead of just the toy programs I have been playing around with so fa

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

2017-08-08 Thread Cameron Simpson
On 08Aug2017 22:30, boB Stepp wrote: On Mon, Aug 7, 2017 at 10:20 PM, Cameron Simpson wrote: 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