Új hozzászólás Aktív témák
-
sztikac
őstag
Sziasztok, a Learn Python 3 The Hard Way könyvből tanulom a Python-t és van ez a feladat:
from sys import argvfrom 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)
indata = in_file.read()
print(f"The input file is {len(indata)} bytes long")
print(f"Does the output file exist? {exists(to_file)}")
print("Ready, hit RETURN to continue, CTRL-C to abort.")
input()
out_file = open(to_file, 'w')
out_file.write(indata)
print("Alright, all done.")out_file.close()
in_file.close()Ezt teljesen világos is, hogy mit-miért csinál.
Aztán van ugye a feladatok között egy ilyen:See how short you can make the script. I could make this one line long.
Ezzel eddig jutottam (még elég messze vagyok az 1 sortól
):from sys import argvscript, from_file, to_file = argvin_data = open(from_file).read()open(to_file, 'w').write(in_data)Ez így lefut, rendben le is másolja a megadott fájlt, csak ugye ebben az esetben nincs file descriptorom így nem tudom min meghívni a close()-t. Úgy tudom a program lefutása után az OS úgyis bezárja a nyitott fájlokat, de szabályos ez így?
Új hozzászólás Aktív témák
- ÁRGARANCIA!Épített KomPhone i7 14700KF 32/64GB RAM RTX 5070 Ti 16GB GAMER PC termékbeszámítással
- Dell Latitude 7290,12.5",FHD,i5-7300U,8GB DDR4,256GB SSD,WIN11
- Apple iPhone 13 / 128GB / Kártyafüggetlen / 12Hó garancia / Akku:100%
- Apple iPhone SE 2022 64GB, Kártyafüggetlen, 1 Év Garanciával
- Asus 17 TUF Gaming FHD IPS 144Hz G-Sync Ryzen7 7435HS 16GB 512GB Nvidia RTX 4060 8GB Win11 Garancia
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
):
