Web Design and Development Forums

split in Python

This is a discussion on "split in Python" within the Perl, Python, Ruby and Others section. This forum, and the thread "split in Python are both part of the Program Your Website category.

Old Jun 4th, 2006, 22:40   #1 (permalink)
New Member
 
Join Date: Aug 2003
Location: USA
Posts: 8
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 Jun 5th, 2006, 00:51   #2 (permalink)
New Member
 
Join Date: Aug 2003
Location: USA
Posts: 8
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 Jun 5th, 2006, 08:24   #3 (permalink)
Reputable Member
 
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 294
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
__________________
Graham Ellis ...
Open Source trainer with Well House Consultants
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

Tags
split, python

Thread Tools
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

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
Open-Source Ajax/PHP (or Python) Webmail calande Job Opportunities 0 Feb 3rd, 2008 02:03
Python directory not viewable by FTP MikeHopley Perl, Python, Ruby and Others 0 Jan 20th, 2008 11:22
Split-Visionz split-visionz Free Web Site Critique 16 Dec 24th, 2007 04:44
split a string into an array djanim8 ASP Forum 0 Oct 11th, 2006 13:04
split-visionz.net split-visionz Free Web Site Critique 3 Jun 27th, 2006 11:35



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 23:10.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59