LECTURE 9 The Standard Library Part 3

Size: px
Start display at page:

Download "LECTURE 9 The Standard Library Part 3"

Transcription

1 LECTURE 9 The Standard Library Part 3

2 THE STANDARD LIBRARY In this lecture, we will briefly cover each of the remaining Standard Library modules that you absolutely must know about. Some of the remaining modules will be introduced later on when we cover specific applications domains in Python such as web development, data persistence, etc. os time argparse sys

3 OS SERVICES The os module provides a common interface for operating system dependent functionality. Most of the functions are actually implemented by platform-specific modules, but there is no need to explicitly call them as such.

4 OS SERVICES We ve already seen how the os module can be used to work with files. We know that there are built-in functions to open and close files but os extends file operations. os.rename(current_name, new_name) renames the file current_name to new_name. os.remove(filename) deletes an existing file named filename.

5 OS SERVICES There are also a number of directory services provided by the os module. os.listdir(dirname) lists all of the files in directory dirname. os.getcwd() returns the current directory. os.chdir(dirname) will change the current directory. >>> os.listdir("demos") ['frac.py', 'dogs.py', 'football.csv', 'csv_parser.py'] >>> os.listdir(".") ['lect5.py', 'demos', 'lect3.py', 'lect2.py'] >>> os.getcwd() '/home/faculty/carnahan/cis4930' >>> os.chdir(os.getcwd() + "/demos") >>> os.getcwd() '/home/faculty/carnahan/cis4930/demos >>> os.rename("dogs.py", "cats.py") >>> os.listdir(".") ['frac.py', 'football.csv', 'cats.py', 'csv_parser.py'] >>> os.remove("cats.py") >>> os.listdir(".") ['frac.py', 'football.csv', 'csv_parser.py']

6 OS SERVICES Use os.mkdir(dirname) and os.rmdir(dirname) to make and remove a single directory. Use os.makedirs(path/of/dirs) and os.removedirs(path/of/dirs) to make and remove a hierarchy of directories. Make sure directories are empty before removal! >>> os.makedirs("dir1/dir2/dir3") >>> os.listdir(".") ['frac.py', 'dir1', 'football.csv', 'csv_parser.py'] >>> f = open("dir1/dir2/dir3/test", "w") >>> f.write("hi!") >>> f.close() >>> for line in open("dir1/dir2/dir3/test", "r"):... print line... hi! >>> os.remove("dir1/dir2/dir3/test") >>> os.removedirs("dir1/dir2/dir3") >>> os.listdir(".") ['frac.py', 'football.csv', 'csv_parser.py']

7 OS SERVICES The os.walk(path) method will generate a tuple (dirpath, dirnames, filenames) for each directory found by traversing the directory tree rooted at path. >>> os.makedirs("dir1/dir2/dir3") >>> os.listdir(".") ['frac.py', 'dir1', 'football.csv', 'csv_parser.py'] >>> os.mkdir("dir1/dir2/dir4") >>> f = open("dir1/dir2/d2file", "w") >>> f = open("dir1/dir2/dir3/d3file", "w") >>> f = open("dir1/dir2/dir4/d4file", "w") >>> path = os.getcwd() >>> for (path, dirs, files) in os.walk(path):... print "Path: ", path... print "Directories: ", dirs... print "Files: ", files... print "---"

8 OS SERVICES The os.walk(path) method will generate a tuple (dirpath, dirnames, filenames) for each directory found by traversing the directory tree rooted at path. Path: /home/faculty/carnahan/cis4930/demos Directories: ['dir1'] Files: ['frac.py', 'football.csv', 'csv_parser.py'] --- Path: /home/faculty/carnahan/cis4930/demos/dir1 Directories: ['dir2'] Files: [] --- Path: /home/faculty/carnahan/cis4930/demos/dir1/dir2 Directories: ['dir4', 'dir3'] Files: ['d2file'] --- Path: /home/faculty/carnahan/cis4930/demos/dir1/dir2/dir4 Directories: [] Files: ['d4file'] --- Path: /home/faculty/carnahan/cis4930/demos/dir1/dir2/dir3 Directories: [] Files: ['d3file'] ---

9 OS SERVICES The os module includes an os.stat(path) method which will return file attributes related to the path provided (equivalent of stat() system call). Result is a stat structure which includes st_size: size of file in bytes. st_atime: time of most recent access. st_uid: user id of owner. st_nlink: number of hard links. >>> import os >>> stat_info = os.stat("football.csv") >>> stat_info posix.stat_result(st_mode=33216, st_ino= l, st_dev=20l, st_nlink=1, st_uid=87871, st_gid=300, st_size=648l, st_atime= , st_mtime= , st_ctime= ) >>> stat_info.st_mtime

10 OS SERVICES The os.system(cmd) function executes the argument cmd in a subshell. The return value is the exit status of the command. >>> os.system("ls") csv_parser.py dir1 football.csv frac.py 0 >>> os.system("touch newfile.txt") 0 >>> os.system("ls") csv_parser.py dir1 football.csv frac.py newfile.txt 0

11 OS SERVICES The os.exec(path, args) function will start a new process from path using the args as arguments, replacing the current one. Alternatives include os.execve(), os.execvp(), etc as usual. Arguments depend on version used. carnahan@diablo:~/cis4930/demos> python2.7 Python (default, Oct , 01:47:54) [GCC (Red Hat EL4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.execvp("python2.7", ("python2.7", "csv_parser.py")) Aston_Villa has a minimum goal difference of 1 carnahan@diablo:~/cis4930/demos>

12 OS SERVICES Combine the os.exec*() functions with os.fork() and os.wait() to spawn processes from the current process. The former makes a copy of the current process, the latter waits for a child process to finish. Use os.spawn() on Windows. import os import sys pid = os.fork() if not pid: os.execvp( python2.7, ( python2.7, csv_parser.py )) os.wait()

13 TIME The time module includes implementations for a handful of time-related functions. The simplest and most common use of the time module is to retrieve the current time in seconds since 1/1/1970. >>> import time >>> time.time()

14 TIME The methods time.localtime(t) and time.gmtime(t) accept as an argument seconds since Unix time 0. Both return a time tuple (year, month, day, hour, minute, second, day of week, day of year, daylight savings flag). >>> t = time.time() >>> time.gmtime(t) # GMT time.struct_time(tm_year=2015, tm_mon=1, tm_mday=28, tm_hour=9, tm_min=24, tm_sec=17, tm_wday=2, tm_yday=28, tm_isdst=0) >>> lt = time.localtime(t) # Local Time >>> lt time.struct_time(tm_year=2015, tm_mon=1, tm_mday=28, tm_hour=4, tm_min=24, tm_sec=17, tm_wday=2, tm_yday=28, tm_isdst=0) >>> time.mktime(lt) # Only on localtime

15 TIME The time module also provides a number of functions for converting and formatting time tuples as strings. >>> t = time.time() >>> now = time.localtime(t) >>> print time.asctime(now) Wed Jan 28 04:27: >>> print time.strftime("%y/%m/%d %H:%M", now) 15/01/28 04:27 >>> print time.strftime("%m/%d/%y %H:%M", now) 01/28/15 04:27 >>> print time.strptime("28 Jan 15", "%d %b %y") time.struct_time(tm_year=2015, tm_mon=1, tm_mday=28, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=28, tm_isdst=-1) Do not use strptime on Windows it will typically not be defined.

16 TIME You can use time s methods to time the execution of a program. Use either time.time() for wall time or time.clock() for cpu time. Also, time.sleep(s) will cause the process to sleep for s seconds. On Windows, time.time() and time.clock() both measure the wall time. >>> import time >>> def sleep_func(t):... time.sleep(t)... >>> def cpu_time():... start = time.clock()... sleep_func(5)... print "CPU time:", time.clock() - start... >>> cpu_time() CPU time: 0.0 >>> def wall_time():... start = time.time()... sleep_func(5)... print "Wall time:", time.time() - start... >>> wall_time() Wall time:

17 ARGPARSE The argparse module is a very powerful tool for organizing and processing arguments to your python program. argtest.py import argparse carnahan@diablo:~>python2.7 argtest.py carnahan@diablo:~>python2.7 argtest.py --help usage: argtest.py [-h] parser = argparse.argumentparser() parser.parse_args() optional arguments: -h, --help show this help message and exit carnahan@diablo:~>python2.7 argtest.py spam usage: argtest.py [-h] argtest.py: error: unrecognized arguments: spam By default, argparse will specify actions for the help and h arguments. Namely, it ll tell the user their options.

18 ARGPARSE We can add positional arguments which are required. import argparse parser = argparse.argumentparser() parser.add_argument("name", help="enter a name to be greeted.", type=str) args = parser.parse_args() print "Hello, "+args.name carnahan@diablo:~>python2.7 argtest.py class Hello, class

19 ARGPARSE Now, let s add an optional argument. import argparse parser = argparse.argumentparser() parser.add_argument("name", help="enter a name to be greeted.", type=str) parser.add_argument("--bye", help="say goodbye instead of greet.", action="store_true") args = parser.parse_args() if not args.bye: print "Hello, "+args.name else: print "Goodbye, "+args.name

20 ARGPARSE argtest.py class Hello, class argtest.py class --bye Goodbye, class argtest.py usage: argtest.py [-h] [--bye] name argtest.py: error: too few arguments argtest.py -h usage: argtest.py [-h] [--bye] name positional arguments: name enter a name to be greeted. optional arguments: -h, --help show this help message and exit --bye say goodbye instead of greet.

21 SYS The sys module implements functions for accessing and manipulating the runtime environment. The most common way to use sys is to access arguments to a python program. testargs.py import sys for i in range(len(sys.argv)): print "sys.argv[" + str(i) + "] is " + sys.argv[i] carnahan@diablo:~>python testargs.py here are some arguments sys.argv[0] is testargs.py sys.argv[1] is here sys.argv[2] is are sys.argv[3] is some sys.argv[4] is arguments

22 SYS The path used to look for modules is stored in sys.path. You can manipulate it like a list. systest.py import sys print "path has", len(sys.path), "members" sys.path.insert(0, "samples") import sample carnahan@diablo:~>python systest.py path has 8 members Hello from the sample module! Traceback (most recent call last): File "systest.py", line 9, in? import math ImportError: No module named math sys.path = [] import math Use sys.builtin_module_names to see which modules are built into the interpreter. The sys module is one of them.

23 SYS The sys.modules dictionary contains all of the modules currently imported. >>> import sys >>> sys.modules.keys() ['copy_reg', 'sre_compile', '_sre', 'encodings', 'site', ' builtin ', 'sysconfig', ' main ', 'encodings.encodings', 'math', 'abc', 'posixpath', '_weakrefset', 'errno', 'encodings.codecs', 'sre_constants', 're', '_abcoll', 'types', '_codecs', 'encodings. builtin ', '_warnings', 'encodings.latin_1', 'genericpath', 'stat', 'zipimport', '_sysconfigdata', 'warnings', 'UserDict', 'sys', 'codecs', 'readline', 'os.path', 'signal', 'traceback', 'linecache', 'posix', 'encodings.aliases', 'exceptions', 'sre_parse', 'os', '_weakref'] Use sys.platform to determine the host platform. >>> sys.platform 'linux2'

24 SYS For profiling, use the sys.setprofile(profiler) function. The profiler function must be defined by you. It will profile every function or method called until you disable the profiler by passing None to sys.setprofile. For tracing, use sys.settrace(tracer) with a self-definer tracer. To exit a program before it terminates itself, use sys.exit(). It will raise a SystemExit exception which, if not caught, will end the program. You can also set a function object to sys.exitfunc to specify cleanup actions. Optional arguments: - 0 is considered a successful termination. - Some error message will print to stderr and return 1.

25 NEXT LECTURE We ll discuss development tools for Python including logging, testing, and debugging.

LECTURE 7. The Standard Library Part 1: Built-ins, time, sys, and os

LECTURE 7. The Standard Library Part 1: Built-ins, time, sys, and os LECTURE 7 The Standard Library Part 1: Built-ins, time, sys, and os THE PYTHON LANGUAGE Believe it or not, you now have all the Python syntax and structures you need already. At this point, we can turn

More information

LECTURE 4 Python Basics Part 3

LECTURE 4 Python Basics Part 3 LECTURE 4 Python Basics Part 3 INPUT We ve already seen two useful functions for grabbing input from a user: raw_input() Asks the user for a string of input, and returns the string. If you provide an argument,

More information

FILE HANDLING AND EXCEPTIONS

FILE HANDLING AND EXCEPTIONS FILE HANDLING AND EXCEPTIONS INPUT We ve already seen how to use the input function for grabbing input from a user: input() >>> print(input('what is your name? ')) What is your name? Spongebob Spongebob

More information

CS Programming Languages: Python

CS Programming Languages: Python CS 3101-1 - Programming Languages: Python Lecture 5: Exceptions / Daniel Bauer (bauer@cs.columbia.edu) October 08 2014 Daniel Bauer CS3101-1 Python - 05 - Exceptions / 1/35 Contents Exceptions Daniel Bauer

More information

Interacting with Unix

Interacting with Unix Interacting with Unix Synopsis Getting the Process ID #include pid_t getpid(void); Example: #include #include int main(){ pid_t n = getpid(); printf("process id is %d\n",

More information

Overview of Time Related Data Structures and Functions in Unix/C. It s About Time

Overview of Time Related Data Structures and Functions in Unix/C. It s About Time Overview of Time Related Data Structures and Functions in Unix/C It s About Time 1. time_t Same as an unsigned long. Time in seconds since Midnight GMT Jan 1, 1970. a. char * ctime(time_t x) will return

More information

Programming in Python Advanced

Programming in Python Advanced Programming in Python Advanced Duration: 3 days, 8 hours a day Pre-requisites: * Participants should be comfortable with the following technologies: Basic and working knowledge of the Pyton If new to the

More information

CSE 158/258. Web Mining and Recommender Systems. Tools and techniques for data processing and visualization

CSE 158/258. Web Mining and Recommender Systems. Tools and techniques for data processing and visualization CSE 158/258 Web Mining and Recommender Systems Tools and techniques for data processing and visualization Some helpful ideas for Assignment 2... 1. How can we crawl our own datasets from the web? 2. How

More information

Scripting With Jython

Scripting With Jython Scripting With Jython In this chapter, we will look at scripting with Jython. For our purposes, we will define scripting as the writing of small programs to help out with daily tasks. These tasks are things

More information

Day 6: Modules, Standard Library

Day 6: Modules, Standard Library Day 6: Modules, Standard Library Suggested reading: Learning Python (4th Ed.) Ch.21: Modules: The Big Picture Ch.22: Module Coding Basics http://docs.python.org/release/2.4.3/modindex.html 1 Turn In Homework

More information

Python File Modes. Mode Description. Open a file for reading. (default)

Python File Modes. Mode Description. Open a file for reading. (default) UNIT V FILES, MODULES, PACKAGES Files and exception: text files, reading and writing files, format operator; command line arguments, errors and exceptions, handling exceptions, modules, packages; Illustrative

More information

Using Python for shell scripts

Using Python for shell scripts Using Python for shell scripts January 2018 1/29 Using Python for shell scripts Peter Hill Outline Using Python for shell scripts January 2018 2/29 Advantages/disadvantages of Python Running a parameter

More information

Systems Programming/ C and UNIX

Systems Programming/ C and UNIX Systems Programming/ C and UNIX A. Fischer CSCI 4547/6647 What is Time? November 6, 2017 A. Fischer CSCI 4547/6647[1ex]What is Time? Systems Programming Lecture 8... 1/24 November 6, 2017 1 / 24 Outline

More information

Python Essential Reference, Second Edition - Chapter 5: Control Flow Page 1 of 8

Python Essential Reference, Second Edition - Chapter 5: Control Flow Page 1 of 8 Python Essential Reference, Second Edition - Chapter 5: Control Flow Page 1 of 8 Chapter 5: Control Flow This chapter describes related to the control flow of a program. Topics include conditionals, loops,

More information

Introduction to python

Introduction to python Introduction to python 13 Files Rossano Venturini rossano.venturini@unipi.it File System A computer s file system consists of a tree-like structured organization of directories and files directory file

More information

Preview. Review. System Data Files (Password File) System Data Files (Password File) System Data Files (Password File)

Preview. Review. System Data Files (Password File) System Data Files (Password File) System Data Files (Password File) Review Preview link(), unlink() System Call remove(), rename() System Call Symbolic Links Symbolic link to directory Symbolic link to a executable file symlink() System Call File Times utime() System Call

More information

Lecture 23: System-Level I/O

Lecture 23: System-Level I/O CSCI-UA.0201-001/2 Computer Systems Organization Lecture 23: System-Level I/O Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com Some slides adapted (and slightly modified) from: Clark Barrett

More information

Examination C++ Programming

Examination C++ Programming LUND INSTITUTE OF TECHNOLOGY 1(8) Department of Computer Science Examination C++ Programming 2011 08 20, 8.00 13.00 Aid at the exam: one C++ book. The copies of the lecture slides are not allowed. You

More information

Weights and Biases Documentation

Weights and Biases Documentation Weights and Biases Documentation Release 0.6.17 Weights and Biases Aug 13, 2018 Contents 1 Intro 1 2 Quickstart - Existing Project 3 3 Weights & Biases Run API 5 3.1 Saving run files..............................................

More information

What we already know. more of what we know. results, searching for "This" 6/21/2017. chapter 14

What we already know. more of what we know. results, searching for This 6/21/2017. chapter 14 What we already know chapter 14 Files and Exceptions II Files are bytes on disk. Two types, text and binary (we are working with text) open creates a connection between the disk contents and the program

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Regular Expressions and Other Modules Eric Kutschera University of Pennsylvania February 20, 2015 Eric Kutschera (University of Pennsylvania) CIS 192 February 20, 2015 1 / 32

More information

Welcome to. Python 2. Session #5. Michael Purcaro, Chris MacKay, Nick Hathaway, and the GSBS Bootstrappers February 2014

Welcome to. Python 2. Session #5. Michael Purcaro, Chris MacKay, Nick Hathaway, and the GSBS Bootstrappers February 2014 Welcome to Python 2 Session #5 Michael Purcaro, Chris MacKay, Nick Hathaway, and the GSBS Bootstrappers February 2014 michael.purcaro@umassmed.edu 1 Building Blocks: modules To more easily reuse code,

More information

Script language: Python Data and files

Script language: Python Data and files Script language: Python Data and files Cédric Saule Technische Fakultät Universität Bielefeld 4. Februar 2015 Python User inputs, user outputs Command line parameters, inputs and outputs of user data.

More information

Confuse. Release 0.1.0

Confuse. Release 0.1.0 Confuse Release 0.1.0 July 02, 2016 Contents 1 Using Confuse 3 2 View Theory 5 3 Validation 7 4 Command-Line Options 9 5 Search Paths 11 6 Your Application Directory 13 7 Dynamic Updates 15 8 YAML Tweaks

More information

Spring INF Principles of Programming for Informatics. Manipulating Files

Spring INF Principles of Programming for Informatics. Manipulating Files Manipulating Files Copyright 2017, Pedro C. Diniz, all rights reserved. Students enrolled in the INF 510 class at the University of Southern California (USC) have explicit permission to make copies of

More information

Contents. NOTICE & Programming Assignment #1. QnA about last exercise. File IO exercise

Contents. NOTICE & Programming Assignment #1. QnA about last exercise. File IO exercise File I/O Examples Prof. Jin-Soo Kim(jinsookim@skku.edu) TA - Dong-Yun Lee(dylee@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Contents NOTICE & Programming Assignment

More information

A function is a way to turn a bunch of related statements into a single "chunk"

A function is a way to turn a bunch of related statements into a single chunk Copyright Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See http://software-carpentry.org/license.html for more information. A function is a way to turn a

More information

LECTURE 2. Python Basics

LECTURE 2. Python Basics LECTURE 2 Python Basics MODULES ''' Module fib.py ''' from future import print_function def even_fib(n): total = 0 f1, f2 = 1, 2 while f1 < n: if f1 % 2 == 0: total = total + f1 f1, f2 = f2, f1 + f2 return

More information

CSCI-E28 Lecture 3 Outline. Directories, File Attributes, Bits, File Operations. Write our own versions of Unix programs

CSCI-E28 Lecture 3 Outline. Directories, File Attributes, Bits, File Operations. Write our own versions of Unix programs CSCI-E28 Lecture 3 Outline Topics: Approach: Directories, File Attributes, Bits, File Operations Write our own versions of Unix programs Featured Commands: ls, ls -l Main Ideas: Adirectory is a list of

More information

Important Dates. October 27 th Homework 2 Due. October 29 th Midterm

Important Dates. October 27 th Homework 2 Due. October 29 th Midterm CSE333 SECTION 5 Important Dates October 27 th Homework 2 Due October 29 th Midterm String API vs. Byte API Recall: Strings are character arrays terminated by \0 The String API (functions that start with

More information

This manual is for Libffi, a portable foreign-function interface library. Copyright c 2008, 2010, 2011 Red Hat, Inc. Permission is granted to copy,

This manual is for Libffi, a portable foreign-function interface library. Copyright c 2008, 2010, 2011 Red Hat, Inc. Permission is granted to copy, Libffi This manual is for Libffi, a portable foreign-function interface library. Copyright c 2008, 2010, 2011 Red Hat, Inc. Permission is granted to copy, distribute and/or modify this document under the

More information

file_object=open( file_name.txt, mode ) f=open( sample.txt, w ) How to create a file:

file_object=open( file_name.txt, mode ) f=open( sample.txt, w ) How to create a file: UNIT 5 FILES, MODULES AND PACKAGES Files: text files, reading and writing files, format operator, command line arguments, Errors and Exceptions: handling exceptions, Modules, Packages; Illustrative programs:

More information

Table of Contents EVALUATION COPY

Table of Contents EVALUATION COPY Table of Contents Introduction... 1-2 A Brief History of Python... 1-3 Python Versions... 1-4 Installing Python... 1-5 Environment Variables... 1-6 Executing Python from the Command Line... 1-7 IDLE...

More information

Argparse Tutorial Release 2.7.9

Argparse Tutorial Release 2.7.9 Argparse Tutorial Release 2.7.9 Guido van Rossum and the Python development team December 10, 2014 Python Software Foundation Email: docs@python.org Contents 1 Concepts 1 2 The basics 2 3 Introducing Positional

More information

SYSTEM INFORMATION. UNIX Programming 2015 Fall by Euiseong Seo

SYSTEM INFORMATION. UNIX Programming 2015 Fall by Euiseong Seo SYSTEM INFORMATION UNIX Programming 2015 Fall by Euiseong Seo Host Information POSIX defines host information as follows OS name (Linux) OS release (3.13.0) OS version (#60-Ubuntu SMP Web Aug 13) Node

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Regular Expressions and maybe OS Robert Rand University of Pennsylvania October 1, 2015 Robert Rand (University of Pennsylvania) CIS 192 October 1, 2015 1 / 16 Outline 1 Regular

More information

Modules and Programs 1 / 14

Modules and Programs 1 / 14 Modules and Programs 1 / 14 Python Programs Python code organized in modules, packages, and scripts. We ve already used some modules, now we ll learn what they are, how they re orgainized in packages,

More information

EXAMINATIONS 2012 MID-YEAR NWEN 241 SYSTEMS PROGRAMMING. The examination contains 5 questions. You must answer ALL questions

EXAMINATIONS 2012 MID-YEAR NWEN 241 SYSTEMS PROGRAMMING. The examination contains 5 questions. You must answer ALL questions EXAMINATIONS 2012 MID-YEAR NWEN 241 SYSTEMS PROGRAMMING Time allowed: Instructions: THREE HOURS The examination contains 5 questions. You must answer ALL questions Each question is worth 36 marks. The

More information

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo I/O OPERATIONS UNIX Programming 2014 Fall by Euiseong Seo Files Files that contain a stream of bytes are called regular files Regular files can be any of followings ASCII text Data Executable code Shell

More information

System Calls. Library Functions Vs. System Calls. Library Functions Vs. System Calls

System Calls. Library Functions Vs. System Calls. Library Functions Vs. System Calls System Calls Library Functions Vs. System Calls A library function: Ordinary function that resides in a library external to the calling program. A call to a library function is just like any other function

More information

CIS 192: Lecture 6: Helpful Modules (os, sys, itertools, random, and re)

CIS 192: Lecture 6: Helpful Modules (os, sys, itertools, random, and re) CIS 192: Lecture 6: Helpful Modules (os, sys, itertools, random, and re) Lili Dworkin University of Pennsylvania Announcement For next week, make sure to install wxpython! You might run into trouble, in

More information

Memory Mapped I/O. Michael Jantz. Prasad Kulkarni. EECS 678 Memory Mapped I/O Lab 1

Memory Mapped I/O. Michael Jantz. Prasad Kulkarni. EECS 678 Memory Mapped I/O Lab 1 Memory Mapped I/O Michael Jantz Prasad Kulkarni EECS 678 Memory Mapped I/O Lab 1 Introduction This lab discusses various techniques user level programmers can use to control how their process' logical

More information

OstrichLib Documentation

OstrichLib Documentation OstrichLib Documentation Release 0.0.0 Itamar Ostricher May 10, 2016 Contents 1 utils package 3 1.1 collections utils module......................................... 3 1.2 path utils module.............................................

More information

Chapter 1 - Introduction. September 8, 2016

Chapter 1 - Introduction. September 8, 2016 Chapter 1 - Introduction September 8, 2016 Introduction Overview of Linux/Unix Shells Commands: built-in, aliases, program invocations, alternation and iteration Finding more information: man, info Help

More information

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo

I/O OPERATIONS. UNIX Programming 2014 Fall by Euiseong Seo I/O OPERATIONS UNIX Programming 2014 Fall by Euiseong Seo Files Files that contain a stream of bytes are called regular files Regular files can be any of followings ASCII text Data Executable code Shell

More information

Design Choices 2 / 29

Design Choices 2 / 29 File Systems One of the most visible pieces of the OS Contributes significantly to usability (or the lack thereof) 1 / 29 Design Choices 2 / 29 Files and File Systems What s a file? You all know what a

More information

Python Tutorial. Day 1

Python Tutorial. Day 1 Python Tutorial Day 1 1 Why Python high level language interpreted and interactive real data structures (structures, objects) object oriented all the way down rich library support 2 The First Program #!/usr/bin/env

More information

rpaths Documentation Release 0.2 Remi Rampin

rpaths Documentation Release 0.2 Remi Rampin rpaths Documentation Release 0.2 Remi Rampin June 09, 2014 Contents 1 Introduction 1 2 Classes 3 2.1 Abstract classes............................................. 3 2.2 Concrete class Path............................................

More information

Reading and Writing Files on Your Computer

Reading and Writing Files on Your Computer Reading and Writing Files on Your Computer Code Snippets HW2-3, HW2-4 Function Recap #!/usr/bin/env python3 Though it s called sentence in main, in replace_hello() that value is called text def replace_hello(text):

More information

File System (FS) Highlights

File System (FS) Highlights CSCI 503: Operating Systems File System (Chapters 16 and 17) Fengguang Song Department of Computer & Information Science IUPUI File System (FS) Highlights File system is the most visible part of OS From

More information

Processes in linux. What s s a process? process? A dynamically executing instance of a program. David Morgan. David Morgan

Processes in linux. What s s a process? process? A dynamically executing instance of a program. David Morgan. David Morgan Processes in linux David Morgan What s s a process? process? A dynamically executing instance of a program 1 Constituents of a process its code data various attributes OS needs to manage it OS keeps track

More information

Cross-platform daemonization tools.

Cross-platform daemonization tools. Cross-platform daemonization tools. Release 0.1.0 Muterra, Inc Sep 14, 2017 Contents 1 What is Daemoniker? 1 1.1 Installing................................................. 1 1.2 Example usage..............................................

More information

CS108 Lecture 09: Computing with Text Reading and writing files. Aaron Stevens 6 February Overview/Questions

CS108 Lecture 09: Computing with Text Reading and writing files. Aaron Stevens 6 February Overview/Questions CS108 Lecture 09: Computing with Text Reading and writing files Aaron Stevens 6 February 2009 1 Overview/Questions Review: string operators and operations Additional examples, if needed How else can we

More information

Files and Directories Filesystems from a user s perspective

Files and Directories Filesystems from a user s perspective Files and Directories Filesystems from a user s perspective Unix Filesystems Seminar Alexander Holupirek Database and Information Systems Group Department of Computer & Information Science University of

More information

File I/O. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

File I/O. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University File I/O Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Unix Files A Unix file is a sequence of m bytes: B 0, B 1,..., B k,..., B m-1 All I/O devices

More information

Python Call Graph. Release Gerald Kaszuba

Python Call Graph. Release Gerald Kaszuba Python Call Graph Release 1.0.1 Gerald Kaszuba Sep 21, 2017 Contents 1 Screenshots 3 2 Project Status 5 3 Features 7 4 Quick Start 9 5 Documentation Index 11 5.1 Usage Guide...............................................

More information

Processes. Johan Montelius KTH

Processes. Johan Montelius KTH Processes Johan Montelius KTH 2017 1 / 47 A process What is a process?... a computation a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other

More information

f90 unix file: Unix File Operations Module March 9, 2009

f90 unix file: Unix File Operations Module March 9, 2009 f90 unix file: Unix File Operations Module March 9, 2009 1 Name f90 unix file Module of Unix file operations 2 Usage USE F90 UNIX FILE This module contains part of a Fortran API to functions detailed in

More information

Systems Programming/ C and UNIX

Systems Programming/ C and UNIX Systems Programming/ C and UNIX A. Fischer CSCI 4547 / 6647 November 1, 2013 A. Fischer CSCI 4547 / 6647 () Systems Programming Lecture 8... 1/41 November 1, 2013 1 / 41 Outline 1 Signals for Threads Signals

More information

A process. the stack

A process. the stack A process Processes Johan Montelius What is a process?... a computation KTH 2017 a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other processes

More information

File I/O. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

File I/O. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University  Embedded Software Lab. 1 File I/O Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University http://nyx.skku.ac.kr Unix files 2 A Unix file is a sequence of m bytes: B 0, B 1,..., B k,..., B m-1 All I/O devices are represented

More information

Come to the Dark Side Python's Sinister Secrets

Come to the Dark Side Python's Sinister Secrets Come to the Dark Side Python's Sinister Secrets @markbaggett 1 Get-ADUser -Filter "Mark Baggett" fl -Properties * Mark Baggett Penetration Testing and Incident Response Consulting Senior SANS Instructor

More information

Processes. What s s a process? process? A dynamically executing instance of a program. David Morgan

Processes. What s s a process? process? A dynamically executing instance of a program. David Morgan Processes David Morgan What s s a process? process? A dynamically executing instance of a program 1 Constituents of a process its code data various attributes OS needs to manage it OS keeps track of all

More information

17: Filesystem Examples: CD-ROM, MS-DOS, Unix

17: Filesystem Examples: CD-ROM, MS-DOS, Unix 17: Filesystem Examples: CD-ROM, MS-DOS, Unix Mark Handley CD Filesystems ISO 9660 Rock Ridge Extensions Joliet Extensions 1 ISO 9660: CD-ROM Filesystem CD is divided into logical blocks of 2352 bytes.

More information

Fall 2015 COMP Operating Systems. Lab #3

Fall 2015 COMP Operating Systems. Lab #3 Fall 2015 COMP 3511 Operating Systems Lab #3 Outline n Operating System Debugging, Generation and System Boot n Review Questions n Process Control n UNIX fork() and Examples on fork() n exec family: execute

More information

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1 Shell Scripting Todd Kelley kelleyt@algonquincollege.com CST8207 Todd Kelley 1 If we have a set of commands that we want to run on a regular basis, we could write a script A script acts as a Linux command,

More information

PLEAC-Python

PLEAC-Python Prev PLEAC-Python Next 3. Introduction #introduction # There are three common ways of manipulating dates in Python # mxdatetime - a popular third-party module (not discussed here) # time - a fairly low-level

More information

ffmpy3 Documentation Release Eric Ahn

ffmpy3 Documentation Release Eric Ahn ffmpy3 Documentation Release 0.2.3 Eric Ahn February 03, 2017 Contents 1 Installation 3 2 Quickstart 5 3 Documentation 7 3.1 ffmpy3.................................................. 7 3.2 Examples.................................................

More information

Computational Methods of Scientific Programming. Lecturers Thomas A Herring Chris Hill

Computational Methods of Scientific Programming. Lecturers Thomas A Herring Chris Hill 12.010 Computational Methods of Scientific Programming Lecturers Thomas A Herring Chris Hill Overview Part 1: Python Language Basics getting started. Part 2: Python Advanced Usage the utility of Python

More information

Class extension and. Exception handling. Genome 559

Class extension and. Exception handling. Genome 559 Class extension and Exception handling Genome 559 Review - classes 1) Class constructors - class myclass: def init (self, arg1, arg2): self.var1 = arg1 self.var2 = arg2 foo = myclass('student', 'teacher')

More information

UNIX System Calls. Sys Calls versus Library Func

UNIX System Calls. Sys Calls versus Library Func UNIX System Calls Entry points to the kernel Provide services to the processes One feature that cannot be changed Definitions are in C For most system calls a function with the same name exists in the

More information

Programming Language B

Programming Language B Programming Language B Takako Nemoto (JAIST) 28 January Takako Nemoto (JAIST) 28 January 1 / 20 Today s quiz The following are program to print each member of the struct Student type object abe. Fix the

More information

I/O and Shell Scripting

I/O and Shell Scripting I/O and Shell Scripting File Descriptors Redirecting Standard Error Shell Scripts Making a Shell Script Executable Specifying Which Shell Will Run a Script Comments in Shell Scripts File Descriptors Resources

More information

Operating System Labs. Yuanbin Wu

Operating System Labs. Yuanbin Wu Operating System Labs Yuanbin Wu CS@ECNU Operating System Labs Project 4 (multi-thread & lock): Due: 10 Dec Code & experiment report 18 Dec. Oral test of project 4, 9:30am Lectures: Q&A Project 5: Due:

More information

Modules and scoping rules

Modules and scoping rules C H A P T E R 1 1 Modules and scoping rules 11.1 What is a module? 106 11.2 A first module 107 11.3 The import statement 109 11.4 The module search path 110 11.5 Private names in modules 112 11.6 Library

More information

Coding Getting Started with Python

Coding Getting Started with Python DEVNET-3602 Coding 1002 - Getting Started with Python Matthew DeNapoli, DevNet Developer Evangelist Cisco Spark How Questions? Use Cisco Spark to communicate with the speaker after the session 1. Find

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Probability and Simulations (With Other Modules) Harry Smith University of Pennsylvania October 11, 2017 Harry Smith (University of Pennsylvania) CIS 192 Lecture 7 October 11,

More information

examples from first year calculus (continued), file I/O, Benford s Law

examples from first year calculus (continued), file I/O, Benford s Law examples from first year calculus (continued), file I/O, Benford s Law Matt Valeriote 5 February 2018 Grid and Bisection methods to find a root Assume that f (x) is a continuous function on the real numbers.

More information

CSC108: Introduction to Computer Programming. Lecture 11

CSC108: Introduction to Computer Programming. Lecture 11 CSC108: Introduction to Computer Programming Lecture 11 Wael Aboulsaadat Acknowledgment: these slides are based on material by: Velian Pandeliev, Diane Horton, Michael Samozi, Jennifer Campbell, and Paul

More information

Course Objectives. At the conclusion of this course, students will be able to:

Course Objectives. At the conclusion of this course, students will be able to: Course Objectives At the conclusion of this course, students will be able to: Execute Python code in a variety of environments Use correct Python syntax in Python programs Use the correct Python control

More information

Project 1: Implementing a Shell

Project 1: Implementing a Shell Assigned: August 28, 2015, 12:20am Due: September 21, 2015, 11:59:59pm Project 1: Implementing a Shell Purpose The purpose of this project is to familiarize you with the mechanics of process control through

More information

CS246-Assign01 V1.1: Winter 2013

CS246-Assign01 V1.1: Winter 2013 CS246-Assign01 V1.1: Winter 2013 http://plg.uwaterloo.ca/~holt/cs/246/2013/asgn01/asgn01.htm Submit. Instructions to submit assignments (using Marmoset): https://marmoset.student.cs.uwaterloo.ca/ Instructions

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Regular Expressions and Other Modules Raymond Yin University of Pennsylvania October 5, 2016 Raymond Yin (University of Pennsylvania) CIS 192 October 5, 2016 1 / 49 Outline 1

More information

Lecture 21 Systems Programming in C

Lecture 21 Systems Programming in C Lecture 21 Systems Programming in C A C program can invoke UNIX system calls directly. A system call can be defined as a request to the operating system to do something on behalf of the program. During

More information

Exception Handling. Genome 559

Exception Handling. Genome 559 Exception Handling Genome 559 Review - classes Use your own classes to: - package together related data - conceptually organize your code - force a user to conform to your expectations Class constructor:

More information

Senthil Kumaran S

Senthil Kumaran S Senthil Kumaran S http://www.stylesen.org/ Agenda History Basics Control Flow Functions Modules History What is Python? Python is a general purpose, object-oriented, high level, interpreted language Created

More information

Contents. Programming Assignment 0 review & NOTICE. File IO & File IO exercise. What will be next project?

Contents. Programming Assignment 0 review & NOTICE. File IO & File IO exercise. What will be next project? File I/O Prof. Jin-Soo Kim(jinsookim@skku.edu) TA - Dong-Yun Lee(dylee@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Contents Programming Assignment 0 review & NOTICE

More information

Operating System Labs. Yuanbin Wu

Operating System Labs. Yuanbin Wu Operating System Labs Yuanbin Wu CS@ECNU Operating System Labs Project 3 Oral test Handin your slides Time Project 4 Due: 6 Dec Code Experiment report Operating System Labs Overview of file system File

More information

argcomplete Documentation Andrey Kislyuk

argcomplete Documentation Andrey Kislyuk Andrey Kislyuk May 08, 2018 Contents 1 Installation 3 2 Synopsis 5 2.1 argcomplete.autocomplete(parser).................................... 5 3 Specifying completers 7 3.1 Readline-style completers........................................

More information

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring 2009 Topic Notes: C and Unix Overview This course is about computer organization, but since most of our programming is

More information

structs as arguments

structs as arguments Structs A collection of related data items struct record { char name[maxname]; int count; ; /* The semicolon is important! It terminates the declaration. */ struct record rec1; /*allocates space for the

More information

Python at Glance. a really fast (but complete) ride into the Python hole. Paolo Bellagente - ES3 - DII - UniBS

Python at Glance. a really fast (but complete) ride into the Python hole. Paolo Bellagente - ES3 - DII - UniBS Python at Glance a really fast (but complete) ride into the Python hole. Paolo Bellagente - ES3 - DII - UniBS Python 2.7 isn t compatible with python 3!!!! Rule #1: RTFM Read The F*****g Funny Manual Rule

More information

Automating common tasks

Automating common tasks Chapter 16 Automating common tasks One of the great advantages of the Python language is the ability to write programs that scan through your computer and perform some operation on each file.filesareorganized

More information

Idioms and Anti-Idioms in Python

Idioms and Anti-Idioms in Python Idioms and Anti-Idioms in Python Release 2.6.3 Guido van Rossum Fred L. Drake, Jr., editor October 06, 2009 Python Software Foundation Email: docs@python.org Contents 1 Language Constructs You Should Not

More information

Introduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas

Introduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas Introduction to Python Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas If you have your own PC, download and install a syntax-highlighting text editor and Python

More information

CS , Spring Sample Exam 3

CS , Spring Sample Exam 3 Andrew login ID: Full Name: CS 15-123, Spring 2010 Sample Exam 3 Mon. April 6, 2009 Instructions: Make sure that your exam is not missing any sheets, then write your full name and Andrew login ID on the

More information

Command Interpreters. command-line (e.g. Unix shell) On Unix/Linux, bash has become defacto standard shell.

Command Interpreters. command-line (e.g. Unix shell) On Unix/Linux, bash has become defacto standard shell. Command Interpreters A command interpreter is a program that executes other programs. Aim: allow users to execute the commands provided on a computer system. Command interpreters come in two flavours:

More information

Python 3 Quick Reference Card

Python 3 Quick Reference Card Python 3 Quick Reference Card Data types Strings: s = "foo bar" s = 'foo bar' s = r"c:\dir\new" # raw (== 'c:\\dir\\new') s = """Hello world""" s.join(" baz") n = len(s) "Ala ma {} psy i {} koty".format(2,3)

More information

Introduction to Linux and Cluster Computing Environments for Bioinformatics

Introduction to Linux and Cluster Computing Environments for Bioinformatics Introduction to Linux and Cluster Computing Environments for Bioinformatics Doug Crabill Senior Academic IT Specialist Department of Statistics Purdue University dgc@purdue.edu What you will learn Linux

More information

Hacettepe University Computer Engineering Department. Programming in. BBM103 Introduction to Programming Lab 1 Week 4. Fall 2018

Hacettepe University Computer Engineering Department. Programming in. BBM103 Introduction to Programming Lab 1 Week 4. Fall 2018 Hacettepe University Computer Engineering Department Programming in BBM103 Introduction to Programming Lab 1 Week 4 Fall 2018 Install PyCharm Download Link : https://www.jetbrains.com/pycharm-edu/download/#section=windows

More information