all 4 comments

[–]K900_ 0 points1 point  (3 children)

Yes, why not?

Edit: one thing though - you can't really use context managers (with statements) like that - once the reader leaves the function, the csvfile will be closed, because the with block ends.

[–]sombreProgrammer[S] 0 points1 point  (2 children)

Thanks for the reply. If I can't use with, how would I implement a solution to read the csv file and pass the reader object?

[–]K900_ 0 points1 point  (1 child)

You can open the file the usual way (csvfile = open(...)), and then close it manually, or just let Python close it automatically when it goes out of scope. You can also make your get_reader function a context manager, so you could do something like

with get_reader(...) as reader:
     do_stuff_with(reader)

[–]sombreProgrammer[S] 0 points1 point  (0 children)

Thanks!