|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
||||
|
||||
|
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! |
|
#2
|
||||
|
||||
|
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 ![]()
__________________
*** Experimental Python Markup CGI V2 *** |
|
#3
|
||||
|
||||
|
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
|
|
#4
|
||||
|
||||
|
I figured it out.
Thanks for the help. |
|
#5
|
||||
|
||||
|
I knew it was something like that, happens to me all the time.
Grim ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > TypeError: unsubscriptable object? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|