Code Monkey home page Code Monkey logo

csharp-to-python's Introduction

csharp-to-python

Python script for converting C# code to Python.

5-1-2012 NSC

When tasked with redeveloping an existing (and very robust) ASP.NET application
using Python, a search for converters yielded minimal useful results.  Several 
commercial tools exists, as well as a handful of online services (one of which has been 
down for at least six months as of today), but none were really working for the 
task at hand.

While prototyping and familiarizing myself with Python, several pages
and webmethods were converted by hand.  In doing so a repeatable process emerged.

Under the hood Python and C# have more differences than can be discussed, 
however the pure syntax of a source file, line by line, is moderately translatable.

This conversion script was created to speed up the repetitive refactoring operations
for each function in C#.  It greatly reduced overall conversion time.

Keep in mind, since C# and Python are both OO languages, this process is by no means foolproof.

It should be noted, as you would expect, that language specific classes and types are not 
easily converted, and this script does not attempt to do so.

What it does is simple - find and replace operations on a block of source code, line by line.
Converting common C# language keywords to their Python equivalent.


Use is simple:
1) create a file called convert.in, and place the block of C# code in it.
    (This utility works best one function at a time.)
2) run this script (./convert.py)
3) the results of the conversion will be written to convert.out.

NOTE: there is a mode that makes a fair attempt at converting .aspx files to standard html.
To try that:
1) place your .aspx markup in convert.in
2) run this script with an argument (./convert.py aspx)
3) results are in convert.out.

FINAL NOTE:
Every programmer has different habits, naming conventions, etc.  Certain parts of this
process were specifically intended for converting *my own naming conventions* in the C# code.

Those lines are commented out, but left here as a reference/guide as you create your own 
customized replacements.

csharp-to-python's People

Watchers

Mark James avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.