newbie question - python blocking on int()?

Chris Liechti cliechti at gmx.net
Mon Jun 10 19:59:33 EDT 2002


Michael Davis <michael at damaru.com> wrote in 
news:4LaN8.2488$Vr2.586019 at news20.bellglobal.com:
> I'm writing a specialized ftp client. I'm parsing the output of ftp.dir, 
> which gives me a string like this (call it str):
> 
> -rw-r--r--   1 fred       527 Jun  4 22:58 report.php
> 
> and I'm getting the various parts like this:
> 
> details = string.split( str )
> permissions = details[0]
> size = details[3]
> name = details[7]
> debug( "added remote file size %5d: %s" % (int(size), name) )
> 
> This works. But when I replace the 3rd line with this:
> 
> size = int( details[3] )
> 
> python hangs on that line. Why?

not when i try it... what do you mean by "hangs" does it takes forever or 
do you see an error message? if its the later, then you might have assigned 
something to "int" somewhere else, hiding the builtin function.

note that you should not use "str" as a name as that is a builtin 
object/function that can be very handy. e.g. in python 2.2+ you could have
written "details = str.split(line)"
(or even "details = line.split()" which i prefer)

also note that split() might not be safe for every case. e.g when the user 
name contains a space (if possible) and surely when the filename has a 
space in it.

chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list