python - Why does os.path.getsize give me the wrong size? -
I have a small HTML file named home.html
that I'm serving , And I found out that the os.path.getsize ('home.html') returns a different number from
len (open ('home.html'). Read ())
. The number given by os.path.getsize
is 925, while the number given by lane
is 910. I know 910 is the correct number and not 925 because the page will not show the use of chrome using 925, but it uses 910 completely. Can anyone tell me what is going wrong?
inb4 I do not think this is a unicode thing, because I'm on windows, I'm using Python 2.7, the result of file.read
/ Code> not a unicode
object, and all the characters in my HTML are ASCIII here is the content of home.html
:
& Lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Body style = "text-align: center;" & Gt; & Lt; A href = "https://github.com/ChrisCalderon/Yashttpd" & gt; & Lt; Img style = "position: full; top: 0; right: 0; range: 0;" src = "https://camo.githubusercontent.com/a6677b08c955af8400f44c6298f40e7d19cc5b2d/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67" alt = "I fork" data-oracles on GitHub src = "https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png" & Gt; & Lt; / A & gt; & Lt; H1 & gt; ECoO server & lt; / H1> & Lt; P & gt; The requests are then parsed: & lt; / P & gt; & Lt; Iframe src = "echo" style = "border: none; width: 40%; height: 325 px;" Scroll = "off" & gt; If you see the text, then your browser does not support iframe! & Lt; / Iframe & gt; & Lt; P & gt; The entire code for this site & lt; A href = "myhandler.html" & gt; Here & lt; / A & gt; & Lt; / P & gt; & Lt; P & gt; All of this is made with Yashttpd by clicking on the above ribbon, find it in my GitHub repository! & Lt; / P & gt; & Lt; / Body & gt; & Lt; / Html & gt;
Edit: I would like to mention that os.path.getsize
was working to serve my favicon.ico file correctly.
The file has 15 lines and you can type the size of disk and size The difference between the middle 15 is in memory on the line, the line end is the sequence "\ r \ n"
, but when you read it (unless you open the file Do not use binary mode) Python (or underlying functionality) changes those sequences that line the python end only "\ n"
.
Both values are correct:
- The file is 925 bytes long on the disk end with
\ r \ n
- The file ended with a long time in memory 910 byte memory, with the lines being
\ n
only
Comments
Post a Comment