[Ironpython-users] How can IronPython access a public static value defined in C#?

Dino Viehland dinov at microsoft.com
Sat Jun 18 19:56:46 CEST 2011


Doug wrote:
> I asked:
> 
> Consider this C# code:
> 
> public static class Graphics {
>  public static Color white = new Color(255, 255, 255); }
> 
> I can compile and import this from IronPython:
> 
> >>> import clr
> >>> clr.AddReference("Graphics")
> >>> import Graphics
> >>> Graphics.white
> <Color 255,255,255>
> 
> But I can't:
> 
> >>> import clr
> >>> clr.AddReference("Graphics")
> >>> from Graphics import *
> >>> white
> Traceback (most recent call last):
>  File "/home/dblank/Calico/src/engine.py", line 159, in execute
>    source.Execute(self.manager.scope)
>  File "<string>", line 1, in <module>
> <type 'exceptions.NameError'>: name 'white' is not defined
> 
> Is there something I can do to make white accessible with "from ... import
> *"?

If you mark the field as readonly we'll let you import it using import *. Without
it being read-only we don't put it in Graphics.__all__ and therefore it doesn't
get imported.


More information about the Ironpython-users mailing list