But that’s not all it’s useful for! You see, Python let’s you extract DocStrings from the code programmatically! And here’s what that looks like:Īdd(self, a, b) unbound module.Foo method This lets you try out small snippets of Python code so you can test if what you thought was going to happen when executing that code is actually what’s going to happen. This makes it possible to have an interactive interpreter for Python which will just give you a prompt and let you type lines of code on-the-fly, which it will python Since Python is an interpreted language, it doesn’t actually have to know what code you might want to execute. If you’re not a Python programmer, this might be the right time to tell you about the interactive interpreter. Now there are tools which can extract this documentation, but we’ll get to that later on, because there is a much more interesting thing you can do with this documentation. If your editor has syntax highlighting, the DocStrings will probably stand out quite nicely against the rest of the code, so it’s easy to spot.Īccessing DocStrings with the interactive interpreter As you can see, the docstring comes right after the declaration of the module, class or method. Most Python developers use triple quoting for their DocStrings (which is what they’re called). They’re not comments, they’re strings, so they actually stand out from the rest of the implementation, since strings aren’t found in most other language in those locations. These strings then become the documentation for that piece of code. Python allows you to place strings in your module, class and method definitions. Let’s look at some of the things you can do with inline Python documentation. In Python, that’s actually not far from the truth. You may have heard some code monkeys say “The code IS the documentation”. ScriptDoc, etc) which, in turn, use different documentation standards, causing unknown chaos documentation even within the same language space. Different people use different documentation generators (Doxygen VS. This is nice, of course, but the comments get out of date and you have to regenerate the documentation each time. Most languages have third party tools that parse the source code and extract documentation from comments. I’m talking about inline documentation here: annotating modules, classes, methods, etc. Why Python Rocks III: Parameter expansionįirst up: Documentation.Why Python Rocks I: Inline documentation.So I’m writing a bunch of articles showing off Python’s Awesome. So what’s cool about Python? I can’t count the number of times I’ve had to show skeptics why Python is cool, what Python can do that their favorite language can’t do.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |