Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error passing variable from another module

I have been trying to pass a variable from one module to another in Python but I get an error.

afile.py

class Window:
    def __init__(self, master, *args):
        .....

    def browse_file(self):
        self.filename = fd.askopenfilename()
        self.textfile.config(text=self.filename)

bfile.py

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import pandas as pd
from afile import Window

df = pd.read_html(Window.filename, encoding='utf-8')[0]

what am I doing wrong?

>Solution :

Window is a class, but in your bfile.py it has not be instantiated to create an object.

The .filename object attributes does not exist until after the object has been initialized. (You can have class attributes, but that is not in your code.) You need to first create the object, then access the attribute.

The Window.__init__ method requires an argument called master. You will need to pass in something there to get your object created.

import pandas as pd
from afile import Window

df = pd.read_html(Window(master=???).filename, encoding='utf-8')[0]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading