تابع open در زبان پایتون (قسمت1)
متودهای تابع open در پایتون

💻 تابع open در زبان پایتون | (قسمت 2)

جلسه شصتم| آموزش پایتون مقدماتی

مدّرس:  احمد احمدی


🧾 خلاصه این جلسه: 

✅ در جلسه شصتم از دوره آموزش پایتون، به ادامه بررسی تابع open پرداختیم. در این جلسه درباره mode = a که دروابع به معنای append کردن یا همان ضمیمه کردن به انتهای فایل است، صحبت کردیم و به صورت عملی نیز تفاوت آن را با mode = w نیز بررسی نمودیم.

 [ دانلود فایل جوپیتر نوتبوک این جلسه (حتماً دانلود شود) ]


4 دیدگاه. ارسال دیدگاه جدید

  • ‘a+’ Mode:
    File Creation: Creates the file if it doesn’t exist.
    File Pointer Position: Positioned at the end of the file initially.
    Use Case: Appending new data to an existing file without removing previous content.
    Existing Content: Existing content is not removed; new data is added after it.
    Append and Read: Allows both appending new data and reading from the file.

    ‘w+’ Mode:
    File Creation: Creates the file if it doesn’t exist or truncates existing content.
    File Pointer Position: Positioned at the beginning of the file initially.
    Use Case: Writing new data and potentially overwriting or replacing existing content.
    Read and Write: Allows both reading and writing to the file.

    ‘r+’ Mode:
    File Creation: Requires the file to already exist; won’t create a new file.
    File Pointer Position: Positioned at the beginning of the file initially.
    Use Case: Reading from and writing to an existing file without truncating its content.
    Existing Content: Existing content can be read and modified.
    Read and Write: Allows both reading and writing to the file.

    پاسخ
  • +w میاد و content های داخل فایل را پاک میکنه یا فایلی را بوجود میاره. اما +r فقط فایلی را که وجود داره را میخونه و رایت می کنه. pointer در هر دو فایل در اول فایل میاد.
    +a هم به آخر فایل اضافه میکنه و فقط به فایل قبلی اضافه میشه.

    پاسخ

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

این فیلد را پر کنید
این فیلد را پر کنید
لطفاً یک نشانی ایمیل معتبر بنویسید.
برای ادامه، شما باید با قوانین موافقت کنید

keyboard_arrow_up