Python Forum

Full Version: call a function from other functions ...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello all ...

im writing a code to check the system if it linux or windows and do so if expressions after checking the system ....

this is my code :

import os
import sys

import zipfile

q = os.getenv("APPDATA")
d = os.getenv("userprofile")


def systemtype():
    lo = sys.platform
    if lo == "win32":
        print(lo)

    elif lo == "linux2":
        pass
        

systemtype()



def unzipfiles():
    if os.path.isdir(q+"/d"):
        pass
    else:
    
        zip_ref = zipfile.ZipFile(q + "\d.zip", 'r')
        zip_ref.extractall(q)
        print(os.getcwd())
        
        

unzipfiles()
i need to call the function systemtype() from the unzipfiles() if the system = windows then extract all files from d.zip to C:\Users\root\AppData\Roaming\d ... if the system is linux extract all files from d.zip to /tmp ....

how i can do that ?
Functions that print are mainly useful for the final user of your code, but not so for the rest of your program. Useful functions don't print something, they return something. For example they can return a boolean value
def system_is_windows():
    return sys.platform in ('win32', 'windows')

def system_is_linux():
    return sys.platform.startswith('linux')

def unzipfiles():
    ...
    if system_is_windows():
        ...
    elif system_is_linux():
        ....
    else:
        raise NotImplementedError('Function unzipfiles() is not yet implemented on this OS')
    ...
By the way, use python 3!
thank u very much @Gribouillis
works <3