str() and repr() question

adima agibov at gmail.com
Thu Apr 26 04:12:07 EDT 2007


Hi All!
Sorry, my English isnt good, but get a try to describe my problem.

Today we wrote next script:

import os, glob, time, string
files_to_test = ( "J:\\BWNEW\\!Unerase\\test.test", "L:\\Temp\Nick\
\test.test", "F:\\TRANSIT\\nick\\test.test")
outfile="c:\\temp\\statistic"


def DoTestTime(file):
	StartTime = time.time()
	filehandle = open(file)
	alllines = filehandle.read()
	filehandle.close()

	FileSize  = os.path.getsize(file)
	EndTime = time.time()
	return time.ctime() , "\tDisk\t" , file[:3] , "\tfile size (bytes) =
\t" , FileSize , "\taccess time =\t" , EndTime - StartTime


if __name__ == "__main__":
	out = open(outfile, 'w')
	for EachFile in files_to_test:
		str = DoTestTime(EachFile)
		print type(str)
		for s in str:
			print s
			out.write(str(s))
	out.close()

When I executed it, the output was
C:\test\py>File_Stat.py
Thu Apr 26 12:08:33 2007
<type 'str'>
Traceback (most recent call last):
  File "C:\test\py\File_Stat.py", line 26, in ?
    out.write(str(s))
TypeError: 'tuple' object is not callable

When I replace "str" with "repr" in out.write(str(s)), script executed
normally.

Where is the problem here?
Thanks in advance.




More information about the Python-list mailing list