Your SlideShare is downloading. ×
0
Py2(Files)
Py2(Files)
Py2(Files)
Py2(Files)
Py2(Files)
Py2(Files)
Py2(Files)
Py2(Files)
Py2(Files)
Py2(Files)
Py2(Files)
Py2(Files)
Py2(Files)
Py2(Files)
Py2(Files)
Py2(Files)
Py2(Files)
Py2(Files)
Py2(Files)
Py2(Files)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Py2(Files)

285

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
285
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  1. files<br />
  2. To open file>>><br />>>x=open(‘file path’)<br />And we have two kind of paths :<br />*Absolute path (whish start with (/) in dos and() in Linux ) <br />And* relative path ( if you already in directory )<br />Example:<br />/home/aa/a.txt >>>>> absolute path<br />a.txt >>>>>relative path <br />
  3. Read mode:<br />*read() >>read hall the file >>one string<br />**readline() >>read file line by line >> one line of text<br />***readlines() >> read all lines of text in one times >> list every item represent line of text <br />Example:<br />Let we have the flowing text in ((ww.txt ))file :<br />
  4. F:ww.txt<br />
  5. Hint :<br />>> x.read(6)<br />
  6. seek<br />To move the pointer fellow the text >>>><br />x.seek(num. of liters , mode)<br />3 mode using with seek ( 0 , 1 , 2) <br /> 0 >> from the beginning <br />1 >> from the current position<br />>> from the end of the file <br />Example:<br />x.seek(2 ,1)<br />Move pointer from the current position to 2 liters forward >><br />x.seek(-4,2)<br />Move pointer from the end of the file 4 liter backward <<<br />
  7. Example:<br />a.txt file contain (abcdef)<br />print the liter from :<br /><ul><li>a > b
  8. c >f
  9. a >f ???/</li></li></ul><li>
  10. write mode:<br /> the file contains (abcdef) before open to write in it …<br />x= open (‘ww.txt’,’w’)<br />the file become empty >>><br />and ready to over write in it<br />>>ss =x.write(‘ff’)<br />>>print ss<br />>>ff<br />>>ss=x.write(‘hh’)<br />>>print ss<br />>>ffhh <br />
  11. Ex: in ww.txt replace ( a )by( aaaa)??<br />1- open file<br />2-read file<br />3-replase (a) by (aaaa)<br />4-save the change and close the file<br />5-open file and write the new data <br />
  12. append mode:<br />هو أيضا يستخدم في الكتابة بداخل الملفات لكن لا يتم مسح بيانات الملفات كلها قبل البدء في كتابة بيانات جديدة <br />فقط يقوم بإضافة البيانات الجديدة إلى نهاية الملف بالترتيب ...<br />Ex: add (gklmno) to the ww.txt file ??<br />
  13. Why ???<br />
  14. Again ::<br />To open file we write <br />X=open(‘file location’ , ‘mode of open’ ,’buffer’)<br />Mode of buffering<br />عند تعديل الملف فإن البيانات المعدلة لا يتم تخزينها أو كتابتها مباشرة في ال وبالتالي نقوم بتحديد عدد الأحرف التي بعدها سوف يتم التخزين فية (أرسال البيانات )... <br />hard<br /> 0 >> write direct in hard <br />-1 >> operating system control the buffering <br />Any number >> user take the decision about buffering<br />
  15. x.flush() <br />data in buffer >> x.flush() >> store in hard <br />
  16. x.close () >>> flushing before close file <br />
  17. good luck !<br />By/ salma subh<br />

×