{"action":"created","issue":{"url":"https://api.github.com/repos/bbcmicrobit/micropython/issues/126","labels_url":"https://api.github.com/repos/bbcmicrobit/micropython/issues/126/labels{/name}","comments_url":"https://api.github.com/repos/bbcmicrobit/micropython/issues/126/comments","events_url":"https://api.github.com/repos/bbcmicrobit/micropython/issues/126/events","html_url":"https://github.com/bbcmicrobit/micropython/issues/126","id":119496769,"number":126,"title":"Weird behavior of struct.pack","user":{"login":"deshipu","id":1181357,"avatar_url":"https://avatars.githubusercontent.com/u/1181357?v=3","gravatar_id":"","url":"https://api.github.com/users/deshipu","html_url":"https://github.com/deshipu","followers_url":"https://api.github.com/users/deshipu/followers","following_url":"https://api.github.com/users/deshipu/following{/other_user}","gists_url":"https://api.github.com/users/deshipu/gists{/gist_id}","starred_url":"https://api.github.com/users/deshipu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deshipu/subscriptions","organizations_url":"https://api.github.com/users/deshipu/orgs","repos_url":"https://api.github.com/users/deshipu/repos","events_url":"https://api.github.com/users/deshipu/events{/privacy}","received_events_url":"https://api.github.com/users/deshipu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-11-30T13:56:43Z","updated_at":"2015-11-30T14:48:56Z","closed_at":null,"body":"So once I got I2C working, I started to make use of struct.pack to send the right bytes, and I stumbled upon this:\r\n\r\n```\r\n>>> import struct\r\n>>> struct.pack(\"f\", 0.1)\r\nb'\\xcc\\xcc\\xcc='\r\n>>> struct.pack(\"<f\", 0.1)\r\nb'\\xcc\\xcc\\xcc='\r\n>>> struct.pack(\"<ccf\", 0, 4, 0.1)\r\nb'\\xcc\\xcc\\xcc='\r\n>>> struct.pack(\"<c\", 0)          \r\nb''\r\n>>> struct.pack(\"<c\", b'\\xff')\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\nTypeError: can't convert bytes to int\r\n```\r\n\r\nComparing it to cPython3:\r\n```\r\n>>> import struct\r\n>>> struct.pack(\"<c\", 0xff)\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\nstruct.error: char format requires a bytes object of length 1\r\n>>> struct.pack(\"<c\", b'\\xff')\r\nb'\\xff'\r\n```"},"comment":{"url":"https://api.github.com/repos/bbcmicrobit/micropython/issues/comments/160651089","html_url":"https://github.com/bbcmicrobit/micropython/issues/126#issuecomment-160651089","issue_url":"https://api.github.com/repos/bbcmicrobit/micropython/issues/126","id":160651089,"user":{"login":"deshipu","id":1181357,"avatar_url":"https://avatars.githubusercontent.com/u/1181357?v=3","gravatar_id":"","url":"https://api.github.com/users/deshipu","html_url":"https://github.com/deshipu","followers_url":"https://api.github.com/users/deshipu/followers","following_url":"https://api.github.com/users/deshipu/following{/other_user}","gists_url":"https://api.github.com/users/deshipu/gists{/gist_id}","starred_url":"https://api.github.com/users/deshipu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deshipu/subscriptions","organizations_url":"https://api.github.com/users/deshipu/orgs","repos_url":"https://api.github.com/users/deshipu/repos","events_url":"https://api.github.com/users/deshipu/events{/privacy}","received_events_url":"https://api.github.com/users/deshipu/received_events","type":"User","site_admin":false},"created_at":"2015-11-30T14:48:56Z","updated_at":"2015-11-30T14:48:56Z","body":"(I know that \"b<f\" is invalid, but still)\r\n"}}