{"id":1153,"date":"2024-11-12T19:14:34","date_gmt":"2024-11-12T11:14:34","guid":{"rendered":"https:\/\/gemmartdesign.com\/?p=1153"},"modified":"2024-11-29T20:56:16","modified_gmt":"2024-11-29T12:56:16","slug":"python-post6","status":"publish","type":"post","link":"https:\/\/gemmartdesign.com\/?p=1153","title":{"rendered":"Python\u7df4\u7fd2#6-\u4f7f\u7528file\u6307\u4ee4\u505a\u4e82\u6578\u8207\u7d71\u8a08\u6a21\u7d44"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u672c\u5468\u76ee\u6a19<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u719f\u6089Python\u7684\u57fa\u790e\u8a9e\u6cd5\u8207\u8cc7\u6599\u7d50\u69cb<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4efb\u52d9<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b78\u7fd2\u51fd\u6578\u7684\u5b9a\u7fa9\u548c\u4f7f\u7528\uff08Parameters\u3001Return Values\uff09<\/li>\n\n\n\n<li>\u7df4\u7fd2\u8a2d\u8a08\u548c\u4f7f\u7528\u51fd\u6578\uff0c\u4e26\u5b8c\u6210\u66f4\u591a\u5b57\u4e32\u8655\u7406\u7df4\u7fd2\uff08\u4f8b\u5982\u6587\u5b57\u67e5\u627e\u548c\u66ff\u63db\uff09<\/li>\n\n\n\n<li>\u5b78\u7fd2file open, write, read\u6307\u4ee4<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u5c08\u6848\u7df4\u7fd2<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u5beb\u5165\u591a\u884c\u6578\u5b57\u4e26\u8a08\u7b97\u591a\u500b\u6578\u5b57\u7e3d\u548c<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>with open(\"1112data.txt\",mode=\"w\") as file:\n    file.write(\"5\\n6\\n7\\n8\\n9\")\nsum=0\nwith open(\"1112data.txt\",mode=\"r\") as file:\n    data=file.read()\n    print(\"\u6578\u5b57\u5206\u5225\u70ba:\",data)\nwith open(\"1112data.txt\",mode=\"r\") as file:\n    for line in file:\n        sum+=int(line)\nprint(\"\u7e3d\u548c:\",sum)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Output<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6578\u5b57\u5206\u5225\u70ba: 5\n6\n7\n8\n9\n\u7e3d\u548c: 35<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u5468\u76ee\u6a19 \u719f\u6089Python\u7684\u57fa\u790e\u8a9e\u6cd5\u8207\u8cc7\u6599\u7d50\u69cb \u4efb\u52d9 \u5c08\u6848\u7df4&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1245,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","pagelayer_contact_templates":[],"_pagelayer_content":"","_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[9],"tags":[],"class_list":["post-1153","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/posts\/1153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1153"}],"version-history":[{"count":1,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/posts\/1153\/revisions"}],"predecessor-version":[{"id":1155,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/posts\/1153\/revisions\/1155"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/media\/1245"}],"wp:attachment":[{"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}