Re: [Tutor] question about metaclasses

2018-01-18 Thread Steven D'Aprano
On Thu, Jan 18, 2018 at 05:31:24PM +, Albert-Jan Roskam wrote: > > Don't make the mistake of doing this: > > > > from collections import namedtuple > > a = namedtuple('Bag', 'yes no dunno')(yes=1, no=0, dunno=42) > > b = namedtuple('Bag', 'yes no dunno')(yes='okay', no='no way', dunno='not a

Re: [Tutor] Writing to a file

2018-01-18 Thread Alan Gauld via Tutor
On 18/01/18 20:51, Devansh Rastogi wrote: > When do you actually use json or pickle, I understand that with data > written to .json files can be used by programs written in other languages, > and pickle is for python specific objects. Yes, that's correct. > So are there specific objects > for

[Tutor] Writing to a file

2018-01-18 Thread Devansh Rastogi
Hello, I'm new to python and programming as such and as an exercise for I/O am writing a small program that reads data from a .txt file, and analyzes the text, ie, number of words/characters, avg. length of words, and frequency of words and characters. Once the text has been analyzed, the

Re: [Tutor] question about metaclasses

2018-01-18 Thread Albert-Jan Roskam
On Jan 10, 2018 19:32, Peter Otten <__pete...@web.de> wrote: > > Albert-Jan Roskam wrote: > > > Why does following the line (in #3) > > > # 3- > > class Meta(type): > > def __new__(cls, name, bases, attrs): > > for attr, obj in

Re: [Tutor] question about metaclasses

2018-01-18 Thread Albert-Jan Roskam
On Jan 10, 2018 18:57, Steven D'Aprano wrote: > > On Wed, Jan 10, 2018 at 04:08:04PM +, Albert-Jan Roskam wrote: > > > In another thread on this list I was reminded of > > types.SimpleNamespace. This is nice, but I wanted to create a bag > > class with constants that are