Python Forum
Importing vars from another file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Importing vars from another file
#1
Hello everyone :)
While doing my homework I came across the following problem:

We have to develop a GUI with PyQt - this task was not a problem.

The variables come from the QLineEdit and are always the same. Our professor wants us to write
a file named 'vars.py' and import the file into our 'main.py' - now I'm in trouble Huh Huh Huh

Generally it wasn't a problem to import and use vars in other tasks before. But since the vars are coming from the GUI,
I don't know how to handle it. Using the (quoted) variables inside the main.py works perfectly.

I have tried this solution:

main.py
from vars import Incoming
# more code

def ShowStock(self):   
        """sep = "-"
        vendor = self.inhersteller.text().upper()
        size = self.ingr.text().upper()
        quant = self.inanz.text()          
        extension = ".hand"
        directory = "base"
        filename = vendor + "." + size + extension
        savefolder = os.path.join(directory, filename)
        """
        Incoming(self)
        
        if not vendor or not size:
            Empty()
        else:        
            if not os.path.isfile(savefolder):
                NoFile()
            else:
                # much more code
vars.py
def Incoming(self):
        sep = "-"
        vendor = self.inhersteller.text().upper()
        size = self.ingr.text().upper()
        quant = self.inanz.text()          
        extension = ".hand"
        directory = "base"
        filename = vendor + "." + size + extension
        savefolder = os.path.join(directory, filename)  
Error message is: builtins.NameError: name 'vendor' is not defined

Hope you can understand where the problem is.
Thank you very much in advance :)
Reply


Forum Jump:

User Panel Messages

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