0
files<br />
To open file>>><br />>>x=open(‘file path’)<br />And we have two kind of paths :<br />*Absolute path (whish start with (/) ...
Read mode:<br />*read()   >>read hall the file >>one string<br />**readline() >>read file line by line >> one line of text...
F:ww.txt<br />
Hint :<br />>> x.read(6)<br />
seek<br />To move the pointer fellow the text >>>><br />x.seek(num. of  liters , mode)<br />3 mode using with seek ( 0 , 1...
Example:<br />a.txt file contain   (abcdef)<br />print the liter from :<br /><ul><li>a > b
c >f
a >f     ???/</li></li></ul><li>
write mode:<br /> the file contains (abcdef) before open  to write in it …<br />x= open (‘ww.txt’,’w’)<br />the file  beco...
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 cha...
append mode:<br />هو أيضا يستخدم في الكتابة بداخل الملفات لكن لا يتم مسح بيانات الملفات كلها قبل البدء في كتابة بيانات جدي...
Why ???<br />
Again ::<br />To open file we write <br />X=open(‘file location’ ,  ‘mode of open’  ,’buffer’)<br />Mode of buffering<br /...
x.flush() <br />data in buffer  >>  x.flush()   >> store in hard  <br />
x.close ()    >>>     flushing  before close file <br />
Upcoming SlideShare
Loading in...5
×

Py2(Files)

287

Published on

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

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

No notes for slide

Transcript of "Py2(Files)"

  1. 1. files<br />
  2. 2.
  3. 3. 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 />
  4. 4. 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 />
  5. 5. F:ww.txt<br />
  6. 6.
  7. 7.
  8. 8.
  9. 9. Hint :<br />>> x.read(6)<br />
  10. 10. 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 />
  11. 11. Example:<br />a.txt file contain (abcdef)<br />print the liter from :<br /><ul><li>a > b
  12. 12. c >f
  13. 13. a >f ???/</li></li></ul><li>
  14. 14. 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 />
  15. 15. 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 />
  16. 16. append mode:<br />هو أيضا يستخدم في الكتابة بداخل الملفات لكن لا يتم مسح بيانات الملفات كلها قبل البدء في كتابة بيانات جديدة <br />فقط يقوم بإضافة البيانات الجديدة إلى نهاية الملف بالترتيب ...<br />Ex: add (gklmno) to the ww.txt file ??<br />
  17. 17. Why ???<br />
  18. 18. 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 />
  19. 19. x.flush() <br />data in buffer >> x.flush() >> store in hard <br />
  20. 20. x.close () >>> flushing before close file <br />
  21. 21. good luck !<br />By/ salma subh<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×