Pulling numbers from ASCII filename not working
Dave Hansen
iddw at hotmail.com
Thu Jan 26 09:57:53 EST 2006
On Thu, 26 Jan 2006 06:39:20 GMT in comp.lang.python, Dennis Lee
Bieber <wlfraed at ix.netcom.com> wrote:
>On 25 Jan 2006 12:42:20 -0800, "IamIan" <iansan at gmail.com> declaimed the
>following in comp.lang.python:
[...]
>> I tried print repr(filename) and it returned the actual filename:
>> 'n16w099.asc' , 'n17w062.asc' , etc.
>
> You may have problems with the longitude... those leading zeroes may
>be taken as Octal notation...
Shouldn't be a problem unless you make it one. Int defaults to
decimal, unless you specify a base or tell it to infer the base from
the number format by specifying a base of zero.
>>> a = int("062")
>>> a
62
>>> a = int("062",0)
>>> a
50
Hard to interpret "099" as an octal number in any case:
>>> a = int("099",0)
Traceback (most recent call last):
File "<pyshell#59>", line 1, in -toplevel-
a = int("099",0)
ValueError: invalid literal for int(): 099
>>>
Regards,
-=Dave
--
Change is inevitable, progress is not.
More information about the Python-list
mailing list