Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
call python function
#1
I created a .py file, the code is a function that simply calculates v*p

def amount(v,p):
    amt=v*p
    return amt
now i saved it as calc_val.py , i am using windows 7, so from dos prompt i go to the path where i saved the file

and did this

python calc_val.py, i got back the dos prompt, question is, is this function "saved" somewhere ? like how functions are saved in oracle ? and if so how can i see it ?

and, from dos prompt, can i pass in the arguments to a python function ? if not, then does that mean the only way i can create a python function with arguments is to get into python using ide and can't use a .py file ?

how can i call above function from dos prompt ,

I got it, i learnt how to import the .py file, and then call the function by using the file_name.function_name(arguments)

however, the question still is, is this function saved somewhere ? if not, i have to import the file name everytime i use it ?
Reply
#2
Yes, you will need to import the function every time. But you have options to do that in different ways. You could make one script which will import all your functions. Or if you really need just single functions separately, you can play with if __name__ == “__main__”, for example:
http://thepythonguru.com/what-is-if-__name__-__main__/
This will make your python script an executable. In that case you may want to use command line arguments, to pass them to function. Check this out:
https://www.tutorialspoint.com/python/py...uments.htm
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  not able to call the variable inside the if/elif function mareeswaran 3 538 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,878 May-02-2023, 08:40 AM
Last Post: Gribouillis
  how to call an object in another function in Maya bstout 0 2,639 Apr-05-2021, 07:12 PM
Last Post: bstout
  In this function y initially has no value, but a call to foo() gives no error. Why? Pedroski55 8 4,894 Dec-19-2020, 07:30 AM
Last Post: ndc85430
  Struggling for the past hour to define function and call it back godlyredwall 2 3,041 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  list call problem in generator function using iteration and recursive calls postta 1 2,469 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  function call at defined system time? Holon 5 4,275 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,617 Jul-27-2020, 04:19 PM
Last Post: buran
  Python: Call function with variabele? Ending in error. efclem 5 4,042 Apr-22-2020, 02:35 PM
Last Post: buran
  How to mock an object that is created during function call? Schlangenversteher 0 2,770 Jan-31-2020, 01:36 PM
Last Post: Schlangenversteher

Forum Jump:

User Panel Messages

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