Editing Python Code Example Files
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 3: | Line 3: | ||
When I learn a new thing in Python I often keep an example file. I can then use it for reference and/or copy code out of it for other uses. I have a few "tricks" that I will describe here. | When I learn a new thing in Python I often keep an example file. I can then use it for reference and/or copy code out of it for other uses. I have a few "tricks" that I will describe here. | ||
I like to have many examples in one file to make them easy to review, and find the right example. Comments can be used to turn on/off some of the code. I use a technique to make it easy to control | I like to have many examples in one file to make them easy to review, and find the right example. Comments can be used to turn on/off some of the code. I use a technique to make it easy to control | ||
− | examples by commenting a single line: put each example in a function and then comment in/out the function call. | + | examples by commenting a single line: put each example in a function and then comment in/out the function call. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
= How = | = How = | ||
I think this is best seen with a commented example file. The example is very simple, the central point is the technique of using subroutines. You should be able to copy the code into your IDE of choice and run it. | I think this is best seen with a commented example file. The example is very simple, the central point is the technique of using subroutines. You should be able to copy the code into your IDE of choice and run it. | ||
− | + | ||
<pre> | <pre> | ||
− | + | comming... | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</pre> | </pre> |