python 3.x - Why does urlopen read() produce unexpected behavior -


this naive question because i'm python beginner here goes...

this works...

import urllib.request web=urllib.request.urlopen('ftp://pubftp.spp.org/markets/rtbm/lmp_by_settlement_loc/2015/05/05/') filelist=web.read().decode('utf-8').split('\r\n') 

but doesn't

filelist=urllib.request.urlopen('ftp://pubftp.spp.org/markets/rtbm/lmp_by_settlement_loc/2015/05/05/').read().decode('utf-8').split('\r\n')` 

specifically, either hangs , have cancel command or returns list item 0 empty string

another bit of strange behavior occurs if do

web=urllib.request.urlopen('ftp://pubftp.spp.org/markets/rtbm/lmp_by_settlement_loc/2015/05/05/') web.read() #dumps contents expected web.read() #now displays b'' 

i'm guessing these 2 bits of behavior related , read() changes underlying object reason.

obviously it's easy enough use former syntax i'm sure gotcha come bite me else in future if don't know going on.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -