SlideShare a Scribd company logo
Python for Ethical Hackers
Mohammad reza Kamalifard
Python Language Essentials
Module 2: System Programming
Part 1 :
File Handling
File I/O in Python
open (file_name,access_mode,buffering)
read(byte_count)
write(data)
close()
os.rename()
os.remove()
File access modes
r
Opens a file for reading only. The file pointer is placed at
the beginning of the file. This is the default mode.
w
Opens a file for writing only. Overwrites the file if the file
exists. If the file does not exist, creates a new file for
writing.
a
Opens a file for appending. The file pointer is at the end of
the file if the file exists. That is, the file is in the
append mode. If the file does not exist, it creates a new file
for writing.
Full list :
http://www.tutorialspoint.com/python/python_files_io.htm
Creating File
>>> file = open('pysec.txt', 'w')
>>> file
<open file 'pysec.txt', mode 'w' at 0x7f3e7c8dc4b0>
>>> for count in range(0,100):
... file.write(str(count) + 'n')
...
>>> file.close()
>>>
$ cat pysec.txt
0
1
2
3
4
5
6
7
.
.
.
93
94
95
96
97
98
99
Append to File
>>> file = open('pysec.txt', 'a')
>>> file
<open file 'pysec.txt', mode 'w' at 0x7f3e7c8dc4b0>
>>> for count in range(100,200):
... file.write(str(count) + 'n')
...
>>> file.close()
>>>
$ cat pysec.txt
0
1
2
3
4
5
.
.
.
191
192
193
194
195
196
197
198
199
read file
>>> file = open('pysec.txt','r')
>>> for line in file.readlines():
... print line.strip()
...
0
1
2
3
4
.
.
196
197
198
199
rename file and remove file
>>> import os
>>> os.rename('pysec.txt', 'pysec101.txt')
>>>
$
$ ls
code pysec101.txt pres_file handling.txt
os.remove(file_name)
>>> import os
>>>os.remove('pysec101.txt')
$
$ ls
code pres_file handling.txt
This work is licensed under the Creative Commons
Attribution-NoDerivs 3.0 Unported License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/3.0/
Copyright 2013 Mohammad reza Kamalifard.
All rights reserved.

More Related Content

PDF
File operations
PPTX
Python data file handling
DOC
Uop pos 433 week 4 file processing commands worksheet new
PDF
Workshop programs
PPT
Essential UNIX skills for biologists
PPTX
File accessing modes in c
PDF
Files in c
File operations
Python data file handling
Uop pos 433 week 4 file processing commands worksheet new
Workshop programs
Essential UNIX skills for biologists
File accessing modes in c
Files in c

What's hot (15)

PPTX
Programming in C
DOCX
Linux midterm quiz
DOC
PDF
Fun with python
PPT
File handling-dutt
PDF
AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)
PPT
File management and handling by prabhakar
PDF
2Bytesprog2 course_2014_c1_sets
PPT
Unix Basics 04sp
PDF
cs3157-summer06-lab1
PPTX
Code tacoma command_line
PDF
2 × 3 = 6
PPTX
Command Line Awesome, WordCamp Grand Rapids 2014
PDF
2Bytesprog2 course_2014_c4_binaryfiles
PPT
Filing system in PHP
Programming in C
Linux midterm quiz
Fun with python
File handling-dutt
AVTOKYO2013.5 Detail of CVE-2013-4787 (Master Key Vulnerability)
File management and handling by prabhakar
2Bytesprog2 course_2014_c1_sets
Unix Basics 04sp
cs3157-summer06-lab1
Code tacoma command_line
2 × 3 = 6
Command Line Awesome, WordCamp Grand Rapids 2014
2Bytesprog2 course_2014_c4_binaryfiles
Filing system in PHP
Ad

Viewers also liked (7)

PDF
جلسه سوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PDF
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
PDF
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
PDF
Tehlug 26 Nov 2013 Hackers,Cyberwarfare and Online privacy
PPTX
Raccoon rabies
PPTX
Iht spt ppn_23022012
PPT
Lecture04 abap on line
جلسه سوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
Tehlug 26 Nov 2013 Hackers,Cyberwarfare and Online privacy
Raccoon rabies
Iht spt ppn_23022012
Lecture04 abap on line
Ad

Similar to اسلاید دوم جلسه هفتم کلاس پایتون برای هکرهای قانونی (20)

PPTX
Chapter 08 data file handling
PPTX
Data File Handling in Python Programming
PPT
Python file handlings
PPTX
DFH PDF-converted.pptx
PPTX
file handling in python using exception statement
PPTX
File Handling Python
PPTX
Python programming file handling mhhk.pptx
PPT
File Handling as 08032021 (1).ppt
PPTX
FILE HANDLING in python to understand basic operations.
PPTX
Python-FileHandling.pptx
PDF
CHAPTER 2 - FILE HANDLING-txtfile.pdf is here
PPTX
pp5-filehandling- python 200824063109 (1).pptx
PDF
03-01-File Handling.pdf
PDF
Python Files I_O17.pdf
PPTX
File handling & basic operation on file in python
PPTX
Chapter - 5.pptx
PPTX
this is about file concepts in class 12 in python , text file, binary file, c...
PPTX
File handling in Python
PPTX
FILE HANDLING COMPUTER SCIENCE -FILES.pptx
PPT
Python File functions
Chapter 08 data file handling
Data File Handling in Python Programming
Python file handlings
DFH PDF-converted.pptx
file handling in python using exception statement
File Handling Python
Python programming file handling mhhk.pptx
File Handling as 08032021 (1).ppt
FILE HANDLING in python to understand basic operations.
Python-FileHandling.pptx
CHAPTER 2 - FILE HANDLING-txtfile.pdf is here
pp5-filehandling- python 200824063109 (1).pptx
03-01-File Handling.pdf
Python Files I_O17.pdf
File handling & basic operation on file in python
Chapter - 5.pptx
this is about file concepts in class 12 in python , text file, binary file, c...
File handling in Python
FILE HANDLING COMPUTER SCIENCE -FILES.pptx
Python File functions

More from Mohammad Reza Kamalifard (20)

PDF
PDF
Introduction to Flask Micro Framework
PDF
Pycon - Python for ethical hackers
PDF
جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PDF
جلسه چهارم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PDF
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
PDF
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
PDF
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PDF
جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
PDF
اسلاید اول جلسه اول دوره پاییز کلاس پایتون برای هکرهای قانونی
PDF
اسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونی
PDF
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
PDF
اسلاید ارائه دوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
PDF
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
PDF
اسلاید ارائه سوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
PDF
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
PDF
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی
PDF
اسلاید سوم جلسه هفتم کلاس پایتون برای هکرهای قانونی
PDF
اسلاید اول جلسه هفتم کلاس پایتون برای هکرهای قانونی
PDF
اسلاید اول جلسه پنجم کلاس پایتون برای هکرهای قانونی
Introduction to Flask Micro Framework
Pycon - Python for ethical hackers
جلسه دوم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه چهارم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه پنجم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۲
جلسه هفتم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
جلسه اول پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲
اسلاید اول جلسه اول دوره پاییز کلاس پایتون برای هکرهای قانونی
اسلاید دوم جلسه یازدهم کلاس پایتون برای هکر های قانونی
اسلاید اول جلسه یازدهم کلاس پایتون برای هکرهای قانونی
اسلاید ارائه دوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه سوم جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی
اسلاید سوم جلسه هفتم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه هفتم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه پنجم کلاس پایتون برای هکرهای قانونی

Recently uploaded (20)

PDF
Classroom Observation Tools for Teachers
PDF
01-Introduction-to-Information-Management.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
master seminar digital applications in india
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Pre independence Education in Inndia.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Classroom Observation Tools for Teachers
01-Introduction-to-Information-Management.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Week 4 Term 3 Study Techniques revisited.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Supply Chain Operations Speaking Notes -ICLT Program
PPH.pptx obstetrics and gynecology in nursing
O5-L3 Freight Transport Ops (International) V1.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
master seminar digital applications in india
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Pre independence Education in Inndia.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf

اسلاید دوم جلسه هفتم کلاس پایتون برای هکرهای قانونی

  • 1. Python for Ethical Hackers Mohammad reza Kamalifard
  • 2. Python Language Essentials Module 2: System Programming Part 1 : File Handling
  • 3. File I/O in Python open (file_name,access_mode,buffering) read(byte_count) write(data) close() os.rename() os.remove()
  • 4. File access modes r Opens a file for reading only. The file pointer is placed at the beginning of the file. This is the default mode. w Opens a file for writing only. Overwrites the file if the file exists. If the file does not exist, creates a new file for writing. a Opens a file for appending. The file pointer is at the end of the file if the file exists. That is, the file is in the append mode. If the file does not exist, it creates a new file for writing. Full list : http://www.tutorialspoint.com/python/python_files_io.htm
  • 5. Creating File >>> file = open('pysec.txt', 'w') >>> file <open file 'pysec.txt', mode 'w' at 0x7f3e7c8dc4b0> >>> for count in range(0,100): ... file.write(str(count) + 'n') ... >>> file.close() >>>
  • 7. Append to File >>> file = open('pysec.txt', 'a') >>> file <open file 'pysec.txt', mode 'w' at 0x7f3e7c8dc4b0> >>> for count in range(100,200): ... file.write(str(count) + 'n') ... >>> file.close() >>>
  • 9. read file >>> file = open('pysec.txt','r') >>> for line in file.readlines(): ... print line.strip() ... 0 1 2 3 4 . . 196 197 198 199
  • 10. rename file and remove file >>> import os >>> os.rename('pysec.txt', 'pysec101.txt') >>> $ $ ls code pysec101.txt pres_file handling.txt os.remove(file_name) >>> import os >>>os.remove('pysec101.txt') $ $ ls code pres_file handling.txt
  • 11. This work is licensed under the Creative Commons Attribution-NoDerivs 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/3.0/ Copyright 2013 Mohammad reza Kamalifard. All rights reserved.