Python Forum
Call a .xlsx file outside a class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Call a .xlsx file outside a class
#3
(Apr-24-2020, 03:42 PM)Jeff900 Wrote: You need to understand that when you run import calculus, the code will run. After that you could create an Tentativa() object. You can use the __init__ for that of write an function for it. When using __init__, the class can look like this.

class Tentativa():
    def __init__(self, soma, count, col_data, col_new, lin_new, filename):
        self.soma = soma
        self.count = count
        self.col_data = col_data
        self.col_new = col_new
        self.lin_new = lin_new
        self.filename = filename
Then after importing the class you can create an object. Like this.

obj = calculus.Tentativa(1, 2, 3, 4, 5, 'filename')
You can use obj.filename as reference to the filename now. Does this solve your problem?

Yes! It works. I just had to put in __init__ and in the function "calculo" here:

def calculo(self):
        import openpyxl as xl
        
        filename = self.filename #<------ also put here 
        wb = xl.load_workbook(filename)
        sheet = wb['Sheet1'] #this is object
Thank you so much!!!
Reply


Messages In This Thread
Call a .xlsx file outside a class - by criscferr - Apr-24-2020, 01:47 PM
RE: Call a .xlsx file outside a class - by Jeff900 - Apr-24-2020, 03:42 PM
RE: Call a .xlsx file outside a class - by criscferr - Apr-24-2020, 04:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,524 Nov-09-2023, 10:56 AM
Last Post: mg24
  How to call a class in other class? 3lnyn0 3 953 Oct-24-2022, 09:18 AM
Last Post: GenTorossi
  Convert legacy print file to XLSX file davidm 1 1,832 Oct-17-2021, 05:08 AM
Last Post: davidm
  guys please help me , pycharm is not able to identify my xlsx file CrazyGreenYT7 1 2,033 Jun-13-2021, 02:22 PM
Last Post: Larz60+
  Python3 doesn't populate xlsx file with openpyxl Auldyin75 2 2,558 Feb-16-2021, 12:00 PM
Last Post: Auldyin75
  how do i store then call a mp3 from sqlite3 .db file gr3yali3n 3 5,819 Dec-11-2020, 10:28 AM
Last Post: snippsat
  subprocess call cannot find the file specified RRR 6 16,684 Oct-15-2020, 11:29 AM
Last Post: RRR
  Call a python file with anothr python file skaailet 3 2,328 Apr-30-2020, 03:41 PM
Last Post: deanhystad
  Is it mandatory to call superclass init inside the class init? psolar 3 6,105 Feb-14-2020, 09:16 PM
Last Post: wavic
  How to Call a method of class having no argument dataplumber 7 6,525 Oct-31-2019, 01:52 PM
Last Post: dataplumber

Forum Jump:

User Panel Messages

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