zaterdag 20 juli 2013

Python : Improving your print()

the print() function is a function that is the used the most during programming. It sends a piece of string to the console so we can get some feedback.

Of course on the way we are adding a lot of print() to debug, to print data and even to print error messages.

messages
Using print to share messages can be handy for developers. But it is totaly not for artists. Artist will most of the time not look to consoles and just say that the tool is broken and don't look further. For artist you will have to embed the messaging more inside the tool or using messageboxes.

variables print("assetsToBuild=%s" % assetsToBuild)
when printing data of integers, arrays to see if the content is correct of the container it can get confusing which variable is which, especially if you have other prints coming in from other modules.

For me I found a solution that gives a clear overview of what is happening in my code which is the following:

assetsToBuild = ["harry","mario","box"]
print("assetsToBuild=%s" % assetsToBuild)
output : assetsToBuild = ["harry","mario","box"]

this will give much more meaning to the print. The label is the same as the variable.
This makes debugging easier and is a great motivation to choose good variable names.

Conclusion
When placing data in the console try to respect a good structure. This will help you so much in visualising what code is doing. Motivates your variable names. And this way you will have to do less time in cleaning up your output prints.

Geen opmerkingen:

Een reactie posten