[Chennaipy] ChennaiPy Feb Meeting Minutes(27/Feb/2021)

Kamesh Jayachandran kamesh.jayachandran at gmail.com
Sat Feb 27 09:37:29 EST 2021


Hi All,

1. defaultdict:
Rengaraj gave a talk on 'defaultdict'.
He covered how to set the default value by 'type' and function object.
Before this session I used to think the only purpose of 'defaultdict' was
to avoid 'KeyError'. In this session I learnt that even the seemingly
'read' operation to a non-existent key lookup creates an entry in the
dictionary. Moment you look for d['non-existent'] you get the 'key' named
'non-existent' with the default value.
He showed one program he wrote 3 years ago where he was summing the value
of one key, without 'defaultdict' he needed to write 4 lines of code (if
... else) to do the same. With defaultdict he can just do it in one line.

2. Garbage collector in python:
Ibrahim gave a talk on 'Garbage collection in python'.

   - Everything in python is 'PyObj' whose 3 key attributes are 'type',
   'value' and 'refcount'.
   - If you have a=5 and b=5 there will be a single PyObj with the value
   '5' and two references to it from 'a' and 'b'. When 'a' or 'b' changes it
   creates another Pyobj with the new value and reduces the ref count of the
   old PyObj. You can confirm it by the 'id' function a=5, b=5 id(a) == id(b)
   - You can check the ref count of the object/variable using
   sys.getrefcount() interestingly in my simple program of a=5,
   sys.getrefcount(a) gives 21. Not sure what those '20' other references are.
   May be other items in the current stack/runtime with the value '5'.
   - Drawbacks of ref counter

            a=[5]
            a.append(a) This creates a cyclical reference which would lead
to 'a' never having '0' refcount and hence it would never be garbage
collected.

   - objgraph.show_refs generates a nice graphic of the object and its
   references.
   - Covered Various generations of objects and how they are garbage
   collected by looking for cyclic references.

  ------------
3. C++ adopting python ideas. Vijaykumar was sharing the C++ syntax
enhancements inspired from python language.
(I had a few minutes internet connectivity issue during this session).

   - C++17 (2017 standard/edition): range based loops

for (auto m: list) {
}

   - structured bindings(a.k.a tuple unpacking in python)
   pair <int, string> foo()
   {
   return {1, "hello world"};
   }

   auto [line, str] = foo();
   - C++20 export, import module.

4. Ranga gave a lightning talk on kubernetes installation on AWS.

Thanks
With regards
Kamesh Jayachandran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/chennaipy/attachments/20210227/e30f0333/attachment.html>


More information about the Chennaipy mailing list