Time
2 hours
Difficulty
Intermediate
CEU/CPE
2

Video Transcription

00:00
Hello, everyone. And welcome back to Intermediate Python here on Cyber Eri on demand if you're watching this video, hopefully that means that you went through lesson zero, which is our introduction. You saw what our objectives are. You saw what the prerequisites are and you feel comfortable saying that this is the class for you. If you haven't checked that video out,
00:17
I do highly recommend you do. It's gonna give you some core base information, understand what we're gonna be doing in this course.
00:23
Now That said, today's video is going to be lesson one user input. It's gonna be the first of two videos in this lesson we're gonna cover to specific objectives in this video. We're going to learn to use an interpreter, input from the user. And in the next video, the next part of this lesson, we're going to learn to use command line arguments so that we can actually take
00:41
information from the user when they invoke our program
00:44
and make decisions or use that in our program in some way. Now, to do that, we're gonna go ahead. We're gonna jump into a bunch of'em over here,
00:51
and we're just gonna be working out of the soup on TVM for the whole course. A CZ you can see here. I just have my Terminator shell up and I'm gonna be working out of them as our text editor. So I understand you're to show a good way of understanding user input and interpreting it. What we want to do is we want to come up with a use case and one of the most important use cases. Here
01:08
is something that we call token ization, not organization is a fancy way of saying of describing using discrete pieces of data. So a token is really just any piece of data that would be considered atomic for your process. So any core piece of data that is, you know, the smallest thing that you referenced in your program
01:26
and a lot of cases that might be a single character and a lot of cases that might be a number. In other cases, it might be a string.
01:32
All that matters is that that is what your program uses as its atomic units, smallest unit of data.
01:38
So in this case, we're going to create a program that we're gonna called interpreter,
01:45
give our shebang line here,
01:51
and we're going to just real quick comment and say exactly what our objective is in this particular project. And in this video in general, we're gonna say we're going to create
02:04
interpreter
02:06
dot Pod is a script which takes input
02:12
of arbitrary
02:15
length,
02:15
separated by a
02:19
limiter
02:23
and
02:24
identifies
02:29
number,
02:34
type
02:36
of
02:37
token.
02:39
So that is our sort of thesis statement for this script, we're going to take an arbitrarily long input
02:45
separated by able emitter character, a sort of a special character that we're gonna use to say This is the break point between two tokens and then we're going to use that, and we're going to identify the number of tokens we got and what type they are. And for the sake of simplicity, we're only going to accept two kinds of tokens are only going to interpret do kinds of Duncan,
03:02
which is going to be strings and numbers.
03:06
And to do that, all we're gonna have to do here is we're gonna say, First of all, we're gonna say riddle, emitter
03:13
is the pipe care.
03:15
Now we're going to create our main, and the first we want to do is just make sure that we can successfully take input from the user. Now, in our last class, we did this very briefly, and it's actually not a terribly complex process. While you're going to do is create a variable which I'm going to go user data and you're going to set that equal to the results of the input function.
03:31
And the argument that you can give to input is what will be printed to the screen as a prompt.
03:36
So in our case, we're going to say
03:38
insert
03:39
deluded
03:43
data
03:46
and then we're just going to print our user data as sort of sanity check
03:52
and we're gonna return.
03:53
Then we're going to go ahead and invoke me so that it will actually run.
04:01
And we're gonna go back out of here, and we're going to just make sure that we wrote our program correctly,
04:14
but
04:16
and you could see that it takes that input and it prints back out exactly the same way. So we're off to a good start. We're now successfully taking in storing in
04:25
Let's do something a little bit more interesting with it. Now, we talked about the fact that this pipe character is gonna be our limiter character. That's the character that tells us where to separate data. And in order to make use of that, we need to find some way to actually break the streams apart. Fortunately, Python has a really, really fantastic utility called Split
04:44
We're gonna do is we're gonna create a new variable called split data.
04:46
We're gonna sit that go to the result of user data, not split,
04:51
and it's going to take a keyword argument, which is something we'll talk about here in just a little while when we talk about taking command line or when we talk about our deep dives into modules in our later lesson. But user data not split,
05:03
we're going to say Sepp equals
05:05
the pipe care
05:11
and then we're going to Instead of printing user data,
05:14
we're going to print split data and see if we did this right.
05:28
And you can see now that instead of being this string with this token in it, with this organization in it, it's now been broken apart into individual characters, individual strings in this list. Now that's a good start, but we need to be able to do next. Is figure out how to break out one.
05:44
How to get rid of this nonsense whitespace year, since that's not one of our tokens or part of our tokens,
05:48
and how to interpret these numbers as numbers.

Up Next

Intermediate Python

This Intermediate Python course uses and builds upon the materials from Intro to Python, using the Python language to accomplish more complex and difficult tasks from building Modules from scratch to constructing and using custom Classes. You’ll learn to make the most of Python’s object orientation, and set yourself up for advanced applications.

Instructed By

Instructor Profile Image
Joe Perry
Senior Technical Instructor at FireEye, Inc
Instructor