write()

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

    #1

    write()

    I copied the lines

    f=open('/tmp/workfile', 'w')
    print f
    f.close()

    from Python 2.4 Documentation 7.2. But it said IOerror No such file or
    directory" '/tmp/workfile'

    Is it something about the os? I'm using Python 2.4 under WinXP.
    Thanks. Without / I can open it.

  • miker2@optusnet.com.au

    #2
    Re: write()


    manuhack wrote:
    I copied the lines
    >
    f=open('/tmp/workfile', 'w')
    print f
    f.close()
    >
    from Python 2.4 Documentation 7.2. But it said IOerror No such file or
    directory" '/tmp/workfile'
    >
    Is it something about the os? I'm using Python 2.4 under WinXP.
    Thanks. Without / I can open it.

    f=open(r'c:\bla h\blah').read()

    Comment

    • manuhack

      #3
      Re: write()

      How about write mode? Changing r to w doesn't work...

      miker2@optusnet .com.au wrote:
      manuhack wrote:
      I copied the lines

      f=open('/tmp/workfile', 'w')
      print f
      f.close()

      from Python 2.4 Documentation 7.2. But it said IOerror No such file or
      directory" '/tmp/workfile'

      Is it something about the os? I'm using Python 2.4 under WinXP.
      Thanks. Without / I can open it.
      >
      >
      f=open(r'c:\bla h\blah').read()

      Comment

      • miker2@optusnet.com.au

        #4
        Re: write()


        manuhack wrote:
        How about write mode? Changing r to w doesn't work...
        >
        miker2@optusnet .com.au wrote:
        manuhack wrote:
        I copied the lines
        >
        f=open('/tmp/workfile', 'w')
        print f
        f.close()
        >
        from Python 2.4 Documentation 7.2. But it said IOerror No such file or
        directory" '/tmp/workfile'
        >
        Is it something about the os? I'm using Python 2.4 under WinXP.
        Thanks. Without / I can open it.

        f=open(r'c:\bla h\blah').read()
        what is it that you want to do??

        in XP if i have or want to create a file in c:\ called test.txt i would
        do this:

        f = open(r'c:\test. txt', 'w')
        f.write("rock the house party")
        f.close()

        Comment

        • Rick Zantow

          #5
          Re: write()

          "manuhack" <manuhack@gmail .comwrote in news:1153981114 .837884.232610
          @p79g2000cwp.go oglegroups.com:
          I copied the lines
          >
          f=open('/tmp/workfile', 'w')
          print f
          f.close()
          >
          from Python 2.4 Documentation 7.2. But it said IOerror No such file or
          directory" '/tmp/workfile'
          >
          Is it something about the os? I'm using Python 2.4 under WinXP.
          Thanks. Without / I can open it.
          >
          The problem is probably that you don't have a '/tmp' directory. WinXP
          doesn't create a directory structure to match a file path specification. If
          you first create the '/tmp' directory (which is a directory off the root of
          your hard drive on WinXP, so that if your current directory is on a D:
          drive it would be D:\tmp), then your code would work.

          --
          rzed

          Comment

          • manuhack

            #6
            Re: write()

            Then is there any way to create a directory under XP using Python?

            Rick Zantow wrote:
            "manuhack" <manuhack@gmail .comwrote in news:1153981114 .837884.232610
            @p79g2000cwp.go oglegroups.com:
            >
            I copied the lines

            f=open('/tmp/workfile', 'w')
            print f
            f.close()

            from Python 2.4 Documentation 7.2. But it said IOerror No such file or
            directory" '/tmp/workfile'

            Is it something about the os? I'm using Python 2.4 under WinXP.
            Thanks. Without / I can open it.
            >
            The problem is probably that you don't have a '/tmp' directory. WinXP
            doesn't create a directory structure to match a file path specification. If
            you first create the '/tmp' directory (which is a directory off the root of
            your hard drive on WinXP, so that if your current directory is on a D:
            drive it would be D:\tmp), then your code would work.
            >
            --
            rzed

            Comment

            • Dale Strickland-Clark

              #7
              Re: write()

              manuhack wrote:
              Then is there any way to create a directory under XP using Python?
              import os
              os.mkdir("C:\\m yosisbroken")

              --
              Dale Strickland-Clark
              Riverhall Systems www.riverhall.co.uk

              Comment

              • Andy Salnikov

                #8
                Re: write()


                "manuhack" <manuhack@gmail .comwrote in message
                news:1153981114 .837884.232610@ p79g2000cwp.goo glegroups.com.. .
                >I copied the lines
                >
                f=open('/tmp/workfile', 'w')
                print f
                f.close()
                >
                from Python 2.4 Documentation 7.2. But it said IOerror No such file or
                directory" '/tmp/workfile'
                >
                Is it something about the os? I'm using Python 2.4 under WinXP.
                Thanks. Without / I can open it.
                >
                In addition to what others said, if you need to open a temporary file,
                it's better to use os.tmpfile() to get a file descriptor and not to
                rely on magic file names like '/tmp/workfile'. So instead of open()
                you should do:

                import os

                f = os.tmpfile()

                This should work fine of both Windows and UNIX systems.

                Andy.


                Comment

                Working...