<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 22, 2013 at 10:25 AM, Sven Hennig <span dir="ltr"><<a href="mailto:shennig93@googlemail.com" target="_blank">shennig93@googlemail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div> <div><div dir="ltr" style="zoom:1"><span lang="en"><span>Hello,</span> <span>I would like to</span> <span>learn</span> <span>a programming language and</span> <span>have decided to use</span> <span>Python.</span> <span>I have</span> <span>some programming</span> <span>experience</span> <span>and doing well</span> <span>in Python.</span> <span>What</span> <span>really</span> <span>causes me</span> <span>problems</span> <span>is</span> <span>OOP.</span><br>
<span>I'm just dont get it..</span><span>.</span> <span>I'm missing</span> <span>a</span> <span>really</span> <span>Practical</span> <span>example</span><span>.</span> <span>In every</span> <span>book</span> <span>I've read</span> <span>are</span> <span>the</span> <span>examples</span> <span>of</span> <span>such</span> <span>Class</span> <span>Dog and</span> <span>the</span> <span>function</span> <span>is</span> <span>bark</span><span>.</span> <span>Has anyone</span> <span>an</span> <span>OOP</span> <span>example for me</span> <span>as it is really</span> <span>used in</span> <span>real</span> <span>code</span><span>,</span> <span>so I can</span> <span>better</span> <span>understand the concept</span><span>?</span> <span>I</span> <span>do not know why</span> <span>this</span> <span>is so hard for</span> <span>me</span><span>.</span><br>
<br><span>Greetings</span><span class=""><font color="#888888"><br><span>Sven</span></font></span></span></div></div></div></div><br></blockquote><div><br>The actual code I have is in PHP, so it's not exactly useful to post
here, but I can give you an outline of a class I used and found useful. The
class was created to help me manipulate network subnets in an interface
to handle DHCP and DNS on a server.<br> <br></div><div>class subnet:<br><br></div><div> def __init__(cidr):<br></div><div> # Do some stuff with the CIDR notation of the subnet (<a href="http://1.2.3.0/24">1.2.3.0/24</a> syntax)<br>
<br></div><div> def netmask:<br></div><div> # Calculate the netmask and return it (ie, 255.255.255.0)<br><br></div><div> def first_ip:<br></div><div> # Calculate and return the first IP in the range.<br><br></div>
<div> def last_ip:<br></div><div> # Calculate and return the last IP in the range<br><br></div><div> def number_of_addresses:<br></div><div> # Calculate the number of usable addresses in the range and return that value<br>
<br></div><div>The benefit to me was that I could create an instance of the subnet object for a group (say, "lab_1"), and then pull out various information. Calling "lab_1.first_ip()" returns the first possible IP address. That was a lot more readable and a lot more concise than something like "first_ip(<a href="http://1.2.3.0/24">1.2.3.0/24</a>)".<br>
<br><br></div><div>I hope this helps!<br><br>Andy<br></div><div> <br></div></div></div></div>