PRO_PYTHON_CODE Telegram 1475
🖥 Как в одну строку кода прочитать файл и удалить пробелы в начале и конце каждой строки

Вот нехитрый однострочник, который позволяет упростить чтение файла в Python.

print([line.strip() for line in open("filename.txt")])


Этот однострочник:

- Открывает файл "filename.txt".
- Читает его построчно.
- Удаляет пробелы в начале и в конце каждой строки.
- Сохраняет очищенные строки в виде списка.

@pro_python_code
Please open Telegram to view this post
VIEW IN TELEGRAM



tgoop.com/pro_python_code/1475
Create:
Last Update:

🖥 Как в одну строку кода прочитать файл и удалить пробелы в начале и конце каждой строки

Вот нехитрый однострочник, который позволяет упростить чтение файла в Python.


print([line.strip() for line in open("filename.txt")])


Этот однострочник:

- Открывает файл "filename.txt".
- Читает его построчно.
- Удаляет пробелы в начале и в конце каждой строки.
- Сохраняет очищенные строки в виде списка.

@pro_python_code

BY Python RU


Share with your friend now:
tgoop.com/pro_python_code/1475

View MORE
Open in Telegram


Telegram News

Date: |

Telegram has announced a number of measures aiming to tackle the spread of disinformation through its platform in Brazil. These features are part of an agreement between the platform and the country's authorities ahead of the elections in October. 6How to manage your Telegram channel? Users are more open to new information on workdays rather than weekends. The imprisonment came as Telegram said it was "surprised" by claims that privacy commissioner Ada Chung Lai-ling is seeking to block the messaging app due to doxxing content targeting police and politicians. Concise
from us


Telegram Python RU
FROM American