file open/read/name etc, not working

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

    file open/read/name etc, not working

    import os

    print os.path.exists( 'C:/Python25/myPrograms/netflix/test.txt')
    d=open('C:/Python25/myPrograms/netflix/flim.txt', 'r')
    d.readline()

    returns true in the shell but prints no text even though the document
    contains text.

    d.name returns nothing, d.name() raises an error.
  • globalrev

    #2
    Re: file open/read/name etc, not working

    On 15 Maj, 18:12, globalrev <skanem...@yaho o.sewrote:
    import os
    >
    print os.path.exists( 'C:/Python25/myPrograms/netflix/test.txt')
    d=open('C:/Python25/myPrograms/netflix/flim.txt', 'r')
    d.readline()
    >
    returns true in the shell but prints no text even though the document
    contains text.
    >
    d.name returns nothing, d.name() raises an error.
    wow im an idiot. print...

    Comment

    • John Machin

      #3
      Re: file open/read/name etc, not working

      On May 16, 2:12 am, globalrev <skanem...@yaho o.sewrote:
      import os
      >
      print os.path.exists( 'C:/Python25/myPrograms/netflix/test.txt')
      d=open('C:/Python25/myPrograms/netflix/flim.txt', 'r')
      Two different paths again.
      d.readline()
      This reads one line and then does absolutely nothing with it. The
      Python interactive shell prints the result of each expression, which
      is a Good Thing. For Python to do the same when running a script would
      be a Bad Thing.

      readline and readlines are old hat; instead, iterate over the file
      object, like this:

      for line in d:
      print line,
      >
      returns true in the shell but prints no text even though the document
      contains text.
      >
      d.name returns nothing, d.name() raises an error.
      d.name should return the name of the file; I suspect that you again
      have done nothing with it. d.name() would raise an exception because
      d.name is not a method, so you can't call it.

      HTH,
      John

      Comment

      • Andreas Tawn

        #4
        RE: file open/read/name etc, not working

        >import os
        >
        >print os.path.exists( 'C:/Python25/myPrograms/netflix/test.txt')
        >d=open('C:/Python25/myPrograms/netflix/flim.txt', 'r')
        >d.readline()
        >
        >returns true in the shell but prints no text even though the document
        >contains text.
        >
        >d.name returns nothing, d.name() raises an error.
        >--
        >http://mail.python.org/mailman/listinfo/python-list
        Try...

        import os

        print os.path.exists( 'C:/Python25/myPrograms/netflix/test.txt')
        d=open('C:/Python25/myPrograms/netflix/flim.txt', 'r')
        for line in d:
        print line


        And I'm guessing that's a typo in flim.txt?

        Cheers,

        Drea

        Comment

        • globalrev

          #5
          Re: file open/read/name etc, not working

          On 15 Maj, 18:33, "Andreas Tawn" <andreas.t...@u bisoft.comwrote :
          import os
          >
          print os.path.exists( 'C:/Python25/myPrograms/netflix/test.txt')
          d=open('C:/Python25/myPrograms/netflix/flim.txt', 'r')
          d.readline()
          >
          returns true in the shell but prints no text even though the document
          contains text.
          >
          d.name returns nothing, d.name() raises an error.
          --
          http://mail.python.org/mailman/listinfo/python-list
          >
          Try...
          >
          import os
          >
          print os.path.exists( 'C:/Python25/myPrograms/netflix/test.txt')
          d=open('C:/Python25/myPrograms/netflix/flim.txt', 'r')
          for line in d:
          print line
          >
          And I'm guessing that's a typo in flim.txt?
          >
          Cheers,
          >
          Drea
          nah no typos i figured this out

          Comment

          Working...