📺 Develpreneur YouTube Episode

Video + transcript

Python Certification Training - FileIO

2021-09-02 •Youtube

Detailed Notes

This episode looks into File IO (reading, writing, and appending) in Python as we continue moving through topics on the certification syllabus

Useful Links: https://docs.python.org/3/library/io.html https://realpython.com/read-write-files-python/ https://medium.com/swlh/python-stringio-and-bytesio-compared-with-open-c0e99b9def31

Learn more about the overall certification and syllabus here: https://pythoninstitute.org/certification/pcap-certification-associate/pcap-exam-syllabus/

Github repository for code examples: https://github.com/robbroadhead/PythonCertificationSeries

Transcript Text
[Music]
well hello and welcome back we are
continuing our series of
uh tutorials basically we're going
through our pursuit of python
certification
gone through a lot of different topics
and today we are going to go through
file io and let me clean up a couple
just random stuff that's open
so there's going to be a couple of files
that are going to be of note
in our repository if you're looking at
some of the
uh some of the examples you're following
along
we'll have files.py but there's also
going to be a file we create
and there's also which should already
exist there's going to be a readme.md
file and we're using that just for
examples you can
adjust those however you need
so first thing you need to do in dealing
with a file
is you have to be able to open it
you want to open it and do something
with it
and python it's pretty easy
open
is just a file name
a mode and then optionally you have an
encoding
so i can do this or
this one would be valid
now the r is for read
there's a w
for right
and then you can also do
a b for binary
but let's let's sort of look at what
we've got so far so let's say we open
this
and i'm just going to do a little uh
it's a nice little snippet or whatever
so i'm going to open the file
i'm going to read the first line of the
file
and then while that line is not an empty
line i'm just going to print it
and then i'm going to read the next line
of the file and i'm going to close it
because once you open it you want to
close it otherwise depending on how
things go you could have resource locks
and stuff like that
now typically what's going to happen let
me actually get rid of that first
typically what's going to happen so
let's just do this
i'm going to run this one through
so if i go here
so the readme let me go over that so the
readme.md file let's look at that
whoop
there we go
um here oh it's doing it as a markup but
kind of like that there we go so that's
all it is it's pretty straightforward
and what you'll see here is
it has the
that tag and it comes and does that now
note that it's actually doing the um
when i do a print
that print has
embedded in there basically we can't see
it
it has the uh the line the
line terminator end of line so if i come
in here
um
well that's because i'm doing a print so
it's going to do that every time
if i did that without the line feed
and i could pull that off i could come
in
and i could actually replace
the
the line feed in it
and then i would be okay let's see if i
do
now another one
i should be sure is i can do there's a
limit i can do so if i do a limit let's
just say 10.
now you'll see here it's going to read
but it's only going to go
ten characters out one two three four
five six seven eight nine ten
so it's only gonna read that it's only
gonna pull that line
out to a certain number of characters
but notice that it's still
if you look here like so
oh
so the first one i did i read the line
but then i come into the loop
and these are all at a length of 10
and so
it's
not actually it's limiting it so it's
either going to be in this case either
10 characters or
the end of line
which can be valuable at times where
it's like okay i want to read
but if i hit the end of a line then i'm
just gonna you know cut it off there
which would be fairly useful if you run
into things like if you're doing like
some comma separated value or some sort
of
file separator
some character separated
text file or something like that
so we can do that we can read we do read
line we can also do
let's just go ahead and do this as we do
a straight read now this one's going to
do by number of characters
so if i do read
then it goes all the way
it's going to go all the way out um let
me do
this
let's just change that so we do both of
them read
and so now
when i do it i'm not getting
that extra line when i do that realign
it ends up slapping essentially a
l end of line character on it when i do
a read then it's just gonna straight
through and dump that thing out and so
here
i could actually do it like this
and i'm gonna get the same thing because
it just reads the whole file at this
point
and let me get that back
oh let's do that
and let's do it this way
and then i'm gonna do it this way we'll
get all of those examples in there
so let's do it let's read it 15 at a
time
so let's make sure all of those oh let's
do this um
so
note also
uh let's see
file
a
time
and this one will be just read
complete file let's do it that way
so now if we
look now
this is an interesting one
because what you're going to see here
is not what you probably expected
before when i did all these things they
work fine but here like read 15 there's
nothing read the complete file nothing
and that's because
f
that little pointer to the file has gone
all the way through
so i can come up here
and i can do
um
and i get to actually have a lot of
different options i can do here as you
can see i've got a lot of your normal
functions available
but what i can do is i can come in and i
can open it again
or
i can do close
and then open it
and let me go and get rid of the
encoding so you can just see the
difference
uh here
and so now we're going to see them
and
notice that there's no real difference
in what i'm seeing because this is utf-8
in general
so if i don't close it
that
file pointer has gotten to the end the
first time through
and now it's not going to do anything
for me any good it's you know it's not
terribly useful
so if i close and reopen it
that's uh that's going to probably be
the easiest way to deal with it
particularly when you focus on the
the functions that we're going to have
within
the um
within the certification
now another thing i can do
uh well okay so we've got redline and
we've got read
let's go ahead
and
close that file
and now
what i can do
is i'm going to do f dot write
[Music]
this is a
line this is a second line
and close it
actually i'm not going to close it so
let's do this first
so let's go through here
oh and run it and it says create a
simple file well did it create the file
yes it is let's see what it says
so
notice that it ran these lines together
even though those separate
writes
then there was issues with that
now
that f-close
doesn't isn't really needed
in this one exactly because once
python
once that the script completes the
application is done it closes all the
file handles
however if i do this and i try to work
with it within the application before
it's closed out that before a close has
either been explicitly like here called
or implicitly because the script is done
there's gonna be issues with it i'm not
gonna be able to find that file it's not
gonna be in the state that i think it is
so what i can do here is i can do this
oh
there we go i'm gonna run that and now
let's look at that file
and notice i've got this is line and
this is second line now notice
that what i've got here
is
test.text
has been rewritten when i did that open
it was rewritten
but if i come in
and do this
oh i'm sorry i can't do both so i can't
do right i can do append so it's an a
um let's do this
this is create a simple file
let's do this let's do
and to file
and so i've got to close it so i can
reopen it in a pin mode
and now
if i run it
uh let's see oh did i print it out
oh i'm sorry i did so i did it right
right
print print pen to sip file
do that
there we go and so now
if i cat there we go
so now i've got it so in this script so
now you can see where i hit this
twice when this script runs
i blow away the file that exists this
time because i open it for write not for
append
this time i come in and i do a an append
and now i can do all of those same
things
in a binary fashion
so let me first do
because we mentioned that so let's do
this
so let's go ahead and do this readme
except for open it in binary
and i'm going to do
read
and let's just do this
now let's see what it looks like if i
open up binary mode
[Music]
oh
there
now here we see it's got this little b
because basically it took all of that
stuff and now i can see
my line feeds
so this isn't a stream or it's not doing
the printable carry it's just taking the
whole thing
so now i could take
let's see
do i
have i don't have like a good binary
sitting around but
um i can open things like
executables or other binary files that
also means that i can do
let me just do this like so if i do
input
text
and then i just insert one two three
four five six seven eight nine ten or
zero
uh well i'm gonna let first let's see
what happens when i do a read
line
and so here
when i do the binary and i do the reline
it still recognizes my line
but
it's a binary string and it brings that
end line in there that line feed in
there
i can also do that
so like if i do let's take the same
thing and let's do
let's see what happens if i do the same
thing and i create a simple
i'm just going to call it a b file
instead of typing binary
well shoot i probably should just for
note sake
and i'm gonna do b
so let's see what that looks like
oh so here we go
binary mode does not take an encoding
argument oops sorry i forgot about that
i do that
because binary is straight binary
encoding is for strings
and so here what i'm going to see in the
simple binary file
when i do that
byteslate object like object is required
not a string so i can't send it a string
in this case
i could say um
let's just call it temp
equals
this
and write temp
and let's do it again temp equals this
and let's just bail out so let's not
append to it at this point we'll just do
that open it right so now
we run it we're gonna see again it's not
a string even though it's writing temp
it's a string it's not a bytes object
so instead
i can do this
and make it a bite
[Music]
and now it runs and so i've got this
simple binary file
created and if i do what did i call that
test.text
let's see it looks basically the same
but now it's saying that this is bytes
because i can also do
the same thing
and so now i could take a temp equals
let's just get rid of this part
and come to come three four and five
against six so temp's now an array
but it still doesn't like it as a list
so i'd have to convert that over
i don't think i can do it this simply
i don't know because it's going to do
that so
if i do it like this it's going to treat
it essentially it's going to say those
are hard bites so it's going to
yeah
so if i test that yeah so i just have
that
it's a direct version of that but i
could do bytes um
i can do a byte array and and things
like that where
um
i can write those out and i can write
characters as needed into it so now i
can actually get pretty specific with
what i do um let's just do it same thing
let's just do like temp equals 12.
and let's whoop let's see what it says
when i set an integer note
integer doesn't count so i have to get
it converted to bytes
so i could probably do
[Music]
this
two bytes
and i need to give it a length so let's
say a length of
one
and byte order i don't think i need that
so let's see
so if i do that
oh i do need bite order
and
i don't know my bite order offhand
let's just see what that does
but what i can do is i can go in i'm not
going to get too deep into it and this
one uh mostly because of where i'm at oh
it's either little or big oh big indian
or little indian
which
there we go
and so now
oh if i look
it's what is that test.text
yes
and so
that's it's writing that character so i
need something that's like
let's do 68
oh and that's just one that's the
problem so it's like this two
let's see what that does
there okay
so now
it's creating it's a capital d because
that is if you do a 68
the ascii code 68 it's a d so it's
converting that in for us as we look at
the file
but it's actually
um
you see this like null d as it's putting
that space before it
so you can play around with that and do
binary reads and writes i think that was
everything i really wanted to mess with
you can also read into
so i can do
uh
which basically is just going to push
one value into another
so if i do this
i'm going to open it for read binary
temp
equals f dot read
into
oops it's not that way
[Music]
hmm
uh let me do it this way
i'm gonna copy and paste some stuff
because it's easier that way so file
name equals
just that text so i have to create a
byte array
and oops i got import os
because this is
where i get obviously os.path
and so i'm going to get the size of the
file
i'm going to open it as a read into
i'm going to open it as f
so this one's a little different instead
of doing
assigning it and then doing something
with it i'm just going to say hey i'm
going to grab it
and i'm going to read
into my buffer the file
and then i'm gonna do
print buffer
and it's like i like it because it's a
byte array
i think
no it does and so it just tells me that
that is a bite array if i do a string i
don't know if i can do a string of a
bible right so find out in a minute
uh
yep
so it doesn't really do much for me
again
uh where was that up here
you can see so it's really it's that hex
value
uh it's a capital d because
the ascii of 68 is a capital d so it's
actually i'm seeing it
converted into that string because of
the output we're seeing here
i think that's enough for now we've gone
pretty deep into files it should allow
you the basics of reading and writing
and doing some stuff with them and
understand what you need for this
certification so
we'll uh we'll call it a an episode for
here
and go out there and have yourself a
great day a great week and we will talk
to you
next time
you
Transcript Segments
0.46

[Music]

26.32

well hello and welcome back we are

29.119

continuing our series of

31.519

uh tutorials basically we're going

34

through our pursuit of python

36.32

certification

37.68

gone through a lot of different topics

40.16

and today we are going to go through

42.879

file io and let me clean up a couple

46.32

just random stuff that's open

51.44

so there's going to be a couple of files

53.28

that are going to be of note

56

in our repository if you're looking at

57.84

some of the

59.44

uh some of the examples you're following

61.039

along

62.48

we'll have files.py but there's also

64.479

going to be a file we create

66.24

and there's also which should already

68.32

exist there's going to be a readme.md

70.56

file and we're using that just for

72.799

examples you can

75.36

adjust those however you need

77.84

so first thing you need to do in dealing

79.439

with a file

81.28

is you have to be able to open it

84.159

you want to open it and do something

85.92

with it

86.799

and python it's pretty easy

88.88

open

90.079

is just a file name

92.24

a mode and then optionally you have an

94.96

encoding

96.799

so i can do this or

99.68

this one would be valid

102.079

now the r is for read

105.04

there's a w

106.399

for right

107.68

and then you can also do

110.56

a b for binary

113.04

but let's let's sort of look at what

114.96

we've got so far so let's say we open

116.719

this

117.52

and i'm just going to do a little uh

119.119

it's a nice little snippet or whatever

120.88

so i'm going to open the file

122.719

i'm going to read the first line of the

124.159

file

125.92

and then while that line is not an empty

128.16

line i'm just going to print it

129.92

and then i'm going to read the next line

131.2

of the file and i'm going to close it

133.68

because once you open it you want to

135.44

close it otherwise depending on how

137.599

things go you could have resource locks

140.08

and stuff like that

141.44

now typically what's going to happen let

142.879

me actually get rid of that first

145.92

typically what's going to happen so

147.36

let's just do this

148.72

i'm going to run this one through

152

so if i go here

154.4

so the readme let me go over that so the

157.28

readme.md file let's look at that

159.84

whoop

161.28

there we go

162.8

um here oh it's doing it as a markup but

167.519

kind of like that there we go so that's

169.36

all it is it's pretty straightforward

172.56

and what you'll see here is

175.2

it has the

177.76

that tag and it comes and does that now

180.239

note that it's actually doing the um

185.2

when i do a print

187.84

that print has

189.28

embedded in there basically we can't see

191.599

it

192.319

it has the uh the line the

195.2

line terminator end of line so if i come

197.12

in here

200.959

um

202.8

well that's because i'm doing a print so

204.4

it's going to do that every time

206.56

if i did that without the line feed

209.12

and i could pull that off i could come

210.72

in

211.599

and i could actually replace

213.84

the

214.64

the line feed in it

216.4

and then i would be okay let's see if i

218.879

do

224.959

now another one

227.04

i should be sure is i can do there's a

228.799

limit i can do so if i do a limit let's

231.36

just say 10.

237.92

now you'll see here it's going to read

240.799

but it's only going to go

245.519

ten characters out one two three four

247.439

five six seven eight nine ten

250.159

so it's only gonna read that it's only

251.76

gonna pull that line

254.48

out to a certain number of characters

255.92

but notice that it's still

259.68

if you look here like so

264.88

oh

266.479

so the first one i did i read the line

269.12

but then i come into the loop

271.04

and these are all at a length of 10

273.84

and so

275.12

it's

276

not actually it's limiting it so it's

278.16

either going to be in this case either

280.72

10 characters or

282.72

the end of line

284.88

which can be valuable at times where

286.479

it's like okay i want to read

288.479

but if i hit the end of a line then i'm

289.84

just gonna you know cut it off there

292.32

which would be fairly useful if you run

294.32

into things like if you're doing like

296.4

some comma separated value or some sort

298.479

of

300.08

file separator

301.919

some character separated

303.68

text file or something like that

306.639

so we can do that we can read we do read

309.12

line we can also do

312.16

let's just go ahead and do this as we do

314.4

a straight read now this one's going to

316.08

do by number of characters

318.639

so if i do read

323.28

then it goes all the way

325.12

it's going to go all the way out um let

327.12

me do

329.039

this

334

let's just change that so we do both of

335.6

them read

336.639

and so now

339.759

when i do it i'm not getting

343.039

that extra line when i do that realign

345.36

it ends up slapping essentially a

348.56

l end of line character on it when i do

350.8

a read then it's just gonna straight

352.72

through and dump that thing out and so

355.039

here

356.8

i could actually do it like this

362.4

and i'm gonna get the same thing because

363.919

it just reads the whole file at this

365.36

point

369.36

and let me get that back

372.88

oh let's do that

376.56

and let's do it this way

385.039

and then i'm gonna do it this way we'll

387.039

get all of those examples in there

392.319

so let's do it let's read it 15 at a

394.56

time

397.12

so let's make sure all of those oh let's

398.96

do this um

401.36

so

404.319

note also

406.72

uh let's see

410.08

file

415.44

a

418

time

420.4

and this one will be just read

428.24

complete file let's do it that way

430.4

so now if we

434.84

look now

436.8

this is an interesting one

439.28

because what you're going to see here

441.599

is not what you probably expected

444.319

before when i did all these things they

445.68

work fine but here like read 15 there's

447.759

nothing read the complete file nothing

449.919

and that's because

451.52

f

452.479

that little pointer to the file has gone

454.72

all the way through

457.44

so i can come up here

461.039

and i can do

462.639

um

467.68

and i get to actually have a lot of

469.36

different options i can do here as you

470.72

can see i've got a lot of your normal

472.56

functions available

475.36

but what i can do is i can come in and i

477.599

can open it again

479.039

or

479.84

i can do close

483.199

and then open it

486.08

and let me go and get rid of the

487.12

encoding so you can just see the

488.319

difference

495.12

uh here

499.44

and so now we're going to see them

501.36

and

502.24

notice that there's no real difference

503.919

in what i'm seeing because this is utf-8

506.4

in general

509.28

so if i don't close it

511.12

that

512.08

file pointer has gotten to the end the

514.8

first time through

516.719

and now it's not going to do anything

518.56

for me any good it's you know it's not

520.719

terribly useful

522.56

so if i close and reopen it

524.399

that's uh that's going to probably be

525.839

the easiest way to deal with it

527.839

particularly when you focus on the

530.399

the functions that we're going to have

531.68

within

532.839

the um

534.8

within the certification

537.519

now another thing i can do

539.76

uh well okay so we've got redline and

541.6

we've got read

542.88

let's go ahead

544.399

and

545.76

close that file

547.519

and now

560.959

what i can do

563.12

is i'm going to do f dot write

568.14

[Music]

569.519

this is a

574.839

line this is a second line

580

and close it

583.839

actually i'm not going to close it so

585.279

let's do this first

586.959

so let's go through here

588.839

oh and run it and it says create a

591.839

simple file well did it create the file

594.56

yes it is let's see what it says

598.399

so

599.44

notice that it ran these lines together

602.079

even though those separate

603.68

writes

606.48

then there was issues with that

609.12

now

610.32

that f-close

613.2

doesn't isn't really needed

615.519

in this one exactly because once

618.959

python

620.32

once that the script completes the

622.48

application is done it closes all the

625.04

file handles

626.64

however if i do this and i try to work

628.8

with it within the application before

631.92

it's closed out that before a close has

634.64

either been explicitly like here called

637.92

or implicitly because the script is done

641.12

there's gonna be issues with it i'm not

642.48

gonna be able to find that file it's not

644.079

gonna be in the state that i think it is

645.839

so what i can do here is i can do this

654.16

oh

656.24

there we go i'm gonna run that and now

658

let's look at that file

661.68

and notice i've got this is line and

663.279

this is second line now notice

666.24

that what i've got here

668.72

is

670.16

test.text

672.079

has been rewritten when i did that open

675.519

it was rewritten

678.24

but if i come in

680.64

and do this

686.839

oh i'm sorry i can't do both so i can't

690

do right i can do append so it's an a

694

um let's do this

699.839

this is create a simple file

703.12

let's do this let's do

707.44

and to file

710.639

and so i've got to close it so i can

712.56

reopen it in a pin mode

714.639

and now

717.6

if i run it

719.839

uh let's see oh did i print it out

725.36

oh i'm sorry i did so i did it right

727.44

right

728.639

print print pen to sip file

732.48

do that

734.079

there we go and so now

735.76

if i cat there we go

738.399

so now i've got it so in this script so

740.8

now you can see where i hit this

742.839

twice when this script runs

745.76

i blow away the file that exists this

747.279

time because i open it for write not for

749.04

append

750

this time i come in and i do a an append

755.36

and now i can do all of those same

757.36

things

758.72

in a binary fashion

760.88

so let me first do

764.079

because we mentioned that so let's do

766.16

this

767.12

so let's go ahead and do this readme

768.8

except for open it in binary

777.12

and i'm going to do

780.24

read

782.079

and let's just do this

786

now let's see what it looks like if i

787.279

open up binary mode

788.76

[Music]

790.399

oh

791.92

there

794.16

now here we see it's got this little b

797.44

because basically it took all of that

798.8

stuff and now i can see

801.279

my line feeds

802.8

so this isn't a stream or it's not doing

804.72

the printable carry it's just taking the

806.079

whole thing

808.16

so now i could take

810.72

let's see

811.68

do i

812.839

have i don't have like a good binary

816.399

sitting around but

818.399

um i can open things like

821.36

executables or other binary files that

824.16

also means that i can do

826.56

let me just do this like so if i do

828.079

input

829.92

text

832.88

and then i just insert one two three

835.12

four five six seven eight nine ten or

837.279

zero

841.04

uh well i'm gonna let first let's see

842.88

what happens when i do a read

845.199

line

852.56

and so here

854.88

when i do the binary and i do the reline

858.079

it still recognizes my line

860.88

but

862.399

it's a binary string and it brings that

865.04

end line in there that line feed in

867.36

there

868.88

i can also do that

870.48

so like if i do let's take the same

872.24

thing and let's do

875.199

let's see what happens if i do the same

876.959

thing and i create a simple

880.079

i'm just going to call it a b file

882.16

instead of typing binary

884.56

well shoot i probably should just for

886.56

note sake

896.48

and i'm gonna do b

899.44

so let's see what that looks like

904.959

oh so here we go

907.519

binary mode does not take an encoding

909.36

argument oops sorry i forgot about that

912.32

i do that

916.32

because binary is straight binary

918.32

encoding is for strings

923.279

and so here what i'm going to see in the

926.16

simple binary file

927.839

when i do that

929.6

byteslate object like object is required

931.68

not a string so i can't send it a string

934.639

in this case

937.279

i could say um

940.399

let's just call it temp

941.92

equals

946.8

this

949.839

and write temp

952.399

and let's do it again temp equals this

962.8

and let's just bail out so let's not

964.56

append to it at this point we'll just do

966.079

that open it right so now

970.72

we run it we're gonna see again it's not

973.04

a string even though it's writing temp

974.639

it's a string it's not a bytes object

977.199

so instead

980.079

i can do this

989.839

and make it a bite

993.41

[Music]

998.32

and now it runs and so i've got this

1000

simple binary file

1001.759

created and if i do what did i call that

1004.88

test.text

1008.399

let's see it looks basically the same

1010.16

but now it's saying that this is bytes

1012

because i can also do

1016.16

the same thing

1017.6

and so now i could take a temp equals

1020.48

let's just get rid of this part

1028.559

and come to come three four and five

1030.079

against six so temp's now an array

1036.319

but it still doesn't like it as a list

1037.919

so i'd have to convert that over

1040.559

i don't think i can do it this simply

1044.64

i don't know because it's going to do

1045.679

that so

1051.44

if i do it like this it's going to treat

1052.96

it essentially it's going to say those

1054.4

are hard bites so it's going to

1056.64

yeah

1058.08

so if i test that yeah so i just have

1060.64

that

1062.16

it's a direct version of that but i

1064.48

could do bytes um

1066.96

i can do a byte array and and things

1068.64

like that where

1070.799

um

1072.08

i can write those out and i can write

1074.799

characters as needed into it so now i

1076.72

can actually get pretty specific with

1078.72

what i do um let's just do it same thing

1082.24

let's just do like temp equals 12.

1086.64

and let's whoop let's see what it says

1088.72

when i set an integer note

1091.12

integer doesn't count so i have to get

1093.2

it converted to bytes

1095.28

so i could probably do

1096.65

[Music]

1100.559

this

1101.52

two bytes

1104.4

and i need to give it a length so let's

1106.32

say a length of

1108.72

one

1113.76

and byte order i don't think i need that

1115.6

so let's see

1118.72

so if i do that

1121.6

oh i do need bite order

1125.039

and

1127.12

i don't know my bite order offhand

1132.559

let's just see what that does

1134.24

but what i can do is i can go in i'm not

1136.08

going to get too deep into it and this

1137.76

one uh mostly because of where i'm at oh

1140.08

it's either little or big oh big indian

1142.16

or little indian

1145.679

which

1148.4

there we go

1149.52

and so now

1151.12

oh if i look

1155.84

it's what is that test.text

1158.64

yes

1159.6

and so

1161.12

that's it's writing that character so i

1162.799

need something that's like

1164.48

let's do 68

1168.32

oh and that's just one that's the

1169.919

problem so it's like this two

1175.76

let's see what that does

1180.72

there okay

1182.08

so now

1184.559

it's creating it's a capital d because

1186.4

that is if you do a 68

1189.28

the ascii code 68 it's a d so it's

1193.28

converting that in for us as we look at

1195.84

the file

1197.84

but it's actually

1199.76

um

1202.799

you see this like null d as it's putting

1204.48

that space before it

1207.12

so you can play around with that and do

1209.2

binary reads and writes i think that was

1211.28

everything i really wanted to mess with

1214.72

you can also read into

1216.64

so i can do

1218.799

uh

1220.4

which basically is just going to push

1222.4

one value into another

1224.24

so if i do this

1227.919

i'm going to open it for read binary

1233.039

temp

1234.48

equals f dot read

1239.2

into

1243.76

oops it's not that way

1246.37

[Music]

1251.36

hmm

1253.039

uh let me do it this way

1254.88

i'm gonna copy and paste some stuff

1256.559

because it's easier that way so file

1258.32

name equals

1260.08

just that text so i have to create a

1262.72

byte array

1265.12

and oops i got import os

1269.28

because this is

1271.6

where i get obviously os.path

1274.24

and so i'm going to get the size of the

1275.679

file

1276.799

i'm going to open it as a read into

1280.4

i'm going to open it as f

1282.159

so this one's a little different instead

1283.6

of doing

1284.72

assigning it and then doing something

1286

with it i'm just going to say hey i'm

1287.28

going to grab it

1288.48

and i'm going to read

1290.88

into my buffer the file

1293.6

and then i'm gonna do

1295.2

print buffer

1297.76

and it's like i like it because it's a

1299.76

byte array

1301.2

i think

1306.24

no it does and so it just tells me that

1307.84

that is a bite array if i do a string i

1311.12

don't know if i can do a string of a

1312.159

bible right so find out in a minute

1316

uh

1317.6

yep

1319.52

so it doesn't really do much for me

1321.6

again

1323.12

uh where was that up here

1324.799

you can see so it's really it's that hex

1327.52

value

1328.64

uh it's a capital d because

1331.039

the ascii of 68 is a capital d so it's

1333.44

actually i'm seeing it

1335.76

converted into that string because of

1337.36

the output we're seeing here

1339.919

i think that's enough for now we've gone

1341.28

pretty deep into files it should allow

1342.96

you the basics of reading and writing

1344.32

and doing some stuff with them and

1346

understand what you need for this

1347.44

certification so

1349.44

we'll uh we'll call it a an episode for

1352

here

1352.72

and go out there and have yourself a

1354.08

great day a great week and we will talk

1356.24

to you

1357.28

next time

1373.12

you