Oh, that's right, I remember now. I thought that's what I had been using but obviously not.
os.sep it is

I don't use it very often as most of the file paths I deal with are assmbled via environment variables and/or taken from a mini-database setup that describes my generic file structure


On 16/05/12 9:55 AM, Ean Carr wrote:
Yup, what Nathan said. Do you use os.path.split() much, Frank? I've always thought it was a bit weird. Would be a lot more intuitive if that returned the same thing as os.sep.split(mystring) which I find myself doing a heck of a lot more often. If I explicitly want the basename or dirname, I use os.path.basename() or os.path.dirname(). -Ean

On Tue, May 15, 2012 at 10:51 PM, Nathan Rusch <[email protected] <mailto:[email protected]>> wrote:

    Unfortunately os.path.split only splits once, at the
    last-occurring instance of os.sep.

    *From:* Frank Rueter <mailto:[email protected]>
    *Sent:* Tuesday, May 15, 2012 2:41 PM
    *To:* [email protected]
    <mailto:[email protected]>
    *Subject:* Re: [Nuke-python] Re: Seeing inside a string, to
    replace a file path
    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 <mailto:[email protected]>
    *Sent:* Tuesday, May 15, 2012 1:39 PM
    *To:* [email protected]
    <mailto:[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]
    <mailto:[email protected]>,
    http://forums.thefoundry.co.uk/
    http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python


    _______________________________________________
    Nuke-python mailing list
    [email protected]  
<mailto:[email protected]>,http://forums.thefoundry.co.uk/
    http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

    ------------------------------------------------------------------------
    _______________________________________________
    Nuke-python mailing list
    [email protected]
    <mailto:[email protected]>,
    http://forums.thefoundry.co.uk/
    http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

    _______________________________________________
    Nuke-python mailing list
    [email protected]
    <mailto:[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

Reply via email to