-2

My windows batch file:

python test.py
pause

test.py:

import test_import
print(greeting)

test_import.py:

greeting='hello world'

This isn't working. I'm getting an error message, saying 'greeting' is not defined. I'd like to show you the output, but I'm having trouble with that too.

What do I need to change withint test_import.py, so the variable is accessible within the main module?

vegebond
  • 197
  • 1
  • 2
  • 6

1 Answers1

3

change your test.py:

import test_import
print(test_import.greeting)

or

from test_import import greeting
print(greeting)
Alex Python
  • 329
  • 1
  • 8