2020-03-03

Some useful py notes

import random

blogpost=random.some_py_notes ;)

Several useful py notes will be shared in this post: generators & pickle.

Instead of using whole object and preventing RAM over-consumption, generator is more recommended way, cause: cursor
By cursor logic, it retrieves raw within fetch one concept, not a bunch of object. So that, performance and speed of query is boosted. Yield is used instead of return in order to returning value.
Generator file type is also recommended from a performance and size aspects.
While the size of list is 1448 bytes, the generator's is just 120bytes. That's because it's not storing all the data, just a cursor to loop through the data.
Check this out:


 Another useful py method is pickle. Instead of applying commands over and over again, use pickle  to save in global scope as a backup file and  restore then. Use cases samples: saving pre-processed data sets or ML model.
Feel free to post feedback :)

No comments:

Post a Comment