I am using getopt to process a command line optional argument, which should accept a list. Something like this:
foo.py --my_list=[1, 2, 3, 4,5]
Maybe you should just enclose the argument in quotes?
foo.py "--my_list=[1, 2, 3, 4,5]"
Otherwise every space will be treated as a separator for arguments.