hmm, had a little play with this.
first question, are you getting the string from somewhere else, and
capturing it as a raw string? if you don't you'll get weirdness:
>>> toto= *r*'\\titan\3D\work\Pitch\maya\scenes'
>>> toto
'\\\\titan\\3D\\work\\Pitch\\maya\\scenes' # <-- correctly escaped
>>> toto= '\\titan\3D\work\Pitch\maya\scenes'
>>> toto
'\\titan\x03D\\work\\Pitch\\maya\\scenes' # <-- \3 has been converted to
\x03, probably not what you want
enyhoo, assuming you're getting it correctly, you could regex your way
though it, or just go lazy and split on '\', and remove any blank entries.
then you can capture the first entry:
>>> toto.split('\\')
['', '', 'titan', '3D', 'work', 'Pitch', 'maya', 'scenes']
>>> [x for x in toto.split('\\') if x ] # <--- 'if x' ie, if the
value evaluates as True in pythonspeak. blank strings evaluate as false,
therefore get removed
['titan', '3D', 'work', 'Pitch', 'maya', 'scenes']
# assign to a variable, capture the first entry
>>> totosplit = [x for x in toto.split('\\') if x ]
>>> totosplit[0]
'titan'
On Thu, Feb 7, 2013 at 11:17 AM, Jeremy YeoKhoo <[email protected]> wrote:
> Hi guys,
>
> Would anyone know how I can partition or rather grab a first element of a
> string of an escape character "\\"?
>
> Say for an example...
> toto= '\\titan\3D\work\Pitch\maya\scenes'
>
> I want to grab 'titan' or the first element after the \\ and between the \
> characters?
>
> -Jeremy
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.