I have a function that converts args
given by argparse
to a filename
:
def args2filename(args, prefix):
filename = prefix
kwargs = vars(args)
for key, value in sorted(kwargs.items()):
filename += f'_{key}={value}'
return filename
What is the Python convention for such functions? I'd guess it would be more appropriate to use args_to_filename
(or maybe argstofilename
as in 2to3
) instead of args2filename
, but I couldn't find a reference.
I've found this answer for Python, but it addresses the case when you have a class. @lvc suggests from_foo
, if Bar.__init__
already takes a different signature:
class Bar:
@classmethod
def from_foo(cls, f):
'''Create a new Bar from the given Foo'''
ret = cls()
# ...
So, I'm looking for a Pythonic answer in these two cases, i.e., when I don't necessarily need a class, and when I have one.