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
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 753 May-02-2023, 08:40 AM
Last Post: Gribouillis
  how to call an object in another function in Maya bstout 0 2,042 Apr-05-2021, 07:12 PM
Last Post: bstout
  Combine Two Recursive Functions To Create One Recursive Selection Sort Function Jeremy7 12 7,195 Jan-17-2021, 03:02 AM
Last Post: Jeremy7
  How to call multiple functions sequentially Mayo 2 9,159 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 3,417 Dec-19-2020, 07:30 AM
Last Post: ndc85430
  Struggling for the past hour to define function and call it back godlyredwall 2 2,159 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  list call problem in generator function using iteration and recursive calls postta 1 1,863 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  function call at defined system time? Holon 5 3,158 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,040 Jul-27-2020, 04:19 PM
Last Post: buran
  module to store functions/variables and how to call them? mstichler 3 2,344 Jun-03-2020, 06:49 PM
Last Post: mstichler

Forum Jump:

User Panel Messages

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