Using and Mastering Cookiecutter Transcripts
Chapter: Creating Cookiecutter templates
Lecture: Demo: Choice values

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Let's return to our attempt to making the user enter something meaningful at a given step.
0:06 So we saw that blank values kind of indicate you should type something but it doesn't really mean it, if you don't type it it's just empty
0:13 this required we will be able to use this at some point, using the pre generation hook to check for that value
0:20 no, no, that's not actually a value, you should have typed in something. But, if this is a bounded set, let's suppose that your favorite color,
0:27 you could only have like the basic colors, cyan, green, yellow, red and so on. Well, if that's the case, we can make them pick one of them, like so,
0:36 we come over here and within quotes, we could put stuff so let's say red, blue, green, yellow, cyan, white and black,
0:46 I don't know if that covers it, but that seems like some of the basic console colors that we can use, this is just a what is called a choice variable.
0:54 Now, those of you who know Python, this is actually a Python list, right here,
0:59 but really just a list in basic plain text here, of what the choices are. Now if we run this, again, it's going to be a little bit different,
1:09 my project name will be with some choices, like this, creator, now I have to enter something for now, I can test this later,
1:19 when we get to the hooks, look at this, boom, select a favorite color,
1:22 now there is still a default, it's still going to give me red if I just hit enter, but I do love yellow, so let's go with yellow, now,
1:30 if we open up the with, let's see what we got. Over here in colors, check that out, we have yellow right there,
1:37 alright, and that came from our choice variable so here is a way to make the user sort of choose from a constraint set,
1:45 so it's in one sense a default value, and it's pretty good, if you've got a bounded small set of things to pick from,
1:52 I totally recommend this, it's very user friendly, but if you have an entirely open end of things like this that has to be answered,
1:59 like what is your name, well there is not really a list for that, so we are going to have to check that in some other way.


Talk Python's Mastodon Michael Kennedy's Mastodon