Introduction to Programming with Python

Slides:



Advertisements
Similar presentations
Module 4.2 File management 1. Contents Introduction The file manager Files – the basic unit of storage The need to organise Glossary 2.
Advertisements

Computer Science 111 Fundamentals of Programming I Files.
Last Week Looping though lists Looping using range While loops.
Why use Files? Your Python Program External File (secondary storage) Write to file (Save) Read from file (Load) …so we can have access to ‘stored’ data.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Computer Systems Week 10: File Organisation Alma Whitfield.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 17 Reading and Writing Files 5/10/09 Python Mini-Course: Lesson 17 1.
Integrated Development Environment (IDE)
Copyright © 2001 by Wiley. All rights reserved. Chapter 2: Using Visual Basic to Create a First Project Getting Started with VB Development Environment.
File I/O Michael Ernst UW CSE 140 Winter File Input and Output As a programmer, when would one use a file? As a programmer, what does one do with.
Internal Lab Registeration labreg/lab/signup.aspxhttp:// labreg/lab/signup.aspx
File I/O Ruth Anderson UW CSE 160 Spring File Input and Output As a programmer, when would one use a file? As a programmer, what does one do with.
5 1 Data Files CGI/Perl Programming By Diane Zak.
16. Python Files I/O Printing to the Screen: The simplest way to produce output is using the print statement where you can pass zero or more expressions,
Last Week Lists List methods Nested Lists Looping through lists using for loops.
1 More About HTML Images and Links. 22 Objectives You will be able to Include images in your HTML page. Create links to other pages on your HTML page.
FILES. open() The open() function takes a filename and path as input and returns a file object. file object = open(file_name [, access_mode][, buffering])
File I/O Ruth Anderson UW CSE 140 Winter File Input and Output As a programmer, when would one use a file? As a programmer, what does one do with.
1 Open Microsoft office word. Create a new blank document.
C Programming Lecture 3 : C Introduction 1 Lecture notes : courtesy of Woo Kyun and Chang Byung-Mo.
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.
Python: File Directories What is a directory? A hierarchical file system that contains folders and files. Directory (root folder) Sub-directory (folder.
1 Microsoft Access Security Warnings Note: This presentation was created with "Access 2002". You might have slightly different warnings with other versions.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
 CSC 215 : Procedural Programming with C C Compilers.
MS-DOS is an acronym for MicroSoft Disk Operating System It is a CUI based operating system. It provides user with a command prompt (generally called.
Writing & reading txt files with python 3
File Writing Upsorn Praphamontripong CS 1110
Managing results files
Ruth Anderson UW CSE 160 Winter 2016
Sequential Input and Output using Text Files
පාඨමාලා මාතෘකා Microsoft SQL Server Databases සැකසීම
Ruth Anderson UW CSE 160 Winter 2017
Ruth Anderson UW CSE 160 Spring 2018
Introduction to Programming with Python
Microsoft Azure Fundamentals Microsoft Azure මූලික දැනුම
Introduction to Programming with Python
Introduction to Programming with Python
Introduction to Programming with Python
Introduction to Programming with Python
File IO and Strings CIS 40 – Introduction to Programming in Python
Fundamentals of Programming I Files
File Handling.
Customizing Views Views Customize කර ගැනීම
ETI Base Code ETI මුලධර්මයන් හදුනාගනිමු
Microsoft Azure Fundamentals Microsoft Azure මූලික දැනුම
මුහම්මද් සල්ලල්ලාහු අලෙයිහි වසල්ලම්
Basics of MVC MVC වල මුලික කොටස්
Microsoft Azure Fundamentals Microsoft Azure මූලික දැනුම
Creating and Configuring Models Models create කිරීම සහ config කර ගැනීම
වී පොහොර සහනාධාර මුදල් ප්‍රදාන වැඩසටහන 2017/18 මහ කන්නය
Visual Basic 6 Programming.
Customizing Controllers Controllers Customizing කර ගැනීම
Creating Your First C Program Using Visual Studio 2010
How to save information in files open, write, close
Creating Your First C Program Using Visual Studio 2010
‘Shifters’ in bilingual education : Problems and challenges of learning through a second language Marie Perera 1Department of Humanities Education, University.
Introduction to Programming with Python
Introduction to Programming with Python
Introduction to Programming with Python
Topics Introduction to File Input and Output
Microsoft Azure Fundamentals Microsoft Azure මූලික දැනුම
Introduction to Programming with Python
Introduction to Programming with Python
මොඩියුල විශ්ලේෂණය Stored Procedure හඳුන්වා දීම.
Introduction to Programming with Python
Introduction to Computer Science
How to read from a file read, readline, reader
Presentation transcript:

Introduction to Programming with Python Files සමඟ වැඩකිරීම Dileepa S. Rajapaksa | http://www.windowsgeek.lk @dsrajapaksa Microsoft Virtual Academy

කලින් Video එකෙන් … List එකක් නිර්මාණය හා භාවිතය අගයන් සෙවීම Loop එකක ඇති සියළුම අගයන් ඔස්සේ Loop කිරීම list එකක් පිළිවලකට සකසා print කිරීම Microsoft Virtual Academy

Demo කලින් Video එකේ අභියෝගයට පිළිතුරු Microsoft Virtual Academy

තොරතුරු file වල save කරන්නේ කොහොමද? Last part Practice your language Microsoft Virtual Academy

කවදා හෝ පසුව මතක්කර ගැනීම සඳහා කෙටියෙන් සටහක් යෙදීමට අවශ්‍යවෙලා තියෙනවාද? වට්ටෝරුවක් සඳහ මිලදී ගැනීමට අවශ්‍ය ද්‍රව්‍ය list එකක්? අමුත්තන්ගේ list එකක්? දුරකතන අංක list එකක්?

පසුව මතක්කර ගැනීමට සමහර වේලාවන්හිදී වැඩසටහන් සඳහාත් යම් දේවල් ලියාගැනීමට සිදුවෙනවා. මම පොතක කියවමින් සිටි පිටුව. පරිගණක ක්‍රීඩාවක ඔබ සොයාගනු ලැබූ නිදන් වස්තු

File සමග වැඩ කිරීම. Microsoft Virtual Academy Last part Practice your language Microsoft Virtual Academy

වැඩසටහනකට සටහන් තබාගැනීමට ඇති ක්‍රම අතරින් file එකක ලියාගැනීම යනු එක් ක්‍රමයක්.

Python code එකක් ආධාරයෙන් file එකක ලියන්නේ කොහොමද? file එකක සෑදීමට සහ open කිරීමට open function එක භාවිතා කරන්න myFile = open(fileName, accessMode) මෙදී ඔබ දැක්විය යුතුයි file එකේ නම access mode එක

File name එක මොකක්ද? File name එක යනු file එකේ extension එකත් සහිතව නමයි. data.txt, mytimes.csv File එක ඔබගේ වැඩසටහන පවතින folder එකේම නිර්මාණය කළ යුතුයි. සාමාන්‍යයෙන් පවතින directory එක C:/Users/<user name>/Documents/Visual Studio 2013/Projects/<project name>/ If you want to use a file from another directory you will need to do the following: Import os Then verify if the path exists: os.getcwd() os.path.exists(direct) Then read the file: x_file = open(os.path.join(direct, "5_1.txt"), "r")

Geek Tip! Project එක භාවිතා කරන folder එක දන්නේ නැත්නම් ඔබට පුළුවන් ඔබගේ code එක සහිත window එකේ tab එක මත right click කරලා Open Containing Folder තෝරන්න.එවිට Windows explorer හි එම folder එක open වේවි.

මොකක්ද Access mode එක? අපි access mode එකෙන් ලබාදෙන්නේ අපි file එක open කලාට පසුව කරන්නේ මොකක්ද කියන එක. පහත ඕනැම එකක් Access mode එක වශයෙන් භාවිතා කරන්න පුළුවන්. Access mode Action r Read the file w Write to the file a Append to the existing file content b Open a binary file You can find more information at the following link: https://docs.python.org/3/library/functions.html#open

සම්පූර්ණ Code එක… fileName = "GuestList.txt" accessMode = "w" myFile = open(fileName, accessMode) You can find more information at the following link: https://docs.python.org/3/library/functions.html#open

Demo File එකක් නිර්මාණය කිරීම සහ දැන් භාවිතා කරන Folder එක Visual Studio මගින් දැනගැනීම Last part Practice your language Microsoft Virtual Academy

File වල ලිවීම Microsoft Virtual Academy Last part Practice your language Microsoft Virtual Academy

අපිට file එකක් තියෙනවා, කොහොමද අපි දැන් ලියන්නේ ? write function එක යොදා ගැනීම. fileName = "GuestList.txt" accessMode = "w" myFile = open(fileName, accessMode) myFile.write("Hi there!") myFile.write("How are you?") You can find more information at the following link: https://docs.python.org/3/library/functions.html#open

කොහොමද අළුත් පේළියක් ආරම්භ කරන්නේ? ආයිත් හිතලා බලන්න print statement එකක් ගැන. කොහොමද ඔබ පේළි කීපයක් ලිවූවේ? “\n” fileName = "GuestList.txt" accessMode = "w" myFile = open(fileName, accessMode) myFile.write("Hi there!\n") myFile.write("How are you?")

වැඩක් අවසානයේදී file එක close කිරීම හැම විටම වැදගත්. Close method එක යොදා ගැනීම. fileName = "GuestList.txt" accessMode = "w" myFile = open(fileName, accessMode) myFile.write("Hi there!\n") myFile.write("How are you?") myFile.close() You can find more information at the following link: https://docs.python.org/3/library/functions.html#open

Demo තොරතුරු file එකකට ලිවීම Microsoft Virtual Academy Last part Practice your language Microsoft Virtual Academy

CSV Files Last part Practice your language Microsoft Virtual Academy

කොමා වලින් වෙන්කර දැක්වීම තොරතුරු file වල ගබඩාකිරීමේ පොදු ක්‍රමයයි CSV file එකක ඇති data වෙන් වෙන්නේ character එකකින් (බොහෝවිට කොමාවකින් ) සෑම පේළියකින්ම එක data record එකක් නිරූපණය කරනවා. සමහර අවස්ථා වලදී Character Separated Values කියලත් කියනවා. ඒ data වෙන් කරන character එක වෙනස් වෙන්න පුළුවන් නිසා. CSV-Comma-Separated Values

ඔබේ අභියෝගය… පහත ඇති CSV file එක නිර්මාණය කරන්න!

වෙනස් අමුත්තන් 5කගේ නම් සහ වයස් User ගෙන් ලබාගෙන ඒ නම් සහ වයස් CSV File එකකට ඇතුලත් කරන්න.

සාරාංශය… File සමග වැඩ කිරීම. තොරතුරු file එකකට ලිවීම open() Function එක භාවිතය Write function එක භාවිතය CSV Files භාවිතය. Microsoft Virtual Academy

සුභ පැතුම් ! දැන් ඔබට තොරතුරු , බාහිර ගොනුවක් වෙත සුරැකීමට හැකියාව ඇත දැන් ඔබට තොරතුරු , බාහිර ගොනුවක් වෙත සුරැකීමට හැකියාව ඇත Microsoft Virtual Academy