why is function executing twice?
<p>Am experiencing a bizarre problem with my python script the file is being red twice.</p>

<p>Script:</p>

<pre><code>import platform as serverPlatform


class platform:

  @staticmethod
  def kernel():
    return serverPlatform.release()

  @staticmethod
  def cpu():
    with open('/proc/cpuinfo', 'r') as f:
        print("x")
        for line in f:
            if line.strip():
                if line.rstrip('\n').split(':')[0].startswith('model name'):
                    model_name = line.rstrip('\n').split(':')[1]

print platform.cpu()
</code></pre>

<p>The code above prints "x" twice:</p>

<pre><code>[root@localhost lib]# python platform.py
x
x
</code></pre>

<p>However if i remove the class and run the code found inside the <code>cpu()</code> method directly it prints me "x" only once.(python script without the class)</p>

<pre><code>with open('/proc/cpuinfo', 'r') as f:
    print("x")
    for line in f:
        if line.strip():
            if line.rstrip('\n').split(':')[0].startswith('model name'):
                model_name = line.rstrip('\n').split(':')[1]
</code></pre>

<p>What am I doing wrong in my initial script and why is it printing me "x" twice? Thanks in advance</p>

<p><strong><em>UPDATE</em></strong></p>

<p>Ok I realised my mistake as silly as it may sound I imported the module platform in a script containing the custom class names platform. So i changed the name of the class from <strong>platform</strong> to <strong>platforms</strong></p>

<pre><code>import platform as serverPlatform


class platforms:

  @staticmethod
  def kernel():
    return serverPlatform.release()

  @staticmethod
  def cpu():
    with open('/proc/cpuinfo', 'r') as f:
        print("x")
        for line in f:
            if line.strip():
                if line.rstrip('\n').split(':')[0].startswith('model name'):
                    model_name = line.rstrip('\n').split(':')[1]

print platforms.cpu()
</code></pre>