Title: file.seek(file.tell()) needed: bad docs or a bug? · Issue #93079 · python/cpython · GitHub
Open Graph Title: file.seek(file.tell()) needed: bad docs or a bug? · Issue #93079 · python/cpython
X Title: file.seek(file.tell()) needed: bad docs or a bug? · Issue #93079 · python/cpython
Description: The following produces a file containing b'hello\n ', i.e. hello followed by a newline and a space: with open("asd.txt", "w") as file: file.write("hello\n") with open("asd.txt", "r+") as file: file.read(4) file.write(" ") But if I add fi...
Open Graph Description: The following produces a file containing b'hello\n ', i.e. hello followed by a newline and a space: with open("asd.txt", "w") as file: file.write("hello\n") with open("asd.txt", "r+") as file: file...
X Description: The following produces a file containing b'hello\n ', i.e. hello followed by a newline and a space: with open("asd.txt", "w") as file: file.write("hello\n") wi...
Opengraph URL: https://github.com/python/cpython/issues/93079
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"file.seek(file.tell()) needed: bad docs or a bug?","articleBody":"The following produces a file containing `b'hello\\n '`, i.e. `hello` followed by a newline and a space:\r\n\r\n```python3\r\nwith open(\"asd.txt\", \"w\") as file:\r\n file.write(\"hello\\n\")\r\n\r\nwith open(\"asd.txt\", \"r+\") as file:\r\n file.read(4)\r\n file.write(\" \")\r\n```\r\n\r\nBut if I add `file.seek(file.tell())`, then it instead produces `b'hell \\n'` as I would expect:\r\n\r\n```python3\r\nwith open(\"asd.txt\", \"w\") as file:\r\n file.write(\"hello\\n\")\r\n\r\nwith open(\"asd.txt\", \"r+\") as file:\r\n file.read(4)\r\n file.seek(file.tell())\r\n file.write(\" \")\r\n```\r\n\r\nIs this correct behaviour? I can't find any mention of it in the docs. (I can't use `file.seek(4)` because that \"produces undefined behaviour\" according to docs.)","author":{"url":"https://github.com/Akuli","@type":"Person","name":"Akuli"},"datePublished":"2022-05-22T21:10:47Z","url":"https://github.com/python/cpython/issues/93079"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0ced1e2e-3d81-e02e-e949-6e0dff05ca20 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B29C:3F8AB1:4879B24:5BDB1CA:6B022C22 |
| html-safe-nonce | 729dd0405a606cd5e1614db158fb6fbaafbdc2373fefc4ca55a902ff73a706e2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMjlDOjNGOEFCMTo0ODc5QjI0OjVCREIxQ0E6NkIwMjJDMjIiLCJ2aXNpdG9yX2lkIjoiNzE5MzYwNTEyMDU4NjgyMDY0MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ca79666c224015218484d5997de0442b8e2808efee3fc869307484dcfd057802 |
| hovercard-subject-tag | issue:1244367723 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/93079/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dfeab2b06e74f747b6ece1bd96617b9dcd8399e946f57adc1dc88522707768da/python/cpython/issues/93079 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dfeab2b06e74f747b6ece1bd96617b9dcd8399e946f57adc1dc88522707768da/python/cpython/issues/93079 |
| og:image:alt | The following produces a file containing b'hello\n ', i.e. hello followed by a newline and a space: with open("asd.txt", "w") as file: file.write("hello\n") with open("asd.txt", "r+") as file: file... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Akuli |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width