Home > Software design >  Pass multiple variables from one module to another
Pass multiple variables from one module to another

Time:04-25

I have several modules in the folder "Programm/modules" which are called by another script in "Programm".

One for example looks like this:

"calculate.py"

def calculate():
  x = 1   2
  y = 3   4
  return x
  return y

this I would like to load into another module "print.py"

import os
import sys
sys.path.append(".")
import modules.calculate

def print():
  print(x)
  print(y)

But I get the error "ModuleNotFoundError: No module named 'calculate'"

What's wrong?

EDIT

Thx guys, I can now load the module with:

from modules.calculate import calculate

And I changed the return to:

return x, y

But now I get:

"NameError: name "x" is not defined"

How can I import "x" and "y" into "print.py"?

CodePudding user response:

if your programm folder looks like this:

├── programm.py
├── modules
│   ├── calculate.py

from modules.calculate import calculate

  • Related