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

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

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

    Alexnb wrote:
    I don't get why yall are being so rude about this.
    We're frustrated with your apparent inability to understand anything
    we're saying.
    My problem is this; the
    path, as a variable conflicts with other characters in the path, creating
    escape characters I don't want, so I need a way to send the string to the
    os.startfile() in raw, or, with all the backslashes doubled.
    No, no, no, no, NO! That is not your problem! You are drawing unfounded
    conclusions from the fact that you had to double up backslashes when the
    filename came from a string literal. The situation is entirely different
    when the filename comes from user input. No doubling up of backslashes
    is necessary when the filename comes from user input. TRUST ME!

    For simplicity, start with this code to convince yourself:

    import os
    filename = raw_input("Plea se enter a filename: ")
    os.startfile(fi lename)

    Once you get that to work, replace raw_input with a function that gets
    the filename from your GUI.

    Hope this helps,

    --
    Carsten Haese

    Comment

    • Alexnb

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


      Well, I don't understand why I don't need to change anything because say I
      run that code, which goes straight from the entry box to the startfile()
      function. It doesn't work with some of the paths, that is the whole problem.
      the problem is when I enter a path with those certain characters next to
      each other. Everyone seems like there is some huge thing that I am
      missing... and I don't know what it is, because when I run that code, with
      that path I was talking about, I get an error, and it shows me that it is
      because of the \0.


      Jerry Hill wrote:
      >
      On Wed, Jun 11, 2008 at 4:16 PM, Alexnb <alexnbryan@gma il.comwrote:
      >>
      >I posted the underlying code, but I haven't made the GUI code because if
      >I
      >can't get the underlying code right it doesn't matter, well in my eyes it
      >doesn't but I am probably wrong. But it will look somehting like this:
      >
      What you're missing is that all of the problems you're having with
      escape characters *only apply to string literals inside your python
      source code.* If you're getting the string from the console, you
      don't need to escape or change anything. If you're getting the string
      from a Tk text box, you don't need to escape or change anything. If
      you're getting the string from the filesystem, you don't need to
      escape or change anything.
      >
      The only place you have to be careful is when you type out a literal
      string inside your .py source code. When you do that, you need to
      properly escape backslashes, either by putting them in raw strings, or
      by doubling up your backslashes.
      >
      If you haven't already, reread the section of the python tutorial
      about string literals: http://docs.python.org/tut/node5.html.
      >
      --
      Jerry
      --

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

      Comment

      • Carsten Haese

        #33
        Re: basic code of what I am doing

        Alexnb wrote:
        Okay, so I wrote some code of basically what I will be doing, only with
        exactly what I need for this part of the program but here you go: [...]
        Finally...
        path = "\"" + path + "\""
        That line of code is unnecessary. Delete it.

        --
        Carsten Haese

        Comment

        • Alexnb

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


          Haha, okay well sorry that I was being so stupid, but I get it now and I
          apoligize for causing you all the frustration. But I did get it to work
          finally.


          Carsten Haese-2 wrote:
          >
          Alexnb wrote:
          >I don't get why yall are being so rude about this.
          >
          We're frustrated with your apparent inability to understand anything
          we're saying.
          >
          >My problem is this; the
          >path, as a variable conflicts with other characters in the path, creating
          >escape characters I don't want, so I need a way to send the string to the
          >os.startfile () in raw, or, with all the backslashes doubled.
          >
          No, no, no, no, NO! That is not your problem! You are drawing unfounded
          conclusions from the fact that you had to double up backslashes when the
          filename came from a string literal. The situation is entirely different
          when the filename comes from user input. No doubling up of backslashes
          is necessary when the filename comes from user input. TRUST ME!
          >
          For simplicity, start with this code to convince yourself:
          >
          import os
          filename = raw_input("Plea se enter a filename: ")
          os.startfile(fi lename)
          >
          Once you get that to work, replace raw_input with a function that gets
          the filename from your GUI.
          >
          Hope this helps,
          >
          --
          Carsten Haese

          --

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

          Comment

          • Ethan Furman

            #35
            Re: basic code of what I am doing [was problems with opening filesdue to file's path]

            Alexnb wrote:
            Haha, okay well sorry that I was being so stupid, but I get it now
            and I apoligize for causing you all the frustration. But I did get it to
            work finally.
            >

            Comment

            Working...