Python Forum
call a variable from one function to another ...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
call a variable from one function to another ...
#4
Roughly. Low level stuff.
Anytime a function return a variable.
It is put on the stack.
Function closes.
Then stack item is assign to variable.

python bytecode.
import os
import dis

def qassam():
    filename = "/root/Downloads/scapy.txt"
    return filename


def fileex():
    filename = qassam()
    if os.path.isfile(filename):
        print("is there")
    else:
        print("else ... ")

dis.dis(fileex)
Output:
10 0 LOAD_GLOBAL 0 (qassam) 2 CALL_FUNCTION 0 4 STORE_FAST 0 (filename) 11 6 LOAD_GLOBAL 1 (os) 8 LOAD_ATTR 2 (path) 10 LOAD_METHOD 3 (isfile) 12 LOAD_FAST 0 (filename) 14 CALL_METHOD 1 16 POP_JUMP_IF_FALSE 28 12 18 LOAD_GLOBAL 4 (print) 20 LOAD_CONST 1 ('is there') 22 CALL_FUNCTION 1 24 POP_TOP 26 JUMP_FORWARD 8 (to 36) 14 >> 28 LOAD_GLOBAL 4 (print) 30 LOAD_CONST 2 ('else ... ') 32 CALL_FUNCTION 1 34 POP_TOP >> 36 LOAD_CONST 0 (None) 38 RETURN_VALUE
99 percent of computer problems exists between chair and keyboard.
Reply


Messages In This Thread
RE: call a variable from one function to another ... - by Windspar - Sep-16-2018, 10:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  not able to call the variable inside the if/elif function mareeswaran 3 749 Feb-09-2025, 04:27 PM
Last Post: mareeswaran
  Variable Substitution call keys Bobbee 15 3,226 Aug-28-2024, 01:52 PM
Last Post: Bobbee
  Variable for the value element in the index function?? Learner1 8 3,330 Jan-20-2024, 09:20 PM
Last Post: Learner1
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 1,809 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 8,516 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  Function parameter not writing to variable Karp 5 2,369 Aug-07-2023, 05:58 PM
Last Post: Karp
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 2,103 May-02-2023, 08:40 AM
Last Post: Gribouillis
  Retrieve variable from function labgoggles 2 1,957 Jul-01-2022, 07:23 PM
Last Post: labgoggles
  Cant transfer a variable onto another function KEIKAS 5 3,135 Feb-09-2022, 10:17 PM
Last Post: deanhystad
  how to call an object in another function in Maya bstout 0 2,790 Apr-05-2021, 07:12 PM
Last Post: bstout

Forum Jump:

User Panel Messages

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