Posts

Showing posts from May, 2020

Django Model Module

Image
Django - " models.Model " Module in Python In Django, a model is a class which is used to contain essential fields and methods. Each model class maps to a single table in the database. Django Model is a subclass of  django.db.models.Model  and each field of the model class represents a database field (column). Django provides us a database-abstraction API which allows us to create, retrieve, update and delete a record from the mapped table. Model is defined in  Models.py  file. This file can contain multiple models. Let's see an example here, we are creating a model  Employee  which has two fields  first_name  and  last_name . Example: from django.db import models   class Employee(models.Model):       first_name = models.CharField(max_length=30)       last_name = models.CharField(max_length=30)  The  first_name  and  last_name  fields ar...

OS Module

Image
OS Module  in Python with Examples The OS module in python provides functions for interacting with the operating system. OS, comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality. The *os* and *os.path* modules include many functions to interact with the file system. It is possible to automatically perform many operating system tasks. The OS module in Python provides functions for creating and removing a directory (folder), fetching its contents, changing and identifying the current directory, etc. 1. os.name:  This function gives the name of the operating system dependent module imported. The following names have currently been registered: ‘posix’, ‘nt’, ‘os2’, ‘ce’, ‘java’ and ‘riscos’. import os  print(os.name) Output in Windows: nt Output in Mac: posix 2. os.getcwd():   Function os.getcwd(), returns the Current Working D...