Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > Other Languages

Reply
 
LinkBack Thread Tools
Old June 4th, 2006, 06:40 PM   #1
New Member
 

Join Date: Aug 2003
Location: USA
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 pmichael is on a distinguished road
split in Python

I can get the fullpath filename into a variable
CurDoc=App.ActiveDocument.Name

when I print I see "F:\dir1\dir2\dir3\dir5\filename.ext"

I need to get just 'filename.ext' into a variable. So I try:
NewFileName=CurDoc.split("\")[5]

or if it isn't zero-based I can put 6, but that's not the issue right now ...

I'm doing this within the Paint Shop Pro pspscripting environment which uses Python.

Every time I try to run this I get the error:

Executing RunScript
File "<string>", line 49
NewFileName=CurDoc.split("\")[5]
^
SyntaxError: invalid token

and that ^ is actually pointing at the period between CurDoc and split.

Any PSP scripters or Python users?

Thanks!
pmichael is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old June 4th, 2006, 08:51 PM   #2
New Member
 

Join Date: Aug 2003
Location: USA
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 pmichael is on a distinguished road
Re: split in Python

Figured it out. "\" needs to be escaped, so "\\" is the solution.
pmichael is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old June 5th, 2006, 04:24 AM   #3
Reputable Member
 

Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 grahame is a jewel in the rough grahame is a jewel in the rough grahame is a jewel in the rough
Re: split in Python

You could also use a raw string (r"\") - they're typically much better that adding extra \ escapes all through a string.

-- Graham
grahame is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Tags
split , python


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python directory not viewable by FTP MikeHopley Other Languages 0 January 20th, 2008 07:22 AM
Split-Visionz split-visionz Full Website Reviews 16 December 24th, 2007 12:44 AM
split a string into an array djanim8 Classic ASP 0 October 11th, 2006 09:04 AM
split-visionz.net split-visionz Full Website Reviews 3 June 27th, 2006 07:35 AM


Search Engine Optimization by vBSEO 3.2.0 RC8