-



Download 9,79 Mb.
Pdf ko'rish
bet44/64
Sana16.01.2022
Hajmi9,79 Mb.
#372467
1   ...   40   41   42   43   44   45   46   47   ...   64
Bog'liq
[Nichola Lacey] Python by Example Learning to Pro(1)


Creates a new file and writes to that file. If the file 
already exists, a new file will be created, overwriting 
the existing file. 

Creates a new file and writes to that file. If the file 
already exists, the program will crash rather than 
overwrite it.  

Opens for reading only and will not allow you to make 
changes. 

Opens for writing, appending to the end of the file. 
 
 
 
 


Challenges 111 - 117: Reading and Writing to a .csv File 
993 
 
 
 
Example Code 
 
 
 
 
 
 
import csv 
This must be at 
the top of your 
program to allow 
Python to use the 
.csv library of 
commands. 
file = open (“Stars.csv”,“w”) 
newRecord = “Brian,73,Taurus\n” 
file.write(str(newRecord)) 
file.close() 
This will create a new file called “Stars.csv”, overwriting any 
previous files of the same name. It will add a new record and 
then close and save the changes to the file. 
file = open (“Stars.csv”,“a”) 
name = input(“Enter name: ”) 
age = input(“Enter age: ”) 
star = input(“Enter star sign: ”) 
newRecord = name + “,” + age + “,” + star + “\n” 

Download 9,79 Mb.

Do'stlaringiz bilan baham:
1   ...   40   41   42   43   44   45   46   47   ...   64




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish