find
will work magic for you.
find -name datafile.dat -execdir ~/a.py '{}' \;
The find searches recursively in all subdirectories for files that match a set of rules and performs an action on them.
The -name rule will let you find files with a name that matches what you give it. You can use globbing, for example, "*.dat" would find all the .dat files.
If necessary, you can use -regex instead of -name to match with a regex pattern instead of a glob pattern, so you could do ".*\.dat$" to match all the .dat files.
The -execdir will execute whatever command you give it from the directory of the found file, replacing "{}" with the found file.