You can try to use verbatim mode, i.e.
\verb!my_name! -- this is output always as
\texttt or use
xparse and define a command with verbatim argument 'v', but this macro can't be used in another macro.
This works with spaces too.
\begingroup...\endgroup is to prevent the leaking of
\ttfamily to the following text.