The difference between the two answers you cite is because of how the script is used.
In the negative answer, the python script was listed directly as the PAM module. This will not work. PAM modules need to be shared objects, e.g. binary compiled code. The are directly linked into the running process that is uses PAM as needed. A Python script isn't compiled code.
In the positive answer, the PAM module used is pam_exec. pam_exec is a shared object:
/usr/lib64/security/pam_exec.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=d0c1dbb05c0689e3645193b45d3125d3b27b32ce, stripped
pam_exec then runs a program, which CAN be a Python script. Because it runs a program rather than dynamically linking to an shared object, it doesn't have the same limitation. This is the whole point of pam_exec really.
So yes, you can use Python, but you must pam_exec the script. Do be aware of this note from pam_exec, it's important:
Commands called by pam_exec need to be aware of that the user can have control over the environment.