{"id":18706078,"url":"https://github.com/uxmal/pytocs","last_synced_at":"2025-04-04T22:08:39.253Z","repository":{"id":35248440,"uuid":"39508154","full_name":"uxmal/pytocs","owner":"uxmal","description":"Converts Python source to C#","archived":false,"fork":false,"pushed_at":"2023-03-09T05:55:57.000Z","size":2336,"stargazers_count":572,"open_issues_count":18,"forks_count":166,"subscribers_count":40,"default_branch":"master","last_synced_at":"2025-03-28T21:08:12.769Z","etag":null,"topics":["csharp","python","transpiler"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uxmal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-07-22T13:38:45.000Z","updated_at":"2025-03-06T15:18:14.000Z","dependencies_parsed_at":"2024-11-07T12:13:04.501Z","dependency_job_id":"4b01baae-44c0-4553-a24d-fd2198a5846c","html_url":"https://github.com/uxmal/pytocs","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uxmal%2Fpytocs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uxmal%2Fpytocs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uxmal%2Fpytocs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uxmal%2Fpytocs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uxmal","download_url":"https://codeload.github.com/uxmal/pytocs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247256115,"owners_count":20909240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","python","transpiler"],"created_at":"2024-11-07T12:12:53.878Z","updated_at":"2025-04-04T22:08:39.239Z","avatar_url":"https://github.com/uxmal.png","language":"C#","readme":"# pytocs\n\n[![Join the chat at https://gitter.im/uxmal/pytocs](https://badges.gitter.im/uxmal/pytocs/Lobby.svg)](https://gitter.im/uxmal/pytocs?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nConverts Python source to C#\n\npytocs is a command line tool I wrote as a hobby project to convert Python source code to C#. \nI've uploaded it here in case someone finds it useful.\n\n## How to run pytocs\n\nJust git clone the project, and use Visual Studio or MSBuild to compile the `pytocs.sln` file. If you're unable or unwilling to build pytocs from source, the latest continuous integration build\nis available at [appveyor.com](https://ci.appveyor.com/project/uxmal/pytocs/build/artifacts). \n\n## Examples\n\nTo convert a Python file, hand it to `pytocs`:\n\n    pytocs foo.py\n\t\nTo convert all files in a directory (recursively), use the `-r` parameter:\n\n    pytocs -r \n\t\nThe following python fragment:\n\n```Python\n# Some code below\ndef hello():\n   print \"Hello World\";\n```\n\nTranslates to:\n\n```C#\npublic static class hello {\n\n    public static object hello() {\n\t    Console.WriteLine(\"Hello World\");\n    }\n}\n```\n\nA more ambitious sample:\n```Python\nclass MyClass:\n    # member function calling other function\n    def calc_sum(self, x, y):\n       return self.frobulate('+', x, y)\n\n    # arithmetic and exceptions\n    def frobulate(self, op, x, y):\n        if op == '+':\n            return x + y\n        elif op == '-':\n            return x - y\n        else:\n            raise ValueError(\"Unexpected argument %s\" % op)\n\n    # static method using for..in and enumerate, with tuple comprehension\n    def walk_list(lst):\n        for (i,strg) in lst.iterate():\n            print \"index: %d strg: %s\\n\" % (i, strg)\n \n    # list comprehension, generating linQ output.\n    def apply_map(mapfn, filterfn):\n        return [mapfn(n) for n in lst if filterfn]\n```\nTranslates to:\n```C#\nusing System;\n\nusing System.Linq;\n\npublic static class readme {\n    \n    public class MyClass {\n        \n        // member function calling other function\n        public virtual object calc_sum(object x, object y) {\n            return this.frobulate(\"+\", x, y);\n        }\n        \n        // arithmetic and exceptions\n        public virtual object frobulate(object op, object x, object y) {\n            if (op == \"+\") {\n                return x + y;\n            } else if (op == \"-\") {\n                return x - y;\n            } else {\n                throw new ValueError(String.Format(\"Unexpected argument %s\", op));\n            }\n        }\n        \n        // static method using for..in and enumerate, with tuple comprehension\n        public static object walk_list(object lst) {\n            foreach (var _tup_1 in lst.iterate()) {\n                var i = _tup_1.Item1;\n                var strg = _tup_1.Item2;\n                Console.WriteLine(String.Format(\"index: %d strg: %s\\n\", i, strg));\n            }\n        }\n        \n        // list comprehension\n        public static object apply_map(object mapfn, object filterfn) {\n            return (from n in lst\n                where filterfn\n                select mapfn(n)).ToList();\n        }\n    }\n}\n```\n\n## Roadmap\n\nThe next big items on the list are:\n* Take the types that are inferred and apply them to the code to get away from everything being `object`.\n* Place local variable declarations at the statement that dominates all definitions of said variables.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuxmal%2Fpytocs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuxmal%2Fpytocs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuxmal%2Fpytocs/lists"}