Ok so I was working on file handling, nothing special just making new (.txt) files and putting some text in it. That works fine the problem is that when I try to read the file from within python nothing comes up and when I try to open the file once I close it from python it has all this weird letters along with what i wrote in that file. I know this doesn't make sense at all so here is an example of what is going on.

new_file = open("Test.txt", "w")
new_file.write("Hello World")
print new_file.read()
new_file.close()

Ok so thats what I wrote into the IDlE, the first problem is that when I ask python to print what I wrote into that file, I dont get anything back just a blank line. Then when I go and check the new file this is what I get :


Hello World ¦’{á ª ù° §xÝã 4¶ ðF¸ ±ß) ‹œ p| ³(Êî`ü¶ 0Ḡµ kv€™ §™ Í3 x• x• ¸²Ê+ b¹ ð¹ »îí'(üº ð¹ ½š½ø„§ ð¹¾Z->`º Pžº ÂvÙÈw· °X· ÄÊú¬à|ž ÷° ÆÞ;0R§ ð¹ Èùoˆ&· ð¹É›ÀȘ ð¼™ ÐD[| {ž °
¨ Ô¬Ð0n¸ 0æ¸ × Ö J˜ P ÙŽú< – €K— Û¬å "· ð¹ â"±„`¬› 0œ ã&¯Ö'² ps¨ å^Á×`|ž %Ÿ æò÷@О ÐE§ èür¼0ùž ð¹ ë"
uX™ž E§ òœ÷˜ ¹ 𕹠ߙÌO h¸ ðN¸ ûNrÎà°¨ |¨ üîĨ L— P™ ýFylà™µ °é¶ ß\Šç´ °µ uráàlº ð¹ Y®œ } ¥ ÿäXÄ– ð– ¯êÆ ¤› P| ‘ê ôª ð7¶ f¹ôž ð¹ !ÓP¹ F¹ $½(oͳ ð¹ )WÂ@A— ™ +'£] %Ÿ Ð%Ÿ ,y0€º ðк /m>³‰ © ÞŠv@Á˜ §™ ;ñYÝ· ð¹<_Õ`nº ð¹=Íì – ð¹ Bhk€7¶ 0è¶ I93•°± üª #7€M˜ PM˜ VwMÚÀ ¹ ð¹ ]ßàpÀ§ ð¹ _÷1+ ?¶ 0ච`ã8`§› °¨› fÃhk@ª ð]² gY3
ÀO— ȼž kÕã´Ðn² ð¹ pC4¿ˆAº ð¹q¹ÄÔàóž ð¹ u1¯æ°ü™ s xAŒ}ø¤— pG— yYP˜ˆ† ðž ƒmÔ®Àö° Ðø° „Un,à™ ð£› …Si8† p¥ ‰WÒ º PÓº ™Š
 œ Ðrž ’Ó¡°ñ¹ ݺ —£‹' K— pK— ›ÙÈ4 L¨ ð¹ ¢Ç1Øöº Öº FHJH¿¶ ð¹ òÜÎV`ûž ð¹ I‹gÀ ¼çf( À˜ 0™ À–`Ÿ ð¹ Â?jÀ@™ а™ Û½œ@%Ÿ 0+Ÿ ÇóŒXàwž °wž È_Ëò §œ ð¹ ÈŠ°¸¨‰– ð– ÐU¥ÞàÖ– °Ö– ÑK‘H•¨ ð¹ ÕûŒFØK¨ pu¨ Ö³,²È³ °Ô³ ùKˆÏ ¶ ð¹ ¥ÏèÚ°#» ð¹ Þ £› ¨› ¥Á…û`D² °Z² §°†¯à ¹ °N¹ ìE‰¡ zž Ðyž í3´  ± V± ñ«ÿC@“ž 0yž ÷‡=ü |ž °Õž

Recommended Answers

All 4 Replies

Line four didn't get you anything? You should've gotten an IO error; you're not supposed to read from files you open for writing. If even you had opened the file as w+, you still should've gotten that blank line, because of the position you are in the file (past what you have written). Files are sequential.

As to that junk text, I have no idea what's going on there.

Well that was very simple i feel so dumb

Is everything okay now?

yea thank for the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.