Python Forum
How to pass multiple arguments into function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to pass multiple arguments into function
#5
Thanks, it works, but I want to pass df to another function I use below code, but it gives
AttributeError: 'MyData' object has no attribute 'df'
How to pass the variables from one function another?

import logging
import pandas as pd
 
class MyData:
 
    def __init__(self):
 
        self.mode = None
        self.colNames = []
    def read_data(self, inFile, colNames, mode):
        try:
            df_tmp = pd.read_csv(inFile)
            self.mode = mode
            self.colNames = colNames
            print(mode)
            print(colNames)
            df = df_tmp[colNames]
            logging.debug("Read data successfully")
            print(df.head)
            data.mod_data()
        except OSError as e:
            logging.debug("File read fail check fail reason below")
            logging.debug(e.errno)
    def mod_data(self):
        self.df=(data.df)
        print("New Df.......")
        print(df)
 
logging.basicConfig(filename='temp_log.txt', level=logging.DEBUG)
logging.debug("Hello new log")
logging.debug("Initialize file read...")
 
data = MyData()
data.read_data(r'inFile.csv', 'col1', 'NOM')
Reply


Messages In This Thread
RE: How to pass multiple arguments into function - by Mekala - Jul-11-2020, 07:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to pass encrypted pass to pyodbc script tester_V 0 979 Jul-27-2023, 12:40 AM
Last Post: tester_V
  calling external function with arguments Wimpy_Wellington 7 1,642 Jul-05-2023, 06:33 PM
Last Post: deanhystad
Sad Iterate randint() multiple times when calling a function Jake123 2 2,193 Feb-15-2022, 10:56 PM
Last Post: deanhystad
  Regex - Pass Flags as a function argument? muzikman 6 3,818 Sep-06-2021, 03:43 PM
Last Post: muzikman
  'namespace' shorthand for function arguments? shadowphile 5 2,732 Aug-11-2021, 09:02 PM
Last Post: shadowphile
  Checking the number of arguments a function takes Chirumer 3 2,291 Jul-06-2021, 04:56 PM
Last Post: Chirumer
  Function - Return multiple values tester_V 10 4,754 Jun-02-2021, 05:34 AM
Last Post: tester_V
  Possible to dynamically pass arguments to a function? grimm1111 2 2,319 Feb-21-2021, 05:57 AM
Last Post: deanhystad
  Why Pass Functions as arguments? muzikman 14 6,024 Jan-18-2021, 12:08 PM
Last Post: Serafim
  how to pass arguments between pythons scripts? electricDesire 2 2,274 Oct-19-2020, 07:19 PM
Last Post: electricDesire

Forum Jump:

User Panel Messages

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