WRITE FILES using Python! (.txt, .json, .csv) ✍

Поделиться
HTML-код
  • Опубликовано: 15 янв 2025

Комментарии • 18

  • @BroCodez
    @BroCodez  6 месяцев назад +5

    # Python writing files (.txt, .json, .csv)
    # --------- .txt ---------
    txt_data = "I like pizza!"
    file_path = "output.txt"
    try:
    with open(file_path, 'w') as file:
    file.write(txt_data)
    print(f".txt file '{file_path}' has been created successfully")
    except FileExistsError:
    print("That file already exists")
    # --------- .json ---------
    import json
    employee = {
    "name": "Spongebob",
    "age": 30,
    "job": "Cook"
    }
    file_path = "output.json"
    try:
    with open(file_path, 'w') as file:
    json.dump(employee, file, indent=4)
    print(f"JSON file '{file_path}' has been created successfully")
    except FileExistsError:
    print("That file already exists!")
    # --------- .csv---------
    import csv
    employees = [["Name", "Age", "Job"],
    ["Spongebob", 30, "Cook"],
    ["Patrick", 37, "Unemployed"],
    ["Sandy", 27, "Scientist"]]
    file_path = "output.csv"
    try:
    with open(file_path, "w", newline="") as file:
    writer = csv.writer(file)
    for row in employees:
    writer.writerow(row)
    print(f"csv file '{file_path}' was created")
    except FileExistsError:
    print("That file already exists!")

  • @rayhan5537
    @rayhan5537 6 месяцев назад +5

    Been learning python through your 12 hr vid and its helped alot

  • @Stephen47
    @Stephen47 6 месяцев назад +13

    Nuke codes folder lmao, bro is the cultured teacher xD

    • @toke7342
      @toke7342 Месяц назад

      It's a joke bro

  • @mustafaarac550
    @mustafaarac550 15 дней назад

    Great video! Also glad to know that you're a souls fan

  • @PrinceVegeta2710
    @PrinceVegeta2710 4 месяца назад +3

    3:18 Nuclear Launch Codes 😂😂😂😂😂😂😂😂
    FBI OPEN UP ! 🚓🚓

  • @YuttanaNoiphlai-k5w
    @YuttanaNoiphlai-k5w 6 месяцев назад

    Лаба твои инсайды просто бомба! Жду новых идей.

  • @rajushah8748
    @rajushah8748 6 месяцев назад +1

    Thank you bro code . I know nothing about python yet , I'm currently learning JavaScript through your free JavaScript course. And I'm here to thank you ❤❤❤❤

  • @AbelFikadu-lt1ei
    @AbelFikadu-lt1ei 6 месяцев назад

    Thank you bro code that was very helpful!!!

  • @morrixbongs8996
    @morrixbongs8996 6 месяцев назад

    New in here... Eager to learn about coding

  • @_MEga_Bit
    @_MEga_Bit 6 месяцев назад +1

    Bro is a souls player

  • @MarianoBustos-i1f
    @MarianoBustos-i1f 6 месяцев назад

    much appreciated Bro

  • @hoanginh1437
    @hoanginh1437 6 месяцев назад

    thats useful bro
    can you do a free course about data structures and algorithms java pls bro i beg you

  • @OldSoulSerenade750
    @OldSoulSerenade750 6 месяцев назад

    Thanks bro

  • @t.bo.a7061
    @t.bo.a7061 2 месяца назад

    Why is python allowed to do all this

  • @theherok_plays
    @theherok_plays 6 месяцев назад +1

    I was gonna like the video but it has 69 likes so i wont ruin it, anyways W vid

  • @t.o.x.i.cplayers2095
    @t.o.x.i.cplayers2095 6 месяцев назад

    Hi this video is 🎉🎉