Tuesday, 15 June 2010

Python reading from file stops abruptly -



Python reading from file stops abruptly -

i reading text file of 750 lines. code:

x = 0 open(path.join(_path, _filename), 'ru') f: line in f: print x, line x += 1

process stops @ line 713. print-out:

709 83968|10-07-2014 04:00:00|4607|8059|jnbo=4y8%_lllc*6k/&:).|"lc[ib91/""l+e>\b%3k#vm&"|"phs[d_(""%our3\6vh^<!m"""|74005|57009|0|0 710 83969|10-07-2014 04:00:00|1391|8059|i?wwb^!kfy3ey\qd50h/.0|ksn<u$-&?*end,=ghl3<n%|ahc\uj70%)0/:2k&7a22f&|74005|57009|0|0 711 84349|10-07-2014 04:00:00|36518|8059|c$>p!_8!ttdjk*ke+u=y@.|o!!lb_i2+ard]w!)u_s56)|"a3$(74q2\74_/2'3;<\%5"""|74005|74004|0|0 712 80354|10-07-2014 04:00:00|7267|8059|k@a#jk4lc;m_-o!<#.95b/|n8#2r&=b[4]d7kod\3`ci#|"b,[`z=k$*#36;7""l;9^,6("|74005|57009|0|0 713 76910|10-07-2014

and excerpt file:

83968|10-07-2014 04:00:00|4607|8059|jnbo=4y8%_lllc*6k/&:).|"lc[ib91/""l+e>\b%3k#vm&"|"phs[d_(""%our3\6vh^<!m"""|74005|57009|0|0 83969|10-07-2014 04:00:00|1391|8059|i?wwb^!kfy3ey\qd50h/.0|ksn<u$-&?*end,=ghl3<n%|ahc\uj70%)0/:2k&7a22f&|74005|57009|0|0 84349|10-07-2014 04:00:00|36518|8059|c$>p!_8!ttdjk*ke+u=y@.|o!!lb_i2+ard]w!)u_s56)|"a3$(74q2\74_/2'3;<\%5"""|74005|74004|0|0 80354|10-07-2014 04:00:00|7267|8059|k@a#jk4lc;m_-o!<#.95b/|n8#2r&=b[4]d7kod\3`ci#|"b,[`z=k$*#36;7""l;9^,6("|74005|57009|0|0 76910|10-07-2014 04:00:00|49425|8059|"d'a\<(%n?fs\arp??""cj0."|"h`]8#e^"")t""p""0':]oz%v*"|"f'),+f`6wu?ut>""=k<#pc."|74005|74004|0|0 84356|10-07-2014 04:00:00|3236|8059|"gt&]s-7<a%msbo>""z2(t%+"|f6ydp\;o@_4?bw!1vic1o!|p/o/9w)(yj&+:\=hk)*oa$|74005|55427|0|0 89539|10-07-2014 04:00:00|1113|8059|"gp',l]bzvelbmy`6(&4%^%"|"l2`gstcj:^.\g\i:'sq*t'"|"jd^28<ikkq6=%7v/fx6-['"|74005|74004|0|0

line 713 3rd bottom in fragment.

i guess thinks reaches end (maybe eof character?).

any ideas wrong file?

update: whole file > http://dpaste.com/3ccgzy9

update 2: screenshot vim : https://dl.dropboxusercontent.com/u/2423935/err.jpg (line cause problem highlighted)

update 3: seems pasting dpaste solves problem. however, cannot because file prior parsing downloaded ftp server. code using download ftp:

try: connection = ftp("<server_ip>") connection.login("<username>", "<pass>") connection.cwd("dir1") filenames = connection.nlst() filenames = sorted(filenames) name in filenames: exists = path.isfile(path.join(_path, name)) if not exists: # fetch it!! localfile = open(path.join(_path, name), 'wb') connection.set_pasv(false) connection.retrbinary("retr " + name, localfile.write, 1024) except all_errors e: log.error("cannot connect ftp server because %s" % repr(e))

update 4: actual file: https://dl.dropboxusercontent.com/u/2423935/source.txt , hex dump: https://dl.dropboxusercontent.com/u/2423935/hex.txt

i coulnd't reproduce problem on info provided. however, guess, maybe has buffering? then, try:

sys.stdout.flush()

after print. i'm pointing in direction because doesn't show error.

otherwise please seek provide whole file in unchanged form (eg upload somewhere).

python file

No comments:

Post a Comment