-1

I would like to create a Class that would convert common date formats to their python equivalent.

I thought of an enum class but I have a problem when I have variable names with hyphens (which is not possible in python).

import enum
class DateFormatList(enum.Enum):
   yyyymmdd = '%Y%m%d'
   yymmdd = '%y%m%d'   

I have issue with:

mmm-dd-yyyy = '%b-%d-%Y'

Any suggestion about how to do this?

  • 2
    Python variable names cannot have hyphens as it can't be distinguished from subtraction. https://stackoverflow.com/questions/2064329/why-python-does-not-allow-hyphens – SteveK Apr 12 '20 at 13:50

1 Answers1

0

Python does not allow hyphens in the variable name because it is treated as a subtraction operator. Before you call the class, you could convert the hyphens in the string to an underscore, or some other character. And have your enum reflect that character

Sri
  • 2,281
  • 2
  • 17
  • 24