Thursday, March 17, 2022

file operations in python

 # -*- coding: utf-8 -*-

"""

Created on Wed Feb 23 06:55:56 2022


@author: durga

"""


# import os



# file1 = open("test123.txt")


# print(file1)


# file1 = open("img.jpg")


# print(file1)

# print(file1.read())


# file1 = open("employee_class.py")


# print(file1)

# print(file1.read())


# =============================================================================

# =============================================================================


# file2 = open("D:/python/Evening_batch/entry_test.py")

# print(file2)

# print(file2.read())


# =============================================================================

# file modes

# =============================================================================

# r = read default

# a = append mode

# w = write mode and opens also

# x = create  new



# file1 = open("test.txt",'r')

# print(file1)

# print(file1.read())



# file1 = open("test.txt",'a')

# print(file1)


file1 = open("test.txt",'w')

print(file1)


for i in range(100,200):

    file1 = open(f"test6{i}.txt",'x')

    print(file1)


#t= text default, text mode

#b= binary mode..(images)



# file1 = open("test.txt",'r')

# print(file1.read())




# file2 = open("D:/python/morning_class/test7.txt",'r')

# print(file2.read())


# file2 = open("D:/python/morning_class/test.txt",'r')

# print(file2.read(7))


# file2 = open("D:/python/morning_class/test.txt",'r')

# print(file2.read(10))


# =============================================================================

# readline()

# =============================================================================

# file2 = open("D:/python/morning_class/test.txt",'r')

# print(file2.readline())

# print(file2.readline())

# print(file2.readline())

# print(file2.readline())

# print(file2.readline())





# file2 = open("D:/python/morning_class/test.txt",'r')

# print(file2.readline(10))

# print(file2.readline(7))


# =============================================================================

# close the files

#variable.close()

# =============================================================================

file2 = open("D:/python/morning_class/test.txt",'r')

print(file2.readline(10))

# file2.close()

# print(file2.readline(10))



# =============================================================================

# write the extra lines

#variable.write()

# =============================================================================

file2 = open("D:/python/morning_class/test.txt",'a')

file2.write("extraline append to  nextline")


file2 = open("D:/python/morning_class/test.txt",'r')

print(file2.read())

file2.close()


#file2 = open("D:/python/morning_class/test.txt",'r')

print(file2.read())



file2 = open("D:/python/morning_class/test9.txt",'x')

file2.write("extraline append to  nextline")


# file2 = open("D:/python/morning_class/test9.txt",'r')

# print(file2.read())

# file2.close()



# a= dir(os)

# print(a)


#CRUD----create,read,update,delete

# os.remove("test7.txt")





abstract base class in python



# ========================================================================

# example 4

# ========================================================================

# Python program invoking a

# method using super()


import abc

from abc import ABC, abstractmethod


class A(ABC):

def fun1(self):

print("Abstract Base Class")


class K(A):

def fun2(self):

super().fun1()

print("subclass ")


# Driver code

r = K()

r.fun2()







# -*- coding: utf-8 -*-

"""

Created on Mon Mar  7 23:10:32 2022


@author: durga

"""


# Python program showing

# abstract base class work

# Python program showing

# abstract base class work


# from abc import ABC, abstractmethod


# class Animal(ABC):

# def move(self):

# pass


# class Human(Animal):

# def move(self):

# print("I can walk and run")


# class Snake(Animal):

# def move(self):

# print("I can crawl")


# class Dog(Animal):

# def move(self):

# print("I can bark")


# class Lion(Animal):

# def move(self):

# print("I can roar")

#

# # Driver code

# R = Human()

# R.move()


# K = Snake()

# K.move()


# R = Dog()

# R.move()


# K = Lion()

# K.move()






# from abc import ABC, abstractmethod


# class Polygon(ABC):


# @abstractmethod

# def noofsides(self):

# pass


# class Triangle(Polygon):


# # overriding abstract method

# def noofsides(self):

# print("I have 3 sides")


# class Pentagon(Polygon):


# # overriding abstract method

# def noofsides(self):

# print("I have 5 sides")


# class Hexagon(Polygon):


# # overriding abstract method

# def noofsides(self):

# print("I have 6 sides")


# class Quadrilateral(Polygon):


# # overriding abstract method

# def noofsides(self):

# print("I have 4 sides")


# # Driver code

# R = Triangle()

# R.noofsides()


# K = Quadrilateral()

# K.noofsides()


# R = Pentagon()

# R.noofsides()


# K = Hexagon()

# K.noofsides()






# Python program showing

# implementation of abstract

# class through subclassing


# import abc


# class parent:

# def geeks(self):

# pass


# class child(parent):

# def geeks(self):

# print("child class")


# # Driver code

# print( issubclass(child, parent))

# print( isinstance(child(), parent))







# Python program showing

# abstract properties


import abc

from abc import ABC, abstractmethod


class parent(ABC):

@abc.abstractproperty

def geeks(self):

return "parent class"

class child(parent):

@property

def geeks(self):

return "child class"


try:

r =parent()

print( r.geeks)

except Exception as err:

print (err)


r = child()

print (r.geeks)

c# variables


using System;

namespace HelloWorld

{


    public class lecture

    {

        public int age;//This is the variable type of integer


        //entry point of the our program

        public static void Main(string[] args)

        {

            int age = 15;

            string name = "srilatha";

            float p = 15.4f;

            bool is_working = true;

            char c = 'a';



            Console.WriteLine(age);

            Console.WriteLine(name);

            Console.WriteLine(p);

            Console.WriteLine(c);

            Console.WriteLine(is_working);



            Console.Read();

        }

    }

}




output:

15

srilatha

15.4

a

True

python class topic video