💻 تابع 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 هم به آخر فایل اضافه میکنه و فقط به فایل قبلی اضافه میشه.
سلام وقتبخیر ❤️🫡
بسیار عالی. ممنون از مشارکتتون.