'Apart from using 'with', what else can I do to have the same results?
The code:
with open("integers.txt", "r") as fin, \
open("products.txt", "w") as fout:
The answers should be put in another file.
Solution 1:[1]
Apart from using 'with', what else can I do to have the same results?
with open("integers.txt", "r") as fin, open("products.txt", "w") as fout:
You can replace this with
/as
block with two variables:
fin = open("integers.txt", "r")
fout = open("products.txt", "w")
Then you only have to remember to write
fin.close()
fout.close()
at the end of your program.
I would suggest you to read the documentation about open
and with
/as
blocks.
What's more I don't get why you are doing this:
def mult(a, b=1, c=1, d=1, e=1, f=1, g=1):
return a * b * c * d * e * f * g
This function can only have 7 arguments, why don't you use *args
?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | FLAK-ZOSO |