Last active
December 18, 2021 18:19
-
-
Save MarkCLewis/c90da4a0baa5ecedd4f449634a5be7e1 to your computer and use it in GitHub Desktop.
File Reading Comparison (dnamic vs. static)
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 readData(filename): | |
f = open(filename, 'r') | |
v1 = int(f.readline()) | |
v2 = f.readline() | |
v3 = f.readline() | |
f.close() | |
return (v1, v2, v3) | |
def mult(x, y): | |
print(x, y) # Added for debugging | |
return x * y | |
def useData(x, y, desc): | |
# Imagine this has more too it | |
print(f'{mult(x, y)} {desc}') | |
(x, y, desc) = readData('data.txt') | |
useData(x, y, desc) |
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 readData(filename: String): (Int, Int, String) = | |
val f = io.Source.fromFile(filename) | |
val lines = f.getLines | |
val v1 = lines.next().toInt | |
val v2 = lines.next() | |
val v3 = lines.next() | |
f.close() | |
(v1, v2, v3) | |
def mult(x: Int, y: Int): Int = x * y | |
def useData(x: Int, y: Int, desc: String) = | |
// Imagine this has more too it | |
println(s"${mult(x, y)} $desc") | |
@main def start = | |
val (x, y, desc) = readData("data.txt") | |
useData(x, y, desc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment