SunQuest
           Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old April 15th, 2004, 09:23 PM
Baltor's Avatar
Baltor Baltor is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 67 Baltor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m
Reputation Power: 5
Exclamation 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!

Reply With Quote
  #2  
Old April 15th, 2004, 10:34 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
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 ***

Reply With Quote
  #3  
Old April 16th, 2004, 11:07 AM
Baltor's Avatar
Baltor Baltor is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 67 Baltor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m
Reputation Power: 5
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

Reply With Quote
  #4  
Old April 16th, 2004, 11:10 AM
Baltor's Avatar
Baltor Baltor is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 67 Baltor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m
Reputation Power: 5
I figured it out.
Thanks for the help.

Reply With Quote
  #5  
Old April 16th, 2004, 11:19 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
I knew it was something like that, happens to me all the time.
Grim

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > TypeError: unsubscriptable object?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway