newbie question - python blocking on int()?
michael at damaru.com
Mon Jun 10 23:16:36 EDT 2002
Chris Liechti wrote:
> 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
>> size = details
>> name = details
>> debug( "added remote file size %5d: %s" % (int(size), name) )
>> This works. But when I replace the 3rd line with this:
>> size = int( details )
>> 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.
Thanks for replying. Actually, it's the former - when I say 'hangs', I mean
that the program appears to stop running at that point. If I write:
size = int( details )
it prints "one" but not "two".
As far as the other points go, luckily I'm in control of all the file names,
and I can ensure that none has spaces. Spaces in filenames were always a
terrible idea, I think. And I didn't call the string 'str', I called it
'line', which I don't think is a reserved word or function name.
> 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.
Custom Programming - Web Development - Database Design
More information about the Python-list