[IronPython] How to convert between C# and IronPython

Andrew Evans evans.d.andrew at gmail.com
Thu Aug 5 07:55:19 CEST 2010


Hey thanks for your help makes better sense now.

Thank you

it is very much appreciated :-)

On Wed, Aug 4, 2010 at 7:37 PM, Jeff Hardy <jdhardy at gmail.com> wrote:

> D'oh, forgot to remove some semicolons (Python will ignore them anyway):
>
> >         from System.Security.Cryptography import RNGCryptoServiceProvider
> >         from System import BitConverter, Random
> >
> >         rndC = RNGCryptoServiceProvider()
> >         rndC.GetBytes(rndBytes)
> >         seed = BitConverter.ToInt32(rndBytes, 0)
> >         rand = Random(seed)
> >
> >         return rand.Next(min, max)
>
> - Jeff
>
> On Wed, Aug 4, 2010 at 8:36 PM, Jeff Hardy <jdhardy at gmail.com> wrote:
> > Hi Andrew,
> > Jimmy has already shown how to create a byte array, so I'll translate the
> rest:
> >
> >         from System.Security.Cryptography import RNGCryptoServiceProvider
> >         from System import BitConverter, Random
> >
> >         rndC = RNGCryptoServiceProvider()
> >         rndC.GetBytes(rndBytes)
> >         seed = BitConverter.ToInt32(rndBytes, 0);
> >         rand = Random(seed);
> >
> >         return rand.Next(min, max);
> >
> > In general, to convert C# to Python:
> >
> > drop semicolons ( ; )
> > drop braces ( { } )
> > drop 'new'
> > drop types
> > drop namespaces
> >
> > add 'def' to functions
> > change foreach to for
> > remove parens ( ( ) ) from if, for, while
> > add colons ( : ) after class, def, if, while
> >
> > change 'using Foo' to 'from Foo import *' (bad style in Python, but it
> works)
> >
> > and a few other, more complicated steps
> >
> > Heck, writing a script to do it wouldn't be all that hard, and it
> > shows just how much noise is in C#.
> >
> > - Jeff
> >
> > On Wed, Aug 4, 2010 at 5:02 PM, Andrew Evans <evans.d.andrew at gmail.com>
> wrote:
> >> Hello
> >>
> >> I am trying to follow a tutorial written for silverlight and C# and
> convert
> >> the code to Iron Python. However I am unsure about how to use this code
> as
> >> IronPython
> >>
> >>         Byte[] rndBytes = new Byte[10];
> >>
> >>         RNGCryptoServiceProvider rndC = new RNGCryptoServiceProvider();
> >>         rndC.GetBytes(rndBytes);
> >>         int seed = BitConverter.ToInt32(rndBytes, 0);
> >>         Random rand = new Random(seed);
> >>
> >>         return rand.Next(min, max);
> >>
> >> what modules do I need. How do I use Byte in IronPython etc
> >>
> >> Any ideas advice *cheers
> >>
> >>
> >>
> >> _______________________________________________
> >> Users mailing list
> >> Users at lists.ironpython.com
> >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> >>
> >>
> >
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100804/95089d47/attachment.html>


More information about the Ironpython-users mailing list