Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have found the perfect piece of code that does what I want for something and have it running in Python 2 but I desperately need it to be in C# as that is what I am writing my main application in. I have tried for ages to convert it manually and there are no online converters because the two languages are just too different to convert automatically. I know it is a big ask but is there any change one of you could have a go at converting the code from Python 2 into C#? The code is in the first link and the 'what it should do' is in the last post of the last link. Thank you for any help.

I think my main problem is that Python annoyingly does not require data types when initializing variables which makes it much harder to convert...

Code: http://04819193935789338545.googlegroups.com/attach/635a5f7d08fa9a7a/check_capabilities.py?part=4&view=1&vt=ANaJVrFW4aLpCAf5vlei2dM7vN-AWAK3Kjd4mSUAqxk55sqmPSn_MfPSCUBALdPXaKggUyRtWbqz9ixrxBDndGrgTdBUHiEkdOMP5Dlc_peGxOVgNSoUkoQ
Page: https://groups.google.com/forum/#!topic/metoffice-datapoint/lO7TysG4-CI
By the way the code is the same file as the attachment in the Google post
Posted
Updated 5-Nov-13 7:51am
v2

1 solution

Just write the code in C#. It has a lot of similarities with Python, yet the languages are very different, and the frameworks you might have used can be even more different. What I see from code sample, is very different from .NET and C#. You could not talk about anything like automatic translation. Just go ahead: on input, you should have understanding of the goals of your code, Python code, understanding of .NET and C#, on output — new code in C#.

—SA
 
Share this answer
 
Comments
Henry Hunt 5-Nov-13 14:04pm    
Ok thank you, I will have another go at writing it...one thing though: would this be a DateTime or an int?: nextExpected = time() + updateRate, and is time() just the current time?
Sergey Alexandrovich Kryukov 5-Nov-13 14:14pm    
Not clear what int, but here is the hint: .NET System.DateTime has the presentation as the number of "ticks", the number of 100-nanosecond intervals that have elapsed since January 1, 0001 at 00:00:00.000 in the Gregorian calendar. The data type is Int64. This is the most universal and modern presentation.

Please see: http://msdn.microsoft.com/en-us/library/z2xf7zzk%28v=vs.110%29.aspx.

Will you accept this answer now (green "Accept" button)? In all cases, your follow-up questions will be welcome.

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900