determining bytes read from a file.
vineeth
nvineeth at gmail.com
Thu Dec 13 22:41:19 EST 2007
On Dec 13, 7:50 pm, Chris <cwi... at gmail.com> wrote:
> A couple potential optimizations:
>
>
>
> > # create the member variable name.
> > mem_var_name = options.inputfilename
> > mem_var_name = mem_var_name.replace(' ','_')
> > mem_var_name = mem_var_name.replace('.','_')
>
> mem_var_name = options.inputfilename.replace(' ','_').replace('.','_')
> No need to assign it 3 times.
>
> > while i < len(hex_data):
> > outfile_c.write( "0x%c%c" % ( hex_data[i],hex_data[i+1] ) )
> > i += 2
> > if i != len(hex_data):
> > outfile_c.write(",")
> > if i % 32 == 0:
> > outfile_c.write("\n")
>
> This could be re-written as such:
>
> for x in xrange(0, len(hex_data), 32):
> output_c.write('%s\n' % ','.join(['0x%s'%''.join(['%c'%a for a in
> hex_data[x:x+32][i:i+2]]) for i in xrange(0, 32, 2)]
Thanks everyone for all the suggestions, and the optimizations, I am
still a newbie and not aware of these ,
thanks!
More information about the Python-list
mailing list