Python Forum
How to call a variable declared in a function in another python script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to call a variable declared in a function in another python script
#1
Hi,

I had two python scripts r1.py and r2.py
In r1.py I used a variable named "test" in a function and I want to use this in r2.py.
I tried but not able to get it.
Please help

r1.py
test = 10
def f1():
	global test
	test = test + 100
r2.py
import r1
a = test + 100
print a
output: When I ran python r2.py
Output:
Traceback (most recent call last): File "r2.py", line 2, in <module> a = test + 100 NameError: name 'test' is not defined
Reply


Messages In This Thread
How to call a variable declared in a function in another python script - by lravikumarvsp - Jun-04-2018, 02:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Is possible to run the python command to call python script on linux? cuten222 6 828 Jan-30-2024, 09:05 PM
Last Post: DeaD_EyE
  Variable for the value element in the index function?? Learner1 8 726 Jan-20-2024, 09:20 PM
Last Post: Learner1
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 639 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 1,423 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  Function parameter not writing to variable Karp 5 1,019 Aug-07-2023, 05:58 PM
Last Post: Karp
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,424 Jun-29-2023, 11:57 AM
Last Post: gologica
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 830 May-02-2023, 08:40 AM
Last Post: Gribouillis
  Trouble with threading and reading variable from a different script Lembas 14 3,174 Apr-26-2023, 11:21 PM
Last Post: Lembas
  Retrieve variable from function labgoggles 2 1,079 Jul-01-2022, 07:23 PM
Last Post: labgoggles
Question How can I import a variable from another script without executing it ThomasFab 12 7,975 May-06-2022, 03:21 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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