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\\!Un erase\\test.tes t", "L:\\Temp\N ick\
\test.test", "F:\\TRANSIT\\n ick\\test.test" )
outfile="c:\\te mp\\statistic"
def DoTestTime(file ):
StartTime = time.time()
filehandle = open(file)
alllines = filehandle.read ()
filehandle.clos e()
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(Each File)
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\Fil e_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. 2 1390
adima schrieb:
str = DoTestTime(Each File)
^^^
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" <ag****@gmail.c omwrote in message
news:11******** **************@ t38g2000prd.goo glegroups.com.. .
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\\!Un erase\\test.tes t", "L:\\Temp\N ick\
\test.test", "F:\\TRANSIT\\n ick\\test.test" )
outfile="c:\\te mp\\statistic"
def DoTestTime(file ):
StartTime = time.time()
filehandle = open(file)
alllines = filehandle.read ()
filehandle.clos e()
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(Each File)
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\Fil e_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.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: tcronj |
last post by:
Have reasently upgraded to PySQLite 0.5.
I now have to "typecast" returned values to the "string expecting" GUI
widgets (wxPython).
Afrer reading the explanation, I'm still not clearer wich is better to
use... str() or repr()
example: self.wxTextCtrl.Setvalue( str(val))
## or repr(val)
|
by: George Sakkis |
last post by:
Hi all,
I find the string representation behaviour of builtin containers
(tuples,lists,dicts) unintuitive in that they don't call recursively str()
on their contents (e.g. as in Java) :
###########################################
>>> class A(object):
>>> def __str__(self): return "a"
|
by: Brent |
last post by:
I'd like to subclass the built-in str type. For example:
--
class MyString(str):
def __init__(self, txt, data):
super(MyString,self).__init__(txt)
self.data = data
|
by: Johny |
last post by:
Where and when is good/nescessary to use `repr` instead of `str` ?
Can you please explain the differences
Thanks
LL
|
by: Gabriel Genellina |
last post by:
Hello
Is this the intended behavior?
Python 3.0a4+ (py3k, Apr 12 2008, 02:53:16) on
win32
Type "help", "copyright", "credits" or "license" for more information.
"b'abc'"
'abc'
'abc'
| |
by: Christian Heimes |
last post by:
Gabriel Genellina schrieb:
Yes, it's on purpose but it's a bug in your application to call str() on
a bytes object or to compare bytes and unicode directly. Several months
ago I added a bytes warning option to Python. Start Python as "python
-bb" and try it again. ;)
Christian
|
by: Russell E. Owen |
last post by:
I have code like this:
except Exception, e:
self.setState(self.Failed, str(e))
which fails if the exception contains a unicode argument.
I did, of course, try unicode(e) but that fails.
The following works, but seems rather messy:
except Exception, e:
|
by: Rafe |
last post by:
Forgive me if I mangle any terminology here, but please correct me if
I do...
I have an object which acts exactly like a string as long as I stay in
Python land. However, I am using the object in Softimage|XSI a 3D
application on Windows. It was created while (briefly) owned by
Microsoft, so knowledge of COM with excel or anything else should be
applicable I should think. I should also say I am a COM novice and
still learning Python...
|
by: est |
last post by:
From python manual
str( )
Return a string containing a nicely printable representation of an
object. For strings, this returns the string itself. The difference
with repr(object) is that str(object) does not always attempt to
return a string that is acceptable to eval(); its goal is to return a
printable string. If no argument is given, returns the empty string,
''.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |