text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
could check is the name empty if so | 3,100.079 | 4.76 |
don't create the student object is the | 3,102.64 | 4.64 |
house one of those four houses if not | 3,104.839 | 4.72 |
don't create the student object but that | 3,107.28 | 4.24 |
would be rather decoupled from the | 3,109.559 | 3.921 |
student itself right get student | 3,111.52 | 4.279 |
currently exists as just my own function | 3,113.48 | 5.639 |
in my student. piy file but classes and | 3,115.799 | 5.32 |
really object-oriented programming more | 3,119.119 | 5.561 |
generally encourages you to encapsulate | 3,121.119 | 6.841 |
inside of a class all functionality | 3,124.68 | 5.76 |
related to that class so if you want to | 3,127.96 | 4.68 |
validate that a name exists if you want | 3,130.44 | 4.639 |
to validate that a house is correct that | 3,132.64 | 5.28 |
belongs just uh fundamentally in the | 3,135.079 | 5.48 |
class called student itself not in some | 3,137.92 | 4.72 |
random function that you wrote elsewhere | 3,140.559 | 4 |
again this is just methodology because | 3,142.64 | 4 |
again if we think about writing code | 3,144.559 | 3.681 |
that gets longer and longer more and | 3,146.64 | 3.6 |
more complicated it should make just | 3,148.24 | 3.8 |
intuitive sense that if you keep all the | 3,150.24 | 4.599 |
house uh and all the Stu all of the name | 3,152.04 | 4.519 |
and all of the house related code in the | 3,154.839 | 3.601 |
student it's just better organization | 3,156.559 | 3.681 |
right keep all of the related code | 3,158.44 | 3.28 |
together and that's probably going to | 3,160.24 | 3.2 |
set you up for more success and indeed | 3,161.72 | 3.48 |
that's part of this methodology of | 3,163.44 | 4.24 |
objectoriented programming let me go | 3,165.2 | 6.56 |
ahead now and change my students classes | 3,167.68 | 7.84 |
init method to do this if the name is | 3,171.76 | 6.44 |
blank so if not name and we've seen this | 3,175.52 | 4.48 |
kind of syntax before if you say in | 3,178.2 | 5 |
Python pythonic if not name that's like | 3,180 | 5.72 |
doing something like this if name equals | 3,183.2 | 4.84 |
equals quote unquote but I can do this a | 3,185.72 | 4 |
little more elegantly just say if not | 3,188.04 | 3.4 |
name would be the more pythonic way to | 3,189.72 | 5.8 |
do it well I want to return an error | 3,191.44 | 5.44 |
like I might want to do something like | 3,195.52 | 4.16 |
this print missing name but this is not | 3,196.88 | 5.6 |
good enough it does not suffice to just | 3,199.68 | 4.919 |
print out missing name and then let the | 3,202.48 | 3.839 |
rest of the code go through all right | 3,204.599 | 3.48 |
well what could I do instead in the past | 3,206.319 | 3.321 |
we've seen another technique I could do | 3,208.079 | 3.961 |
cy. exit and I could say something like | 3,209.64 | 3.919 |
missing name and I could go up here and | 3,212.04 | 3.759 |
I could import CIS but this is a really | 3,213.559 | 4.8 |
obnoxious solution to the problem just | 3,215.799 | 5 |
because you or maybe a colleague messed | 3,218.359 | 4.881 |
up and called a function with an invalid | 3,220.799 | 4.121 |
name you're going to quit my whole | 3,223.24 | 4.599 |
program like that's really really | 3,224.92 | 5.56 |
extreme of a response and you probably | 3,227.839 | 4.121 |
don't want to do that if your program's | 3,230.48 | 2.879 |
in the middle of running you might want | 3,231.96 | 2.96 |
to clean some stuff up you might want to | 3,233.359 | 3.561 |
save files you don't want to just exit a | 3,234.92 | 4.399 |
program sometimes in some arbitrary line | 3,236.92 | 4.439 |
just because input was invalid so I | 3,239.319 | 4 |
don't think we want to do that either | 3,241.359 | 4.72 |
but we do now have a mechanism for | 3,243.319 | 5.121 |
signaling errors unfortunately I can't | 3,246.079 | 3.72 |
do something like this I could try | 3,248.44 | 4.32 |
returning none and say uhuh this student | 3,249.799 | 4.32 |
does not exist I'm going to hand you | 3,252.76 | 4.319 |
back none instead but it's too late if | 3,254.119 | 4.521 |
we scroll back down to where I'm | 3,257.079 | 4.48 |
creating the student it's on line 17 now | 3,258.64 | 4.719 |
where I've highlighted this code the | 3,261.559 | 4.04 |
student has already been created | 3,263.359 | 4 |
there is an object somewhere in the | 3,265.599 | 4.361 |
computer's memory that's structured as a | 3,267.359 | 4.361 |
student it just doesn't have any values | 3,269.96 | 4.44 |
inside of it but it's too late therefore | 3,271.72 | 5.119 |
to return none that ship has sailed the | 3,274.4 | 4.52 |
object exists you can't just suddenly | 3,276.839 | 3.681 |
say nope nope there is no object there | 3,278.92 | 3.96 |
is an object it's up to you to Signal an | 3,280.52 | 4.799 |
error and how do you signal an error | 3,282.88 | 4.199 |
well we've actually seen this before but | 3,285.319 | 3.321 |
we haven't had occasion to create our | 3,287.079 | 4.161 |
own errors it turns out in Python | 3,288.64 | 5.199 |
there's another keyword related to | 3,291.24 | 5.4 |
exceptions that python itself uses to | 3,293.839 | 4.641 |
raise all of those exceptions we've | 3,296.64 | 3.479 |
talked about in the past when you've | 3,298.48 | 4.839 |
caught things like value errors or other | 3,300.119 | 5.48 |
such exceptions that come with python | 3,303.319 | 5 |
well it turns out you the programmer can | 3,305.599 | 5.441 |
raise that is create your own exceptions | 3,308.319 | 4.48 |
when something just really goes wrong | 3,311.04 | 3.12 |
not wrong enough that you want to quit | 3,312.799 | 3.52 |
and exit the whole program but enough | 3,314.16 | 4 |
that you need to somehow alert the | 3,316.319 | 4.24 |
programmer that there has been an error | 3,318.16 | 5.04 |
something exceptional in a very bad way | 3,320.559 | 4.681 |
something exceptional has happened and | 3,323.2 | 5.399 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.