If I do this code in the command line:

f = open(fl, 'r')
txt = ""
for line in f:
    txt+=line
f.close()
print txt

I get all the output for the file fl, but if I do:

def editfl(self, fl):
        f = open(fl, 'r')
        txt = ""
        for line in f:
            txt+=line
        f.close()
        self.notebook_1.SetSelection(2)
        self.dedfrom = "fm"
        self.dedfl = fl
        self.text_ctrl_8.SetValue(txt)

then I only get the first 8-9 lines,
Until now it only occurs with this file (a log file generated by logkeys),
other (longer) files appear right...

What is causing the problems?

P.S.:If I try it with gedit I only get a bunch of weird not ASCII signs.
in bash, `cat` does output the content of the file right :s

Recommended Answers

All 2 Replies

You should print explicitely the content of the file using repr()

content = open(fl,'r').read()
print repr(content)

You should be able to see if your file contains wild characters. You can also try the 'rb' opening mode if you are using windows, to see if it makes any difference.

Text files use mode "r" and the contents are usually read until they reach the EOF marker (end of file). Non ASCII files can contain an EOF marker anywhere in the file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.