python - Writing to file limitation on line length -


i've been trying write lines file based on specific file names same directory, search of file names in log file(given input), , modified date of files. output limiting me under 80 characters per line.

      def getfiles(flag, file):          if (flag == true):             file_version = open(file)             if file_version:                 s = mmap.mmap(file_version.fileno(), 0, access=mmap.access_read)             file_version.close()          file = open('allmodules.txt', 'wb')         i, values in dict.items():             # search keys in version file             if (flag == true):                 index = s.find(bytes(i))                 if index > 0:                     s.seek(index + len(i) + 1)                     m = s.readline()                     line_new = '{:>0}  {:>12} {:>12}'.format(i, m, values)                     file.write(line_new)                     s.seek(0)             else:                 file.write(i +'\n')          file.close()       if __name__ == '__main__':         dict = {}         file in os.listdir(os.getcwd()):             if os.path.splitext(file)[1] == '.psw' or os.path.splitext(file)[1] == '.pkw':                 time.ctime(os.path.getmtime(file))                 dict.update({str(os.path.splitext(file)[0]).upper():time.strftime('%d/%m/%y')})         if (len(sys.argv) > 1) :             if os.path.exists(sys.argv[1]):                 getfiles(true, sys.argv[1])         else:             getfiles(false, none)  

the output like:

      bw_lib_incl         13.1 rev. 259 [20140425 16:28]          16/05/14  

the interpretation of data correct, again formatting not correct time put on next line (not on same). happening lines of new file.

could give me hint?

m = s.readline() has \n @ end of line. you're doing .format(i, m, values) writes m in middle of string.

i leave exercise reader find out what's happening when you're writing such line file. :-)

(hint: m = s.readline().rstrip('\n'))


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -