Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: create_example_csv.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- This script creates an example CSV file ('example.csv') with sample data.
- Requirements:
- - Python 3.x
- Usage:
- 1. Save this script as 'create_example_csv.py'.
- 2. Run the script.
- Note: Adjust the 'example_filename' variable in the script as needed.
- """
- import csv
- def create_example_csv(filename):
- # Define the data to be written to the CSV file
- data = [
- ['Name', 'Age', 'City'],
- ['John Doe', 25, 'New York'],
- ['Jane Smith', 30, 'San Francisco'],
- ['Bob Johnson', 22, 'Los Angeles']
- ]
- # Write data to the CSV file
- with open(filename, 'w', newline='') as csvfile:
- csvwriter = csv.writer(csvfile)
- csvwriter.writerows(data)
- if __name__ == "__main__":
- # Set the filename for the example CSV file
- example_filename = 'example.csv'
- # Create the example CSV file in the current working directory
- create_example_csv(example_filename)
- print(f"Example CSV file '{example_filename}' created in the current working directory.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement