Text
día seis
Python 3
Slicing a list
list = [’a’, ’b’, ’c’, ’d’, ’e’, ’f’]
print (list[0:3]) #Start at index 0, end at 2 print(list[:3]) #Same thing print(list[-1]) #last index in list print(list[1]) #second index of list print(list[2:]) #start at third index, end at final index
list.reverse() #start at ‘f’, end at ‘a’
Add to list
list.append(’z’)
print(list) #z now appears at end of list
list.insert(0,’z’)
print(list) #z now appears as first index
list = [’a’, ’b’, ’c’, ’d’, ’e’, ’f’] list2 = [’eggs’, ‘berries’, ‘muffins’]
list.extend(list2) #adds the 2nd list to the first list
print(list) #must use .extend to add each item #.append would add the list itself
removing from list
list.remove(’a’)
list.pop() #removes last index in list
sorting a list
list3 = [9,32,1,4,8,10]
list3.sort() #organizes the numbers in ascending order
list3.sort(reverse=True) #now the numbers descend
Sorted function can also be used. Also to reverse the numbers.
sort_it = sorted(list3)
print(sort_it)
sort_it = sorted(list3, reverse=True)
print (sort_it)
If you want the lowest or highest number or to add up all the numbers
print(min(list3)) print(max(list3)) print(sum(list3))
Finding the index location
list = [’a’, ’b’, ’c’, ’d’, ’e’, ’f’]
print(list.index(’a’))
The value printed is 0
If I wanted to find if a value is in the list
print(’apple’ in list) The print comes back as False because ‘apple’ is not in the list
Looping through each item of a list
for item in list: print(item)
We then get one item per line showing our entire list. “Item” is a new variable created for the loop, it’s not a keyword.
If I want to get the index and also show each item in a list, I use enumerate
letters = ['apple','bath','cows','donut','elf','fur']
for index, letter in enumerate(letters): print(index,letter)
I can also start from a certain index until the end of the list
for index, letter in enumerate(letters, start=2):
Join a string
I can assign a string to join with my list
letter_join = ' * '.join(letters)
print(letter_join) The print will show my list, but now a * will be between each item. I can also use .split() to make the list as it originally was.
letter_split = letter_join.split(’ * ‘)
print(letter_split)
Tuples
Similar to a list, but they can’t/won’t be changed (un-mutable).
things = (’glass’, ‘iron’, ‘steel’, ‘bronze’, ‘wood’)
So if you tried to assign a tuple variable to another, it won’t mutate. Lists are for modifying.
Sets
things = {’glass’, ‘iron’, ‘steel’, ‘bronze’, ‘wood’}
Item order in sets does not matter and sets get rid of duplicate items. If you added a second ‘glass’ to the end of the set, when printed it would not show.
You can compare sets to each other to see what items they have.
things = {'glass', 'iron', 'steel', 'bronze', 'wood', 'glass'} more_things = {'glass', 'iron', 'marble', 'tin', 'plastic'}
print(things.intersection(more_things))
The print out will show glass and iron are in the set. You can use .difference() to show what is not alike in things (bronze, wood, glass). To put it all together in one set, .union() will show every item in both sets.
Empty Lists, Tuples, Sets
empty_list = [ ] empty_tuple = ( ) empty_set = set()
Note that if you did empty_set = { }, that would be a dictionary, not an empty set.
0 notes
Text
día cinco
ArcPy
You can add a new toolbox with a script by right clicking on the toolbox window.
A script file is needed to make a script for the new tool. In script properties, parameters can also be added with display names and the data types for those displayed names. Parameter properties below that have further options; if they are required, input or output, and others. When the script is run, those parameter blank-boxes will be present.
Python 3
A class is a keyword that can group functions together and can be called.
class math:
def addition (x,y): add = x +y print (add)
math.addition(9,2)
More functions can be put into the class, such as other math operations. To call the class type out the classname.functionname()
Spanish
¿Cómo estás hoy? Dejame revisar. (dejar - to leave or to allow. revisar - to check) ¿Quieres ayuda? Sí, eso sería muy bueno. (sería, I would be/it would be, same spelling) Disfruta tu día (disfrutar - to enjoy)
0 notes
Text
día cuatro
Python 3
open keyword
text = “I put information here”
file = open(r"c:\users\johnsmith7\documents\file.txt", 'w') file.write(text) file.close()
Open keyword allows the creation of a file if it doesn’t exist and can add text to that file. First line creates the string to add. The open keyword then opens the file you want to open or create. I put r before my string to avoid a unicodeecape because of the common file-path involving “Users” and also important to write the actual file and not just a directory location. At the very end of my open line, I put ‘w’ which tells python to write, but you can also read or append file if you wish (r, r+, w+, a and others). Then finish the process with the .write(text), which actually writes it. Also .close() to finish the process. After that you can go to the directory to see your new file.
ArcPy
With tool execution, messages are written that tell you information such as when an operation started/ended, parameter values, warnings, and errors. These messages appear in the result menu in arcgis. With python, you can print the messages out or write them to file. Error messages have ID codes can be looked up in the help file. The GetMessages() function returns all the messages from a tool that was last used. It can also filter the types of messages.
Result() also returns information about executed tools with messages, parameters, and outputs. But these results can be returned even have several other tools have been run. Need to return here and detail properties/methods.
0 notes
Text
día tres
ArcPy
Command Lines.... sys.argv Used to make life more efficient through scripted programs. In this example, we use the class “fields”, which is some object represented in a table column.
import sys, arcpy
arcpy.env.workspace = “C:/9824/something”
featureClass = sys.argv[1]
for field in arcpy.ListFields(featureClass): print field.name
You can use system arguments to list feature class names. This is done by defining command line parameters. You can add more than one command line parameter and specify which one to list through an index number. sys.argv[0] is not used because that is the file name and it is not needed.
Also, if you want to list more than one parameter, you can make a loop.
import sys, arcpy
arcpy.env.workspace = “C:/9824/something”
if len(sys.argv) > 1: for featureClass in sys.argv[1:]: print featureClass for field in arcpy.ListFields(featureClass): print field.name
With the len keyword, we say that if the number of parameters is greater than 1, then loop through the command line arguments till there are none left. Then like before, the fields are shown to the user. Note that you must put in the command line parameters window what your parameters are.
Spanish
Buenos días. Hoy comí cereal para el desayuno. No hay bananos. Necesito comprar más. Yo también comí un pepino porque son buenas meriendas. Quizas yo debería comer una manzana esta noche. Necesito cocinar la cena pero no sé qué cocinar. Quizas debería comer a pinky; él es delicioso. 🐷 😋
0 notes
Text
Día Dos
El alfabeto español:
H is silent. Unless next to C.
Ge = heeh Gi = hei
Gue = geh Gui = gee Que = qeh Qui = qee
Guas = gwas, el paraguas
J is an H-sound.... San José
Ñ = año, any-o
R = tongue roll, carro
Vowels are the backbone to everything, the sound is always the same:
A: ah, mamá E: eh, bebé I: ei, iglú O: oh, oso U: ooh (like cute) uva
Habla de ti mismo:
Me llamo ______. Soy de _______. Nací en _______. Voy a la escuela a ________. Trabajo en _______. Me gusta el trabajo porque es _______ (adj). Me gusta la escuela porque es ________(adj). En mi tiempo libre yo _________ (verb) con mi(s) _________. Después del trabajo voy a mi clase de _______. Mi asignatura favorita es _____________. Tengo _____ hermano(s). En el futuro, quiero ser un ________ porque creo que es __________. (adj)
Python 3
global x Creates a global variable. Global variables can be accessed anywhere in your code, but a local variable can only be accessed within a certain block of code. Example would be in a function, where variables won’t be recognized outside the function. If you create a variable outside a function, it will be recognized anywhere and is considered global. However, a problem exists with globals where they can’t be modified inside a function without the global keyword. Global variables can be assigned to local variables to go around the use of keywords.
Using the return keyword in a function is a way to break control out of the function and will give-back a value that is called. print on the other hand, doesn't affect a program in anyway, and displays information just for the user’s sake. Functions always return; without an expression the value returned is ‘none.’
0 notes
Text
día uno
Python 3
If and else: If-statement is triggered, else will not run. If-statement is false, else will run.
Multiple If-statements: elif. Once elif is true, the block below it is not searched, even with another elif below it.
Functions: def name(parameters): everything here is in the function With blank space above, function ends.
A function has to be “called.” Otherwise, a blank screen will appear.
name() on its own line below the function calls it.
def adding (x, y): #make a function with parameters z = x + y print("x is ", x) #use print to show numbers print(z) adding(5,3) #call a function whenever it is needed
------------ x is 5 This is what is called 8 -------------
Parameters run in the order they are placed above in the function. In calling the function, you can redefine your parameters if you wish such as adding(y = 3, x = 5) If you define parameters in the function def adding (x = 7, y = 1): , you don’t have to add anything to the parameters when calling adding()
Parameters can be more than two.
def measurement (width, length, height = “4″, area = “1200″): print(width, length, height, area)
measurement(10,12,area = “480″)
‘’’I can skip height because it’s defined above and when I redefine area, the value changes... 10,12,4,480′’’
ArcPy
It has a “List” command. In the parameters you can put a * after a letter to see more than one character print arcpy.ListTools(”F*”): which shows me all tools starting only with the letter F. And you can find an order of letters such as F*nes which find tools starting with F and some word that contains nes.
You can also search with if-statements.
if “LineStatistics_sa” in arcpy.ListTools(): print “Tool found.”
else: print “Not found.”
Every tool has an alias. If you refer to a tool you have to type it as <Toolname>_<toolbox alias>() or Buffer_analysis() Tools also have parameters to run such as specific names, data types, direction values, and required/optional values. It’s important to read the arcgis help files to see what parameters are needed for tools. For example Clip (Analysis) has a help file that you can read and shows all the information needed under “Syntax”. { } around a parameter means optional.
First define your workspace environment then create variables to easily assign locations of parameters. shp are shape files. Then type the command to do the clip with your assigned parameters. In Arcmap, you can find the output file and see that it created a clip. You can also drag and drop tools into ArcPy to quickly see what your syntax is and instead of variable names, you can just use the file.shp name. arcpy.env.workspace = r”C:\Users\whatever\something\somewhere”
inputFC = “slope.shp” clipFC = “study_area.shp” outFC = “clip.shp”
arcpy.Clip_analysis(inputFC, clipFC, outFC)
print “Finished output”
0 notes
Photo

This week Missoula strangers im in Jacksonville FL. Whatdaya mean no mountains?
0 notes
Photo

And the world changed forever that day... Too bad I missed that day in this shot.
1 note
·
View note