iVers
iVers

Reputation: 25

How do I pass a variable from an external script to the main?

I'm trying to make a python library and I need to pass the variable x to the main document.

external.py:

def get_x():
     x = '123'

main.py:

import external

external.get_x()
print(x)

This ofcourse wouldn't work as x is not defined in main.py, right?

Upvotes: 1

Views: 149

Answers (1)

Jakub
Jakub

Reputation: 184

external.py:

def get_x():
     x = '123'
     return x

main.py:

import external

x=external.get_x()
print(x)

Upvotes: 2

Related Questions