Skip to content

Instantly share code, notes, and snippets.

View santosadrian's full-sized avatar
💭
Buscándome la vida que la muerte viene sola.

Adrian Santos santosadrian

💭
Buscándome la vida que la muerte viene sola.
View GitHub Profile
@santosadrian
santosadrian / scratch_20.py
Created February 4, 2020 13:21
Example 20
from sys import argv
script, input_file = argv
def print_all(f):
print(f.read())
def rewind(f):
f.seek(0)
@santosadrian
santosadrian / scratch_19.py
Created February 4, 2020 09:38
Example 19
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)
@santosadrian
santosadrian / scratch_18.py
Created February 4, 2020 08:09
Example 18
# 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
@santosadrian
santosadrian / scratch_17.py
Created February 3, 2020 17:55
Example 17
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()
@santosadrian
santosadrian / scratch_16.py
Created February 3, 2020 16:24
Example 16
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("?")
@santosadrian
santosadrian / scratch_15.py
Created February 3, 2020 14:46
Example 15
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
@santosadrian
santosadrian / scratch_14.py
Created February 3, 2020 14:46
Example 14
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)
@santosadrian
santosadrian / scratch_15.py
Created February 3, 2020 12:05
Example 15
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
@santosadrian
santosadrian / scratch_14.py
Created February 3, 2020 12:04
Example 14
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)
@santosadrian
santosadrian / scratch_13.py
Created February 2, 2020 14:36
Example 13
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)