python

stuff goes here

Installing python

Go to https://www.python.org/ Download python 2.7 run installer

Installing Python on Windows http://docs.python-guide.org/en/latest/starting/install/win/

http://www.tylerbutler.com/2012/05/how-to-install-python-pip-and-virtualenv-on-windows-with-powershell/

Add the following to PATH

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27\;C:\Python27\Scripts\", "User")

Install PyCharm

http://www.jetbrains.com/pycharm/

open pycharm

add python interpreters

click install setuptools

click install pop

Installing Modules

run command prompt as administrator

pip install virtualenv

pip install virtualenvwrapper-powershell

in powershell

pip install virtualenv

pip install virtualenvwrapper-powershell

Get-Command *virtualenv*

mkdir '~\.virtualenvs'

Import-Module VirtualEnvWrapper

$env:WORKON_HOME

workon

New-VirtualEnvironment TestEnv

workon

pip install SOAPpy

Set virtual Environment

in Powershell

Set-VirtualEnvironment TestEnv

in command prompt

%USERPROFILE%/.virtualenvs/TestEnv/Scripts/activate.bat

pip install ipython

pip install ipython[notebook]

installing numpy for python 2.x requires Visual Studio 2008 

https://mail.python.org/pipermail/distutils-sig/2014-January/023660.html

    For 2.x, it is expected to fail at that point, since you can't build C extensions with something different than 2008 (with python.org builds).

pip install numpy

pip install pandas

pip list

pip install ipython --upgrade

pip install ipython[notebook] --upgrade

pip install jsonschema

Launch ipython notebook

ipython notebook

Builtin functions

https://docs.python.org/2/library/functions.html

dir() https://docs.python.org/2/library/functions.html#dir

get a list of module attributes/methods

import sys

dir(sys)

make dir() more readable

join the output with newlines so that it prints 1 per line

print "\n".join(dir(r))

help() https://docs.python.org/2/library/functions.html#help

help(sys)

udacity web developement course notes

months = ['January',

          'February',

          'March',

          'April',

          'May',

          'June',

          'July',

          'August',

          'September',

          'October',

          'November',

          'December']

          

def valid_month(month):

        if month.capitalize() in months:

        return month.capitalize()

    else:

    return None

print valid_month("january")

print valid_month("blah")

def valid_day(day):

    if day and day.isdigit:

      int_day = int(day) 

      if int_day > 0 and int_day <= 31:

        return int_day

print valid_day('0')

def valid_year(year):

    if year and year.isdigit():

        year = int(year)

        if year >= 1900 and year <= 2020:

            return year

print valid_year('1900')

Dictionaries

environments = {

'env1': {

   'net_root': "/files/usr", 

'net_path': "/files/usr/domain"

},

'env2': {

   'net_root': "/files/usr", 

'net_path': "/files/usr/domain"

}

}

environments['env1']['net_path']

dd='env2'

environments[dd]['net_path']