Generate Your Text Files With Python Using Cog

The Python Podcast.__init__

Episode | Podcast

Date: Thu, 13 Jan 2022 18:00:00 -0500

<div class="wp-block-jetpack-markdown"><h2>Summary</h2> <p>Developers hate wasting effort on manual processes when we can write code to do it instead. Cog is a tool to manage the work of automating the creation of text inside another file by executing arbitrary Python code. In this episode Ned Batchelder shares the story of why he created Cog in the first place, some of the interesting ways that he uses it in his daily work, and the unique challenges of maintaining a project with a small audience and a well defined scope.</p> <h2>Announcements</h2> <ul> <li>Hello and welcome to Podcast.__init__, the podcast about Python&#8217;s role in data and science.</li> <li>When you&#8217;re ready to launch your next app or want to try a project you hear about on the show, you&#8217;ll need somewhere to deploy it, so take a look at our friends over at Linode. With the launch of their managed Kubernetes platform it&#8217;s easy to get started with the next generation of deployment and scaling, powered by the battle tested Linode platform, including simple pricing, node balancers, 40Gbit networking, dedicated CPU and GPU instances, and worldwide data centers. Go to <a href="https://www.pythonpodcast.com/linode?utm_source=rss&amp;utm_medium=rss">pythonpodcast.com/linode</a> and get a $100 credit to try out a Kubernetes cluster of your own. And don&#8217;t forget to thank them for their continued support of this show!</li> <li>Your host as usual is Tobias Macey and today I&#8217;m interviewing Ned Batchelder about Cog, a tool for generating files or text from embedded Python logic</li> </ul> <h2>Interview</h2> <ul> <li>Introductions</li> <li>How did you get introduced to Python?</li> <li>Can you describe what Cog is and the story behind it?</li> <li>What are the use cases that you initially created Cog to address?</li> <li>What were the shortcomings or extraneous overhead that you encountered in tools such as Jinja, Mako, Genshi, etc. that led you to create a new tool?</li> <li>What was your path from a quick and dirty script that suited your own purposes to turning it into a niche open source project that was general and stable enough for the broader community?</li> <li>One of your claims to fame is your role as the maintainer for coverage.py. How has your experience managing such a widely used project translated to the relatively small and low traffic project like Cog?</li> <li>Can you describe how Cog is implemented? <ul> <li>How did you approach the design of the syntactic elements for embedding Python code into a host file?</li> </ul> </li> <li>What is the workflow for someone using Cog to generate all or parts of a file? <ul> <li>How does the introduction of third party dependencies impact the viability and utility of Cog as compared to other templating systems?</li> </ul> </li> <li>What are the most interesting, innovative, or unexpected ways that you have seen Cog used?</li> <li>What are the most interesting, unexpected, or challenging lessons that you have learned while working on Cog?</li> <li>When is Cog the wrong choice?</li> <li>What do you have planned for the future of Cog?</li> </ul> <h2>Keep In Touch</h2> <ul> <li><a href="https://nedbatchelder.com/?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">Website</a></li> <li><a href="https://github.com/nedbat?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">nedbat</a> on GitHub</li> <li><a href="https://twitter.com/nedbat?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">@nedbat</a> on Twitter</li> <li><a href="https://www.linkedin.com/in/nedbat/?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">LinkedIn</a></li> </ul> <h2>Picks</h2> <ul> <li>Tobias <ul> <li><a href="http://www.samsontech.com/samson/products/microphones/dynamic-microphones/q9u/?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">Samson Q9U Microphone</a></li> </ul> </li> <li>Ned <ul> <li><a href="https://github.com/cantino/mcfly?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">McFly</a> Command Line History Tool</li> <li>Go for a walk</li> </ul> </li> </ul> <h2>Closing Announcements</h2> <ul> <li>Thank you for listening! Don&#8217;t forget to check out our other show, the <a href="https://www.dataengineeringpodcast.com?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">Data Engineering Podcast</a> for the latest on modern data management.</li> <li>Visit the <a href="https://www.pythonpodcast.com?utm_source=rss&amp;utm_medium=rss">site</a> to subscribe to the show, sign up for the mailing list, and read the show notes.</li> <li>If you&#8217;ve learned something or tried out a project from the show then tell us about it! Email <a href="mailto:hosts@podcastinit.com">hosts@podcastinit.com</a>) with your story.</li> <li>To help other people find the show please leave a review on <a href="https://itunes.apple.com/us/podcast/podcast.-init/id981834425?mt=2&amp;uo=6&amp;at=&amp;ct=&amp;utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">iTunes</a> and tell your friends and co-workers</li> </ul> <h2>Links</h2> <ul> <li><a href="https://nedbatchelder.com/code/cog?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">Cog</a></li> <li><a href="https://about.bostonpython.com/?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">Boston Python</a></li> <li><a href="https://en.wikipedia.org/wiki/Lotus_Software?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">Lotus</a></li> <li><a href="https://en.wikipedia.org/wiki/HCL_Domino?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">Lotus Notes</a></li> <li><a href="https://www.zope.org/?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">Zope</a></li> <li><a href="https://pythonhosted.org/Cheetah/?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">Cheetah Template Engine</a></li> <li><a href="https://coverage.readthedocs.io/en/latest/?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">Coverage.py</a> <ul> <li><a href="https://www.pythonpodcast.com/coverage-py-with-ned-batchelder-episode-121/?utm_source=rss&amp;utm_medium=rss">Podcast Episode</a></li> </ul> </li> <li><a href="https://en.wikipedia.org/wiki/Unix_philosophy?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">Unix Philosophy</a></li> <li><a href="https://en.wikipedia.org/wiki/Hungarian_notation?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">Hungarian Notation</a></li> <li><a href="https://jupyter.org/?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">Jupyter Notebooks</a></li> <li><a href="https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-github-profile/customizing-your-profile/managing-your-profile-readme?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">GitHub Profile ReadMe</a></li> <li><a href="https://github.com/nedbat?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">Ned&#8217;s GitHub Profile</a> <ul> <li><a href="https://raw.githubusercontent.com/nedbat/nedbat/main/README.md?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">Raw Markdown</a></li> </ul> </li> </ul> <p>The intro and outro music is from Requiem for a Fish <a href="http://freemusicarchive.org/music/The_Freak_Fandango_Orchestra/?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">The Freak Fandango Orchestra</a> / <a href="http://creativecommons.org/licenses/by-sa/3.0/?utm_source=rss&amp;utm_medium=rss" rel="noopener" target="_blank">CC BY-SA</a></p> </div> <img alt="" height="0" src="https://analytics.boundlessnotions.com/piwik.php?idsite=1&amp;rec=1&amp;url=https%3A%2F%2Fwww.pythonpodcast.com%2Fcog-python-text-generation-episode-347%2F&amp;action_name=Generate+Your+Text+Files+With+Python+Using+Cog+-+Episode+347&amp;urlref=https%3A%2F%2Fwww.pythonpodcast.com%2Ffeed%2F&amp;utm_source=rss&amp;utm_medium=rss" style="border: 0; width: 0; height: 0;" width="0" />