[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] OT - getting file name from path string
- To: pygame-users@xxxxxxxx
- Subject: [pygame] OT - getting file name from path string
- From: altern <altern2@xxxxxxxxx>
- Date: Thu, 29 Jun 2006 09:53:17 -0700
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Thu, 29 Jun 2006 04:01:01 -0400
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:user-agent:mime-version:to:subject:content-type:content-transfer-encoding; b=EGtIf34+vlMnuPllOLwb1LTiFJm0azZZ6dlgEIjJSdvK5mj0DClkHUO5gQ81P2qkoJm/Xl+gOCtK9HzAMHGpQ00v54fqpftd849CKU/m7ipMixv8g43wc+ngdnaV112gTJIeF/uBP8GiC+jwb5MlH6DdhRXtizAUSbc0t5G2Cik=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
- User-agent: Thunderbird 1.5.0.4 (Windows/20060516)
hi
I know this is OT but ...
i need to get the name of a file from the string containing the path. I
did some ugly code (i guess it can be done nicely with regular
expressions but i dont know much about it.) and i am almost there, the
problem is that because the path contains \ backslashes i dont know how
to check if the char is a \
this is the (ugly) code:
p = 'c:\file\myfile.gif'
start = 0
for c in range(len(p)-1, -1, -1): // read starting from end
if start :
if p[c] == '\' : # << THIS iS THE PROBLEM
print '+'*10
while 1: pass
else :
s = s + p[c] ## append
print s
else :
if p[c] == '.' : # already read the extension start getting
the chars into s
start = 1
Basically when it comes to check if I reached the \ i dont know how to
tell python i am looking for a character "\" as this is the scape
character used in strings. I have been looking for tips online but
couldnt get anything clear.
many thanks
enrike