_:nfda4719f6079476f87674627c6e7ecdaxb0
<http://schema.org/articleBody>
"Yet another library has come out of the Sample Programs repo. This one is called Subete, and you can use it to browse the Sample Programs repo in Python.\n\n\n\n\n\nIntroducing Subete\n\n\n\nMany of you are probably already familiar with the Sample Programs repo, a collection of code snippets in as many programming languages as possible. Well since then, many projects have come out of that. For example, we developed a a Python library called SnakeMD which allows you to programmatically generate markdown using Python. No surprise another library that fell out of the Sample Programs repo is Subete.\n\n\n\nSubete is a Python library which allows you to browse all of the code snippets in the Sample Programs repo. To put that into perspective, at the time of writing, the Sample Programs repo contained 603 code snippets across 162 programming languages. All of which can be browsed in Python using Subete. \n\n\n\nThe library works by installing the Sample Programs repo in a temporary directory where the files can be processed into a set of data structures. These data structures can then be traversed to your needs. For example, you might have a website where you want to display some code snippets. Subete can help with that.\n\n\n\nHow to Use Subete\n\n\n\nIf Subete has piqued your interest in any way, I recommend downloading it and giving it a try. To do that, you can use pip:\n\n\n\npip install subete\n\n\n\nWith subete installed, all that's left is to import it in a script:\n\n\n\nimport subete\n\n\n\nOf course, if you actually want to use Subete, you need to take advantage of the `load()` function:\n\n\n\nrepo = subete.load()\n\n\n\nWith the repo loaded, you have access to any language that you can find in the Sample Programs repo. For example, if you want to poke at Python code, you can get the collection as follows:\n\n\n\nrepo[\"Python\"]\n\n\n\nAnd, if you have a particular program you'd like to see, you can key into it directly:\n\n\n\nrepo[\"Python\"][\"Hello World\"]\n\n\n\nOf course, this will return an object. To get the actual code snippet, you call the `code()` method directly:\n\n\n\n>>> repo[\"Python\"][\"Hello World\"].code()\n\"print('Hello, World!')\\n\"\n\n\n\nHow cool is that? That said, if you didn't want to browse the code yourself, there are a few convenience functions for pulling code snippets. For instance, there is the `random_program()` method which can be used to retrieve a random program from the collection:\n\n\n\n>>> repo.random_program().code()\n'class HELLO_WORLD is\\n   main is\\n      #OUT+\"Hello, World!\";\\n   end;\\nend;\\n'\n\n\n\nI'll leave it up to you to figure out what language this is and what the program is doing. \n\n\n\nLooking for Users\n\n\n\nAfter creating this library, I've used it four times in various places. For example, you might have seen my article on how to automate a GitHub profile. In my profile, I automatically share a random code snippet from the collection once a week. In other places, I've used the library to help generate documentation. And once, I even used it to do some visualization. \n\n\n\nThat said, I'd love to see what other folks could do with it. Do you have any applications that might need code snippets on the fly? I'd love to see if anyone could make some use for it. If not, maybe you have some use for some of my other libraries:\n\n\n\nPractice Your Coding Skills With the Sample Programs TemplateSample Programs 500 Code Snippet ReleaseImage Titler 2.2.0 Features Preloaded GUI Settings\n\n\n\nOtherwise, I appreciate you taking some time to check out Subete. See you next time!"
<https://therenegadecoder.com/>