Python inspect.getcomments(module) doesn't return the first comment if it's a shebang -


when python file contains shebang (#!blabla), function getcomments module inspect doesn't return it. can shebang module object?

the shebang valid if first line of file ... so, seems like:

import module fname = module.__file__ open(fname) fin:     shebang = next(fin) 

of course, i've jumped on bunch of subtleties ... (making sure first line comment, making sure we've grabbed .py file instead of .pyc file, etc.). checks , substitutions should easy enough make though if want make more robust.

and, suppose alternative using __file__ magic use inspect.getsourcelines:

 shebang = inspect.getsourcelines(module)[0]  if not shebang.startswith('#!'):     pass #not shebang :) 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -