#NEWLINE# def fix_script( path ) : #NEWLINE# #INDENT# 'Replace #!python with #!/path/to/python\n    Return True if file was changed.' #NEWLINE# if os . path . isfile ( path ) : #NEWLINE# #INDENT# with open ( path , 'rb' ) as script : #NEWLINE# #INDENT# firstline = script . readline ( ) #NEWLINE# if ( not firstline . startswith ( b'#!python' ) ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# exename = sys . executable . encode ( sys . getfilesystemencoding ( ) ) #NEWLINE# firstline = ( ( b'#!' + exename ) + os . linesep . encode ( 'ascii' ) ) #NEWLINE# rest = script . read ( ) #NEWLINE# #UNINDENT# with open ( path , 'wb' ) as script : #NEWLINE# #INDENT# script . write ( firstline ) #NEWLINE# script . write ( rest ) #NEWLINE# #UNINDENT# return True