Python Forum
How to read file inside class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to read file inside class
#6
x is instance of your class. it has instance attribute data. you can work with x.data as with any other name any way you like. I just print it, so that you can see it reads and data is accessible.

alternative is your method to return what it reads
import pandas as pd
import os
class PythonTraining():    
    def read_data(self, filepath):
        base_path = "D:\Data" 
        full_filepath = os.path.join(base_ath, filepath, "outsummary.csv")      
        return pd.read_csv(full_filepath)
x = PythonTraining()
data = read_data("PythonCodes")
print(data.head())
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
How to read file inside class - by Mekala - May-02-2020, 06:49 AM
RE: How to read file inside class - by buran - May-02-2020, 07:07 AM
RE: How to read file inside class - by Mekala - May-02-2020, 08:54 AM
RE: How to read file inside class - by ndc85430 - May-02-2020, 08:54 AM
RE: How to read file inside class - by Mekala - May-02-2020, 09:21 AM
RE: How to read file inside class - by buran - May-02-2020, 09:22 AM
RE: How to read file inside class - by buran - May-02-2020, 09:26 AM
RE: How to read file inside class - by Mekala - May-02-2020, 09:29 AM
RE: How to read file inside class - by buran - May-02-2020, 09:31 AM
RE: How to read file inside class - by Mekala - May-02-2020, 09:49 AM
RE: How to read file inside class - by buran - May-02-2020, 10:08 AM
RE: How to read file inside class - by snippsat - May-02-2020, 11:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Recommended way to read/create PDF file? Winfried 3 2,901 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,469 Nov-09-2023, 10:56 AM
Last Post: mg24
  Navigating file directories and paths inside Jupyter Notebook Mark17 5 718 Oct-29-2023, 12:40 PM
Last Post: Mark17
  How to read module/class from list of strings? popular_dog 1 481 Oct-04-2023, 03:08 PM
Last Post: deanhystad
  read file txt on my pc to telegram bot api Tupa 0 1,129 Jul-06-2023, 01:52 AM
Last Post: Tupa
  parse/read from file seperated by dots giovanne 5 1,125 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Formatting a date time string read from a csv file DosAtPython 5 1,297 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  How do I read and write a binary file in Python? blackears 6 6,698 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
  Read csv file with inconsistent delimiter gracenz 2 1,205 Mar-27-2023, 08:59 PM
Last Post: deanhystad
  Read text file, modify it then write back Pavel_47 5 1,624 Feb-18-2023, 02:49 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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