The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
TypeError: unsubscriptable object?
Discuss TypeError: unsubscriptable object? in the Python Programming forum on Dev Shed. TypeError: unsubscriptable object? Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 15th, 2004, 09:23 PM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Posts: 67
Time spent in forums: 41 m
Reputation Power: 10
|
|
TypeError: unsubscriptable object?
I have this bit of code:
Code:
def convert(self, charFrom, charTo, dir):
if os.path.exists(dir) == True:
finalDir = dir
fileList = os.listdir(finalDir)
os.chdir(finalDir)
for i in fileList:
splitFileName = os.path.splitext(i)
renamedFileNameP1 = splitFileName[0].replace(charFrom, charTo, 10000)
print renamedFileNameP1
print splitFileName[1]
fileName = ''.join[(renamedFileNameP1, splitFileName[1])]
os.rename(i, fileName)
return "Done"
else:
return "Error! The directory: ", dir, " is invalid."
which is supposed to, for all the file in directory dir, replace
all instances of charFrom with charTO. However, I get the error mentioned in the thread title. Does anyone know why?
Thanks.
__________________
Before you criticize someone, walk a mile in their shoes, that way when you do criticize them, you're a mile away and you have their shoes!
|

April 15th, 2004, 10:34 PM
|
 |
Mini me.
|
|
Join Date: Nov 2003
Location: Cambridge, UK
|
|
You didn't supply the traceback so I'm guessing that elsewhere in your program you are trying to call your function with convert[] instead of convert().
Grim 
|

April 16th, 2004, 11:07 AM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Posts: 67
Time spent in forums: 41 m
Reputation Power: 10
|
|
No, I don't do that.
Here's the traceback:
Code:
Traceback (most recent call last):
File "C:\Documents and Settings\Evan\My Documents\Programming\Programs\Python\fileutility.py", line 77, in -toplevel-
start.cmdloop()
File "C:\Python23\lib\cmd.py", line 133, in cmdloop
stop = self.onecmd(line)
File "C:\Python23\lib\cmd.py", line 210, in onecmd
return func(arg)
File "C:\Documents and Settings\Evan\My Documents\Programming\Programs\Python\fileutility.py", line 22, in do_convertUnderscoreToSpace
done = self.convert("_", " ", dir)
File "C:\Documents and Settings\Evan\My Documents\Programming\Programs\Python\fileutility.py", line 69, in convert
fileName = ''.join[(renamedFileNameP1, splitFileName[1])]
TypeError: unsubscriptable object
|

April 16th, 2004, 11:10 AM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Posts: 67
Time spent in forums: 41 m
Reputation Power: 10
|
|
|
I figured it out.
Thanks for the help.
|

April 16th, 2004, 11:19 AM
|
 |
Mini me.
|
|
Join Date: Nov 2003
Location: Cambridge, UK
|
|
I knew it was something like that, happens to me all the time.
Grim 
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|