file handling in the python

technical talkiess
0
print("File mode in the python")
"""
"r"- reading  the file --- default
"w" - writing the file in python
"t" - text mode in the file --- default
"X" - file is not exist then create
a - add file content to the last of the file
b- binary mode in the python file
+ - read plus write the file in the python
"""


f = open("Untitled-1.txt")
# read the file
# content = f.read()
# if you want some specific range of data so then you can simply pass the function in the key
# content = f.read(3)  #its return only 3 character

# if you want to next 3 element then pass the same function with key
# content = f.read(3)  #its return only 3 character
# print(content)

# if you want to iterate the data of the file so you can use the loop in the pythoon.... all

# for line in f:
#     print(line)

# agar apko only one line chaiye to aap readline function use kar sakte hai

# content = f.readline()

# agar apko puri line chaiye to aap readlines karke function hai wo use kar sakte hai .... aur ye list return karta hai

# content = f.readlines()

# content agar apko specific range me data chaiye to aap .... agar isme data kam hoga to pura data return karena is range ka aur nice awale me blank ayenga
content = f.read(344444)
print("1",content)

content = f.read(344444)
print("2",content)

f.close() 

Tags

Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)