{"id":135512,"date":"2026-08-02T17:29:17","date_gmt":"2026-08-02T11:29:17","guid":{"rendered":"https:\/\/rcl-radio.ru\/?p=135512"},"modified":"2026-08-02T17:29:17","modified_gmt":"2026-08-02T11:29:17","slug":"%d0%ba%d0%b0%d0%ba-%d1%87%d0%b8%d1%82%d0%b0%d1%82%d1%8c-%d0%b8-%d0%bf%d0%b8%d1%81%d0%b0%d1%82%d1%8c-%d1%84%d0%b0%d0%b9%d0%bb%d1%8b-%d0%b2-python-open-read-write-%d0%b8-%d0%b7%d0%b0%d1%87","status":"publish","type":"post","link":"https:\/\/rcl-radio.ru\/?p=135512","title":{"rendered":"\u041a\u0430\u043a \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0432 Python: open(), read(), write() \u0438 \u0437\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u0435\u043d with"},"content":{"rendered":"<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438\u00a0\u2014\u00a0\u043e\u0434\u043d\u0430 \u0438\u0437 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432 Python: \u0447\u0442\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0439, \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043b\u043e\u0433\u043e\u0432, \u0438\u043c\u043f\u043e\u0440\u0442\/\u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0444\u0430\u0439\u043b\u043e\u0432, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code class=\"CodeInlined\">open()<\/code>, \u043c\u0435\u0442\u043e\u0434\u044b <code class=\"CodeInlined\">read()<\/code>, <code class=\"CodeInlined\">write()<\/code>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code class=\"CodeInlined\">with<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u0435\u043b\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0439.<\/p>\n<hr \/>\n<h2>\u041e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0444\u0430\u0439\u043b\u0430: \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code class=\"CodeInlined\">open()<\/code><\/h2>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code class=\"CodeInlined\">open(file, mode, encoding=None, ...)<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0447\u0438\u0442\u0430\u0442\u044c \u0438\u043b\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li data-value=\"\" data-shift=\"0\"><code class=\"CodeInlined\">file<\/code>\u00a0\u2014\u00a0\u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 (\u0441\u0442\u0440\u043e\u043a\u0430).<\/li>\n<li data-value=\"\" data-shift=\"0\"><code class=\"CodeInlined\">mode<\/code>\u00a0\u2014\u00a0\u0440\u0435\u0436\u0438\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0430.<\/li>\n<li data-value=\"\" data-shift=\"0\"><code class=\"CodeInlined\">encoding<\/code>\u00a0\u2014\u00a0\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0430 (\u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432).<\/li>\n<\/ul>\n<h3>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0440\u0435\u0436\u0438\u043c\u044b<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u0420\u0435\u0436\u0438\u043c<\/th>\n<th>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code class=\"CodeInlined\">'r'<\/code><\/td>\n<td>\u0427\u0442\u0435\u043d\u0438\u0435 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e). \u0424\u0430\u0439\u043b \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c.<\/td>\n<\/tr>\n<tr>\n<td><code class=\"CodeInlined\">'w'<\/code><\/td>\n<td>\u0417\u0430\u043f\u0438\u0441\u044c. \u0421\u043e\u0437\u0434\u0430\u0451\u0442 \u0444\u0430\u0439\u043b \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439.<\/td>\n<\/tr>\n<tr>\n<td><code class=\"CodeInlined\">'a'<\/code><\/td>\n<td>\u0414\u043e\u0437\u0430\u043f\u0438\u0441\u044c. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043a\u043e\u043d\u0435\u0446 \u0444\u0430\u0439\u043b\u0430.<\/td>\n<\/tr>\n<tr>\n<td><code class=\"CodeInlined\">'x'<\/code><\/td>\n<td>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430. \u0415\u0441\u043b\u0438 \u0444\u0430\u0439\u043b \u0443\u0436\u0435 \u0435\u0441\u0442\u044c\u00a0\u2014\u00a0\u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443.<\/td>\n<\/tr>\n<tr>\n<td><code class=\"CodeInlined\">'b'<\/code><\/td>\n<td>\u0411\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c (\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043a \u0434\u0440\u0443\u0433\u0438\u043c: <code class=\"CodeInlined\">'rb'<\/code>, <code class=\"CodeInlined\">'wb'<\/code> \u0438 \u0442.\u00a0\u0434.).<\/td>\n<\/tr>\n<tr>\n<td><code class=\"CodeInlined\">'t'<\/code><\/td>\n<td>\u0422\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u0440\u0435\u0436\u0438\u043c (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 <code class=\"CodeInlined\">'r'<\/code>, <code class=\"CodeInlined\">'w'<\/code> \u0438 \u0434\u0440.).<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\">f <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"data.txt\"<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"r\"<\/span><span style=\"color: #66cc66;\">,<\/span> encoding<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #483d8b;\">\"utf-8\"<\/span><span style=\"color: black;\">)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>\u0412\u0430\u0436\u043d\u043e:<\/strong> \u0435\u0441\u043b\u0438 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u044c <code class=\"CodeInlined\">encoding<\/code>, \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u041e\u0421 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0430\u0437\u043d\u044b\u0435 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0438, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u0442 \u043a \u0438\u0441\u043a\u0430\u0436\u0435\u043d\u0438\u044e \u0442\u0435\u043a\u0441\u0442\u0430 \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u043a\u0430\u043c. \u0414\u043b\u044f \u043a\u0440\u043e\u0441\u0441\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0445 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u0432\u0441\u0435\u0433\u0434\u0430 \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0439\u0442\u0435 <code class=\"CodeInlined\">encoding=\"utf-8\"<\/code>.<\/p>\n<hr \/>\n<h2>\u0427\u0442\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430: \u043c\u0435\u0442\u043e\u0434\u044b <code class=\"CodeInlined\">read()<\/code>, <code class=\"CodeInlined\">readline()<\/code>, <code class=\"CodeInlined\">readlines()<\/code><\/h2>\n<h3><code class=\"CodeInlined\">read()<\/code>\u00a0\u2014\u00a0\u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u0441\u0451 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435<\/h3>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #ff7700; font-weight: bold;\">with<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"data.txt\"<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"r\"<\/span><span style=\"color: #66cc66;\">,<\/span> encoding<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #483d8b;\">\"utf-8\"<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> f:\r\n    content <span style=\"color: #66cc66;\">=<\/span> f.<span style=\"color: black;\">read<\/span><span style=\"color: black;\">(<\/span><span style=\"color: black;\">)<\/span>\r\n<span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span>content<span style=\"color: black;\">)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0423\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432. \u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043d\u044f\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<h3><code class=\"CodeInlined\">readline()<\/code>\u00a0\u2014\u00a0\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043e \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435<\/h3>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #ff7700; font-weight: bold;\">with<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"data.txt\"<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"r\"<\/span><span style=\"color: #66cc66;\">,<\/span> encoding<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #483d8b;\">\"utf-8\"<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> f:\r\n    <span style=\"color: #ff7700; font-weight: bold;\">while<\/span> <span style=\"color: #008000;\">True<\/span>:\r\n        line <span style=\"color: #66cc66;\">=<\/span> f.<span style=\"color: #dc143c;\">readline<\/span><span style=\"color: black;\">(<\/span><span style=\"color: black;\">)<\/span>\r\n        <span style=\"color: #ff7700; font-weight: bold;\">if<\/span> <span style=\"color: #ff7700; font-weight: bold;\">not<\/span> line:  <span style=\"color: #808080; font-style: italic;\"># \u043a\u043e\u043d\u0435\u0446 \u0444\u0430\u0439\u043b\u0430<\/span>\r\n            <span style=\"color: #ff7700; font-weight: bold;\">break<\/span>\r\n        <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span>line.<span style=\"color: black;\">rstrip<\/span><span style=\"color: black;\">(<\/span><span style=\"color: black;\">)<\/span><span style=\"color: black;\">)<\/span>  <span style=\"color: #808080; font-style: italic;\"># rstrip \u0443\u0431\u0438\u0440\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0440\u043e\u043a\u0438<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<h3><code class=\"CodeInlined\">readlines()<\/code>\u00a0\u2014\u00a0\u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0442\u0440\u043e\u043a<\/h3>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #ff7700; font-weight: bold;\">with<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"data.txt\"<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"r\"<\/span><span style=\"color: #66cc66;\">,<\/span> encoding<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #483d8b;\">\"utf-8\"<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> f:\r\n    lines <span style=\"color: #66cc66;\">=<\/span> f.<span style=\"color: black;\">readlines<\/span><span style=\"color: black;\">(<\/span><span style=\"color: black;\">)<\/span>\r\n<span style=\"color: #808080; font-style: italic;\"># lines \u2014 \u0441\u043f\u0438\u0441\u043e\u043a, \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u2014 \u0441\u0442\u0440\u043e\u043a\u0430 \u0441 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u043c \\n<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0414\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u043f\u043e \u0444\u0430\u0439\u043b\u0443\u00a0\u2014\u00a0\u043e\u043d\u0430 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442 \u043f\u0430\u043c\u044f\u0442\u044c:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #ff7700; font-weight: bold;\">with<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"large_file.txt\"<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"r\"<\/span><span style=\"color: #66cc66;\">,<\/span> encoding<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #483d8b;\">\"utf-8\"<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> f:\r\n    <span style=\"color: #ff7700; font-weight: bold;\">for<\/span> line <span style=\"color: #ff7700; font-weight: bold;\">in<\/span> f:\r\n        <span style=\"color: #808080; font-style: italic;\"># \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u0442\u0440\u043e\u043a\u0438<\/span>\r\n        <span style=\"color: #ff7700; font-weight: bold;\">pass<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<hr \/>\n<h2>\u0417\u0430\u043f\u0438\u0441\u044c \u0432 \u0444\u0430\u0439\u043b: <code class=\"CodeInlined\">write()<\/code><\/h2>\n<p>\u041c\u0435\u0442\u043e\u0434 <code class=\"CodeInlined\">write()<\/code> \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443. \u041e\u043d <strong>\u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442<\/strong> \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0440\u043e\u043a\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438.<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #ff7700; font-weight: bold;\">with<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"output.txt\"<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"w\"<\/span><span style=\"color: #66cc66;\">,<\/span> encoding<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #483d8b;\">\"utf-8\"<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> f:\r\n    f.<span style=\"color: black;\">write<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>\"<\/span><span style=\"color: black;\">)<\/span>\r\n    f.<span style=\"color: black;\">write<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u0412\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>\"<\/span><span style=\"color: black;\">)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0446\u0438\u043a\u043b \u0438\u043b\u0438 <code class=\"CodeInlined\">writelines()<\/code>:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\">lines <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: black;\">[<\/span><span style=\"color: #483d8b;\">\"\u0421\u0442\u0440\u043e\u043a\u0430 1<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>\"<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"\u0421\u0442\u0440\u043e\u043a\u0430 2<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>\"<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"\u0421\u0442\u0440\u043e\u043a\u0430 3<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>\"<\/span><span style=\"color: black;\">]<\/span>\r\n<span style=\"color: #ff7700; font-weight: bold;\">with<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"output.txt\"<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"w\"<\/span><span style=\"color: #66cc66;\">,<\/span> encoding<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #483d8b;\">\"utf-8\"<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> f:\r\n    f.<span style=\"color: black;\">writelines<\/span><span style=\"color: black;\">(<\/span>lines<span style=\"color: black;\">)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: <code class=\"CodeInlined\">writelines()<\/code> \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u044b \u0441\u0442\u0440\u043e\u043a, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432 \u0441\u0430\u043c\u0438 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<hr \/>\n<h2>\u0417\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u0435\u043d <code class=\"CodeInlined\">with<\/code>: \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0439 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440<\/h2>\n<p>\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f <code class=\"CodeInlined\">with<\/code> (\u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0439 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440) \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0444\u0430\u0439\u043b \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0437\u0430\u043a\u0440\u044b\u0442 \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0435.<\/p>\n<p>\u041d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0431\u0435\u0437 <code class=\"CodeInlined\">with<\/code>:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\">f <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"data.txt\"<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"r\"<\/span><span style=\"color: #66cc66;\">,<\/span> encoding<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #483d8b;\">\"utf-8\"<\/span><span style=\"color: black;\">)<\/span>\r\ncontent <span style=\"color: #66cc66;\">=<\/span> f.<span style=\"color: black;\">read<\/span><span style=\"color: black;\">(<\/span><span style=\"color: black;\">)<\/span>\r\n<span style=\"color: #808080; font-style: italic;\"># \u0435\u0441\u043b\u0438 \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442 \u043e\u0448\u0438\u0431\u043a\u0430, \u0444\u0430\u0439\u043b \u043c\u043e\u0436\u0435\u0442 \u043e\u0441\u0442\u0430\u0442\u044c\u0441\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c<\/span>\r\nf.<span style=\"color: black;\">close<\/span><span style=\"color: black;\">(<\/span><span style=\"color: black;\">)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 <code class=\"CodeInlined\">with<\/code>:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #ff7700; font-weight: bold;\">with<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"data.txt\"<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"r\"<\/span><span style=\"color: #66cc66;\">,<\/span> encoding<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #483d8b;\">\"utf-8\"<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> f:\r\n    content <span style=\"color: #66cc66;\">=<\/span> f.<span style=\"color: black;\">read<\/span><span style=\"color: black;\">(<\/span><span style=\"color: black;\">)<\/span>\r\n<span style=\"color: #808080; font-style: italic;\"># \u0444\u0430\u0439\u043b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043a\u0440\u044b\u0442 \u043f\u043e\u0441\u043b\u0435 \u0431\u043b\u043e\u043a\u0430<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u0432\u0430\u0436\u043d\u043e:<\/p>\n<ul>\n<li data-value=\"\" data-shift=\"0\">\u0413\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 <code class=\"CodeInlined\">close()<\/code> \u0434\u0430\u0436\u0435 \u043f\u0440\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\u0445.<\/li>\n<li data-value=\"\" data-shift=\"0\">\u0417\u0430\u0449\u0438\u0442\u0430 \u043e\u0442 \u0443\u0442\u0435\u0447\u0435\u043a \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0445 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u0432 (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u0434\u043e\u043b\u0433\u043e\u0436\u0438\u0432\u0443\u0449\u0438\u0445 \u0441\u043a\u0440\u0438\u043f\u0442\u0430\u0445).<\/li>\n<li data-value=\"\" data-shift=\"0\">\u0427\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u044c: \u0441\u0440\u0430\u0437\u0443 \u0432\u0438\u0434\u043d\u043e \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0444\u0430\u0439\u043b\u043e\u043c.<\/li>\n<\/ul>\n<hr \/>\n<h2>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b<\/h2>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 1: \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e (\u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432)<\/h3>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\">src <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #483d8b;\">\"input.txt\"<\/span>\r\ndst <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #483d8b;\">\"output.txt\"<\/span>\r\n\u00a0\r\n<span style=\"color: #ff7700; font-weight: bold;\">with<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span>src<span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"r\"<\/span><span style=\"color: #66cc66;\">,<\/span> encoding<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #483d8b;\">\"utf-8\"<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> fin<span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span>dst<span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"w\"<\/span><span style=\"color: #66cc66;\">,<\/span> encoding<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #483d8b;\">\"utf-8\"<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> fout:\r\n    <span style=\"color: #ff7700; font-weight: bold;\">for<\/span> line <span style=\"color: #ff7700; font-weight: bold;\">in<\/span> fin:\r\n        fout.<span style=\"color: black;\">write<\/span><span style=\"color: black;\">(<\/span>line<span style=\"color: black;\">)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0417\u0434\u0435\u0441\u044c \u0434\u0432\u0430 \u0444\u0430\u0439\u043b\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u044b \u0432 \u043e\u0434\u043d\u043e\u043c <code class=\"CodeInlined\">with<\/code>\u00a0\u2014\u00a0\u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e.<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 2: \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043b\u043e\u0433 \u0432 \u0444\u0430\u0439\u043b (\u0440\u0435\u0436\u0438\u043c <code class=\"CodeInlined\">'a'<\/code>)<\/h3>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\">log_entry <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #483d8b;\">\"2026-08-01 12:34:56 \u2014 \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432\u043e\u0448\u0451\u043b \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>\"<\/span>\r\n\u00a0\r\n<span style=\"color: #ff7700; font-weight: bold;\">with<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"app.log\"<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"a\"<\/span><span style=\"color: #66cc66;\">,<\/span> encoding<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #483d8b;\">\"utf-8\"<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> f:\r\n    f.<span style=\"color: black;\">write<\/span><span style=\"color: black;\">(<\/span>log_entry<span style=\"color: black;\">)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0420\u0435\u0436\u0438\u043c <code class=\"CodeInlined\">'a'<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u043a\u043e\u043d\u0435\u0446, \u043d\u0435 \u0441\u0442\u0438\u0440\u0430\u044f \u0441\u0442\u0430\u0440\u044b\u0435 \u043b\u043e\u0433\u0438.<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 3: \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u043d\u0435\u0442 (\u0440\u0435\u0436\u0438\u043c <code class=\"CodeInlined\">'x'<\/code>)<\/h3>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #ff7700; font-weight: bold;\">try<\/span>:\r\n    <span style=\"color: #ff7700; font-weight: bold;\">with<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"config.json\"<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"x\"<\/span><span style=\"color: #66cc66;\">,<\/span> encoding<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #483d8b;\">\"utf-8\"<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> f:\r\n        f.<span style=\"color: black;\">write<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">'{\"version\": 1}<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>'<\/span><span style=\"color: black;\">)<\/span>\r\n<span style=\"color: #ff7700; font-weight: bold;\">except<\/span> FileExistsError:\r\n    <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u0424\u0430\u0439\u043b \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u043d\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c.\"<\/span><span style=\"color: black;\">)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u042d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0438 \u0432\u0430\u0436\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432.<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 4: \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c CSV\u2011\u0441\u0442\u0440\u043e\u043a\u0443 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435<\/h3>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u0444\u0430\u0439\u043b <code class=\"CodeInlined\">prices.csv<\/code>:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">text<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #003366;\">\u0422\u043e\u0432\u0430\u0440,\u0426\u0435\u043d\u0430\r\n\u042f\u0431\u043b\u043e\u043a\u0438,120.50\r\n\u0413\u0440\u0443\u0448\u0438,99.00<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0427\u0438\u0442\u0430\u0435\u043c, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0438 \u043f\u0438\u0448\u0435\u043c \u0432 \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\">input_file <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #483d8b;\">\"prices.csv\"<\/span>\r\noutput_file <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #483d8b;\">\"prices_fixed.csv\"<\/span>\r\n\u00a0\r\n<span style=\"color: #ff7700; font-weight: bold;\">with<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span>input_file<span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"r\"<\/span><span style=\"color: #66cc66;\">,<\/span> encoding<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #483d8b;\">\"utf-8\"<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> fin<span style=\"color: #66cc66;\">,<\/span> \\\r\n     <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span>output_file<span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"w\"<\/span><span style=\"color: #66cc66;\">,<\/span> encoding<span style=\"color: #66cc66;\">=<\/span><span style=\"color: #483d8b;\">\"utf-8\"<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> fout:\r\n\u00a0\r\n    <span style=\"color: #808080; font-style: italic;\"># \u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a<\/span>\r\n    fout.<span style=\"color: black;\">write<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"\u0422\u043e\u0432\u0430\u0440,\u0426\u0435\u043d\u0430_\u0440\u0443\u0431<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>\"<\/span><span style=\"color: black;\">)<\/span>\r\n\u00a0\r\n    <span style=\"color: #808080; font-style: italic;\"># \u041f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0435\u0440\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 (\u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a)<\/span>\r\n    next<span style=\"color: black;\">(<\/span>fin<span style=\"color: black;\">)<\/span>\r\n\u00a0\r\n    <span style=\"color: #ff7700; font-weight: bold;\">for<\/span> line <span style=\"color: #ff7700; font-weight: bold;\">in<\/span> fin:\r\n        line <span style=\"color: #66cc66;\">=<\/span> line.<span style=\"color: black;\">strip<\/span><span style=\"color: black;\">(<\/span><span style=\"color: black;\">)<\/span>\r\n        <span style=\"color: #ff7700; font-weight: bold;\">if<\/span> <span style=\"color: #ff7700; font-weight: bold;\">not<\/span> line:\r\n            <span style=\"color: #ff7700; font-weight: bold;\">continue<\/span>\r\n        parts <span style=\"color: #66cc66;\">=<\/span> line.<span style=\"color: black;\">split<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\",\"<\/span><span style=\"color: black;\">)<\/span>\r\n        <span style=\"color: #ff7700; font-weight: bold;\">if<\/span> <span style=\"color: #008000;\">len<\/span><span style=\"color: black;\">(<\/span>parts<span style=\"color: black;\">)<\/span> <span style=\"color: #66cc66;\">!=<\/span> <span style=\"color: #ff4500;\">2<\/span>:\r\n            <span style=\"color: #ff7700; font-weight: bold;\">continue<\/span>\r\n\u00a0\r\n        name<span style=\"color: #66cc66;\">,<\/span> price_str <span style=\"color: #66cc66;\">=<\/span> parts\r\n        <span style=\"color: #ff7700; font-weight: bold;\">try<\/span>:\r\n            price <span style=\"color: #66cc66;\">=<\/span> <span style=\"color: #008000;\">float<\/span><span style=\"color: black;\">(<\/span>price_str.<span style=\"color: black;\">replace<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\",\"<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\".\"<\/span><span style=\"color: black;\">)<\/span><span style=\"color: black;\">)<\/span>\r\n            <span style=\"color: #808080; font-style: italic;\"># \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u0440\u0443\u0431\u043b\u0438 (\u0442\u0443\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440)<\/span>\r\n            price_rub <span style=\"color: #66cc66;\">=<\/span> price * <span style=\"color: #ff4500;\">1.0<\/span>  <span style=\"color: #808080; font-style: italic;\"># \u0431\u0435\u0437 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438, \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430<\/span>\r\n            fout.<span style=\"color: black;\">write<\/span><span style=\"color: black;\">(<\/span>f<span style=\"color: #483d8b;\">\"{name},{price_rub:.2f}<span style=\"color: #000099; font-weight: bold;\">\\n<\/span>\"<\/span><span style=\"color: black;\">)<\/span>\r\n        <span style=\"color: #ff7700; font-weight: bold;\">except<\/span> <span style=\"color: #008000;\">ValueError<\/span>:\r\n            <span style=\"color: #ff7700; font-weight: bold;\">print<\/span><span style=\"color: black;\">(<\/span>f<span style=\"color: #483d8b;\">\"\u041f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u0430 \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430: {line}\"<\/span><span style=\"color: black;\">)<\/span>\r\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<hr \/>\n<h2>\u0411\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b: \u0440\u0435\u0436\u0438\u043c\u044b \u0441 <code class=\"CodeInlined\">'b'<\/code><\/h2>\n<p>\u0414\u043b\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043e\u043a, \u0430\u0440\u0445\u0438\u0432\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u0440\u0435\u0436\u0438\u043c\u044b.<\/p>\n<p>\u0427\u0442\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438:<\/p>\n<div class=\"CodeBlock CodeBlock_overflow_visible CodeBlock_highlight\">\n<div class=\"CodeBlock-StickyWrapper\">\n<div class=\"CodeBlock-Header\">\n<div class=\"CodeBlock-HeaderTitle\">python<\/div>\n<pre class=\"python\" style=\"font-family: monospace; font-size: 14px;\"><span style=\"color: #808080; font-style: italic;\"># \u0427\u0442\u0435\u043d\u0438\u0435<\/span>\r\n<span style=\"color: #ff7700; font-weight: bold;\">with<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"image.png\"<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"rb\"<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> f:\r\n    data <span style=\"color: #66cc66;\">=<\/span> f.<span style=\"color: black;\">read<\/span><span style=\"color: black;\">(<\/span><span style=\"color: black;\">)<\/span>  <span style=\"color: #808080; font-style: italic;\"># data \u2014 bytes<\/span>\r\n\u00a0\r\n<span style=\"color: #808080; font-style: italic;\"># \u0417\u0430\u043f\u0438\u0441\u044c<\/span>\r\n<span style=\"color: #ff7700; font-weight: bold;\">with<\/span> <span style=\"color: #008000;\">open<\/span><span style=\"color: black;\">(<\/span><span style=\"color: #483d8b;\">\"copy.png\"<\/span><span style=\"color: #66cc66;\">,<\/span> <span style=\"color: #483d8b;\">\"wb\"<\/span><span style=\"color: black;\">)<\/span> <span style=\"color: #ff7700; font-weight: bold;\">as<\/span> f:\r\n    f.<span style=\"color: black;\">write<\/span><span style=\"color: black;\">(<\/span>data<span style=\"color: black;\">)<\/span><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0411\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0442\u0435\u043a\u0441\u0442: \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 <code class=\"CodeInlined\">.replace()<\/code>, \u043d\u0435 \u043f\u044b\u0442\u0430\u0439\u0442\u0435\u0441\u044c \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438.<\/p>\n<hr \/>\n<h2>\u0428\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 \u043f\u043e \u0440\u0435\u0436\u0438\u043c\u0430\u043c \u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u043c<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u0417\u0430\u0434\u0430\u0447\u0430<\/th>\n<th>\u0420\u0435\u0436\u0438\u043c<\/th>\n<th>\u041c\u0435\u0442\u043e\u0434<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u041f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u0435\u0441\u044c \u0444\u0430\u0439\u043b<\/td>\n<td><code class=\"CodeInlined\">'r'<\/code><\/td>\n<td><code class=\"CodeInlined\">read()<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u0427\u0438\u0442\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u0440\u043e\u0447\u043d\u043e<\/td>\n<td><code class=\"CodeInlined\">'r'<\/code><\/td>\n<td>\u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u043e \u0444\u0430\u0439\u043b\u0443 \u0438\u043b\u0438 <code class=\"CodeInlined\">readline()<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u0417\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b<\/td>\n<td><code class=\"CodeInlined\">'w'<\/code><\/td>\n<td><code class=\"CodeInlined\">write()<\/code> \u0438\u043b\u0438 <code class=\"CodeInlined\">writelines()<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u0414\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043a\u043e\u043d\u0435\u0446<\/td>\n<td><code class=\"CodeInlined\">'a'<\/code><\/td>\n<td><code class=\"CodeInlined\">write()<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u0421\u043e\u0437\u0434\u0430\u0442\u044c, \u043d\u043e \u043d\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c<\/td>\n<td><code class=\"CodeInlined\">'x'<\/code><\/td>\n<td><code class=\"CodeInlined\">write()<\/code> + \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 <code class=\"CodeInlined\">FileExistsError<\/code><\/td>\n<\/tr>\n<tr>\n<td>\u0420\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438<\/td>\n<td><code class=\"CodeInlined\">'rb'<\/code> \/ <code class=\"CodeInlined\">'wb'<\/code><\/td>\n<td><code class=\"CodeInlined\">read()<\/code>, <code class=\"CodeInlined\">write()<\/code> (\u0441 <code class=\"CodeInlined\">bytes<\/code>)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438\u00a0\u2014\u00a0\u043e\u0434\u043d\u0430 \u0438\u0437 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432 Python: \u0447\u0442\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0439, \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432, \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043b\u043e\u0433\u043e\u0432, \u0438\u043c\u043f\u043e\u0440\u0442\/\u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0444\u0430\u0439\u043b\u043e\u0432, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 open(), \u043c\u0435\u0442\u043e\u0434\u044b read(), write(), \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e with, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u0435\u043b\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0439 \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0439. \u041e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0444\u0430\u0439\u043b\u0430: \u0444\u0443\u043d\u043a\u0446\u0438\u044f open() \u0424\u0443\u043d\u043a\u0446\u0438\u044f open(file, mode, encoding=None, &#8230;) \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 [&hellip;]<\/p>\n","protected":false},"author":9194254,"featured_media":135498,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[556],"tags":[],"class_list":["post-135512","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"views":11,"_links":{"self":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/135512","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/users\/9194254"}],"replies":[{"embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=135512"}],"version-history":[{"count":1,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/135512\/revisions"}],"predecessor-version":[{"id":135513,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/posts\/135512\/revisions\/135513"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=\/wp\/v2\/media\/135498"}],"wp:attachment":[{"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=135512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=135512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rcl-radio.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=135512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}