Thanks Frank.
Do you need to know the separator or is this handled correctly by os?
The docs on python.org seem a bit unclear here? Also they seem to suggest its
only sometimes useful whereas it would appear
it's a very useful tool.
I see also the file is returned as well so I dont need os.path.split[1] for
that.
Cheers
Howard
>________________________________
> From: Frank Rueter <[email protected]>
>To: [email protected]
>Sent: Wednesday, 16 May 2012, 23:46
>Subject: Re: [Nuke-python] Re: Seeing inside a string, to replace a file path
>
>
>os.path.split will only split the item after the last slash:
>p = '/tmp/a/b/c/file.txt'
>s.path.split( p )
>('/tmp/a/b/c', 'file.txt')
>
>whereas os.sep can be used in split() to split the whole thing:
>p.split( os.sep )
>['', 'tmp', 'a', 'b', 'c', 'file.txt']
>
>
>
>
>
>On 16/05/12 7:48 PM, Howard Jones wrote:
>os.path.split is the one I've always used. What's the advantage of os.sep?
>>
>>H
>>
>>
>>
>>________________________________
>> From: Frank Rueter <[email protected]>;
>>To: <[email protected]>;
>>Subject: Re: [Nuke-python] Re: Seeing inside a string, to replace a file
>>path
>>Sent: Tue, May 15, 2012 9:41:23 PM
>>
>>
>>check out os.path.split as well
>>
>>
>>On 16/05/12 8:51 AM, Nathan Rusch wrote:
>>There are a couple things you need to be aware of.
>>>
>>>First, your string includes the ASCII control character \r. You either need
>>>to escape your backslashes by doubling them up or use a raw string:
>>>
>>>"C:\\workFolder\\shots\\renderFolder"
>>># or
>>>r"C:\workFolder\shots\renderFolder"
>>>
>>>Now, the reason you’re hitting a SyntaxError is because your split string is
>>>an unescaped backslash, which makes Python think you’re trying to escape a
>>>single quote inside a single-quoted string and then failing to complete the
>>>string with another single quote. Escaping your backslash will work, but a
>>>safer bet is to use os.sep.
>>>
>>>import os
>>>r"C:\workFolder\shots\renderFolder".split(os.sep)
>>>
>>>
>>>-Nathan
>>>
>>>
>>>From: Noggy
>>>Sent: Tuesday, May 15, 2012 1:39 PM
>>>To: [email protected]
>>>Subject: [Nuke-python] Re: Seeing inside a string, to replace a file path
>>> Thanks! Now I get it. Does split only work on a list? I am getting an
>>>error trying to use split on a string. There's something about this that
>>>isn't clicking for me.
>>>
>>>wPath = "C:\workFolder\shots\renderFolder"
>>>wPath.split('\')[:4]
>>>
>>>SyntaxError: EOL while scanning string
literal
>>>________________________________
>>> _______________________________________________
>>>Nuke-python mailing list
>>>[email protected], http://forums.thefoundry.co.uk/
>>>http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>>>
>>>
>>>
>>>_______________________________________________
Nuke-python mailing list [email protected],
http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>>
>>
>>_______________________________________________
Nuke-python mailing list [email protected],
http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>_______________________________________________
>Nuke-python mailing list
>[email protected], http://forums.thefoundry.co.uk/
>http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>
>
>_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python