eTechtips

Tech Tips and Insights

Category: Python

  • Gallery of Hello World!

    Here is a list of the Hello World Programs for different languages:

    C

    #include <stdio.h>
    int main()
    {
    printf("Hello World!");
    }

    C++

    #include <iostream.h>
    int main()
    {
    cout << "Hello World!" << endl;
    }

    C#

    public class HelloWorld
      public static void Main()
      {
        System.Console.WriteLine("Hello World!");
      }

    Java

    class HelloWorld {
    static void main(String[] args)
    {
    System.out.println("Hello World!");
    }

    SHELL

    echo "Hello World"

    Python 2

    print "Hello World!\n"

    Python 3

    print ("Hello World!")

    Ruby

    puts "Hello World!"

    Perl

    print "Hello World!n";

    PHP

      <?php      
        print "Hello World!";
      ?>

    Rust

    fn main() {
        println("Hello World!");
    }

    This is the simplest form of Hello World for most of these languages.

    0 Comments
  • Python: AttributeError: ‘getopt’ module has no attribute ‘GetoptError’

    So I was figuring out how to parse command line arguments with python and using the getopt module with the following code

    
    #!/usr/bin/env python
    import sys
    import getopt
    
    def main(argv):
       infile = "some.xml"
       try:
          opts,args = getopt.getopt(argv,"hi:d",["help","infile="]
       except getopt.GetoptError:
          usage()
          sys.exit(2)
    
    if __name__ == "__main__":
        main(sys.argv[1:])
    

    And I was getting the following error:

    AttributeError: ‘getopt’ module has no attribute ‘GetoptError’

    So my first problem was that I had named my script getopt.py and after renaming the script, I got the same error. Well you now need to remove the getopt.pyc file that was generated from your earlier running of the poorly named script.

    4 Comments