It's infuriating to look back at what the U.S. government has done for 20 years in Afghanistan, propping up corrupt, unpopular governments, supposedly training and equipping 300,000 Afghan soldiers who just disappeared, sending in drones, bombs, invading homes, killing so many Afghans and U.S. soldiers in vain, spending $300 million a day on these atrocities. Everybody went into the coffers of the weapons makers and the military contractors and hearing the lies after lives that victory was just around the corner. So what do we do now? Yes, we have a responsibility to those Afghans who are desperate to leave, a responsibility to the millions left behind that need humanitarian aid, but we also have a responsibility to stop our government from doing this again. And the best way to do that is to cut the military budget in half. Free up that $350 billion to stop funding war and militarism and instead to fund life, peace and the planet.


Well, good to see you. Nice to see you. Thank you. Nice to be here. Mr. President, thanks for having us here. We're so glad to have you here. Let's just tell him, oh, you get the brakes on. All right. Good. Are you ready? Please. Sure. We'll both order, Mr. President. We'll both order. It really is an old office. Today, it's a pleasure to honor a great American and a trusted officer of this administration, Vern Orr. One can't help but have mixed emotions on occasions like this. We are not only recognizing Vern Orr's outstanding service as the secretary of the Air Force, but we're also saying farewell. Retirement is an anxious and difficult time for some people, but not for Vern. He knows exactly what to expect. He's retired twice before. Once from California state government, and another time from his business in Pasadena. And considering that he's already accepted a directorship at a Pasadena hospital, I suspect that this is just another practice retirement. Vern's timing has always been impeccable. As soon as congressional lethargy over the budget threatened the Social Security Trust Fund, he decided it was time to retire. Well, we're sorry Vern and Joanne are leaving. Of course, you can't feel too badly when you know they're going back to California. Where do I get my hat? Vern, I understand you've been trying unsuccessfully for two months to renew your California driver's license by mail. As a former chief of the California Department of Motor Vehicles, I think you cut through the red tape. I should get out there. We're going to miss Vern Orr, but we're not going to miss him as much as the Air Force is going to miss the Orr team. He has served longer as the secretary of the Air Force than any of his predecessors, and he leaves behind a record of achievement and success that has no effect. You don't have to take my word for how terrific a secretary Vern Orr has been. You can ask the men and women of the Air Force. They all know him, and he knows them. His deep and abiding commitment to the men and women where the Air Force blew and their families has been the hallmark of the Orr secretariat. He has traveled around the world meeting them, getting their views on what is needed to ensure ours is the number one Air Force in the world. He has acted decisively on many of his insights and suggestions, and he's solicited from those Air Force men and women in the field. Under Vern's leadership, the Air Force has grown in every measure. It is stronger, it is larger and better equipped, it is better trained and better led, and its ranks are filled with dedicated capable professionals who know that Vern, this administration and the American people understand and appreciate the Air Force's contribution to the overall national defense. Vern knows how important people are to the Air Force. He also understands and appreciates the need for first class equipment so that our personnel can get their job done and come home safely. Under his leadership, the Air Force developed and acquired a modern weapons systems and technology that have been so vital to accomplish its mission. The Air Force inventory today reflects Vern's uncompromising commitment to quality for America's fighting forces. The B-1B bomber, a long overdue addition to our strategic triad, is being delivered ahead of schedule and under cost. The fleet of modern high quality fighters has doubled and the service has made major improvements in its airlift capability. These are achievements which Vern Oar and the entire Air Force should be justifiably proud. Vern Oar has earned the respect and gratitude of the Air Force as has Joanne for all she's done for the entire Air Force family. She's been a responsible member of the Oar team. Travelling with Vern, she's visited hundreds of Air Force facilities and carried back to Washington a clear picture of the needs of Air Force families. We can all be proud that family values are encouraged and protected in our military services. The Oars have seen to it that this is especially true in the Air Force. And Joanne, to you I offer the thanks of our nation. You've served well and the Air Force is a better place for your having been. The Oars are an Air Force family, leaving Washington won't change that. They leave behind a legacy of excellence in service and a nation, a legacy that will guide Air Force families for years to come. So today, I have the privilege of bestowing on Vern a token of our gratitude for all that he and Joanne have accomplished. And Vern, we Californians are proud of you and we Americans are grateful. We thank you for a job well done and wish you Godspeed. And now I believe we have some presentations. Ladies and gentlemen, the President takes pleasure in awarding the Department of Defense Medal for Distinguished Public Service to Mr. Vern Orr for Distinguished Public Service to the Department of Defense from February 1981 to November 1985 while serving as Secretary of the Air Force. During this period, Mr. Orr provided innovative, energetic leadership and direction as he provided, presided over the Air Force portion of this nation's defense revitalization program. The Air Force's successes with its strategic modernization programs and its great improvements in readiness and sustainability are directly attributable to Mr. Orr's strong leadership. He recognized the importance of people within his organization and created an environment in which all members of the Air Force could realize their full potential. Through these efforts, he established a legacy that resulted in a stronger or capable Air Force and a more effective defense for this nation for many years to come. Mr. Orr's dedication, loyalty, and strong sense of patriotism deserve the highest praise and reflect, most notably, upon himself, the Department of Defense and our nation. Thank you, Mr. President. Thank you very much. And this is a certificate of appreciation to Joanne Orr. I won't read it because I've already said many of the names. But we're very proud to have you. Mr. President, Mr. Vice President, my remarks will be very brief. First, Mr. President, may I say that I have no intention of writing a book. I take note with me. And there will be no book. I've served the President for eight years in California and five years in government. And while that service has been public service, I consider it to be private service. And I have nothing that I'm going to share with the public about those wonderful years. It was Christmas Eve of 1966 when I got a call asking if I would serve in Governor-elect Ronald Reagan's administration, which we did through three different offices. And then in two political campaigns, I tried to be helpful. We first met the Vice President in Detroit the morning after his selection. It's been a wonderful friendship, Mr. Vice President. And I have a feeling that we've seen great deal more. I hope so from our standpoint. I would only like to say that from Joanne and from me, the 13 years that I have served Ronald Reagan's in the greatest years of our lives because of his strong leadership and because of Cap's tremendous doggedness, strength in keeping up the defense budget. Joanne and I go out feeling that these have been the golden years. We'll never regret having served here. We'll look back on them. And to you, Mr. President, Mr. Vice President, William Berger, Secretary of Defense, we're deeply grateful for the opportunity to serve all three of them. Thank you. Thank you very much. I may have one more job for you. I ever get a job during the course cap. All right. Awesome. I don't even have to make it to bed. It's already very, very well done. Thank you, Mr. Vice President. And thank you. You're welcome. We'll see you again. Thank you. Hey, Charlie. How are you? Good.


Anyways, I'll cover this quickly. So holding trades, right? Now, the source, I think anyway, I think of holding or not being able to hold trades can come down to several factors, right? One of them, for me anyway, I'm gonna talk about maybe my personal experience and remembering back to when I had the same issue, right? I think for me, one of the main things was risk, right? And risking too much, right? Risking way too much. So let me break this down on any particular trade. So the first thing is if, for example, you was to risk a penny on that trade, yeah? On any trade, if you lose that penny, how would you feel? How would everybody feel? How would anyone feel about losing a penny? Not bad at all, right? You wouldn't even bat an eyelid, that's exactly you. You wouldn't feel bad, right? Oh, okay, so let's do a bit more of an extreme example, right? Let's say, for example, you lost, I'll do 10K, right? 10,000 pounds on a trade, yeah? How would you feel on that one? Exactly, right? Exactly, tears start coming to your eyes. You know what I mean? So, well, it depends on obviously what 10,000 pounds represents in terms of your risk percentage, but just looking at the amount, right? And what the amount represents to you, right? Right, exactly, stop trading, right? But 10,000 pounds could represent, if it represents 0.1% of your account, it's still, again, a bit, you know, it only represents 0.1%, but you know, you think just of what you could do with that 10,000 pounds, right?  So, the point I'm trying to make is this, is that there's an emotional attachment to what you're risking and the amount you're risking, yeah? Even though, generally, I say 0.1%, yeah? On a trade, a lot of traders, A, don't do it, and B, they're not, they're not ultimately comfortable with what they're risking, they think they are, but they're not. And if you're not, it will manifest itself and it can manifest itself in the fact that you're not accepting of the loss, you're accepting of that loss, you couldn't care less, right? But if you lose that one, it's gonna hurt, right? So, as soon as prices start to go against you on a penny trade, you're just like whatever. As soon as prices start to go against you on a 10,000 pound trade, or $10,000 trade, right?  You're gonna start crying, right? It's supposed to be eyes and tears, but, you know, that's basically what it is. So you need to, and this is how I combated it, is understand the risk. And also I'm gonna extrapolate this, right? So let's say it's somewhere between that amount, right? And then just work your way up from there, right? You say, okay, penny, two-peak, three-peak, 10-peak, whatever it is. And it might seem like a thing where it's like, whoa, do you know what? If I risk a penny, I'm never gonna get rich, right? It's quick. But here's another thing as well, is understanding that the timeline, right?  You have to trade stress-free. You have to not think about the money because ultimately it's about the process.  Because it's just about percentages. It's about scaling up, yeah? If you can't turn one-peak to three-peak, yeah?  It's just not possible. So don't scoff and don't start going, oh, well, I'm never gonna make any money because if you can't do it there, you can't do it on this. Yeah? As was told to me, if you can't handle peanuts, you're definitely not gonna handle coconuts, yeah? So look at trading and trading psychology as a long-term, you know, endeavor. It's a skill that's one of the hardest things you're ever gonna do, right? Ever, ever, ever gonna do in life. Many people give up and you know the statistics, right? But now I'm gonna extrapolate that, yeah? And not just say on one trade. So what I mean by that is if you lose one trade, cool. That's fine, yeah? But how would you feel if you lost 10 trades in a row? If you had a 10 trade losing streak, yeah? Meaning that if you lost, if you were risking, you know, one-peak, right? If you lost 10 trades in a row, which means that you would lose 10 pence, how would you feel? Probably, you know, you wouldn't feel any weight, right? You'd just be like, whatever. It is what it is, it's only 10 pence, yeah? Obviously, 10 pence could be a lot to some people, but generally, you know, unless, if 10 pence is a lot to you, then you really should not be trading at all, right? You should not be trading. So to the point is, is that 10 losing trades, let's just call it a 10 losing trades, right? Which is definitely possible. I've had a 15 trade losing streak. I've had an 11 trade losing streak, right? In the past, and it happens. It's not often, not at all, right? But it can happen. Now, if you lose 10 trades in a row, yeah? This is really how you should measure your risk. If you lose 10 trades in a row, yeah? And it equals up to 10 pence. Are you okay with that? If the answer is yes, then trading at one pence per trade is what you should be doing, yeah? You should think about your risk in terms of how much you will lose if you go on a losing streak, not how much you will lose on one particular trade or two particular trades, yeah? Divide 10 by whatever the risk is, right? So if you're happy to lose, if you say, all right, then I'm gonna lose. If I lose 10 trades, I'm gonna, you know, and I'm happy to lose, I don't know, like let's say for example, 5% of my capital, yeah? 5% of my capital on 10 losing trades. Then what you're saying is, is that if I lose 10 in a row, yeah? My every individual trade should be at least 0.5%.  There are other factors as well, yeah? You haven't accepted, you know, the loss, you haven't understood the law of large numbers, you know, in the fact that every trade is random, a great trade and A1 set up, yeah? The perfect set up can win, right? I mean, can lose, I should say, right? You can have everything line up, yeah? Perfect trade and it can still lose. You can have the worst trade in the world and it can win. You can just place a random trade right now, just press buy or sell without even knowing what's on the price chart and it's 50-50, yeah? Terrible trade, random trade, but it can win or it can lose, but we're not judging our trades over one or two trades, we're judging our trades over 100 trades and 100 perfect trades as well or high, very, very, very high standard, high quality trades, yeah? That's what we're judging ourselves over, not just one or two trades. By the way, is the person who wrote this, who asked a question about holding trades here, are they in the room? Are they in here? If you are, let me know, speak up, yeah? Anyways, so understanding risk, your risk, yeah? Is really important to being able to hold trades and accepting losing trades, not just one, but over a losing streak, 10, 15, 20 trades and it might sound like, well, what the hell? The strategy doesn't work if I lose 20 times but there are strategies that you lose more than you win and are still profitable because it depends on your risk-reward ratio. If you've got a three to one type trading strategy or four to one type trading strategy, then really you only need a win rate of maybe 25% or above that in order to be profitable, right? So some strategies are always about winning win rates. Doesn't really matter about win rates. It matters about when you win, do you win more than you lose and to what degree, great risk-reward. So I think I wrapped that up. I don't wanna go into it so much more depth but I think on the surface level, and I think that person, if they're not in here, if you're still having problems after this, then we'll have to have a maybe a one to one session with you to kind of unpick that but I'm hoping that that does clarify things. Does anyone else have any questions on that, by the way?


All right, let's get started. You folks may need to get back to work You know on a rigid time scale, so Let's not wait around anymore. So I'm Jim DeWiler your instructor. I think this is the first time we've held one of these lives. So I Just wanted to go over some of the some points in lesson two that I think are especially important and Could benefit from you know, seeing me walk through something I'm gonna do a little bit of slides talking through some slides, but before I do that. I wanted to do something a little more Perhaps interesting interactive at any point in This session, please feel free to speak up I'm gonna I'm gonna ask you to speak up at times it asked for volunteers with answers to questions But please don't hesitate to speak up if you want to interrupt me Don't understand something that we we talk about so one of the things that is important to understand in working with Python is how to deal with strings How to get subsets of strings? How to use some of the functions that are available when working with strings and so I just want to work here in the interactive window in Python win To you know demonstrate this string manipulation So I'm gonna create a new variable called x and I'm gonna stick string in it sign a string to it and Something really simple if I wanted to get a specific character out of that larger string. I Can inside square brackets after the string? plug-in Single-digit as I just did there or as we'll see I can plug in Followed by a colon followed by another digit to get Substring so, you know, one of the things to Get used to or keep in mind when dealing with strings is that they are indexed starting with zero as the first character And so if I do print x zero in square brackets, I'll get back the first character in this case a capital P And You know as you would expect them if I did this I'll get the second character I do something like this Anybody know what I'll be what I should You can speak up or you can type it into the chat box Thank you. It says a job. I think you would get the From N. Do you that character number six? So looking reading across That span that range You would start at character three, which is the second and actually in pen Now that the kind of tricky part about this is that, you know, lots of programming languages Provide the means to do this sort of thing and they operate in different ways in some languages You might expect to start at character three and then give me the next six next six characters That's not how Python string slicing works and You also might expect or you might also expect to start a character three and go up to character six And that's also not really how Python works how it works is actually It's going to start a character three and go up to but not include character six So in other words, it'll give me characters three four and five So In space and then that's that's something to get used to How about this? I would not just give you Some characters six all the way through the end Or eight Well, it'll it'll start a character The sixth character, which is at And give you the rest of this Leaving off a second digit by leaving off that second digit you're saying that you want everything beyond Characters seven good Now how about this one I guess that I would go from Last so the Third character in from the right and then to the beginning Yeah, I think I think you're right there and that also says in the chat box That'll it'll spit out pen and that's right. It's gonna by leaving off the first digit saying that you want to start at the beginning of And the second digit after the digit after the colon says Give me everything up to but not including character for so character at position X negative two says pen space STA and the other guesses Yeah, so it's gonna start from the end of the string and When you supply just the single digit you're gonna get back just a single character and Well, if you supply a single digit without the colon I should say As we did here, then you're just gonna get back one character. So we're gonna get starting from the end of the string two characters from the end which is E and So does that mean when you're counting from the end it doesn't have the zero index? Yeah, that's a good question Yeah, I guess that's I guess that's how you would say that is You don't start Zero if you're counting from the end and then how about this one that is you're right now that space STI this one says Because the bones involved and there's nothing before the colon you're saying you want to start at the beginning of the string Yeah, the this can get a little tricky to remember the rules on how these work, but Honestly, I don't What I'm writing Python scripts. I don't really remember all the rules and I have to look them up, but that's okay that's that's one one of the things that distinguishes good Programmers is that they're able to look up in the documentation or they're able to look up on Question-and-answer forums online the answers to the questions that they run into So strings have a number of Methods strings are treated as objects in Python and objects have properties and methods methods being Actions that the object is capable of performing knows how to perform and one of the methods that strings have Is the index method? index method Type in a string dot you'll get a list of its properties and methods index Allows you to find the position of a smaller string within a larger string So in this case if I wanted to find the position of the space in the x variable A space just like I did and it'll return to me for That that's something that can come in handy Another one of these methods is split which can be used as the name applies to split a larger string into smaller string and This is something that Used if you had a comma delimited string Or as I'm doing here basing it found in the string and Now this method is going to return to me list Smaller strings that are created by splitting I'm going to want to do something with that list. I'm doing here is storing that list in a variable called pieces and then I could do work with those Items in the list. So here. I'm just going to print the item app position zero in the list And then as you'd expect print One will give me state another method For strings is the ends with this The ends with method Returns a Boolean a true or false value Depending on whether the string that you It's found at the end of the Variable that's your here the X variable holds Penn State and yes that ends in So I would expect to get back true This then as I'd expect Okay, so that's that's another one of those methods that and then the last one I'll go over is a method called replace this takes two arguments the String that I want to replace help box the old string and a new string Optionally, I could also supply a count. I'm gonna leave that off replace all occurrences of Penn with Pennsylvania That leaves the X variable The Y variable now holds so these are just some of the methods that are available Over how to get a substring out of a larger string as well so Hopefully this will help you on the project to assignment expected to do some string manipulation in that assignment, so Please, you know definitely practice and the interactive window is a good place to do that sort of practicing any questions about Manipulating strings, okay So now I want to go through some slides and I've got some review questions talking about Things that you should remember from lesson one. Okay. Sorry. Are you folks able to see my? Slide that says review where you're still seeing we were but now it's down low. Yeah, okay. I had it up for a second Try again. Okay, you should see it now So when you put a print statement in a Python script, where does that output go? Where were we just working in the Python and Interactive window interactive window, right? I'm having all kinds of trouble with our Point here true or false Variables X lowercase and X uppercase used interchangeably in a Python script. No, that's as false. She'll says false. Yeah, right That's correct Python is an example of a case sensitive language. So those are two separate that's not always the case in other languages, but True or false Python was developed as a scripting language for ArcGIS that says false. She'll says false, right? Yeah, if you learn nothing else from this class, hopefully you'll remember this Python was developed completely independently of ArcGIS and Chosen by Esri as a language to use for geoprocessing scripting. Okay. What's the result of this script? Six, but what about this version? Where Y and X are Stored and he says three three and he's right In this case because X and Y are strings when you do X plus Y the plus Operator takes on a different It operates differently Between two strings you're concatenating or merging the strings together Whereas when you put it between two numbers you're saying that you so that's something that's important to Understand about programming in Python All right, how do you add a comment to a Python script? Yeah that pound sign Yeah, so you you stick the pound sign in your your line of code somewhere now an actual line of code and And the idea is that everything to the right of the pound sign is going to be ignored when your code is executed okay, so and You may have scripts where you do both where you have it at the beginning of the statement or at the end of certain lines And both ways is fine What keywords are used to specify what part of the script I'm to execute and which part should be executed if an error I know what I'm talking about there Right, right yep You would use try and then indent that you would like to try and then Later on after you've got all your code you would have an except at the same indentation level as the try and And then indented underneath that you'll have The code that you would like to execute in the event that your your try code Fails generates an error using try and accept is a good good way to Make sure that your script fails gracefully in other words Error message Now when you're developing the code yourself you may want to avoid using try and accept you may want to see the ugly Ugly error message may point you to where the problem is in your code But then when you've got it working and you think it's it's in good shape Then you should and you're ready to expose it to users then having try and accept is a really good idea Make sure a false the code within a try block and accept block must be indented for spaces True Joe says true. Yeah, that's true So let's talk a little bit about lists I think some of what is in the slides that I have here was already talked about in the first Video session the one that I gave you an old recording So I won't I won't spend a whole lot of time on this but So list is a set of related items Unit in your code It could be numbers it could be strings objects or it could be a mixture of and The items are going to be separated by columns and enclose them brackets It would be we have layers variable and we're assigning to that This list of strings counties and I can retrieve an item from the list using its index position Like we saw with strings the characters within strings the indexing is zero based So I do using that there's variable from the previous bullet point if I do like print layers and then to in square brackets that's going to Counties and One of the things we can do with lists that's useful as we could sort them using the list Sort method so using that same layers list. I could do layers that sort And if I wanted it in descending order Now Oftentimes it's Developers we need to modify lists on the fly so here I've got two list variables list one and list two and One of the things that I can do is I can merge them together and here again, we're using the plus operator and again, it's Doing something different Context that it's being used in when the plus operator is used in between two lists Then it merges those two lists together And so I'm taking that merged list and sticking it sticking it in a third variable This one called list three and you can see that it puts together the two lists or if I want to add an item to the end of the list I Can use a method called So here I've got that that same layers list that I had a couple slides ago And I can add a new layer called streams to the end of that list Or if I want to stick an item into the list not at the end, but it adds Use the insert method It's List variable dot insert and then there's two arguments that I have to supply Before I supply the actual By the position that I want to put it in so if I say then it's going to stick it make it the New item at position one in the list so it replaces it takes counties and roads and shifts them and Plugs in streams into position one okay, now one of the things that you can do with a list is you can get its length and You do that using the Len function Built into Python, so here. I've got a list stored in a variable called children so I could say Len parentheses children to Get back the length So let me ask you a question. How would I output the last item? Let's assume that I I don't know the length of the list so Jill says I could say print children and then in square brackets negative one and Yeah, I think that's I think that's true. I Was looking for something that involves the Len function, but I think you're right about that That's another way so what I was looking for Len would be something like this where I could use the Len function. Yes, Henry has a had had a Print children and then Len children inside the square brackets The only trouble with that is Len children in this case is going to reach or which is going to be one One more than the last item So what you actually have to do is take that Len and subtract one Which I show here, but you know as Jill said an easier way is to using the indexing I Could supply a negative number instead of a positive number to start from the end of the list so another another Programming construct. It's really important to work in any language really and loops are used to repeat certain lines of code There's two types in Python the for loop Which is used to iterate through a list or to to cycle through the items in a list and Then the other is a while loop and we use while loops to Loop until some condition. We'll start with for loops as I said a for loop in Used to iterate through That list could be defined before the for statement Here's an example of that I've got this same children list from the previous slide and I could set up a loop See there The key elements of this are that you start with the word for Skip ahead. You've got the word in After in is going to be your list In this case, I'm pulling the list out of a variable In between for and in is going to be a variable that I come up with whose name I come up with right there That I would like to store an individual item from that list on each pass through the loop so as The code inside the loop gets executed on each pass through their Child here in this case is going to take on a different value. So the first iteration through the loop it will take on The first value in the list in this case stand or print it out goes back to the top of the loop Goes and gets the next item in the list Kyle prints that out etc. Etc Once it's reached the end of the list and it goes back to the top again It sees that there is no more items in the list and it would jump down to the next Line after the loop which we're not seeing here in this in this short little example We can also generate a list within the for statement using the range function Here's an example of that This is the kind of loop that you may be familiar with from other programming the way the range function works is it actually returns a list of numbers and So this returns a list starting with one Going up to ten so this is kind of similar to the way we were seeing getting substrings Slicing a string where it gives you up to but not including the second number So as you see here, it would print one two three all the way down to ten a little bit more about the range method Typically, you're gonna supply two arguments like I showed in the slide Reiterating that you start at one and you stop just before getting to in this case But you can also use it with one argument So if I just applied 11 It would assume a starting point of zero So my list would be a little bit different than the previous example. It would start with zero instead of one Or I can supply three arguments. So here's an example that You might use in a situation where you're dealing with census data US census data Where you've got data for every Every 10 years 1980-1990-2000 etc. So this says to start with 1980 and To go up to but not including 2030 and instead of going Instead of incrementing by one on each pass through loop increment by 10 In other words, the step value is 10 So that would produce this list that you see here, right, so that's that's for loops while loops They said the code is executed until some conditions met so here's an example of that I'm gonna set this variable n equal to zero initialize it to zero and Then I say while n is less than 10 Do something in this case just break and then an important thing here is that n is is changing changed This syntax here might look a little odd to you if you haven't Programmed in Python or other languages use the same syntax Basically, it says take whatever n was before and add one to it and Stick that back into the n variable So if n was zero and would become one we'd go back to the loop Condition statement it would see yes n is still less than 10. So I will Do the code inside again and that would continue until n got up to 10 and at that point n would no longer be less than 10 and It would then jump out of the loop and go down to the first line after the loop now one of the things that You can do with loops that's that can be really useful is you can nest them Here's an example of that. So let's say I've got I've got data for three different states and I've got the same layers In each of those states, I've got cities in Pennsylvania cities in New York cities in New Jersey Roads and I want to do something some sort of processing on all those layers Well, I could have a loop that iterates through all the items in my layers list Then I could immediately follow that up with a nested loop inside that iterates through all the states in my states list and You know notice here. I don't think I mentioned it, but one of the naming conventions that's smart to follow is to if you've got a set of items in a list Name that variable something plural and then when you have a loop where you're iterating through those items Assign the Assign a name to the iterator variable as it's sometimes called a Singular version of that same word. Okay, so layer in layers state in states That just makes the code You know, it makes it easier to interpret than if you said X in layers or something like that so Inside the these nested loops what I'm doing is I'm saying Okay, I want to store in this variable Layer whatever layer happens to be I want to concatenate That with an underscore followed by state. So on the first pass through these loops layer will be cities State will start out as PA. So I would end up with X being cities underscore PA and Then I have this print statement that prints out processing layer cities underscore PA It would go back to the top of the states loop State would become NY So then X would be cities underscore NY would print that out then it would be cities underscore NJ It would get go back to the top of the loop. It would see that there's no more states in the states list So that would take it back to the top of the layers list at that point layer would become counties Then it would start up the states Loop again State would be would start out as PA So I'd have counties underscore PA Etc etc etc Okay, so that's that's an efficient way to deal with a situation like that This is the output that I would expect Cities then all the counties and then all the roads. Here's another example Kind of returning to the idea of having census data. Let's say I've got It at different geographies at the county level at the tracks level at the block so I could Have those different geographic levels stored in a list that I could iterate through that list and Then I could use the range function as we saw Generate a list of years 1990 2000 2010 and you know, I could have a nested loop similar to the previous slide and You know one thing that's a little bit different than the previous slide aside from the range used the range function I've got this little bit going on here. Anybody want to Explain what's going on here? with the str Year negative two Why didn't I just have? Why are as the thing that I'm concatenating with a number so you have to specify that it's a string Good. Yeah, exactly. So yeah, the range function Returns a list of numbers and if I want to Merge that number concatenate that number with other text I Need it to be in the form of a string and so I use the string function to cast that number or convert that number into a Into a string and it just does that on the fly. It doesn't change what's held in the year variable But then also the other thing that's going on here is I'm using that substring notation My layer is actually Named using a convention like counties underscore 90 or counties underscore 00 the year as a string Give me everything everything beyond that so it would give me 90 or zero zero or 10 right now ArcPy has a lot of functions that return lists and And we can use a for loop to iterate through those Here's an example of that. Let's say I've got a shapefile called us boundaries or the path to that shapefile in a variable and Then I can use a use a method called list fields access through the ArcPy module and Then specify the feature class that I want to list the fields in That returns to me a list Here I'm storing that list in the variable and Then as we've seen I can have a for loop that goes through that list Again, I'm doing that plural singular naming and Then so so the field each field Returned by the list fields Method is an object that has properties and methods and one of the properties is its name And other properties it's type, you know, whether it stores Geometry or double precision numbers or strings So, you know in this little example here, I'm simply printing the name of the field Concatenated with a dash Concatenated with the type of field I'll just ask at this point. Did anybody have any trouble or questions about these exercises? So Here's an example where we loop and concatenate Your processing context so Start out importing ArcPy I'm defining a variable called in folder that stores the path to some shapefiles folder that I'm going to store some results in Really what this Example does is it clips all of the Shapefiles in my input folder using a Shapefile that stores the boundary of the state of Nebraska. Okay, so it's it's let's say it's a bunch of national level data Different shapefiles and I want to clip them to the state of Nebraska's boundary And stick them in a separate folder so To do this I'm making use of a method called list feature classes and the list feature classes method Very importantly, it's going to list the feature classes in a particular place Instead of telling it a folder supplying a folder as an argument to the method in parentheses What it does instead is it lists the feature classes in whatever the current workspace is and so an important part of using list feature classes is to first set the workspace and so You get to the workspace property through the ENV or environment module So that's what this line is doing here arc pi dot m dot workspace equals in folder Sets the workspace and then I can list the feature classes in that workspace And then as we've seen we can loop through the items in that list using a for loop and Basically, what I do here is I get the name of the feature class And I merge that together with the results folder where I want to put the output Store that concatenation in a variable called output path and Then I make use of the clip tool in the analysis toolbox It wants to know the name of the input feature class what feature to use to do the clipping and What you want to call the output So that's that's a relatively simple example putting together Both string concatenation and looping Two of the topics we've talked about. I've already talked about string manipulation at the very beginning. So I'll just Think we talked about casting variables in the first now tuples You can also be pronounced tuples, I believe But tuples are another data structure in Python very similar to lists Syntax is going to be same as as a list except replaced the square brackets with a set of parentheses Difference between tuples and lists are immutable, which is just a ten dollar word for Meaning that you can't change the items list. So in other words Here's an example of a list which I know I know it's a list because brackets I can change the With a different string as we see there I Try to do the same thing with a couple the tuple because I'm using parentheses instead of If I try that I'll get an error telling me that Which is kind of a really formal way of saying that you can't change items in a couple so If you have a situation where you have a set of items That you would like to do something with in your in your program It might make that set of items in any way I'm not gonna talk about dictionaries. We'll get to dictionaries later later in the class and I think we already talked about if If L if else conditional statements Comparison operators, I think we're already already discussed what I really wanted to talk about was and demonstrate was so Here we've got a little tiny little script Where I'm defining a variable called a year and I'm assigning it a value of 2010 Loop that says while year is greater than 1970 You know do some print statement and then I say There is a problem with the script Does anybody see it the condition associated with the while loop? Will it ever be met? I should say will it ever be false? So In 70 1970 it start out as to starts out as 2010 and on each pass through the loop. It's having 10 added to it so it'll become 20 20 20 30 So that's an example of an infinite loop Maybe some of you have run into one of these before either in Python or some other language The debugging in Python when there is a toolbar called the debugging toolbar and the reason that I'm talking through this Is that I think it's really important that you folks get in the habit You know unless you can write programs that work right start without You're gonna need to debug your code and going through it one line of time You know if you just hit the run button Try to run the whole thing all at once You know you'll get an error message which may or may not point you to the right to the offending line and to the problem line Whereas if you step through it one line at a time you really will Be able to see what line causes a crash in your code and then you can focus on that line and try to fix it The other thing you can do in a debugging environment is you can set break points Let's say you've got you know Thousand line script you know that the first 900 lines are pretty good. Well, you're not going to want to step through 900 lines of codes to get to the place where you know the problem is and that's where setting a break point towards the end of the script You can run up to the break point and then start stepping You can do in debugging environments is you can watch variables in other words you See what the value held in a variable is and watch how it changes as you There is as we'll see in a second when I get into a demo there is a step over button Which I typically use to step through my code and instead of clicking on that button on the GUI it has a Which is the F10 key so Let's let's Do a little demo and this is going to be the last thing that I do in the live session and at that point I'm finished. I'll open up here I've got a little script and First let me turn off the debugging toolbar because it's not on by default This is what you see when you when you run Python win for the first time after installing it So you have to go to the toolbars menu the view menu then toolbars to turn it on and These are the step buttons and I'll just start with the first one and When I click on it, I'm going to turn this off for now When I click on it, you'll notice that couple things the first you'll see a yellow triangle pointing at The first line in the script And that yellow triangle tells me that I'm in debugging mode I'm executing the script, but it's paused waiting for me to do something You'll also see up in the title bar instead of just saying Python win. It now says Python win dash break Which is just telling me again that it's paused waiting But hit step again, and you'll notice that it opens up another window and this is actually a Initialization script associated with ArcPy you can see the copyright Esri and If I would if I were going to continue hitting step I would be stepping through Esri's You know basically their ArcPy code, and I don't really want to do that What I'm interested in is stepping through my code and so I'm going to get out of here Anytime you're in debugging mode and you want to stop executing the code you can click on this close button And I'm gonna close this Esri module that I'm not really interested in So that's that's one of the step buttons It's going to step through all of the code that is going to be executed as part of your script So you're executing not just the code that you write in your script file But if you're calling on other modules as we are here importing your ArcPy module That that means executing other module code too. So I that's why I don't like the step button in most cases There's also a step out Which enables you I think if I remember correctly if you're in a situation like I was just in where I was in inside the Esri module that I didn't care about I could get out of it using the step out button. I think but the one that I use is this step over and so I'll click on it and then again and The first time you import ArcPy as you may have noticed it takes a while And that's because ArcPy is a fairly large module and it takes it takes a few seconds to load it into memory Then if you run the script again, it's very quick because ArcPy is already loaded into memory But eventually as you see there it the yellow triangle jumps down to the next line telling me that that's The next line that it's about to execute if I continue And so you'll notice that it didn't open up a separate module a separate Esri module it just kept me here in my own module, which is why I want and So I'll hit step over again Setting the workspace also takes a few seconds, but eventually it will Finish and move on to the next line and I can continue hitting step and Notice down in the interactive window it printed Zero because of this loop. I'm saying that I wanted to loop Going from zero to 99 using that range method there. I didn't mean to hit that one And I can continue like that again as I said I like to use F10 instead of clicking on the button. So Now I'm just clicking Okay, so this would continue All the way down to 99 and let's say I want to check out what's happening down here as I mentioned I can Had a break point so to do that. I just place the cursor on whatever line I want to This little hand icon as it says there that toggles a break So when a break point is on I'll see a little move that I would just hit the button again Okay, so if I want to go from some place above the break point and then you know execute down to it I would click on the go button here and you'll see that it did the rest of the loop hitting the print statement on each pass through the loop and then at this point I could use F10 which You know takes me through this list feature classes line Generating a list of the feature classes in this workspace And then I've got a loop that that goes through The items in that feature class now one of the things that I wanted to show you as well was Watch variable that on if it's not on for you. You can click on the the eyeglasses icon. I've got some Things in there already that I'm going to take away Because you won't have anything in there if you want to add something to the watch Window You can just double-click on new item type in the variable I In there and it tells me that the value or the value of I right now is 99 that Through the loop and the last I had was 99 I Could also plug in and it tells me that FC is city boundaries That's the first shapefile found in that workspace Notice that it it's actually prefixed with this little lowercase u which Indicates that the that that string is actually in unit code format I don't want to get too deep into the weeds here basically Esri uses unit code to Allow for characters in languages other than English So it's used to support all the world's languages Again, I don't want to go too deeply into that so as I Continue hitting F10 when I hit I went to the top of the loop here if I hit F10 one more time I should notice that the FC Box changes and it does Okay, so using the watch Window can be an effective way to Follow how your your code is working make sure that variables have the values that you expect now. I could also One of the things I'm doing in this little example script is I'm Describing each feature class on each passer loop Saving that describe object in a So if I try plugging DESC in there Is it tells me it's a geoprocessing describe data object Which isn't particularly useful right So one of the things you can do with this As the column header says you're not limited to just plugging in Variables you can also plug in expressions and so I can do DESC Shape type. That's one of the properties that you can get at that Property that expression returns to me continue hitting F10 I get to a new feature class and FC changes in value if I change if I go through the described line I'll see that Shape type fairies is a polyline. Okay, so And that's hopefully a helpful demo through using the the debugging tools close out of get out of debugging mode here and Let me just open up the I've got an infinite loop This is the same code we saw earlier So I just wanted to show you how you can try to get out of a loop like this so I hit go and I Should have made sure the interactive window was showing it would show you that it's you know spinning out years Unendingly and what I can do is I can go down to the the system tree. I guess this is called You should see a Python win icon. I can right-click on that and I could try this break into running code That's meant to allow you to Stop an infinite loop like this But I found that it doesn't really work Sometimes I've seen where there's a little Python icon down here That I can try hitting that break into Running code and it works Can't find anything on that That menu so if that doesn't work for you you're really left with just closing Python win altogether unfortunately, okay, so That's what I wanted to go over with you At this point, I'll just open it up for questions Does anybody have any questions about any material lesson to or the assignment at the end of lesson to? okay, well, yeah, thanks Jill and Hopefully folks found this helpful I'll post the recording on the as an announcement and You can go through it again if you if you'd like to all right, thanks everybody for attending and We'll see you again down the road