Re: problems with opening files due to file's path

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alexnb

    Re: problems with opening files due to file's path




    Gerhard Häring wrote:

    Alexnb wrote:
    >Okay, so what I want my program to do it open a file, a music file in
    >specific, and for this we will say it is an .mp3. Well, I am using the
    >system() command from the os class. [...]
    >
    >system("\"C:\D ocuments and Settings\Alex\M y Documents\My
    >Music\Rhapsody \Bryanbros\Weez er\(2001)\04 - Island In The Sun.wma\"")
    >[...]
    Try os.startfile() instead. It should work better.

    -- Gerhard

    --


    No, it didn't work, but it gave me some interesting feedback when I ran it
    in the shell. Heres what it told me:
    >>os.startfile( "C:\Documen ts and Settings\Alex\M y Documents\My
    >>Music\Rhapsod y\Bryanbros\Jas on Mraz\I'm Yours (Single)\01 - I'm
    >>Yours.wma")
    Traceback (most recent call last):
    File "<pyshell#1 0>", line 1, in <module>
    os.startfile("C :\Documents and Settings\Alex\M y Documents\My
    Music\Rhapsody\ Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm Yours.wma")

    WindowsError: [Error 2] The system cannot find the file specified:
    "C:\\Docume nts and Settings\\Alex\ \My Documents\\My
    Music\\Rhapsody \\Bryanbros\\Ja son Mraz\\I'm Yours (Single)\x01 - I'm
    Yours.wma"

    See it made each backslash into two, and the one by the parenthesis and the
    0 turned into an x....
    --
    View this message in context: http://www.nabble.com/problems-with-...p17759825.html
    Sent from the Python - python-list mailing list archive at Nabble.com.

  • Mike Driscoll

    #2
    Re: problems with opening files due to file's path

    On Jun 10, 11:45 am, Alexnb <alexnbr...@gma il.comwrote:
    Gerhard Häring wrote:
    >
    Alexnb wrote:
    Okay, so what I want my program to do it open a file, a music file in
    specific, and for this we will say it is an .mp3. Well, I am using the
    system() command from the os class. [...]
    >
    system("\"C:\Do cuments and Settings\Alex\M y Documents\My
    Music\Rhapsody\ Bryanbros\Weeze r\(2001)\04 - Island In The Sun.wma\"")
    [...]
    >
    Try os.startfile() instead. It should work better.
    >
    -- Gerhard
    >>
    No, it didn't work, but it gave me some interesting feedback when I ran it
    in the shell. Heres what it told me:
    >
    >os.startfile(" C:\Documents and Settings\Alex\M y Documents\My
    >Music\Rhapsody \Bryanbros\Jaso n Mraz\I'm Yours (Single)\01 - I'm
    >Yours.wma")
    >
    Traceback (most recent call last):
      File "<pyshell#1 0>", line 1, in <module>
        os.startfile("C :\Documents and Settings\Alex\M y Documents\My
    Music\Rhapsody\ Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm Yours.wma")
    >
    WindowsError: [Error 2] The system cannot find the file specified:
    "C:\\Docume nts and Settings\\Alex\ \My Documents\\My
    Music\\Rhapsody \\Bryanbros\\Ja son Mraz\\I'm Yours (Single)\x01 - I'm
    Yours.wma"
    >
    See it made each backslash into two, and the one by the parenthesis and the
    0 turned into an x....
    --
    View this message in context:http://www.nabble.com/problems-with-...o-file%27s-pat...
    Sent from the Python - python-list mailing list archive at Nabble.com.
    Yeah. You need to either double all the backslashes or make it a raw
    string by adding an "r" to the beginning, like so:

    os.startfile(r' C:\path\to\my\f ile')

    HTH

    Mike

    Comment

    • Alexnb

      #3
      Re: problems with opening files due to file's path


      Hey thanks!, both the raw and the double backslashes worked. You are a
      gentleman and a scholar.

      Mike Driscoll wrote:

      On Jun 10, 11:45 am, Alexnb <alexnbr...@gma il.comwrote:
      >Gerhard Häring wrote:
      >>
      Alexnb wrote:
      >Okay, so what I want my program to do it open a file, a music file in
      >specific, and for this we will say it is an .mp3. Well, I am using the
      >system() command from the os class. [...]
      >>
      >system("\"C:\D ocuments and Settings\Alex\M y Documents\My
      >Music\Rhapsody \Bryanbros\Weez er\(2001)\04 - Island In The Sun.wma\"")
      >[...]
      >>
      Try os.startfile() instead. It should work better.
      >>
      -- Gerhard
      >>>>
      >No, it didn't work, but it gave me some interesting feedback when I ran
      >it
      >in the shell. Heres what it told me:
      >>
      >>os.startfile( "C:\Documen ts and Settings\Alex\M y Documents\My
      >>Music\Rhapsod y\Bryanbros\Jas on Mraz\I'm Yours (Single)\01 - I'm
      >>Yours.wma")
      >>
      >Traceback (most recent call last):
      > File "<pyshell#1 0>", line 1, in <module>
      > os.startfile("C :\Documents and Settings\Alex\M y Documents\My
      >Music\Rhapsody \Bryanbros\Jaso n Mraz\I'm Yours (Single)\01 - I'm
      >Yours.wma")
      >>
      >WindowsError : [Error 2] The system cannot find the file specified:
      >"C:\\Documen ts and Settings\\Alex\ \My Documents\\My
      >Music\\Rhapsod y\\Bryanbros\\J ason Mraz\\I'm Yours (Single)\x01 - I'm
      >Yours.wma"
      >>
      >See it made each backslash into two, and the one by the parenthesis and
      >the
      >0 turned into an x....
      >--
      >View this message in
      >context:http://www.nabble.com/problems-with-...o-file%27s-pat...
      >Sent from the Python - python-list mailing list archive at Nabble.com.
      Yeah. You need to either double all the backslashes or make it a raw
      string by adding an "r" to the beginning, like so:

      os.startfile(r' C:\path\to\my\f ile')

      HTH

      Mike
      --

      --
      View this message in context: http://www.nabble.com/problems-with-...p17761126.html
      Sent from the Python - python-list mailing list archive at Nabble.com.

      Comment

      • Alexnb

        #4
        Re: problems with opening files due to file's path


        Well, now i've hit another problem, this time being that the path will be a
        variable, and I can't figure out how to make startfile() make it raw with a
        variable, if I put startfile(r variable), it doesn't work and
        startfile(rvari able) obviously won't work, do you know how to make that work
        or better yet, how to take a regular string that is given and make every
        single "\" into a double "\\"?

        Mike Driscoll wrote:

        On Jun 10, 11:45 am, Alexnb <alexnbr...@gma il.comwrote:
        >Gerhard Häring wrote:
        >>
        Alexnb wrote:
        >Okay, so what I want my program to do it open a file, a music file in
        >specific, and for this we will say it is an .mp3. Well, I am using the
        >system() command from the os class. [...]
        >>
        >system("\"C:\D ocuments and Settings\Alex\M y Documents\My
        >Music\Rhapsody \Bryanbros\Weez er\(2001)\04 - Island In The Sun.wma\"")
        >[...]
        >>
        Try os.startfile() instead. It should work better.
        >>
        -- Gerhard
        >>>>
        >No, it didn't work, but it gave me some interesting feedback when I ran
        >it
        >in the shell. Heres what it told me:
        >>
        >>os.startfile( "C:\Documen ts and Settings\Alex\M y Documents\My
        >>Music\Rhapsod y\Bryanbros\Jas on Mraz\I'm Yours (Single)\01 - I'm
        >>Yours.wma")
        >>
        >Traceback (most recent call last):
        > File "<pyshell#1 0>", line 1, in <module>
        > os.startfile("C :\Documents and Settings\Alex\M y Documents\My
        >Music\Rhapsody \Bryanbros\Jaso n Mraz\I'm Yours (Single)\01 - I'm
        >Yours.wma")
        >>
        >WindowsError : [Error 2] The system cannot find the file specified:
        >"C:\\Documen ts and Settings\\Alex\ \My Documents\\My
        >Music\\Rhapsod y\\Bryanbros\\J ason Mraz\\I'm Yours (Single)\x01 - I'm
        >Yours.wma"
        >>
        >See it made each backslash into two, and the one by the parenthesis and
        >the
        >0 turned into an x....
        >--
        >View this message in
        >context:http://www.nabble.com/problems-with-...o-file%27s-pat...
        >Sent from the Python - python-list mailing list archive at Nabble.com.
        Yeah. You need to either double all the backslashes or make it a raw
        string by adding an "r" to the beginning, like so:

        os.startfile(r' C:\path\to\my\f ile')

        HTH

        Mike
        --

        --
        View this message in context: http://www.nabble.com/problems-with-...p17761338.html
        Sent from the Python - python-list mailing list archive at Nabble.com.

        Comment

        • Thomas Morton

          #5
          Re: problems with opening files due to file's path

          maybe try string substitution... not sure if that's really the BEST way to
          do it but it should work

          startfile(r"%s" %variable)

          --------------------------------------------------
          From: "Alexnb" <alexnbryan@gma il.com>
          Sent: Tuesday, June 10, 2008 7:05 PM
          To: <python-list@python.org >
          Subject: Re: problems with opening files due to file's path
          >
          Well, now i've hit another problem, this time being that the path will be
          a
          variable, and I can't figure out how to make startfile() make it raw with
          a
          variable, if I put startfile(r variable), it doesn't work and
          startfile(rvari able) obviously won't work, do you know how to make that
          work
          or better yet, how to take a regular string that is given and make every
          single "\" into a double "\\"?
          >
          Mike Driscoll wrote:
          >>
          >On Jun 10, 11:45 am, Alexnb <alexnbr...@gma il.comwrote:
          >>Gerhard Häring wrote:
          >>>
          >Alexnb wrote:
          >>Okay, so what I want my program to do it open a file, a music file in
          >>specific, and for this we will say it is an .mp3. Well, I am using
          >>the
          >>system() command from the os class. [...]
          >>>
          >>system("\"C:\ Documents and Settings\Alex\M y Documents\My
          >>Music\Rhapsod y\Bryanbros\Wee zer\(2001)\04 - Island In The Sun.wma\"")
          >>[...]
          >>>
          >Try os.startfile() instead. It should work better.
          >>>
          >-- Gerhard
          >>>
          >--
          >>http://mail.python.org/mailman/listinfo/python-list
          >>>
          >>No, it didn't work, but it gave me some interesting feedback when I ran
          >>it
          >>in the shell. Heres what it told me:
          >>>
          >>>os.startfile ("C:\Documen ts and Settings\Alex\M y Documents\My
          >>>Music\Rhapso dy\Bryanbros\Ja son Mraz\I'm Yours (Single)\01 - I'm
          >>>Yours.wma" )
          >>>
          >>Traceback (most recent call last):
          >> File "<pyshell#1 0>", line 1, in <module>
          >> os.startfile("C :\Documents and Settings\Alex\M y Documents\My
          >>Music\Rhapsod y\Bryanbros\Jas on Mraz\I'm Yours (Single)\01 - I'm
          >>Yours.wma")
          >>>
          >>WindowsErro r: [Error 2] The system cannot find the file specified:
          >>"C:\\Document s and Settings\\Alex\ \My Documents\\My
          >>Music\\Rhapso dy\\Bryanbros\\ Jason Mraz\\I'm Yours (Single)\x01 - I'm
          >>Yours.wma"
          >>>
          >>See it made each backslash into two, and the one by the parenthesis and
          >>the
          >>0 turned into an x....
          >>--
          >>View this message in
          >>context:http://www.nabble.com/problems-with-...o-file%27s-pat...
          >>Sent from the Python - python-list mailing list archive at Nabble.com.
          >>
          >Yeah. You need to either double all the backslashes or make it a raw
          >string by adding an "r" to the beginning, like so:
          >>
          >os.startfile(r 'C:\path\to\my\ file')
          >>
          >HTH
          >>
          >Mike
          >--
          >http://mail.python.org/mailman/listinfo/python-list
          >>
          >>
          >
          --
          View this message in context:

          Sent from the Python - python-list mailing list archive at Nabble.com.
          >
          --
          http://mail.python.org/mailman/listinfo/python-list

          Comment

          • Alexnb

            #6
            Re: problems with opening files due to file's path


            No this time it perhaps gave me the worst of all heres what I entered, and
            the output
            >>startfile(r"% s"%full) ***full is the path***
            startfile(r"%s" %full)

            WindowsError: [Error 2] The system cannot find the file specified:
            '"C:\\Docume nts and Settings\\Alex\ \My Documents\\My
            Music\\Rhapsody \\Bryanbros\\Ja son Mraz\\I\'m Yours (Single)\x01 - I\'m
            Yours.wma"'


            Thomas Morton wrote:

            maybe try string substitution... not sure if that's really the BEST way to
            do it but it should work

            startfile(r"%s" %variable)

            --------------------------------------------------
            From: "Alexnb" <alexnbryan@gma il.com>
            Sent: Tuesday, June 10, 2008 7:05 PM
            To: <python-list@python.org >
            Subject: Re: problems with opening files due to file's path
            >>
            >Well, now i've hit another problem, this time being that the path will be
            >a
            >variable, and I can't figure out how to make startfile() make it raw with
            >a
            >variable, if I put startfile(r variable), it doesn't work and
            >startfile(rvar iable) obviously won't work, do you know how to make that
            >work
            >or better yet, how to take a regular string that is given and make every
            >single "\" into a double "\\"?
            >>
            >Mike Driscoll wrote:
            >>>
            >>On Jun 10, 11:45 am, Alexnb <alexnbr...@gma il.comwrote:
            >>>Gerhard Häring wrote:
            >>>>
            >>Alexnb wrote:
            >>>Okay, so what I want my program to do it open a file, a music file
            >>>in
            >>>specific, and for this we will say it is an .mp3. Well, I am using
            >>>the
            >>>system() command from the os class. [...]
            >>>>
            >>>system("\"C: \Documents and Settings\Alex\M y Documents\My
            >>>Music\Rhapso dy\Bryanbros\We ezer\(2001)\04 - Island In The
            >>>Sun.wma\"" )
            >>>[...]
            >>>>
            >>Try os.startfile() instead. It should work better.
            >>>>
            >>-- Gerhard
            >>>>
            >>--
            >>>http://mail.python.org/mailman/listinfo/python-list
            >>>>
            >>>No, it didn't work, but it gave me some interesting feedback when I ran
            >>>it
            >>>in the shell. Heres what it told me:
            >>>>
            >>>>os.startfil e("C:\Documen ts and Settings\Alex\M y Documents\My
            >>>>Music\Rhaps ody\Bryanbros\J ason Mraz\I'm Yours (Single)\01 - I'm
            >>>>Yours.wma ")
            >>>>
            >>>Traceback (most recent call last):
            >>> File "<pyshell#1 0>", line 1, in <module>
            >>> os.startfile("C :\Documents and Settings\Alex\M y Documents\My
            >>>Music\Rhapso dy\Bryanbros\Ja son Mraz\I'm Yours (Single)\01 - I'm
            >>>Yours.wma" )
            >>>>
            >>>WindowsError : [Error 2] The system cannot find the file specified:
            >>>"C:\\Documen ts and Settings\\Alex\ \My Documents\\My
            >>>Music\\Rhaps ody\\Bryanbros\ \Jason Mraz\\I'm Yours (Single)\x01 - I'm
            >>>Yours.wma"
            >>>>
            >>>See it made each backslash into two, and the one by the parenthesis and
            >>>the
            >>>0 turned into an x....
            >>>--
            >>>View this message in
            >>>context:http://www.nabble.com/problems-with-...o-file%27s-pat...
            >>>Sent from the Python - python-list mailing list archive at Nabble.com.
            >>>
            >>Yeah. You need to either double all the backslashes or make it a raw
            >>string by adding an "r" to the beginning, like so:
            >>>
            >>os.startfile( r'C:\path\to\my \file')
            >>>
            >>HTH
            >>>
            >>Mike
            >>--
            >>http://mail.python.org/mailman/listinfo/python-list
            >>>
            >>>
            >>
            >--
            >View this message in context:
            >http://www.nabble.com/problems-with-...p17761338.html
            >Sent from the Python - python-list mailing list archive at Nabble.com.
            >>
            >--
            >http://mail.python.org/mailman/listinfo/python-list
            --
            --
            View this message in context: http://www.nabble.com/problems-with-...p17761946.html
            Sent from the Python - python-list mailing list archive at Nabble.com.

            Comment

            • Mike Driscoll

              #7
              Re: problems with opening files due to file's path

              On Jun 10, 1:25 pm, "Thomas Morton" <morton.tho...@ googlemail.com>
              wrote:
              maybe try string substitution... not sure if that's really the BEST way to
              do it but it should work
              >
              startfile(r"%s" %variable)

              I concur. That should work. A slightly more in depth example (assuming
              Windows):

              os.startfile(r' C:\Documents and Settings\%s\Des ktop\myApp.exe' %
              username)

              or

              os.startfile(r' C:\Program Files\%s' % myApp)

              Hopefully this is what you are talking about. If you were referring to
              passing in arguments, than you'll want to use the subprocess module
              instead.

              >
              --------------------------------------------------
              From: "Alexnb" <alexnbr...@gma il.com>
              Sent: Tuesday, June 10, 2008 7:05 PM
              To: <python-l...@python.org >
              Subject: Re: problems with opening files due to file's path
              >
              >
              >
              Well, now i've hit another problem, this time being that the path will be
              a
              variable, and I can't figure out how to make startfile() make it raw with
              a
              variable, if I put startfile(r variable), it doesn't work and
              startfile(rvari able) obviously won't work, do you know how to make that
              work
              or better yet, how to take a regular string that is given and make every
              single "\" into a double "\\"?
              >
              <snip>

              Mike

              Comment

              • Alexnb

                #8
                Re: problems with opening files due to file's path


                That would work, but not for what I want. See the file could be anywhere on
                the user's system and so the entire path will be unique, and that didn't
                work with a unique path. What is the subprocess module you are talking
                about?

                Mike Driscoll wrote:

                On Jun 10, 1:25 pm, "Thomas Morton" <morton.tho...@ googlemail.com>
                wrote:
                >maybe try string substitution... not sure if that's really the BEST way
                >to
                >do it but it should work
                >>
                >startfile(r"%s "%variable)

                I concur. That should work. A slightly more in depth example (assuming
                Windows):

                os.startfile(r' C:\Documents and Settings\%s\Des ktop\myApp.exe' %
                username)

                or

                os.startfile(r' C:\Program Files\%s' % myApp)

                Hopefully this is what you are talking about. If you were referring to
                passing in arguments, than you'll want to use the subprocess module
                instead.

                >>
                >--------------------------------------------------
                >From: "Alexnb" <alexnbr...@gma il.com>
                >Sent: Tuesday, June 10, 2008 7:05 PM
                >To: <python-l...@python.org >
                >Subject: Re: problems with opening files due to file's path
                >>
                >>
                >>
                Well, now i've hit another problem, this time being that the path will
                >be
                a
                variable, and I can't figure out how to make startfile() make it raw
                >with
                a
                variable, if I put startfile(r variable), it doesn't work and
                startfile(rvari able) obviously won't work, do you know how to make that
                work
                or better yet, how to take a regular string that is given and make
                >every
                single "\" into a double "\\"?
                >>
                <snip>

                Mike
                --

                --
                View this message in context: http://www.nabble.com/problems-with-...p17762276.html
                Sent from the Python - python-list mailing list archive at Nabble.com.

                Comment

                • Thomas Morton

                  #9
                  Re: problems with opening files due to file's path

                  heh thanks Mike - glad im not going mad :P

                  Just tested locally in IDLE (I know I know!) and it works for me like this:
                  >>test = os.path.join(os .getcwd(),"NEWS .txt")
                  >>test
                  'D:\\Python25\\ NEWS.txt'
                  >>os.startfile( r"%s"%test)
                  >>>
                  And the file opens...

                  Does the file definitely exist?

                  Tom
                  --------------------------------------------------
                  From: "Alexnb" <alexnbryan@gma il.com>
                  Sent: Tuesday, June 10, 2008 7:37 PM
                  To: <python-list@python.org >
                  Subject: Re: problems with opening files due to file's path
                  >
                  No this time it perhaps gave me the worst of all heres what I entered, and
                  the output
                  >
                  >>>startfile(r" %s"%full) ***full is the path***
                  >
                  startfile(r"%s" %full)
                  >
                  WindowsError: [Error 2] The system cannot find the file specified:
                  '"C:\\Docume nts and Settings\\Alex\ \My Documents\\My
                  Music\\Rhapsody \\Bryanbros\\Ja son Mraz\\I\'m Yours (Single)\x01 - I\'m
                  Yours.wma"'
                  >
                  >
                  Thomas Morton wrote:
                  >>
                  >maybe try string substitution... not sure if that's really the BEST way
                  >to
                  >do it but it should work
                  >>
                  >startfile(r"%s "%variable)
                  >>
                  >--------------------------------------------------
                  >From: "Alexnb" <alexnbryan@gma il.com>
                  >Sent: Tuesday, June 10, 2008 7:05 PM
                  >To: <python-list@python.org >
                  >Subject: Re: problems with opening files due to file's path
                  >>
                  >>>
                  >>Well, now i've hit another problem, this time being that the path will
                  >>be
                  >>a
                  >>variable, and I can't figure out how to make startfile() make it raw
                  >>with
                  >>a
                  >>variable, if I put startfile(r variable), it doesn't work and
                  >>startfile(rva riable) obviously won't work, do you know how to make that
                  >>work
                  >>or better yet, how to take a regular string that is given and make every
                  >>single "\" into a double "\\"?
                  >>>
                  >>Mike Driscoll wrote:
                  >>>>
                  >>>On Jun 10, 11:45 am, Alexnb <alexnbr...@gma il.comwrote:
                  >>>>Gerhard Häring wrote:
                  >>>>>
                  >>>Alexnb wrote:
                  >>>>Okay, so what I want my program to do it open a file, a music file
                  >>>>in
                  >>>>specific, and for this we will say it is an .mp3. Well, I am using
                  >>>>the
                  >>>>system() command from the os class. [...]
                  >>>>>
                  >>>>system("\"C :\Documents and Settings\Alex\M y Documents\My
                  >>>>Music\Rhaps ody\Bryanbros\W eezer\(2001)\04 - Island In The
                  >>>>Sun.wma\" ")
                  >>>>[...]
                  >>>>>
                  >>>Try os.startfile() instead. It should work better.
                  >>>>>
                  >>>-- Gerhard
                  >>>>>
                  >>>--
                  >>>>http://mail.python.org/mailman/listinfo/python-list
                  >>>>>
                  >>>>No, it didn't work, but it gave me some interesting feedback when I
                  >>>>ran
                  >>>>it
                  >>>>in the shell. Heres what it told me:
                  >>>>>
                  >>>>>os.startfi le("C:\Document s and Settings\Alex\M y Documents\My
                  >>>>>Music\Rhap sody\Bryanbros\ Jason Mraz\I'm Yours (Single)\01 - I'm
                  >>>>>Yours.wma" )
                  >>>>>
                  >>>>Traceback (most recent call last):
                  >>>> File "<pyshell#1 0>", line 1, in <module>
                  >>>> os.startfile("C :\Documents and Settings\Alex\M y Documents\My
                  >>>>Music\Rhaps ody\Bryanbros\J ason Mraz\I'm Yours (Single)\01 - I'm
                  >>>>Yours.wma ")
                  >>>>>
                  >>>>WindowsErro r: [Error 2] The system cannot find the file specified:
                  >>>>"C:\\Docume nts and Settings\\Alex\ \My Documents\\My
                  >>>>Music\\Rhap sody\\Bryanbros \\Jason Mraz\\I'm Yours (Single)\x01 - I'm
                  >>>>Yours.wma "
                  >>>>>
                  >>>>See it made each backslash into two, and the one by the parenthesis
                  >>>>and
                  >>>>the
                  >>>>0 turned into an x....
                  >>>>--
                  >>>>View this message in
                  >>>>context:http://www.nabble.com/problems-with-...o-file%27s-pat...
                  >>>>Sent from the Python - python-list mailing list archive at Nabble.com.
                  >>>>
                  >>>Yeah. You need to either double all the backslashes or make it a raw
                  >>>string by adding an "r" to the beginning, like so:
                  >>>>
                  >>>os.startfile (r'C:\path\to\m y\file')
                  >>>>
                  >>>HTH
                  >>>>
                  >>>Mike
                  >>>--
                  >>>http://mail.python.org/mailman/listinfo/python-list
                  >>>>
                  >>>>
                  >>>
                  >>--
                  >>View this message in context:
                  >>http://www.nabble.com/problems-with-...p17761338.html
                  >>Sent from the Python - python-list mailing list archive at Nabble.com.
                  >>>
                  >>--
                  >>http://mail.python.org/mailman/listinfo/python-list
                  >>
                  >--
                  >http://mail.python.org/mailman/listinfo/python-list
                  >>
                  >
                  --
                  View this message in context:

                  Sent from the Python - python-list mailing list archive at Nabble.com.
                  >
                  --
                  http://mail.python.org/mailman/listinfo/python-list

                  Comment

                  • Carsten Haese

                    #10
                    Re: problems with opening files due to file's path

                    Alexnb wrote:
                    No this time it perhaps gave me the worst of all heres what I entered, and
                    the output
                    >
                    >>>startfile(r" %s"%full) ***full is the path***
                    >
                    startfile(r"%s" %full)
                    >
                    WindowsError: [Error 2] The system cannot find the file specified:
                    '"C:\\Docume nts and Settings\\Alex\ \My Documents\\My
                    Music\\Rhapsody \\Bryanbros\\Ja son Mraz\\I\'m Yours (Single)\x01 - I\'m
                    Yours.wma"'
                    Contrary to what other posters have asserted, doing the above can't make
                    a difference. Putting 'r' in front of a string literal tells Python not
                    to give backslashes in the string literal any special treatment. Since
                    there are no backslashes in "%s", the 'r' does nothing.

                    Therefore, (r"%s"%full) is the same as ("%s"%full), which is the same as
                    (full), assuming that `full` is the name of a string.

                    The real answer lies in fixing the code where you're assigning the
                    pathname to 'full', which you haven't posted. Please post the code where
                    you're assigning the pathname, or better yet, post the complete code
                    you're running.

                    --
                    Carsten Haese

                    Comment

                    • Mike Driscoll

                      #11
                      Re: problems with opening files due to file's path

                      On Jun 10, 2:09 pm, Carsten Haese <carsten.ha...@ gmail.comwrote:
                      Alexnb wrote:
                      No this time it perhaps gave me the worst of all heres what I entered, and
                      the output
                      >
                      >>startfile(r"% s"%full)    ***full is the path***
                      >
                      startfile(r"%s" %full)
                      >
                      WindowsError: [Error 2] The system cannot find the file specified:
                      '"C:\\Docume nts and Settings\\Alex\ \My Documents\\My
                      Music\\Rhapsody \\Bryanbros\\Ja son Mraz\\I\'m Yours (Single)\x01 - I\'m
                      Yours.wma"'
                      >
                      Contrary to what other posters have asserted, doing the above can't make
                      a difference. Putting 'r' in front of a string literal tells Python not
                      to give backslashes in the string literal any special treatment. Since
                      there are no backslashes in "%s", the 'r' does nothing.

                      I assumed the OP was trying to do the string substitution within a
                      path. If the OP is instead doing as you think, then you are quite
                      correct.
                      >
                      Therefore, (r"%s"%full) is the same as ("%s"%full), which is the same as
                      (full), assuming that `full` is the name of a string.
                      >
                      The real answer lies in fixing the code where you're assigning the
                      pathname to 'full', which you haven't posted. Please post the code where
                      you're assigning the pathname, or better yet, post the complete code
                      you're running.
                      >
                      --
                      Carsten Haesehttp://informixdb.sour ceforge.net

                      Sometimes I get too eager to help and don't do enough mental
                      processing before answering.

                      Mike

                      Comment

                      • Mike Driscoll

                        #12
                        Re: problems with opening files due to file's path

                        On Jun 10, 1:57 pm, Alexnb <alexnbr...@gma il.comwrote:
                        That would work, but not for what I want. See the file could be anywhere on
                        the user's system and so the entire path will be unique, and that didn't
                        work with a unique path. What is the subprocess module you are talking
                        about?
                        >

                        <snip>

                        As Carsten pointed out, we don't really know what you're doing. Or at
                        least, I don't. Why do you even want to do string substitution? How
                        does the user navigate to the files that the user wants to open? Are
                        you using a GUI or a command line interface?

                        Anyway, Google is your friend. Searching for "python subprocess" gives
                        you this:

                        Source code: Lib/subprocess.py The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace seve...


                        Mike

                        Comment

                        • Alexnb

                          #13
                          Re: problems with opening files due to file's path


                          I am using GUI, Tkinter to be exact. But regardless of how the path gets
                          there, it needs to opened correctly. The problem I am running into is that
                          the program receives a path of a file, either .wma or .mp3 and is supposed
                          to open it. I run into problems when there is either a ")" or a number next
                          to the backslash "\" in the file path. I am looking for a way to make it
                          work with a variable, I can make it work when I physically type it in, but
                          not with a variable that holds the path.



                          Mike Driscoll wrote:

                          On Jun 10, 1:57 pm, Alexnb <alexnbr...@gma il.comwrote:
                          >That would work, but not for what I want. See the file could be anywhere
                          >on
                          >the user's system and so the entire path will be unique, and that didn't
                          >work with a unique path. What is the subprocess module you are talking
                          >about?
                          >>

                          <snip>

                          As Carsten pointed out, we don't really know what you're doing. Or at
                          least, I don't. Why do you even want to do string substitution? How
                          does the user navigate to the files that the user wants to open? Are
                          you using a GUI or a command line interface?

                          Anyway, Google is your friend. Searching for "python subprocess" gives
                          you this:

                          Source code: Lib/subprocess.py The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace seve...


                          Mike
                          --

                          --
                          View this message in context: http://www.nabble.com/problems-with-...p17767518.html
                          Sent from the Python - python-list mailing list archive at Nabble.com.

                          Comment

                          • Grant Edwards

                            #14
                            Re: problems with opening files due to file's path

                            On 2008-06-11, Alexnb <alexnbryan@gma il.comwrote:
                            I am using GUI, Tkinter to be exact. But regardless of how the
                            path gets there, it needs to opened correctly. The problem I
                            am running into is that the program receives a path of a file,
                            either .wma or .mp3 and is supposed to open it. I run into
                            problems when there is either a ")" or a number next to the
                            backslash "\" in the file path. I am looking for a way to make
                            it work with a variable, I can make it work when I physically
                            type it in, but not with a variable that holds the path.
                            You're going to have to show us code and example input and
                            output. Your description of the problem is far too vague for
                            anybody to help you.

                            --
                            Grant Edwards grante Yow! With YOU, I can be
                            at MYSELF... We don't NEED
                            visi.com Dan Rather...

                            Comment

                            • Alexnb

                              #15
                              Re: problems with opening files due to file's path


                              Okay, I don't understand how it is too vague, but here:
                              >>path = "C:\Documen ts and Settings\Alex\M y Documents\My
                              >>Music\Rhapsod y\Bryanbros\Jas on Mraz\I'm Yours (Single)\01 - I'm
                              >>Yours.wma"
                              >>os.startfile( path)
                              Traceback (most recent call last):
                              File "<pyshell#3 9>", line 1, in <module>
                              os.startfile(pa th)
                              WindowsError: [Error 2] The system cannot find the file specified:
                              "C:\\Docume nts and Settings\\Alex\ \My Documents\\My
                              Music\\Rhapsody \\Bryanbros\\Ja son Mraz\\I'm Yours (Single)\x01 - I'm
                              Yours.wma"

                              Here's another way:
                              >>os.startfile( r"%s"%path)
                              Traceback (most recent call last):
                              File "<pyshell#4 0>", line 1, in <module>
                              os.startfile(r" %s"%path)
                              WindowsError: [Error 2] The system cannot find the file specified:
                              "C:\\Docume nts and Settings\\Alex\ \My Documents\\My
                              Music\\Rhapsody \\Bryanbros\\Ja son Mraz\\I'm Yours (Single)\x01 - I'm
                              Yours.wma"

                              Same output, however if I personally input it like so:
                              >>os.startfile( "C:\\Docume nts and Settings\\Alex\ \My Documents\\My
                              >>Music\\Rhapso dy\\Bryanbros\\ Jason Mraz\\I'm Yours (Single)\\01 - I'm
                              >>Yours.wma")
                              It works out fine because I can make each backslash doubles so it doesn't
                              mess stuff up. So if I could take the path varible and make ever "\" into a
                              "\\" then it would also work.

                              Did I clarify?



                              Grant Edwards wrote:
                              >
                              On 2008-06-11, Alexnb <alexnbryan@gma il.comwrote:
                              >
                              >I am using GUI, Tkinter to be exact. But regardless of how the
                              >path gets there, it needs to opened correctly. The problem I
                              >am running into is that the program receives a path of a file,
                              >either .wma or .mp3 and is supposed to open it. I run into
                              >problems when there is either a ")" or a number next to the
                              >backslash "\" in the file path. I am looking for a way to make
                              >it work with a variable, I can make it work when I physically
                              >type it in, but not with a variable that holds the path.
                              >
                              You're going to have to show us code and example input and
                              output. Your description of the problem is far too vague for
                              anybody to help you.
                              >
                              --
                              Grant Edwards grante Yow! With YOU, I can
                              be
                              at MYSELF... We don't NEED
                              visi.com Dan Rather...
                              --

                              >
                              >
                              --
                              View this message in context: http://www.nabble.com/problems-with-...p17768511.html
                              Sent from the Python - python-list mailing list archive at Nabble.com.

                              Comment

                              Working...