Note that there are some explanatory texts on larger screens.

plurals
  1. POUnexpected file behavior python
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/13083183/weird-behavior-when-writing-and-reading-file">Weird behavior when writing and reading file</a> </p> </blockquote> <p>When I try to write into a file and then read it, I get an unexpected result.</p> <p>My code is:</p> <pre><code>f=open("z.txt","w+") f.write("Hello") content=f.read() print content f.close() </code></pre> <p>The outputted file is:</p> <blockquote> <p>Hellolף  ן (I11 (S'QUEUE' p1 (S'exec' p2 S'runcode' p3 (cidlelib.rpc unpickle_code p4 (S'c\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00@\x00\x00\x00s6\x00\x00\x00e\x00\x00d\x00\x00d\x01\x00\x83\x02\x00Z\x01\x00e\x01\x00j\x02\x00d\x02\x00\x83\x01\x00\x01e\x01\x00j\x03\x00\x83\x00\x00Z\x04\x00e\x01\x00j\x05\x00\x83\x00\x00\x01d\x03\x00S(\x04\x00\x00\x00s\x05\x00\x00\x00z.txts\x02\x00\x00\x00w+t\x05\x00\x00\x00HelloN(\x06\x00\x00\x00t\x04\x00\x00\x00opent\x01\x00\x00\x00ft\x05\x00\x00\x00writet\x04\x00\x00\x00readt\x07\x00\x00\x00contentt\x05\x00\x00\x00close(\x00\x00\x00\x00(\x00\x00\x00\x00(\x00\x00\x00\x00s\x17\x00\x00\x00C:/Users/x/Desktop/zt\x08\x00\x00\x00\x01\x00\x00\x00s\x06\x00\x00\x00\x0f\x01\r\x01\x0c\x01' tRp5 tp6 (dp7 ttp8 tp9 . ‘2ר ְ ז׀l Ak !<br> €qg ¸Ck PCk $ ְBkאBkנBk 8Ck<br> xCk XBkxBk °Ck׀CkנCkDk<br> @‘ (Ck˜Ck kצ Ck Ck<br> ְpg DkDֽ˜F ! €qg + ˜Ck<br> (Dk @k @k xDk ר?k @f HDkhDkpDk ˜Dk<br> נDkEk0EkPEk ְ” kצ<br> ְpg ! ˜F ,<br> ״Dk </p> <pre><code>@k @k ר?k </code></pre> </blockquote> <p>What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload