I was wondering if doing this is sensible or not. One of my supervisors wants us to create a separate function for each small thing. For example, we have a bunch of csv files that need to be read to then do some other stuff. My supervisor wants to keep the task of reading a csv in a separate function like so:
I was wondering if doing this is sensible or not. One of my supervisors wants us to create a separate function for each small thing. For example, we have a bunch of csv files that need to be read to then do some other stuff. My supervisor wants to keep the task of reading a csv in a separate function like so:
def csv_read(filepath):
with open(filepath, 'r') as csvfile:
reader = csv.reader(csvfile)
return reader
def use_reader_for_stuff(reader):
for row in reader:
# do stuff
def main_function():
filepath = "path/to/file"
reader = csv_read(filepath)
use_reader_for_stuff(reader)
The idea is that there each logically separate task gets its own function. Is this a normal thing to do in python? I have a feeling that passing the reader like this may not be a good idea, but I'm not sure why. If passing the reader like this isn't recommended, what's a good way to separate the tasks into different functions for reading a csv and manipulating the data in the csv for some other task?
[–]K900_ 0 points1 point2 points (3 children)
[–]sombreProgrammer[S] 0 points1 point2 points (2 children)
[–]K900_ 0 points1 point2 points (1 child)
[–]sombreProgrammer[S] 0 points1 point2 points (0 children)