How to Create and Delete a file in Python?
DATA MUNGING DATA CLEANING PYTHON MACHINE LEARNING RECIPES PANDAS CHEATSHEET     ALL TAGS

How to Create and Delete a file in Python?

How to Create and Delete a file in Python?

This recipe helps you Create and Delete a file in Python

0
This data science python tutorial does the following: 1. Imports the necessary libraries for file handling. 2. Creates a new file and writes into it. 3. Opening the existing file and reading from the file. 4. Deleting the created file.
In [1]:
## How to Create and Delete a file in Python
def Kickstarter_Example_54():
    print()
    print(format('How to create and Delete a file in Python','*^82'))
    import warnings
    warnings.filterwarnings("ignore")

    import os
    # Create a file if it doesn't already exist
    with open('file.txt', 'xt') as f:
        # Write to the file
        f.write('This is a New File. Just Created!')
        # Close the connection to the file
        f.close()
    # Open The File And Read It
    with open('file.txt', 'rt') as f:
        # Read the data in the file
        data = f.read()
        # Close the connection to the file
        f.close()
    # View The Contents Of The File
    print(data)

    # Delete The File
    os.remove('file.txt')
Kickstarter_Example_54()
********************How to create and Delete a file in Python*********************
This is a New File. Just Created!

Relevant Projects

Human Activity Recognition Using Smartphones Data Set
In this deep learning project, you will build a classification system where to precisely identify human fitness activities.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Predict Credit Default | Give Me Some Credit Kaggle
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

Sequence Classification with LSTM RNN in Python with Keras
In this project, we are going to work on Sequence to Sequence Prediction using IMDB Movie Review Dataset​ using Keras in Python.

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Forecast Inventory demand using historical sales data in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

Choosing the right Time Series Forecasting Methods
There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

Resume parsing with Machine learning - NLP with Python OCR and Spacy
In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.