Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Python Programming Language

str() and repr() question

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")

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

        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

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

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

Where is the problem here?
Thanks in advance.

adima schrieb:
>            str = DoTestTime(EachFile)
>            print type(str)
>            for s in str:
>                    print s
>                    out.write(str(s))


> Where is the problem here?
> Thanks in advance.

You have overwritten the built-in str function some lines above.


sinature: http://nospam.nowire.org/signature_usenet.png

"adima" <agi@gmail.com> wrote in message


You might want to check out pychecker.py.  Its output:

    Processing Script1...


    Script1.py:1: Imported module (glob) not used
    Script1.py:1: Imported module (string) not used
    Script1.py:9: Local variable (alllines) not used
    Script1.py:20: (str) shadows builtin

You've replaced the built-in function str with the return value of


Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc