0

Although Python doesn't have the C pre-processor, I wonder, what's a way to declare methods and variables depending on the OS? Something like:

class C1:

#if defined(WINDOWS)
        self.var1 = 1

        def method1(....):
            pass

#elif defined(LINUX)
        self.var2 = 1

        def method2(....):
            pass

#endif

My question isn't how to detect the platform only. But how to define different methods and variables depending on it also.

Kooiomo
  • 55
  • 6
  • 1
    Possible duplicate of [How to check what OS am I running on in Python?](http://stackoverflow.com/questions/1854/how-to-check-what-os-am-i-running-on-in-python) – Joe C Jan 19 '17 at 06:18
  • You can use the output of `platform.system()` in the conditional statements you wrote above, like so. `if platform.system() == 'Linux': #do this` – Anomitra Jan 19 '17 at 06:25

1 Answers1

0

You can detect the current platform as follows

import platform
platform.system()

The output for me is

'Linux'
Anomitra
  • 1,111
  • 15
  • 31