Don't pipe the Python script to mail
instead redirect the output to a temporary file and then cat
that temporary file piping it to the mail
command.
For instance:
python script.py > temp-file.out< temp-file.out mail -s "subject" -a filename.txt example@gmail.com