file open/read/name etc, not working

G

globalrev

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.
 
G

globalrev

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...
 
J

John Machin

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
 
A

Andreas Tawn

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.

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
 
G

globalrev

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top