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

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.

Thomas

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

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

news:1177575127.034458.243760@t38g2000prd.googlegroups.com...

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

    Processing Script1...

    Warnings...

    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
DoTestTime().

-Mark

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