How do I get variables from my main module in Python?
Question: I am a Structural Engineer by trade and I am trying to automate the creation
of 3D models using scripts.

So far I have created three modules; the GUI module using PyQt4, a main module
that controls the signals from the GUI, and an export module which "should"
pull the variables from main module and generate a script that can be read by
my analysis program.

So far the I can't pull the variables from main module when clicking the
export menu in the GUI because variable names are not defined.

If I import the main module into the export module to get the variables, I get
errors with the Ui_MainWindow.

I have tried to simplify what I am doing below.

**main.py module**

    
    
    import sys
    from PyQt4 import QtGui, QtCore
    from gui import Ui_MainWindow
    from export import newFile
    
    class Main(QtGui.QMainWindow):
    
        def __init__(self):
        super(Main, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
    
    
        self.setName()
    
        self.ui.actionExport.triggered.connect(self.exportName)
    
    def exportName(self):
        self.exportStaad = newFile().createNewFile()
    
    def setName(self):
        self.ui.tbo_Name.textChanged.connect(self.name_Changed)
    
    def name_Changed(self):
        someName = self.ui.tbo_Name.text()
        print('Name = ' + someName)
    
    
    app = QtGui.QApplication(sys.argv)
    form = Main()
    form.show()
    app.exec_()
    

gui.py

    
    
    # -*- coding: utf-8 -*-
    
    # Form implementation generated from reading ui file 'gui.ui'
    #
    # Created by: PyQt4 UI code generator 4.11.4
    #
    # WARNING! All changes made in this file will be lost!
    
    from PyQt4 import QtCore, QtGui
    
    try:
        _fromUtf8 = QtCore.QString.fromUtf8
    except AttributeError:
        def _fromUtf8(s):
            return s
    
    try:
        _encoding = QtGui.QApplication.UnicodeUTF8
        def _translate(context, text, disambig):
            return QtGui.QApplication.translate(context, text, disambig, _encoding)
    except AttributeError:
        def _translate(context, text, disambig):
            return QtGui.QApplication.translate(context, text, disambig)
    
    class Ui_MainWindow(object):
        def setupUi(self, MainWindow):
            MainWindow.setObjectName(_fromUtf8("MainWindow"))
            MainWindow.resize(800, 600)
            self.centralwidget = QtGui.QWidget(MainWindow)
            self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
            self.tbo_Name = QtGui.QLineEdit(self.centralwidget)
            self.tbo_Name.setGeometry(QtCore.QRect(80, 60, 150, 20))
            self.tbo_Name.setObjectName(_fromUtf8("tbo_Name"))
            self.lab_Name = QtGui.QLabel(self.centralwidget)
            self.lab_Name.setGeometry(QtCore.QRect(30, 60, 40, 20))
            self.lab_Name.setObjectName(_fromUtf8("lab_Name"))
            MainWindow.setCentralWidget(self.centralwidget)
            self.menubar = QtGui.QMenuBar(MainWindow)
            self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
            self.menubar.setObjectName(_fromUtf8("menubar"))
            self.menuFile = QtGui.QMenu(self.menubar)
            self.menuFile.setObjectName(_fromUtf8("menuFile"))
            MainWindow.setMenuBar(self.menubar)
            self.statusbar = QtGui.QStatusBar(MainWindow)
            self.statusbar.setObjectName(_fromUtf8("statusbar"))
            MainWindow.setStatusBar(self.statusbar)
            self.actionExport = QtGui.QAction(MainWindow)
            self.actionExport.setObjectName(_fromUtf8("actionExport"))
            self.menuFile.addAction(self.actionExport)
            self.menubar.addAction(self.menuFile.menuAction())
    
            self.retranslateUi(MainWindow)
            QtCore.QMetaObject.connectSlotsByName(MainWindow)
    
        def retranslateUi(self, MainWindow):
            MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
            self.lab_Name.setText(_translate("MainWindow", "Name:", None))
            self.menuFile.setTitle(_translate("MainWindow", "File", None))
            self.actionExport.setText(_translate("MainWindow", "Export", None))
    
    
    if __name__ == "__main__":
        import sys
        app = QtGui.QApplication(sys.argv)
        MainWindow = QtGui.QMainWindow()
        ui = Ui_MainWindow()
        ui.setupUi(MainWindow)
        MainWindow.show()
        sys.exit(app.exec_())
    

export.py

    
    
    import sys
    from PyQt4 import QtGui, QtCore
    from os import path
    import math
    
    class newFile():
        def createNewFile(dest):
            '''
            Creates file
            '''
    
            name = QtGui.QFileDialog.getSaveFileName ()
    
            f = open(name, 'w')
            f.write('Hello' + someName)
    
    
            f.close
    


Answer: The method called createNewFile(dest) inside the class newFile uses undefined
var someName at **f.write('Hello' + someName)**. This causes the error as it
is not defined in the class. Define a variable before you use it.

