The document discusses file input and output in Python. It covers opening files, reading the entire file or line by line, writing to files, and closing files. It also covers if/elif/else conditional statements, comparison operators, and examples of problems and solutions involving file I/O and conditional logic.
Functions, Exception, Modules and Files
Functions: Difference between a Function and a Method, Defining a Function, Calling a Function, Returning Results from a Function, Returning Multiple Values from a Function, Functions are First Class Objects, Pass by Object Reference, Formal and Actual Arguments, Positional Arguments, Keyword Arguments, Default Arguments, Variable Length Arguments, Local and Global Variables, The Global Keyword, Passing a Group of Elements to a Function, Recursive Functions, Anonymous Functions or Lambdas (Using Lambdas with filter() Function, Using Lambdas with map() Function, Using Lambdas with reduce() Function), Function Decorators, Generators, Structured Programming, Creating our Own Modules in Python, The Special Variable __name__
Exceptions: Errors in a Python Program (Compile-Time Errors, Runtime Errors, Logical Errors),Exceptions, Exception Handling, Types of Exceptions, The Except Block, The assert Statement, UserDefined Exceptions, Logging the Exceptions
20%
Files: Files, Types of Files in Python, Opening a File, Closing a File, Working with Text Files Containing Strings, Knowing Whether a File Exists or Not, Working with Binary Files, The with Statement, Pickle in Python, The seek() and tell() Methods, Random Accessing of Binary Files, Random Accessing of Binary Files using mmap, Zipping and Unzipping Files, Working with Directories, Running Other Programs from Python Program
Functions, Exception, Modules and Files
Functions: Difference between a Function and a Method, Defining a Function, Calling a Function, Returning Results from a Function, Returning Multiple Values from a Function, Functions are First Class Objects, Pass by Object Reference, Formal and Actual Arguments, Positional Arguments, Keyword Arguments, Default Arguments, Variable Length Arguments, Local and Global Variables, The Global Keyword, Passing a Group of Elements to a Function, Recursive Functions, Anonymous Functions or Lambdas (Using Lambdas with filter() Function, Using Lambdas with map() Function, Using Lambdas with reduce() Function), Function Decorators, Generators, Structured Programming, Creating our Own Modules in Python, The Special Variable __name__
Exceptions: Errors in a Python Program (Compile-Time Errors, Runtime Errors, Logical Errors),Exceptions, Exception Handling, Types of Exceptions, The Except Block, The assert Statement, UserDefined Exceptions, Logging the Exceptions
20%
Files: Files, Types of Files in Python, Opening a File, Closing a File, Working with Text Files Containing Strings, Knowing Whether a File Exists or Not, Working with Binary Files, The with Statement, Pickle in Python, The seek() and tell() Methods, Random Accessing of Binary Files, Random Accessing of Binary Files using mmap, Zipping and Unzipping Files, Working with Directories, Running Other Programs from Python Program
Getting started in Python presentation by Laban KGDSCKYAMBOGO
Python Overview and getting started in Python Language. It includes on how to install, run it and carrying out some simple python codes in different environments(IDLEs)
The basics of Python are rather straightforward. In a few minutes you can learn most of the syntax. There are some gotchas along the way that might appear tricky. This talk is meant to bring programmers up to speed with Python. They should be able to read and write Python.
Outlines of this lecture:
- What is stream?
- File Output Stream Class
- File Input Stream Class
- Byte Array Output Stream Class
- Sequence Input Stream Class
- File Reader Class
- File Writer Class
- Scanner with String
Python 101++: Let's Get Down to Business!Paige Bailey
You've started the Codecademy and Coursera courses; you've thumbed through Zed Shaw's "Learn Python the Hard Way"; and now you're itching to see what Python can help you do. This is the workshop for you!
Here's the breakdown: we're going to be taking you on a whirlwind tour of Python's capabilities. By the end of the workshop, you should be able to easily follow any of the widely available Python courses on the internet, and have a grasp on some of the more complex aspects of the language.
Please don't forget to bring your personal laptop!
Audience: This course is aimed at those who already have some basic programming experience, either in Python or in another high level programming language (such as C/C++, Fortran, Java, Ruby, Perl, or Visual Basic). If you're an absolute beginner -- new to Python, and new to programming in general -- make sure to check out the "Python 101" workshop!
Getting started in Python presentation by Laban KGDSCKYAMBOGO
Python Overview and getting started in Python Language. It includes on how to install, run it and carrying out some simple python codes in different environments(IDLEs)
The basics of Python are rather straightforward. In a few minutes you can learn most of the syntax. There are some gotchas along the way that might appear tricky. This talk is meant to bring programmers up to speed with Python. They should be able to read and write Python.
Outlines of this lecture:
- What is stream?
- File Output Stream Class
- File Input Stream Class
- Byte Array Output Stream Class
- Sequence Input Stream Class
- File Reader Class
- File Writer Class
- Scanner with String
Python 101++: Let's Get Down to Business!Paige Bailey
You've started the Codecademy and Coursera courses; you've thumbed through Zed Shaw's "Learn Python the Hard Way"; and now you're itching to see what Python can help you do. This is the workshop for you!
Here's the breakdown: we're going to be taking you on a whirlwind tour of Python's capabilities. By the end of the workshop, you should be able to easily follow any of the widely available Python courses on the internet, and have a grasp on some of the more complex aspects of the language.
Please don't forget to bring your personal laptop!
Audience: This course is aimed at those who already have some basic programming experience, either in Python or in another high level programming language (such as C/C++, Fortran, Java, Ruby, Perl, or Visual Basic). If you're an absolute beginner -- new to Python, and new to programming in general -- make sure to check out the "Python 101" workshop!
Water scarcity is the lack of fresh water resources to meet the standard water demand. There are two type of water scarcity. One is physical. The other is economic water scarcity.
About
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
Technical Specifications
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
Key Features
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface
• Compatible with MAFI CCR system
• Copatiable with IDM8000 CCR
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
Application
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
Student information management system project report ii.pdfKamal Acharya
Our project explains about the student management. This project mainly explains the various actions related to student details. This project shows some ease in adding, editing and deleting the student details. It also provides a less time consuming process for viewing, adding, editing and deleting the marks of the students.
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Dr.Costas Sachpazis
Terzaghi's soil bearing capacity theory, developed by Karl Terzaghi, is a fundamental principle in geotechnical engineering used to determine the bearing capacity of shallow foundations. This theory provides a method to calculate the ultimate bearing capacity of soil, which is the maximum load per unit area that the soil can support without undergoing shear failure. The Calculation HTML Code included.
Final project report on grocery store management system..pdfKamal Acharya
In today’s fast-changing business environment, it’s extremely important to be able to respond to client needs in the most effective and timely manner. If your customers wish to see your business online and have instant access to your products or services.
Online Grocery Store is an e-commerce website, which retails various grocery products. This project allows viewing various products available enables registered users to purchase desired products instantly using Paytm, UPI payment processor (Instant Pay) and also can place order by using Cash on Delivery (Pay Later) option. This project provides an easy access to Administrators and Managers to view orders placed using Pay Later and Instant Pay options.
In order to develop an e-commerce website, a number of Technologies must be studied and understood. These include multi-tiered architecture, server and client-side scripting techniques, implementation technologies, programming language (such as PHP, HTML, CSS, JavaScript) and MySQL relational databases. This is a project with the objective to develop a basic website where a consumer is provided with a shopping cart website and also to know about the technologies used to develop such a website.
This document will discuss each of the underlying technologies to create and implement an e- commerce website.
3. Opening files
• The open() command returns a file object.
<filehandle> = open(<filename>, <access type>)
• Python can read, write or append to a file:
– 'r' = read
– 'w' = write
– 'a' = append
• Create a file called “hello.txt” containing one line:
“Hello, world!”
>>> myFile = open("hello.txt", "r")
4. Reading the whole file
• You can read the contents of the file into a
single string.
>>> myString = myFile.read()
>>> print myString
Hello, world!
>>> Why is there a
blank line here?
5. Reading the whole file
• Now add a second line to your file (“How ya
doin’?”) and try again.
>>> myFile = open("hello.txt", "r")
>>> myString = myFile.read()
>>> print myString
Hello, world!
How ya doin'?
>>>
6. Reading the whole file
• Alternatively, you can read the file into a
list of strings.
>>> myFile = open("hello.txt", "r")
>>> myStringList = myFile.readlines()
>>> print myStringList
['Hello, world!n', "How ya doin'?n"]
>>> print myStringList[1]
How ya doin'?
7. Reading one line at a time
• The readlines() command puts all the lines into a list
of strings.
• The readline() command returns the next line.
>>> myFile = open("hello.txt", "r")
>>> myString = myFile.readline()
>>> print myString
Hello, world!
>>> myString = myFile.readline()
>>> print myString
How ya doin'?
>>>
8. Writing to a file
• Open the file for writing or appending.
>>> myFile = open("new.txt", "w")
• Use the <file>.write() method.
>>> myFile.write("This is a new filen")
>>> myFile.close()
>>> ^D
> cat new.txt
This is a new file
Always close a file after you
are finished reading from or
writing to it.
9. Print vs write
• <file>.write() does not automatically
append an end-of-line character.
• <file>.write() requires a string as input
>>> newFile.write("foo")
>>> newFile.write(1)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: argument 1 must be string or read-only
character buffer, not int
11. The if statement
>>> if (seq.startswith("C")):
... print "Starts with C"
...
Starts with C
>>>
• A block is a group of lines of code that belong together.
if (<test evaluates to true>):
<execute this block of code>
• In the Python interpreter, the ellipse indicates that you are inside a
block.
• Python uses indentation to keep track of blocks.
• You can use any number of spaces to indicate blocks, but you must
be consistent.
• An unindented or blank line indicates the end of a block.
12. The if statement
• Try doing an if statement without indentation.
>>> if (seq.startswith("C")):
... print "Starts with C"
File "<stdin>", line 2
print "Starts with C"
^
IndentationError: expected an
indented block
13. Multiline blocks
• Try doing an if statement with multiple lines in
the block.
>>> if (seq.startswith("C")):
... print "Starts with C"
... print "All right by me!"
...
Starts with C
All right by me!
14. Multiline blocks
• What happens if you don’t use the same number
of spaces to indent the block?
>>> if (seq.startswith("C")):
... print "Starts with C"
... print "All right by me!"
File "<stdin>", line 4
print "All right by me!"
^
SyntaxError: invalid syntax
16. Examples
seq = 'CAGGT'
>>> if ('C' == seq[0]):
... print 'C is first'
...
C is first
>>> if ('CA' in seq):
... print 'CA in', seq
...
CA in CAGGT
>>> if (('CA' in seq) and ('CG' in seq)):
... print "Both there!"
...
>>>
17. Beware!
= versus ==
• Single equal assigns a variable
name.
>>> myString == "foo"
Traceback (most recent
call last):
File "<stdin>", line 1,
in ?
NameError: name
'myString' is not
defined
>>> myString = "foo"
>>> myString == "foo"
True
• Double equal tests for equality.
>>> if (myString = "foo"):
File "<stdin>", line 1
if (myString = "foo"):
^
SyntaxError: invalid syntax
>>> if (myString == "foo"):
... print "Yes!"
...
Yes!
18. if-else statements
if <test1>:
<statement>
else:
<statement>
• The else block executes only if <test1> is false.
>>> if (seq.startswith('T')):
... print 'T start'
... else:
... print 'starts with', seq[0]
...
starts with C
>>>
Evaluates to
FALSE: no print.
22. Sample problem #1
• Write a program read-first-line.py
that takes a file name from the command
line, opens the file, reads the first line, and
prints the result to the screen.
> python read-first-line.py hello.txt
Hello, world!
>
24. Sample problem #2
• Modify your program to print the first line
without an extra carriage return.
> python read-first-line.py hello.txt
Hello, world!
>
26. Sample problem #3
• Write a program add-two-numbers.py
that reads one integer from the first line of
one file and a second integer from the first
line of a second file and then prints their
sum.
> add-two-numbers.py nine.txt four.txt
9 + 4 = 13
>
28. Sample problem #4
• Write a program find-base.py that takes as
input a DNA sequence and a nucleotide. The
program should print the number of times the
nucleotide occurs in the sequence, or a
message saying it’s not there.
> python find-base.py A GTAGCTA
A occurs at position 3
> python find-base.py A GTGCT
A does not occur at all
Hint: S.find('G') returns -1 if it can't find the requested sequence.
29. Solution #4
import sys
base = sys.argv[1]
sequence = sys.argv[2]
position = sequence.find(base)
if (position == -1):
print base, "does not occur at all"
else:
print base, "occurs at position", position