This is a function of whether or not you've imported "clr" into the module.
Until you import clr, int objects will only have the methods of a Python
int.

PS f:\IronPython-2.0B2> .\ipy.exe
IronPython 2.0 Beta (2.0.0.2000) on .NET 2.0.50727.1434
Copyright (c) Microsoft Corporation. All rights reserved.
>>> a = 42
>>> len(dir(a))
54
>>> import clr
>>> len(dir(a))
65
>>>

This is a property of the current module and not of the objects that you've
passed to it.  If "x.py" contains "def n(x): return len(dir(x))" and "y.py"
contains "import clr" followed by the same function, you get the following
output from using them:

PS f:\IronPython-2.0B2> .\ipy.exe
IronPython 2.0 Beta (2.0.0.2000) on .NET 2.0.50727.1434
Copyright (c) Microsoft Corporation. All rights reserved.
>>> import x, y
>>> a = 42
>>> y.n(a)
65
>>> x.n(a)
54
>>>

So the solution is for you to add an "import clr" at the top of the module
where you're trying to use "ToString".

On Mon, May 5, 2008 at 3:58 AM, Dan Eloff <[EMAIL PROTECTED]> wrote:

> A dictionary has an integer value, it goes into third party code, at
> which point the dictionary very likely goes through some kind of copy
> so that modifications to it will not affect the original.
>
> Before going into thrid party code, d[key].ToString() works, but on
> the copied dictionary, newd[key].ToString() raises:
>
> AttributeError: 'int' object has no attribute 'ToString'
>
> So I'm curious now, how can that happen? Before and after it seems the
> value is <type 'int'>. How does int get .ToString() in the first
> place, and why does it seem to be possible to lose it?
>
> Thanks,
> -Dan
> _______________________________________________
> Users mailing list
> [email protected]
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to