Interfacing with a database

Slides:



Advertisements
Similar presentations
IRRA DSpace April 2006 Claire Knowles University of Edinburgh.
Advertisements

Alternative FILE formats
Meetings A hole in your day? … or an essential contributor to the corporate knowledge base? Copyright Elton Grant Ltd 2011.
Last Week Looping though lists Looping using range While loops.
Pasewark & Pasewark 1 Access Lesson 6 Integrating Access Microsoft Office 2007: Introductory.
1 Access Lesson 6 Integrating Access Microsoft Office 2010 Introductory Pasewark & Pasewark.
1 Lesson 22 Getting Started with Access Essentials Computer Literacy BASICS: A Comprehensive Guide to IC 3, 3 rd Edition Morrison / Wells.
A Web-based Item Bank Search, View, and Select Items for Saving, Editing, and Printing (online testing available too) - Multiple.
Python File Handling. In all the programs you have made so far when program is closed all the data is lost, but what if you want to keep the data to use.
Word Processing Notes: Mail Merge Understand business documents.2 Mail Merge Example Letter shows Merge Fields (placeholders) Letter is Personalized.
Lesson 17 Getting Started with Access Essentials
Relational Databases (MS Access)
CREATING TEMPLATES CREATING CUSTOM CHARACTERS IMPORTING BATCH DATA SAVING DATA & TEMPLATES CREATING SERIES DATA PRINTING THE DATA.
Lesson 1: Exploring Access Learning Objectives After studying this lesson, you will be able to: Start Access and identify elements of the application.
DATABASE What exactly is a database How do databases work? What's the difference between a spreadsheet database and a "real" database?
Working With Files. Sources of Data Adding data to a spreadsheet can be done in several ways, including: – Type it in piece by piece – Read it from a.
Planning.Maryland.gov 2010 C ENSUS S UMMARY F ILE 1 D ATA E NGINE MD State Data Center Affiliate meeting December 10, 2012.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 18 Using text files to share data with other programs 5/07/09 Python Mini-Course:
Database Management Systems (DBMS)
MySQL Importing and creating a database. CSV (Comma Separated Values) file CSV = Comma Separated Values – they are simple text files containing data which.
Files Tutor: You will need ….
HACC Data Repository Using System Reports in the HACC Data Repository August, 2013.
Python focus – files The open keyword returns a file object Opening a file myFile = open('C:\file.txt', arg) Optional argument The second argument controls.
Database (Microsoft Access). Database A database is an organized collection of related data about a specific topic or purpose. Examples of databases include:
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 10: Files.
Edexcel OnCourse Databases Unit 9. Edexcel OnCourse Database Structure Presentation Unit 9Slide 2 What is a Database? Databases are everywhere! Student.
Introduction to EBSCOhost
Spreadsheets.
Introduction to Arrays
Creates the file on disk and opens it for writing
Database Systems Unit 16.
Final Project: Read from a csv file and write to a database table
CSV Classic format Comma Separated Variables (CSV). Easily parsed.
Title Slide Title slide: Add notes here..
Results Introduction Conclusion Participants Data Analysis
Lesson 4: Advanced Transforms
Python I/O.
File Handling Programming Guides.
CSV File Manipulation.
GCSE Computing Databases.
Manipulating Arrays.
Learning Outcomes –Lesson 4
File Handling.
Creates the file on disk and opens it for writing
Data Structures – 1D Lists
Lesson 4: Advanced Transforms
Mini Python Project Lesson 3.
Lesson 4: Advanced Transforms
Chapter 11 Data Structures.
Lists in Python Outputting lists.
Lesson 4: Advanced Transforms
How to save information in files open, write, close
Strings and Serialization
Suppose I want to add all the even integers from 1 to 100 (inclusive)
funCTIONs and Data Import/Export
Files Handling In today’s lesson we will look at:
Introduction to EBSCOhost
Python Lesson’S 1 & 2 Mr. Kalmes.
To understand what arrays are and how to use them
YOUR text YOUR text YOUR text YOUR text
2d Arrays.
Python 16 Mr. Husch.
Guided Lesson Working with Columns.
Just Basic Lessons Mr. Kalmes.
Starter Activities GCSE Python.
File Handling.
Lesson 2: Getting Started
How to read from a file read, readline, reader
Tuple.
Presentation transcript:

Interfacing with a database Python can also be used to write to a database A database is “a persistently organised” collection of data – for example, the contact details on your phone, a TV guide, a stock control system for a product. Database can therefore come in many formats for example, text, spreadsheet and CSV. CSV stands for Comma Separated Variable

An array An array is the word used to describe a list, for example a shopping list shopping_list = [“cake”, “pie”, “ham”, “magazine”] A 3D array is a list which holds more than one list students = [['dave', 14, '11DA'], ['liz', 18, '7ED'], ['kerry', 'liz', '8MD2']] Note the use of the brackets and the layout More on Arrays in another lesson

Writing data from an array to a csv file import csv students = [['dave', 14, '11DA'], ['liz', 18, '7ED'], ['kerry', 'liz', '8MD2']] myfile = open('output.csv','w') wr = csv.writer(myfile, quotechar=None) wr.writerows(students) myfile.close() Creates a file called output, writes each item in the list into the CSV file

Did you get this?

Add another array to the list import csv students = [['dave', 14, '11DA'], ['liz', 18, '7ED'], ['kerry', 'liz', '8MD2']] myfile = open('output.csv','w') wr = csv.writer(myfile, quotechar=None) wr.writerows(students) myfile.close() Add another array here or Create a new array on line two and add the name of the array to the students array Creates a file called output, writes each item in the list into the CSV file

Reading from a database to an array import csv students = [] file = open('output.csv', 'rt') reader = csv.reader(file) for row in reader: print (row) f.close() Does not write to the ‘student list’ only prints the values

YOUR TURN Add to new entries to the CSV Database Save the file Create the code and read all the data from the file Does not write to the ‘student list’ only prints the values

Reading from CSV file to an array import csv students = [] with open('output.csv', 'r') as f: reader = csv.reader(f) students = list(reader) print (students)