Skip to content

Instantly share code, notes, and snippets.

View kaydell's full-sized avatar

Kaydell Leavitt kaydell

  • Self
  • Layton, Utah, USA
View GitHub Profile
@kaydell
kaydell / gist:6826385
Last active December 24, 2015 16:09
Configure Python 3 Without Losing Python 2 On Mac OS X
# This code needs to be placed within the .bash_profile file of the user's home directory
# You can use a text editor such as Text Wrangler.app downloaded from the following
# link to create or edit the file .bash_profile, which is an invisible file because it begins
# with a dot.
# TextWrangler: http://www.barebones.com/products/textwrangler/download.html
# set the path to our Python Library
# require that '$HOME' be set to a dir
if [ -d "$HOME" ]; then
# set the path to our PYTHON_LIB
@kaydell
kaydell / gist:6826647
Created October 4, 2013 14:16
Demonstration #1 of Using the Version of Python That Comes With Mac OS X
#!/usr/bin/env python
import sys
print(sys.version_info)
@kaydell
kaydell / gist:6826708
Created October 4, 2013 14:20
This bash script demonstrates how to specify that you want the script to use Python 3 rather than Python 2 which comes with Mac OS X.
#!/usr/bin/env python3
import sys
print(sys.version_info)
@kaydell
kaydell / python3_gui_template.py
Created October 9, 2013 15:23
Python 3 GUI Starting Point
#!/usr/bin/env python3
def main():
# require Python 3
import sys
if sys.version_info.major < 3:
print("This program requires Python 3 or later")
return
@kaydell
kaydell / ask_int.py
Created October 9, 2013 17:41
A Python 3 Demo of Asking the User To Input An Int
# This script is a demonstration of asking the user to enter an
# int in Python 3
# ask the user to enter an int
string = input("Please enter an int: ")
# the function input() returns a str we need to convert it to be an int
n = int(string)
# echo the int back to the user
@kaydell
kaydell / loop_once_or_more.py
Created October 9, 2013 18:43
This is a demo of doing a loop that happens one or more times in Python 3
while True:
# read number from user
# if the number is in the range to exit, then break out of this loop
if n >= 1 and n <= 10:
break
@kaydell
kaydell / PythonTypes.py
Last active December 27, 2015 14:28
A Python Script That Demonstrates int and float literals and how to get the type of any value.
#!/usr/bin/env python3
"""
Script version: Python 3 (may not work in Python 2)
This script demonstrates setting a variable to an int and to a float.
A float is sometimes called a "real" and an int is also known as a
"whole number".
The point of this demo: