Python Hello World

2015/07/092 min read
bookmark this
Responsive image

Table of Contents

  1. Introduction
  2. Download Python
  3. Good Article
  4. Sample Hello World Code for Python
  5. Another Sample Code for Python
  6. Conclusion

Introduction

So, you want to get started with Python. Also, you prefer a Windows environment, so let's get started a little bit.

Download Python

Go to this link to download Python: https://www.python.org/downloads/release/python-279/. Select the target Windows installer.

Good Article

Check this article to get started: https://www.toptal.com/django/installing-django-on-iis-a-step-by-step-tutorial.

Sample Hello World Code for Python

'''A simple program to create an html file froma given string,
and call the default web browser to display the file.'''

contents = '''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">



  Hello


**Hello, World!




'''

def main():
    browseLocal(contents)

def strToFile(text, filename):
    """Write a file with the given name and the given text."""
    output = open(filename,"w")
    output.write(text)
    output.close()

def browseLocal(webpageText, filename='tempBrowseLocal.html'):
    '''Start your webbrowser on a local file containing the text
    with given filename.'''
    import webbrowser, os.path
    strToFile(webpageText, filename)
    webbrowser.open("file:///" + os.path.abspath(filename)) #elaborated for Mac

main()

Another Sample Code for Python

import os
print "Content-type: text/html\r\n\r\n";

for param in os.environ.keys():
  print "%20s**: %s<\br>" % (param, os.environ[param])

Something to Try

Can I pass a Python command from the UI to the back-end Python code and display the result on the UI?

Conclusion

This post covered the basics of getting started with Python on Windows, including downloading Python, running a simple Hello World program, and exploring sample code. These examples should give you a starting point for further Python development.