• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Py2(Files)
 

Py2(Files)

on

  • 511 views

 

Statistics

Views

Total Views
511
Views on SlideShare
510
Embed Views
1

Actions

Likes
1
Downloads
0
Comments
0

1 Embed 1

http://www.slideshare.net 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Py2(Files) Py2(Files) Presentation Transcript

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