call a function from other functions ... - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: call a function from other functions ... (/thread-12642.html) |
call a function from other functions ... - evilcode1 - Sep-05-2018 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 ? RE: call a function from other functions ... - Gribouillis - Sep-05-2018 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! RE: call a function from other functions ... - evilcode1 - Sep-05-2018 thank u very much @Gribouillis works <3 |