When generating files with the docstrip utility, it adds a preamble of %-commented lines. This easily violates the syntax of output files, if they are not latex formats.
E.g. running pdftex on the file minimal.dtx (see below), will produce a syntactically incorrect skeleton starting with
%%
%% This is file `minimal.py',
%% generated with the docstrip utility.
%%
%% The original source files were:
%% ...
...
\endinput
%%
%% End of file `minimal.py'.
minimal.dtx
%\iffalse -- Ignore driver section when typesetting.
%<*driver>
\iffalse ---- SINGLE-FILE: INS FILE INCLUDED ---- \fi
\begingroup\input{docstrip}
\askforoverwritefalse
\generate{
\file{\jobname.py}{\from{\jobname.dtx}{python}}
}
\endgroup
\documentclass{ltxdoc}
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
$</driver>
%\fi
%
%
% \section{Imports}
% \begin{macrocode}
%<*python>
import sys
import os
%</python>
% \end{macrocode}