[Tutor] grave confusion

Clayton Kirkwood crk at godblessthe.us
Mon Oct 6 04:19:36 CEST 2014


Here's my problem; my code snippet reads a file(presumably an _io.readline,
I'll question this later), with the file.readline(). The output shows
individual characters being read and printed out followed by the "here"
being printed. Also, see below.

 

 

Source data file:

<!-- saved from url=(0040)https://finance.yahoo.com/portfolio/pf_2 -->

html class="yui3-js-enabled" id="yui_3_10_3_4_1412203661632_7637"><div
id="yui3-css-stamp" style="position: absolute !important; visibility: hidden
!important" class=""></div><head><meta http-equiv="Content-Type"
content="text/html; charset=UTF-8">

 

 

Code snippet:

import re, os

for line_in in file.readline():

    print( line_in )

     print("here")

      continue

 

 

Output:

< 

here

!

here

-

here

-

here

here

s

here

a

here

v

here

e

 

Why the individual characters and not the full line? Also, it is very
unclear to me which readline I am using. I have imported os. I am using
pycharm IDE and supposedly it will show me where readline is coming from by
right clicking and choosing find usages. However, it brings up three
readlines which are place holders. It doesn't bring up the os.readline. I am
getting really tired of trying to figure out which function is being used!

 

So, what is happening that I am missing?

 

TIA,

 

Clayton

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141005/0bfdffda/attachment.html>


More information about the Tutor mailing list