implement a cat program in csharp in python

CSharp Implementation

main.cs
using System;
using System.IO;

class Program {
    static void Main(string[] args) {
        if (args.Length == 0) {
            Console.WriteLine("Please provide a file name as a command line argument");
            return;
        }
        try {
            string content = File.ReadAllText(args[0]);
            Console.WriteLine(content);
        } catch (Exception e) {
            Console.WriteLine("Error reading the file: {0}", e.Message);
        }
    }
}
469 chars
18 lines

Python Implementation

main.py
import sys

if len(sys.argv) == 1:
    print("Please provide a file name as a command line argument")
    sys.exit()

try:
    with open(sys.argv[1], 'r') as file:
        content = file.read()
        print(content)
except Exception as e:
    print(f"Error reading the file: {e}")
282 chars
13 lines

Both of these implementations read a file provided as a command line argument and print its contents on the terminal. The CSharp implementation uses .NET's System.IO namespace to read the file, while the python implementation uses python's standard file IO operations.

gistlibby LogSnag