I have a data engineering program that is grabbing some data off of Federal government websites and transforming that data. I'm a bit confused on whether I need to use the 'self' keyword or if it's a better practice to not use a class at all. This is how it's currently organized:
class GetGovtData():
def get_data_1(arg1=0, arg2=1):
df = conduct_some_operations
return df
def get_data_2(arg1=4, arg2=5):
df = conduct_some_operations_two
return df
I'm mostly using a class here for organization purposes. For instance, there might be a dozen different methods from one class that I need to use. I find it more aesthetically pleasing / easier to type out this:
from data.get_govt_data import GetGovtData
df1 = GetGovtData.get_data_1()
df2 = GetGovtData.get_data_2()
Rather than:
from data import get_govt_data
df1 = get_govt_data.get_data_1()
df2 = get_govt_data.get_data_2()
Which just has a boatload of underscores. So I'm just curious if this would be considered bad code to use a class like this, without bothering with 'self'? Or should I just eliminate the classes and use a bunch of functions in my files instead?
Classis not a Python keyword. Did you meanclass? If those two functions are in fact meant to be class methods, or static methods, then use the appropriate decorator to flag them as such. A class method wants to know the class, but doesn't require an instance of the class. A static method is just a function defined inside the class.GetGovtDataand just import it this wayfrom data import GetGovtData(but without class) and then the way you call functions will still hold.staticmethods. My advice: take comments at face value, they are usually meant as advice, and not as gratuitous insults.snake_casefor file names is a convention, and honestly, if that is your main concern for not using a module (which would be the intended use-case, to organize your code, especially functions and classes) then simply breaking that convention and usingCapitalCasewould probably be the least bad solution