This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
script, input_file = argv | |
def print_all(f): | |
print(f.read()) | |
def rewind(f): | |
f.seek(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cheese_and_crackers(cheese_count, boxes_of_crackers): | |
print(f"You have {cheese_count} cheeses!") | |
print(f"You have {boxes_of_crackers} boxes of crackers!") | |
print("Man that's enough for a party!") | |
print("Get a blanket. \n") | |
print("We can just give the function numbers directly:") | |
cheese_and_crackers(20, 30) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this one is like your scripts with argv | |
def print_two(*args): | |
arg1, arg2 = args | |
print(f"arg1: {arg1}, arg2: {arg2}") | |
# ok, that *args is actually pointless, we can just do this shorter | |
def print_two_again(arg1, arg2): | |
print(f"arg1: {arg1}, arg2: {arg2}") | |
# this just takes one argument |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
from os.path import exists | |
script, from_file, to_file = argv | |
print(f"Copying from {from_file} to {to_file}") | |
# we could do these two on one line, how? | |
in_file = open(from_file) | |
in_data = in_file.read() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
script, filename = argv | |
print(f"We're going to erase {filename}.") | |
print("If you don't want that hit CTRL-C {^C}.") | |
print("If you do not want that, hit RETURN.") | |
input("?") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv# Imports module argv from library sys | |
script, filename = argv# get and set script and filename variables from user input | |
txt = open(filename)# set variable txt with a function | |
print(f"Here's your file {filename}")# This prints a sentence and a variable print(f"bla {variable"} | |
print(txt.read()) # this print a call to a function (read) | |
print("Type the filename again:")# print a string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
script, user_name = argv | |
prompt = "$>" | |
print(f"Hi {user_name}, I'm the {script} script") | |
print("I'd like to ask you a few questions.") | |
print(f"Do you like me {user_name}?") | |
likes = input(prompt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv# Imports module argv from library sys | |
script, filename = argv# get and set script and filename variables from user input | |
txt = open(filename)# set variable txt with a function | |
print(f"Here's your file {filename}") # This prints a sentence and a variable print(f"bla {variable"} | |
print(txt.read()) # this print a call to a variable that consist in a function | |
print("Type the filename again:") # print a string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
script, user_name = argv | |
prompt = "$>" | |
print(f"Hi {user_name}, I'm the {script} script") | |
print("I'd like to ask you a few questions.") | |
print(f"Do you like me {user_name}?") | |
likes = input(prompt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
# Read the WYSS section for how to run this | |
script, first, second, third = argv | |
print("The script is called:", script) | |
print("Your first variable is:", first) | |
print("Your second variable is:", second) | |
print("Your third variable is:", third) |