Home‎ > ‎Scripting‎ > ‎

python

stuff goes here

Installing python

Go to https://www.python.org/ Download python 2.7 run installer
Add the following to PATH
[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27\;C:\Python27\Scripts\", "User")

Install 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 
    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

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(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']