Introducing VS Code
A wise person once said "use the right tool for the job." Writing code is no different - it's a job, and there are a lot of tools at your disposal. Some of them are task-specific, and some are general purpose. This set of videos is designed to help you understand how to use the most popular general purpose coding tool - VS Code.
Install and Set Up VS Code
In order to use VS Code, you have to have VS Code. This video will show you where to go to get VS Code and then begin setting it up to your preference.
Knowledge Check
Who created the general purpose IDE VS Code?
Understand What Open Source Really Means
In the last video, I hinted at what "Open Source" means and identified one of the more common characteristics about ("code that can run anywhere"). While that's true, open source software (often abbreviated OSS) is much deeper than that. Let's talk for a moment about the current development landscape and how we got here.
Knowledge Check
True or False: Developers are beginning to prefer to work on open source software so that they can ensure that their application can run anywhere without barriers to entry.
Install Python
To begin our coding journey, we'll be starting off with Python. Python is widely accepted as the most human readable programming language which makes it the most beginner friendly programming language. Once you learn the core constructs of programming in Python, you'll find transitioning to other programming languages much easier.
Knowledge Check
True or False: Python ships with most Linux and Unix operating systems by default.
Work with Python Scripts
Now, I want to stress this - the title of this video might make you think this is a "Python video." It's not. What we're really focused on here is how to interact with and run code that was written in VS Code. It's still focused on how to use the tool. Don't worry if you don't fully grasp how the code works yet - plenty of code-specific content is headed your way.
Knowledge Check
You have a script named "myscript.py". What command can you use to run that script from the terminal?
Importing Python Packages
Now we'll start to shift our attention more towards the usage of Python, still driving home the concepts of how to use the IDE. Off the shelf, programming languages can do a lot, but they can't do everything.. In fact, their real power is hidden away waiting for you to request to access it.
What I mean is that we can import special "code plugins" called packages that unlock the ability to do even more things in code. In this video, we'll import the Datetime package in order to access helper code that helps us work with dates and times (something that Python can't do by default).
This is an important concept because every programming language has this. Python has packages that you can import, JavaScript has modules that you can import, Rust has crates that you can import, etc - they all do the same thing.
Knowledge Check
If you want to work with dates or times in your Python code, what should you type at the top of your script?
CHALLENGE
You are in a job interview for a position that will work with code. The interviewer has asked you to prove that you know how an IDE works. Can you create a file, write some basic Python code, and run the code all within the IDE to validate that you have the experience required for the job?
Solution:
Knowledge Check
True or False: VS Code has a built-in terminal where you can run and debug your code without leaving the app.
Knox's FINAL NOTES:
For your studies, I strongly encourage you to explore other IDEs mentioned in the first video. Pycharm is an excellent Python IDE, and IntelliJ is another great general purpose IDE.
View Transcript
Introducing VS Code
0:00Welcome to the content on getting started with software development
0:03fundamentals and setting up your own development environment.
0:07Look, this is content that I'm particularly excited to talk about because
0:11software development was something that I got started with a little bit later
0:16in my technological career.
0:18I actually began as a hardware person focused on networking appliances, but
0:23software development became a huge part of my career starting around 2017 or so
0:29when I was forced to start automating massive large scale deployments of my
0:35network infrastructure.
0:37The long story short year is that even though it was something that I put off
0:42towards the latter part of my technical implementations, I found out that this
0:47was actually the most valuable thing I have ever added to my skill set was just
0:53understanding software development fundamentals.
0:56That led me down even bigger rabbit holes and architecting some of the most
1:00massive and enjoyable and automated full scale solutions I've worked on in my
1:05entire career.
1:07Now, here we are at the beginning of a software development fundamentals
1:10journey.
1:11And the biggest thing that I want to say here is yes, we could talk a lot about
1:16theory. We could talk about the history of software development.
1:20We could talk a lot about keywords. That's not really my style. I'm more of a
1:24let's jump in and get some wins under our belt. Let's start building things.
1:30Let's start seeing how does it actually work. What happens when I click this
1:33button or turn this knob or flip this switch. That's my style.
1:38And what I propose we do right out of the gate is make sure your environment is
1:43ready for software development. Let's install some applications. Let's learn
1:48how those applications work.
1:50Let's learn how to create some basic software and run it. That's what we're
1:55going to do in this skill. Then once we've got that under our belt nine we know
1:58our environment works, at least with Python.
2:02That'll make transitioning to other programming languages, which is a
2:06requirement for this course, a little bit easier because once you've done one,
2:11the rest of them are pretty similar.
2:13So without further ado, let's get started setting up your environment for
2:16software development. Let's go.
Install and Set Up VS Code
0:00So what is this? What are we looking at here on the screen right now?
0:04Don't focus on the code. Don't focus on the text that you see. Focus on the
0:09entire picture. Focus on the application that I'm looking at.
0:13This is called an interactive
0:15development environment or an IDE.
0:19And I think the key word right there is actually this "I", the interactive part
0:24. It is interactive.
0:26It's more than just a text editor.
0:28It's something that you can not only write text or code in like you see right
0:34here,
0:35but also interact with it. It will actually tell you things about your code.
0:40It can tell you when it's broken. It can tell you when some of these syntax or
0:45the
0:45stylization of the code is wrong. And it can even test your code or debug your
0:52code as we like to say.
0:53Now you're gonna get to know the ins and outs of IDE's quite a bit throughout
0:58this set of videos.
0:59Your first step is just to well get one.
1:02So how do you get an IDE? Well, check this out. If I flip over one page right
1:08here, I've Googled
1:09popular IDE's, even though I already know exactly which one we're gonna be
1:14working with. The thing is with IDE's is there's lots of them.
1:17Sometimes they're free. Sometimes they cost money.
1:21Some IDE's are really good for specific programming languages.
1:27In fact, right here is kind of one that I'm looking at for that example. PyCh
1:31arm.
1:31PyCharm is really good for the Python programming language.
1:36Some programming languages are a little bit more general purpose.
1:42For the most part, this list that you're looking at right here is all pretty
1:47specific to specific programming languages.
1:51IntelliJ for the most part has been used by Java developers, even though it
1:56adds some support for a couple other
1:58programming languages. PyCharm is for Python. Ruby mine is for, well, Ruby.
2:03Visual Studio right here. This is Visual Studio. Basically, the class version
2:09of it is for the dot
2:11net framework, which is heavily used by the C# programming language.
2:16You'll learn more about those key terms and what makes a framework in a
2:20programming languages later.
2:22Just trust me when we're talking about the applications for right now.
2:26Xcode is largely for Apple developers.
2:29And for paid solutions, a lot of software developers do like working with
2:34things like JetBrains.
2:36JetBrains does make a lot of IDE's. If you click on developer tools right here,
2:41you'll see a lot of the items that we just talked about are listed right here.
2:46But for most developers, a one size fits all solution that is modular, meaning
2:53we can add stuff to it, is Visual Studio code.
2:56This is free. This is general purpose.
2:59But we can add extensions or basically like plugins into it that hone in the
3:07ability to work with specific programming languages and do some really cool
3:11stuff with it.
3:11Visual Studio code is open source.
3:15And open source is something we're going to talk a little bit more about what
3:19that means and why it's important and why it's a big deal in the next video.
3:23For now, we're just going to leave it at one sentence.
3:26It means it can really run on anything.
3:29And again, I'll dwell on that what that really means a little bit more in the
3:34next video.
3:35But for now, this is the application that I'm going to be working with.
3:39And quite frankly, this is the application that I actually do my production
3:43software development in right now.
3:45It is free. It is extraordinarily powerful.
3:48And if it doesn't come out of the box with the functionality or the support
3:53that I want, I can add it with extensions.
3:56So what I'd encourage you to do right now is download and install Visual Studio
4:01code.
4:02You can see the various platforms that are supported right here, Mac OS,
4:06Windows and Linux.
4:07And it does work on Apple Silicon.
4:10So if you're working with the ARM CPUs, it'll absolutely work for that too.
4:15So go ahead and install that and then go ahead and open up Visual Studio code,
4:20which is where I am right here.
4:22I'll go ahead and close these files here and kind of show you some of the
4:25things that you can do.
4:26We're going to spend some time setting up Visual Studio code to work the way
4:31that you want it to go here under code, go to settings and take a moment to
4:36actually explore color themes.
4:39I know you're thinking, wait a minute, like this is a software development
4:42course.
4:42And we're talking about color themes.
4:43Yes, we are talking about color things because you know why you're going to be
4:48staring at this screen for a long time.
4:51And it needs to be in a color format that your eyes are comfortable with.
4:56You can even add new color themes by browsing additional color themes right
5:01here at the top.
5:02It'll search for color themes.
5:04You can actually load a huge list, although right now my loading failed.
5:08I think probably because I'm connected to a VPN right now.
5:10So again, I do highly recommend you actually take the time to explore your
5:16themes and pick a color theme that you can stick with.
5:19I know this is it seems silly, but it's actually something that I found has
5:23been a really important thing for me to stay focused in on what it is that I'm
5:28working with.
5:29OK, next thing that I want to talk about is just the layout of VS code right
5:34here.
5:34Now your layout is going to look a little bit different the first time you
5:38launch it.
5:39All of this stuff right here on the right hand side of my screen is actually
5:44going to be on the left hand side of your screen.
5:47I moved it to the right hand side of my screen on purpose.
5:51You might be thinking, why would I have done that?
5:53I'll show you just to flip it back for a second.
5:56This is probably more like what you're seeing by default.
6:00When I click this little gear down here by the bottom, I'll click command
6:04palette and I'll search for the word position.
6:07You see this toggle primary sidebar position.
6:11If I give it a click, it'll flip it over here to the right side.
6:14Now, why did I do that?
6:17It's kind of a subtle thing again.
6:19It's just about keeping my attention and keeping me focused in on working.
6:23Whenever I actually bring up a file, any file that I want to work with, I'll
6:27show you if I bring up just a, you know, a little script right here that I'm
6:30working with.
6:31If I do command B or control B on Windows machines, it collapses that screen.
6:39So I get a little more real estate on my screen to work with.
6:42When I have this stuff over here, this positioned window over here on the right
6:47hand side, it doesn't move my code.
6:50See, check us out.
6:52If I put it back, go to command palette, type in position, toggle the position
6:57bar over here.
6:59Now, when I do command B, see it shifts my code, it's a subtle thing, but it's
7:03another thing that's really, really important for me to be focused in on being
7:07efficient.
7:08So the ability to collapse without shifting my code is just another thing about
7:12setting up my environment in such a way that I can do a lot of software
7:18development over a long period of time and just make it a little bit more
7:21sustainable.
7:23Now, some other things that are going to be helpful to you to actually just
7:27understand how to navigate around VS code.
7:30One of the things VS code shows you is what programming language you're
7:35currently working on.
7:37It's small, it's subtle, but it's right here.
7:42See where it says move right there where my mouse is at the bottom?
7:46That's because I'm actually working with the move programming language right
7:50now.
7:50If I change this to something entirely different, like this markdown file, see,
7:55I changed to the markdown file and now it's pointed out that this is a markdown
8:00language right here.
8:01I can change it one more time to be something like a rust file.
8:06Let's just grab a rust file here.
8:09And there it is.
8:12There we go.
8:12There's a rust file.
8:13And you see now it shows that this is a rust file down there.
8:17So visual studio code can detect what programming language you're working on
8:22just by looking at the file extension.
8:24And importantly, it can also highlight the syntax and understand some of the
8:30things that are going on in that file by this detection.
8:35Sometimes though, it doesn't get the detection just right.
8:38And you can actually click on the language right here and choose all of these
8:44languages that it can support out of the box.
8:46Or maybe not out of the box.
8:48If you need to add support for certain types of programming languages or any
8:53additional functions, this is where VS code really shines.
8:57This is what makes it so popular.
8:58It's the ability to add basically plug ins into VS code on the fly that extends
9:06all of the things that it can do, that it can extend all of the support that it
9:10has.
9:11And that's what these little building blocks right here are.
9:14These represent.
9:14These are the extensions.
9:16If we give it a click right here, I'll collapse the extensions that I have
9:21installed and you can see some of the extensions that it recommends right out
9:25of the box.
9:26But you can search for anything that you want, like Python support search for
9:32Python.
9:33And you'll see a lot of Python extensions pop up for you to work with the
9:38official Microsoft supported Python language extension is probably the one that
9:44you want to go with.
9:46I go ahead and encourage you to click on this Python extension right now.
9:49And where you see right here, it says like disable for me, I would go ahead and
9:53click the install button for you.
9:55Go ahead and do it.
9:56You'll see in just one second, Python support has been dropped into your VS
10:01code application.
10:03That's all you had to do to turn this into a Python development environment.
10:08Feel free to explore other things.
10:11Search for something like go.
10:13The go programming language is very popular this day and age.
10:17So you see this one right here, go team at Google, give that one a click,
10:22install it too.
10:23Now VS code supports go.
10:25You can do the same thing for rust, another programming language that I highly
10:30recommend getting familiar with.
10:32I'm personally using the rust analyzer extension right here.
10:38In my own environment, now there's a lot more extensions that I'll probably
10:42introduce you to when the time comes.
10:44This is all about just getting familiar with the tool, getting familiar with VS
10:49code.
10:49The final thing that I want you to see is the terminal itself.
10:53This is where you can actually run and debug your code.
10:57All you have to do is go to the top window of your screen and click new
11:01terminal.
11:02And it'll pop up a command line terminal right here in the application.
11:07You don't have to jump between applications now, leaving your text editor to go
11:12to a terminal to run a script and see what it does.
11:15Now you can look at it all in one place, thus proving that this really is
11:20interactive.
11:21Now I promise you're going to see so much more of this application, the ins and
11:25outs of what it can do, even in this skill.
11:28So for now, we just wanted to get VS code and start getting familiar with just
11:33the landscape of it.
11:35Take some time to customize it and kind of set it up to work the way that you
11:39would like it to.
11:40Basically, pick a good color theme and choose if you want this window to be
11:45collapsible on the right hand side or the left hand side.
11:48Some of the other things that these icons mean, don't worry.
11:51We're going to explore them as we progress.
11:53But for now, this has been getting your first application installed, the IVE VS
11:59code.
Understand What Open Source Really Means
0:00Now before we dig into this anymore, I wanted to take a moment to elaborate on
0:04what open
0:05source
0:07software
0:09Really means this is very frequently
0:12abbreviated OSS in the software world and if you ever find yourself on this
0:17website
0:18github.com
0:20It's very likely that you're going to be taking a look at open source software
0:25now nothing
0:26There's always these gotchas. There's always these well, maybe not maybe this
0:30you know
0:30Not open to the public but the idea the core ethos of github is a place where
0:37people
0:37Can share their work and share their software out in the open and
0:43Anyone can come along make a copy of that and contribute to it
0:49They could add their own fixes to problems or improvements or features into it
0:54And that's exactly what VS code is right here
0:58You are looking at the core software the actual software that was written that
1:03makes
1:04VS code work and run on your computer
1:07This is a big mindset shift from even I'm gonna say like you know ten years ago
1:14Open source software was less common it was starting to become more common
1:20It was starting to become more of the thing around I'm gonna say 2015 or so
1:25I mean just thinking I'm just thinking personally
1:29You know in my experience working with computers over a really long time
1:33There was you know I started with Windows 95 and it was really Windows 95
1:39all the way through you probably
1:42Windows 8 is where I want to say
1:47When applications were designed to run on Windows they were only
1:52Designed to run on Windows it was uncommon to find an application that ran on
1:58both windows and
2:00a
2:02OS X which is now Mac OS
2:04like multiple operating systems
2:06Windows had their own programming languages
2:10primarily
2:13see sharp was a big one and
2:16C-sharp really belonged to a bigger family of how software was designed and
2:21laid out called the dot net framework
2:25The dot net framework was just that it was a framework
2:28It was basically a scaffolding an architecture and you could drop C-sharp code
2:34into it to make your application work
2:36but for the most part the dot net framework only worked on Windows computers
2:40and
2:42Importantly the dot net framework itself and the C-sharp language were closed
2:48source
2:49So you could learn how to write code in C-sharp and you could write
2:55Applications that worked on Windows, but you couldn't actually contribute to C-
3:00sharp at the same time
3:02So around I'm gonna say like I'm gonna stick to 2014 about 10 years ago at the
3:07time of this recording around 2014
3:10There became this big shift in developers where they didn't want to write
3:15programs
3:16that only ran on one operating system anymore in
3:20Particular they didn't like it when the operating systems also had to be paid
3:25for and licensed
3:26They if they were writing an application they wanted that application to be
3:31able to run anywhere
3:32Which means the language that it was written in as well as the operating system
3:40That it runs on needed to be some form of
3:43free
3:45So they just became a huge cultural movement in software development
3:49Where developers started shifting away from things like the dot net framework
3:54I'm gonna say and I don't want to say like people stop developing for Windows
3:58obviously Windows is still an absolutely massive
4:00humongous operating system and applications are written for it to this day they
4:05just
4:06Forced the hand more or less for Microsoft to transition away from closed
4:12sourced application
4:13Programming to where if a developer wrote a program one time it should be able
4:19to run anywhere
4:20so developers started writing in programming languages like Java or
4:25Python and the big win for these is these programming languages can run
4:32everywhere and
4:34developers also fell in love around this time with
4:37Linux based operating systems because
4:40Linux based operating systems are usually small and they're almost always free
4:46So from their point of view a language that can run anywhere and an operating
4:51system that's free
4:53There's no barrier to entry to use their application
4:55So fast forward to today
4:592024
5:01What happened around this time that made Windows forced that you know had
5:07Windows changed their position on open source software
5:10Well, they recognize this advent was happening right here
5:14that developers themselves were shifting away from the dot net framework and
5:19the C-sharp programming language because that would
5:21restrict their application to only being able to work on Windows which was also
5:27a paid operating system and
5:29In a truly global environment where not everybody has a laptop and can afford
5:34to pay for Windows or things like that
5:36Forcing this hand was actually a barrier to entry for software developers
5:41So recognizing that that's the case
5:44Windows actually started to transition from dot net framework to dot net core
5:50Which is now an open source software version of dot net and today that is now
5:56transitioned to just
5:59dot net so it went from
6:01dot net
6:02framework to dot net core to now dot net and
6:06C-sharp is now open source I
6:10can now run C-sharp written
6:12applications directly on my Mac OS operating system and along with that this
6:19whole advent of
6:20creating
6:22programming languages and applications that software developers like
6:26The ultimate tool VS code came out of that too
6:30As you've seen in the previous video VS code is now
6:33basically a de facto standard for software developers to work with because of
6:38its ability to be
6:39extensible
6:41Anyone can now see exactly where VS code comes from and because they have this
6:47ability they can now build their own
6:50extensions like we explored in the last video and add that extension
6:56to a
6:58marketplace
6:59Where anyone can come along pick the extension and choose to install it
7:03directly into VS code that might have been a subtle thing that
7:06You might have missed but if I flip back here and jump over to my extensions
7:10real quick and just grab an extension like this one
7:13We can actually see that this is a marketplace the rust extension pack what
7:18version it's on who created it
7:21How many times it's been downloaded and importantly ratings from the public of
7:26what they think about it
7:28Then you can also look at what does this actually do it can show you little
7:33snippets like it
7:34What what is this supposed to do or give you links to understand what it does?
7:38Just picking on another one like Azure tools that actually allows you to work
7:43with cloud compute something
7:44We'll talk more about later
7:45You can actually see that this Azure tools extension is an extension pack
7:51It comes with a bunch of additional extensions that you can install right here
7:56And if you scroll down and explore and let me get this terminal out of the way
8:00You can actually show you screenshots of what each of these extensions do and
8:04how you can work with them
8:05Importantly you can see who published this how many times it's been installed
8:10and again ratings for what they think of this extension so far
8:14So all of that is to say is that when you start working with software in
8:19general you
8:20Maybe coming from this mindset if you are at least have been around you know
8:25technology as long as I have for a long time
8:27applications could only work on one operating system and you know what maybe
8:33people still are making
8:34Applications that only work on one operating system you see that very
8:38frequently when you open up something like the Apple App Store
8:41It's very likely that that's only going to work on Apple
8:44But for the most part as a software developer who's getting started
8:48Freshen the game you're going to want to work with open source as much as
8:54possible
8:55Programming languages that are supported everywhere and that's why in the next
9:00video we're going to get started with
9:02Python
9:03So let's pick that up in the next video
Install Python
0:00So with our understanding of using open source software to begin learning some
0:05basic software development fundamentals,
0:07we're going to start by talking about one of the most popular first programming
0:11languages in the world.
0:13And that's Python.
0:15Python is very, very, very, very popular because it is, in my opinion, the most
0:23human readable programming language.
0:27As far as programming languages go, this is the one that reads the most like an
0:32organic human sentence.
0:34Other programming languages that are still really popular, like JavaScript,
0:39have a lot of special characters in it.
0:42You'll see the braces symbol a lot.
0:45You'll see semicolons a lot.
0:48These are symbols that don't show up a lot in human sentences.
0:52Whereas Python really is the most human readable programming language, which
0:57makes it a natural first step for people entering the programming language
1:02world.
1:03Beyond that, Python is very general purpose.
1:10And when I say general purpose, I really mean that you can kind of do a lot of
1:15different things with one single programming language.
1:19For instance, you might want to make websites and do web development.
1:24You can do that in Python.
1:26You might want to get into AI or machine learning in the same kind of vein.
1:33You have data processing and you can do that with Python.
1:39You might just be looking to automate monotonous tasks.
1:42One of the most popular programming and software development fundamental books
1:47ever written is called automate the boring stuff with Python.
1:50And it is actually the book that taught me Python.
1:54Because I wanted to do exactly what the name implied, automate boring monoton
1:58ous work.
1:59In particular, in my case, it was working with Excel files.
2:04I did not fully understand just the breadth of how much stuff you could
2:08actually do with Python.
2:10There was, but because it's such a popular programming language, it is also
2:15just like VS code.
2:18Extensible.
2:21Meaning we can take Python out of the box.
2:24And if it doesn't do exactly what we wanted to do out of the shelf, someone has
2:29likely built a drop in plugin.
2:31Something will explore towards the end of this skill and add functionality to
2:35it.
2:36We can extend its capabilities.
2:39So how do you get Python?
2:41Well, if you're working on a Macbook or a Mac OS machine or a Linux machine,
2:46you already have it.
2:47If you open up a terminal, you can simply type Python 3.
2:51That's all one word like this and press enter.
2:54And you see it launches the Python 3 interpreter.
2:59This prompt with the three dashes right here is how you know you're on the
3:03Python interpreter.
3:05Now, why is it called an interpreter?
3:07Well, because when we write Python code, it actually reads like a human
3:12language, but computers don't actually process human language.
3:16Computers process bits ones and zero zeros and ones like so.
3:24So what the Python interpreter does is it literally interprets our human
3:31readable language on the fly and translates it into what is known as machine
3:40code or byte code.
3:42Those are synonyms.
3:45So this terminal right here is really waiting for us to type in Python syntax
3:51or Python commands so that it can interpret it on the fly into byte code.
3:57Check this out.
3:58If you want to try it, I'll try.
4:00And if you if you have this already loaded up, don't worry if you're on Windows
4:03, we're going to show you what to do next.
4:04You can do print open parentheses, open double quotes.
4:10Hello world.
4:12Close double quotes close parentheses by type enter right here.
4:17It returns the word hello world that I typed right here back to me.
4:21The interpreter interpreted the Python command of print and did the actual
4:27processing right there.
4:29So now what I want to leave the Python interpreter, I'll type exit, open and
4:33close parentheses, and it returns to be back to my terminal.
4:37So this is just understanding that Mac OS and Linux machines come with the
4:41Python interpreter by default. Windows machines, however, don't.
4:46You still have to go out and get Python and Python can actually be a big
4:50installation for anyone working with Windows machines.
4:55So we'll go to Python.org to bring this up.
4:59And to download and install it, I'm going to hover over downloads and you see
5:03Python 3.12.3 right here.
5:06Your version may look different because of the time whenever you recorded this,
5:10they may come out with new versions later.
5:12We'll go ahead and click on Python 3.12.3 and it downloads the installer and
5:17then I'll open the installer to actually launch the installation.
5:21Now, here's what I recommend you do because right now what it wants to do is it
5:25wants to install this in my local profile environment.
5:29What I actually recommend you do is you install this in a path where any user
5:34can get to it.
5:35So let's do customize installation right here.
5:39We'll leave all of these things default.
5:41We're going to set this true to for all users though, right there.
5:45And this will require admin privileges to launch this, but we do want all users
5:50to be able to run our Python scripts.
5:53We'll click next and we're going to change the installation location here.
5:58I'm going to click browse and I'm going to move to my C drive.
6:02So let's go to this PC.
6:04We'll go to the C drive.
6:06I'll make a new folder right here and I'll call it pi 3.12.3 for Python version
6:133.12.3.
6:14And I'll kind of click on it.
6:16I've got it selected and I'll click OK.
6:19So that's where I want to install it.
6:21Let's go ahead and make sure we set install Python 3.12 for all users and add
6:25Python to environment variables as well.
6:29We'll click install and that should kick off the installation.
6:33It's really important that you don't miss any of those steps or those options.
6:37I just want to stress that.
6:39The installation finishes after one moment. There's one final thing that you
6:44can do here.
6:44It shows disable path length limit.
6:46It says this changes your machine to allow programs like Python to bypass the
6:51260 character max path limitation.
6:55Go ahead and do that just in case it's something that you expect to need in
6:58case you do need to have a longer path character limit name when specifying
7:05paths to specific resources.
7:07Now, what can we do?
7:09Let's bring up the command prompt here.
7:11I'll type CMD.
7:12And what I'm going to do is I'm going to run this as administrator.
7:16The big reason I want to run this as administrator is because the Python
7:20installation just changed the path environment variable running it as
7:25administrator will effectively refresh the cache of what it has in the Python
7:31environment variable.
7:33So with the command prompt launch here, I can now type Python 3.
7:37Sure enough, it brings me into the interpreter and I can close that out.
7:41Look, just one other thing I want to point out.
7:43You don't have to go through that big installation as well.
7:46It's now baked into the Microsoft Store.
7:48So if you have access to the Microsoft Store because most enterprises do shut
7:53down access to the Microsoft Store, but if you're just working on your local
7:58computer at home and you can access it, search for Python 3 and download the
8:02Microsoft Store.
8:02And download, you know, whichever version of Python 3 you want, 3.12 is the
8:06most recent version.
8:08It'll do effectively the same thing.
8:11So this is how you go about getting Python 3.
8:15At this point with Python 3 installed and VS code set up, you're ready to work.
Work with Python Scripts
0:00So now we're going to walk through is actually setting up a workspace and
0:04creating our first Python script and running our first Python script from VS
0:09code.
0:10Here's what I want you to do. I want you to bring up a terminal or file
0:14explorer, whichever operating system you're working on.
0:17If you're working on Windows, bring up file explorer. If you're working on Mac
0:21OS or Linux, you can bring up terminal.
0:23Either way is really easy. So from whatever folder you want to begin with,
0:28maybe it's your C drive, in my case, in Mac OS, it's my home folder.
0:33What I want you to do is I want you to make a folder, let's call it make their
0:37and call it like work demos, something like that.
0:41You can just right click, do new folder and make a folder called make them work
0:45demos.
0:46I'll press enter and then I'm going to change into work demos.
0:50Then from here, I'm going to make another folder, call it first demo like so.
0:58I'll press enter and I'll change into first demo. At this point, you can stop.
1:03If you've created these two folders, you're good to go. You can close your
1:07terminal. You can close your file explorer.
1:10We can pick up the rest and do the rest from our ID or interactive development
1:15environment, in this case, VS code.
1:18I'm going to launch VS code, fresh new launch. In my folder section over here,
1:24you know where my little extensions are, you see it looks a little bit
1:28different.
1:29That's because the last time I opened it up, you saw all of those extra buttons
1:33, because I had files already open.
1:36When those files were already open, it triggered some extensions to pop up.
1:41In fact, as I was sitting here, they just started to pop up on their own as
1:45they just got loaded into the program.
1:48At the very top here, we see our file and folder explorer. What I want you to
1:51do is I want you to click on open folder.
1:54I want you to make your way to that folder. I'll go to work demos and then
1:59first demo.
2:00Then with first demo clicked right here, I'm just going to click open.
2:05Now, over here, I'm looking at the contents of first demo. I'll say yes, I
2:08trust the authors, because I am the authors.
2:11Right here, I'm looking at the contents of first demo.
2:14I can right click in here and choose to create a new file. We're going to call
2:19this my demo.py.
2:24Python scripts have the file extension.py or py.
2:30Immediately, I notice down here that VS Code interprets this as a Python file.
2:36I now have my demo.py opened right here on my screen.
2:41I'm free to begin typing effectively whatever Python code I want.
2:47We can do the same thing we already did with print.
2:50I'll do open and close parentheses. I'll do double quotes. I'll say hello world
2:55.
2:56I see the little white dot right here, kind of where my mouse is, a little bit
3:00to the left of my mouse.
3:02That means that I haven't saved this file. That means whatever I've typed here
3:07hasn't actually been committed to disk right now.
3:10So as far as the disk knows, it's just an empty text file. But if I do command
3:15S or control S, I save the file and then it goes away.
3:20I can then go onto a new line and start typing some more stuff. We can type
3:26print.
3:28How are you today?
3:32If I do command S one more time, it saves it. That's fantastic.
3:37So what the print statement does, this is important. It feels kind of silly
3:41right now.
3:42But what the print statement does is it takes anything input, any value that we
3:48give it, and it retipes it in the terminal.
3:53You might be thinking to yourself, well, what good is that? Why do I care about
3:58that?
3:59What developers actually end up using this for is they'll do something really,
4:04really, really complex in code. They'll take a bit of data in and then they'll
4:12change it as this code progresses.
4:15And as it goes from line one to line two to line three to line four, they might
4:21forget how it gets changed along the way. And what they want to do is they want
4:27to put print statements in the middle of their code as it's progressing along
4:32the way to see how everything is changing.
4:36So print is actually a really useful debugging tool, where as data is coming in
4:41, and we want to see what is the application doing with this data at each step
4:45along the way, we actually use print to print out what it's doing along the way
4:51.
4:52Let's tinker with that a little bit, shall we? Let's actually say, I want to
5:08start out by holding just the number zero somewhere. What I might do is I might
5:09actually create something called starter as just the name of some item that we
5:10want to save.
5:13Then what I might do is I might say starter is going to be changed to be
5:19starter plus one.
5:21Then I might say starter becomes starter plus 400,000, nine, 410,000 nine
5:30hundred and seven let's just make something up like that.
5:34Now, at what point, what is starter at this point right here, that becomes the
5:41question.
5:42So you can see, we started out by creating what's known as a variable. This is
5:47just something that we just give it an arbitrary name any name we want to give
5:51it, and we store data inside of it.
5:55So we changed the value of starter to be whatever starter was plus one. Then we
6:01took whatever that was and added 410,000, nine hundred seven. So I could
6:06quickly do some math and see that's 410,000, nine hundred eight.
6:09But if you're not paying close attention, you might just want to be like, Hey,
6:13what is starter at this point in my code and that's what print does.
6:18Now the question is, how did I have this Python script, how do I actually
6:23execute it, how do I run it. There's a couple different ways. We can go back to
6:27our terminal.
6:29We can go into our working demos directory and then our first demo. If I type
6:33LS I see here's my demo.py and I can run the script with Python three, we say
6:39Python three, and then just the name of the script.
6:44And boom, there we go. That's the first way to run your script. You can do it
6:48directly from the terminal. This is usually done when we're done working with
6:53it. This is usually done when we're like, Okay, the script is done.
6:57I don't need to edit it anymore. I don't need to look at the code anymore. I
6:59just want to run it. This is when we usually go to the terminal to do it. If we
7:04're still in the middle of debugging and working with it.
7:08This is when I might still fire up my terminal right here. I could do the exact
7:12same thing from the seat when I do terminal right here. It automatically
7:17launches me into the folder that I had open in my explorer. So if I type LS I
7:21could do the exact same thing.
7:23I can say Python three, my demo.py and it gives me the same results. I could
7:28also go here to run and say start debugging. And it looks like my Python
7:34extension is disabled. Let's go ahead and enable that real quick.
7:39I'll go into extensions with the little blocks. I'll click the dot dot dot and
7:44I'll say enable all extensions.
7:47Now that that's enabled, I should be able to go to run and start debugging. It
7:52says use the Python debugger, which is what I want to do. I'll click that. It's
7:56a Python file. I'll click that. And right here. Look, see, it's running it.
8:01There we go.
8:02So this is typically how we end up working with software. Whenever we start
8:06actually writing and interacting with software, and this is how we're going to
8:10go about running Python scripts. Now in the next video, we're going to really
8:15ratchet this skill up a notch when we start adding extensions and actually
8:20watching it work on the fly.
8:22So until then, now we've actually got a workspace set up where we can see how
8:27to add files. We can see what it's like to write some code into a script, and
8:32then what it's like to execute a script from within an IDE, as well as just to
8:37stand alone terminal.
Importing Python Packages
0:00So in the last video we started to actually explore how to work with Python
0:04scripts, run Python scripts, and develop Python scripts.
0:07But this isn't really useful, is it? Just being able to print arbitrary text
0:12and arbitrary math out to the terminal isn't that great.
0:17Let's start thinking a little bigger. Let's think for a second about what we
0:21might want our software to actually do.
0:23A very common thing that software does is log.
0:28Log data.
0:30Log information.
0:32Now in order to implement an actual logging ability, it's going to require a
0:38lot of steps, a lot of understanding of programming languages and how Python
0:43works.
0:43Going to start out with something really, really basic though.
0:47A common concept that's implemented in just about every piece of software today
0:52.
0:52And that's logging and writing data to a file.
0:55Very frequently, what we do when we write data to a file is as events or things
1:03are happening inside of our application.
1:06Our application is at the same time writing this to a file.
1:12I receive this data. Here's the data.
1:15I process the data in this way. I changed this thing. I made this decision.
1:22It's basically an audit trail of everything the application is done.
1:27Now it's up to you, the software developer, to figure out what it is that you
1:32want to write to this file in the first place.
1:35Maybe you want to write every single tiny little thing down.
1:39Or maybe you only want to know what happened when something went wrong. That's
1:44up to you.
1:44But the thing is, is these log files get big, really, really fast.
1:51So one of the common things that we do is when we write data to a log file,
1:55we actually end up writing them to a bunch of different files.
2:01One of the more common ways that we do this is every day, we create a new file.
2:09So I could look at the events that happened on day one, the events that
2:14happened on day two,
2:15and the events that happened on day three.
2:17And after so many days of past, I may go back and say,
2:22"Okay, I don't care about day one events anymore, and I'll just delete that
2:25file to free up that space."
2:27So far so good understanding that we have what we call log rotation,
2:35a big software development concept you're learning right off the bat.
2:39We write events to a file, and then whenever a new day starts, we'll write
2:44those events to a different file.
2:46And after so many days of past, we'll delete the stale files.
2:51Well, one of the things that we may want to do is we may want to create this
2:57file in our code.
2:59And we may want to use today's date as the name of the file.
3:06It could be something like 2024411.txt is the name of the file.
3:16So if I'm thinking about a file structure, I'll have something like my
3:22application.
3:25And then in that, I'll have a folder called logs.
3:29And then in that, I'll see this file.
3:31And then tomorrow, it'll be 2024412.txt, and so on and so on and so on.
3:40So our first mission is going to be how do we dynamically create this file?
3:46Well, the big challenge that we have is we have to dynamically get today's date
3:51.
3:51And Python can't do that out of the box, believe it or not.
3:56We have to import what we call a module, or basically helper code, or basically
4:02a plugin
4:03into our Python script that has the ability to do it.
4:07Here, what I'm going to do is I'm going to create a new file, and I'll call it
4:11mylogger.py.
4:14See, there's no Python code that I can write this very second that tells me
4:19what today
4:20it is.
4:21What is today's date?
4:23Instead, I have to actually import that ability into my Python script.
4:29And we do that by saying import date time.
4:35Date time is the module.
4:37It is the thing in Python that has the functionality to work with the operating
4:44system and understanding
4:46this computer's date and time.
4:50The reason why we don't have this by default is if I were to, let's pretend
4:55this script
4:56have the ability to work with date and time by default.
4:59Under the hood, that would actually consume more memory from my computer just
5:06to load
5:07all of those processes and background checkers and all of those things that
5:11make that work.
5:12It would consume all of those background resources needed to get date and time.
5:17My script here doesn't need date and time.
5:20See, there's no call to date and time here at any point in this code.
5:25So there's no reason to eat up that overhead on my computer.
5:29But my longer script, I am for sure going to need today's date and time.
5:35So I'm okay importing that functionality.
5:38It's very lightweight.
5:39It's not going to slow my computer down, but we just don't want to import
5:43unnecessary
5:44packages, unnecessary libraries, unnecessary modules into our code if we don't
5:51need to.
5:52So in this case, I do need to get today's date and time.
5:55So the first thing I'm going to do is I'm going to say, let's get today's date
6:00and store
6:00it in a variable.
6:02So I'll create a variable called today's date.
6:04It's today underscore date.
6:07And I'll say using that date, time module.
6:13I want to find a date.
6:15Specifically, I want to know today's date.
6:20It's kind of a weird syntax the first time you see it.
6:23We haven't talked about classes or methods yet.
6:25We will.
6:26What this structure actually means will make more sense as we progress along.
6:31But just for now, I want you to focus in on the key takeaway here.
6:36In order to get additional functionality out of our Python code, we have to
6:41import this
6:42particular package called date time.
6:46So now at this point, today's date is stored right here in this variable called
6:52today date.
6:54How can I check to make sure it's the correct today's date?
6:58Of course, we can use print.
7:00So I'll say print today date.
7:03Now down here in my terminal, I can say Python three, my logger.py.
7:09And sure enough, there is today's date 2024, 411.
7:14But let's say, hmm, I'm not so sure about that format.
7:18Even if year, month, day, maybe I want the more, you know, I guess the more
7:23Americanized
7:24way of doing it, we could do month, day, year.
7:28How can I readjust that?
7:29Well, we can actually reformat the date format that comes back to us using a
7:35specific method.
7:37That's what this is called.
7:39So after we get today by saying today, I'll tack on one more thing that I
7:45wanted to do.
7:46I'll say dot S T R. That's string.
7:51That's what that's short for.
7:53F, that's format, time, then you can kind of see the helper text that my
7:59computer is
8:00getting me right here.
8:01It says if you want your month, day, use percent year percent M percent D. In
8:08my case, I wanted
8:09month, day, year.
8:11So I'll say open parentheses, double quotes percent M, hyphen percent D for hyp
8:19hen percent
8:21capital Y.
8:22It's important that that's capital.
8:24And then take a look at this.
8:26So in this case, I'm now using the date time module to get a date, specifically
8:31today's
8:32date.
8:33And then I'm reformatting the string to be month, day, year.
8:40When I print this, we'll just rerun the command right here.
8:44Now I've got month, day, year.
8:47So at this point, this is where we're going to pause in this part of the
8:50journey.
8:50I know it's kind of like, well, we didn't actually write the file.
8:54The big thing that I wanted you to understand was really about importing
8:58packages that scripts
9:00by default can't do absolutely everything under the sun.
9:05Lots of times we have to go out and get packages and add that functionality to
9:10our script by
9:11importing those packages.
9:14But once I imported the date time package, I could then dynamically figure out
9:19things
9:19like today's date and then even reformat the structure of today's date.
9:24Now that I have today's date, I can create a file with today's date in the name
9:29of it.
9:31The reason why this is a big deal is because every programming language just
9:36about in existence
9:38has this construct to it that by default, it can't do everything under the sun.
9:44You have to add functionality to it.
9:47And it's almost always the very first thing that you declare at the top of your
9:52script.
9:52I'm adding these functions, these resources into my script and into my code so
9:59that I
9:59can use them just a few lines down.
10:03So whether it's JavaScript, Python, Go, Rust, Java, C#, it doesn't matter.
10:10They all start with some type of import or using, use, add, whatever the
10:19statement is,
10:21they're adding functionality to their code.
10:24And now you've kind of seen it firsthand in action using a Python script.
10:29So you've come a long way in this journey.
10:32You started from nothing.
10:34Now you've actually got a full blown development environment with Python code
10:39being imported
10:40and being run locally in the IDE.
10:43I hope this has been informative for you and I'd like to thank you for viewing.
CHALLENGE
0:00So your mission was to create a new file with NVS code and then basically do
0:07whatever you
0:07want to print anything you want to do it but importantly make sure you're
0:11printing out
0:12the date time somewhere using the date time module to get today's date.
0:17Now I'll show you one little additional tip that could make this a little fun
0:21as part of
0:22it.
0:23Let's start by creating a new file.
0:24We'll call this challenge.py.
0:28Like so of course I'm going to import date time into it and then I'm going to
0:33get today's
0:34date and that of course comes from date time, date today.
0:40Now one of the cool things that you can do is you can actually do kind of what
0:44it's
0:44showing you right here how to concatenate string together.
0:48What does that mean?
0:49Concatenate means combine effectively and string is just a string of text
0:56characters.
0:57We haven't talked about primitive data types yet.
1:00We're going to in the next set of videos but one of the very first things I'm
1:03going to
1:03give you a preview into is that there is the concept that text in programming
1:08languages
1:09are very frequently referred to as string and we can combine two strings
1:15together with
1:17concatenation.
1:18Now Python has like 20 different ways to do it.
1:22The later versions of Python use something called string formatting or string
1:28interpolation.
1:29So check this out.
1:30What I can do is I can type print and then instead of typing quotes like you
1:35see here
1:35on the screen what I'm actually going to do is I'm just going to type a lower
1:39case f.
1:40Now what the lowercase f tells Python to do is it's basically saying I'm about
1:46to give
1:46you a bunch of string but in the middle of it we're actually going to insert
1:53Python variables
1:54or Python codes that you need to interpolate into string.
1:59Watch how this works.
2:00This will make a lot more sense when you see it.
2:02We'll just say double quotes and we'll say today is and then I'll say double
2:07braces
2:08and you see this today date variable right here.
2:11I'll put that right here like this.
2:17So take a moment to digest what this is doing.
2:19This is going to print today is and then it's going to print out the contents
2:26of that variable
2:28as part of this big whole string.
2:31This is what that f does right there.
2:35That f says we can actually use these braces to drop in Python code Python
2:43variables and
2:45you'll be able to pull the string out of it that you need.
2:49So now when I say Python three challenge.py look at that.
2:55See today is and the full thing right there.
3:00This is really just to get you acclimated to working with VS code.
3:04This really wasn't about the code at this point.
3:06It was more just about creating files, interactively editing those files and
3:11then running those
3:12files all within one application.
3:15And now we've done that.
3:16I hope this has been informative for you and I'd like to thank you for viewing.
Team training path
Turn this skill into assignable team training
This free skill is a preview of the courses your team can assign, track, and report on with CBT Nuggets.
$708
seat / year