Python Forum
call a function from other functions ...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
call a function from other functions ...
#1
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 ?
Reply
#2
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!
Reply
#3
thank u very much @Gribouillis
works <3
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  not able to call the variable inside the if/elif function mareeswaran 3 616 Feb-09-2025, 04:27 PM
Last Post: mareeswaran
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 1,957 May-02-2023, 08:40 AM
Last Post: Gribouillis
  how to call an object in another function in Maya bstout 0 2,690 Apr-05-2021, 07:12 PM
Last Post: bstout
  Combine Two Recursive Functions To Create One Recursive Selection Sort Function Jeremy7 12 10,622 Jan-17-2021, 03:02 AM
Last Post: Jeremy7
  How to call multiple functions sequentially Mayo 2 13,349 Jan-06-2021, 07:37 PM
Last Post: Mayo
  In this function y initially has no value, but a call to foo() gives no error. Why? Pedroski55 8 4,998 Dec-19-2020, 07:30 AM
Last Post: ndc85430
  Struggling for the past hour to define function and call it back godlyredwall 2 3,100 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  list call problem in generator function using iteration and recursive calls postta 1 2,531 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  function call at defined system time? Holon 5 4,385 Oct-06-2020, 03:58 PM
Last Post: snippsat
  How to call/read function for all elements in my list in python johnny_sav1992 1 2,656 Jul-27-2020, 04:19 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020