Python create file - File I/O with documentation


Python-file I/O


Python file create  is use create a file. You can create is file more than 100.file.

You can also write any text in file. you can edit file like rename,edit file extension. Python file has many more function syntax and method.

1 Write - write a file

2 Writeline - write onle one line

3 Read -  read a file

4 Readline - reada only one line

5 with open(filename,mode)aas e:

6 mode - there is many mode they are r for read, w for write, a for append , wb for write                       binary, rb for read binary and b for binary etc..

yourper = open("sampleme.txt","r")
data =
f = open("another.txt","w")
f.write(" now stop me")

How to find any specific word from wordlist.

It is a true difficult to human to find specific word from wordlist. Thats why we use python.

content = True
i = 1
with open("log.txt") as f:
    while content:
        content = f.readline()
        if "python" in content.lower():
            print("python is present")

First we define a content is true and i is 1. I is use to print line number of word which we find. Open that file or wordlist using read mode means r.

Note: readmode is automatically detect if mode is blank. this program mode is blank and mode it is automatically detect read mode.

Use a while content condition. Your file.txt or wordlist is readline. readline is read only one line. Find python from content means log.txt or yourfile.if find python than print python is present and print i means line number of python. 

Import file from one program to another program

def greet(name):
    print(f"good morning{name}")

if __name__ == "__main__":
    any = input("enter your name")

It is small program

import m_file1

it is upload.

Next teasure for Object Orinted Programming.

It is also known as OOPs. OOPs is stand for object orinted programming. It is make code readable. It is optional to use your program. If you not use OOPs in your program your program is not readable and hard to update your program. There is many function, method and decorator. Such fuction method and decorators are:

1 Getter and Setter (Getter is also known as proporty decorators.)

2 super (It is use to call super class variable and instance variable.)

3 static (It is doesnot use self method. Its run its own function and variable.)

4 self (It mean i,me.)

5 cls (cls means class method.)

6 abstrac class (abstract all class is use to define same fuction to all class.)

Post a Comment