Comment programmer avec python ?

Comment programmer avec python ?


dot py files but what if you want to
access the terminal within a Jupiter notebook and this section will be
exploring how you can do that in this course we work in Jupiter notebooks and
use the site notebook seizure comm but it’s very common that Python is run in a
command line environment in a shell and we’re gonna look at how to run the shell
a notebook seizure comm which is a linux shell and we’re going to launch that
terminal from the library page we’re gonna figure out what type of shell it
is by using this echo and this dollar sign 0 command will see where directory
we’re working from by using the print working directory command and we’ll be
able to list all the items in there and see what’s in there so let’s go ahead
and just look at the library page and see how to launch the terminal so here I
am in my library page that I’m running my demos from and I see a list of items
up here and one of them is terminal it’s possible that your version would look
different where you would just have the image here if you are running at a low
resolution you could just click that you can look at that as you hover over it
should say open terminal it’s most likely that you’ll see this so here is
our terminal and we can use that echo dollar sign 0 to see what it is the type
environment we’re running in our Linux environment and you can do this any
shell that you’re running and we see that we’re running Bash so that’s what
you would use Linux bash you would search on that to figure out how to do
commands if you are searching for a new command the other thing that we can do
here is we can print the working directory so PWD and it says we are in
home and be user so nothing there is looking familiar so I want to list my
directory I’m going to use LS or I can also use a dir command and I see a
couple of things about the operating system
that’s running and that we’re using us anaconda install but we don’t care about
that we care about this library because we are just in our library and we would
like to move to that library so the way that we move to a library is we use the
CD command and that’s changed directory and we could put the name of a directory
if it’s just below where we’re currently at or we can put in a full path so let’s
go ahead and look at our command shell again and so let’s go ahead and change
directory to the library and now we’re in the library we can use dir this time
instead of LS to see what’s in there and we see there are many files these are
all my sample files but we also see that there’s another directory here called
parent directory so I’m going to use the clear command to give us a little more
room and that just clears the screen of the print but everything has still run
there and so I’m going to go ahead and change directory and go to the parent
directory dir hit enter and then we see now our path has changed to parent
directory it’s the library parent directory and we can do LS there to list
our directory or again or we could use dir and we see there’s a couple of
directories and then what’s this here this is a Python file dot py hello world
PI these are just some text files here that we don’t need but we’re interested
in this hello world dot PI file and we would like to run it it’s a Python file
so the way that you will run a Python file is at that terminal prompt that
dollar sign prompt we’re going to type lowercase Python 3 and then the path to
the file including the file name or if it’s in our directory which in this case
it is then we’re just going to go ahead and put the file name in there so let’s
go ahead and look at that so python 3 and then hello world and I’m going to put dot pie in there
and we can run our file and it’s a file that prints hello world so I’ve just run
a Python file from my directory here I can also just run Python right here in
the terminal so now I see these three carrots here the greater than signs and
I can go ahead and I put a print command in there and run it right at the
terminal because I’m now I’m running Python and so this is kind of like our
Jupiter notebooks we can write single lines of code in here assign a value and
then I can say well what is the value of X or I can’t do computations with X and
we see that value there so now I’m running Python and to exit I’m going to
use the exit command and so I’m back but I might want to clean up my command
prompt and so I’m going to do my change directory again and I can use these
ellipses and that will take me back up the directory trees so you see now I’ve
gotten out of the parent directory I’m into library I can do that again and be
back where I started again so to recap in this section we learned how you can
use the Jupiter terminal from within as your notebooks exactly the same way that
you would use the Linux terminal to run your Python program

Leave a Reply

Your email address will not be published. Required fields are marked *