Title: avoid using print() function · Issue #141 · bluerobotics/ping-python · GitHub
Open Graph Title: avoid using print() function · Issue #141 · bluerobotics/ping-python
X Title: avoid using print() function · Issue #141 · bluerobotics/ping-python
Description: This is just a copy of connect_serial() method from brping/device.py (ver 0.1.5) def connect_serial(self, device_name: str, baudrate: int =115200): if device_name is None: print("Device name is required") return try: print("Opening %s at...
Open Graph Description: This is just a copy of connect_serial() method from brping/device.py (ver 0.1.5) def connect_serial(self, device_name: str, baudrate: int =115200): if device_name is None: print("Device name is req...
X Description: This is just a copy of connect_serial() method from brping/device.py (ver 0.1.5) def connect_serial(self, device_name: str, baudrate: int =115200): if device_name is None: print("Device name i...
Opengraph URL: https://github.com/bluerobotics/ping-python/issues/141
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":" avoid using print() function","articleBody":"This is just a copy of connect_serial() method from brping/device.py (ver 0.1.5)\r\n\r\n```py\r\ndef connect_serial(self, device_name: str, baudrate: int =115200):\r\n if device_name is None:\r\n print(\"Device name is required\")\r\n return\r\n\r\n try:\r\n print(\"Opening %s at %d bps\" % (device_name, baudrate))\r\n\r\n ## Serial object for device communication\r\n # write_timeout fixes it getting stuck forever atempting to write to\r\n # /dev/ttyAMA0 on Raspberry Pis, this raises an exception instead.\r\n self.iodev = serial.Serial(device_name, baudrate, write_timeout=1.0)\r\n self.iodev.send_break()\r\n time.sleep(0.001)\r\n self.iodev.write(\"U\".encode(\"ascii\"))\r\n\r\n except Exception as exception:\r\n raise Exception(\"Failed to open the given serial port: {0}\".format(exception))\r\n```\r\n\r\nThe request here is:\r\nKindly avoid using the `print` function in a library like this. If the device name is required, it should be handled as an exception, not with a `print` and `return`:\r\n\r\n```py\r\nraise ValueError(\"Device name is required\")\r\n```\r\n\r\nAnd the next `print` is indeed a logging:\r\n\r\n```py\r\nlogger.info(\"Opening %s at %d bps\", device_name, baudrate)\r\n```\r\n\r\nI've had to use workarounds to prevent these `print`s from being sent to my app's stdout:\r\n\r\n```py\r\ndef brping_muted_print(*args, **kw):\r\n if len(args) == 1:\r\n args = args[0]\r\n log('brping: %s', args)\r\n# brping module uses raw print statements for logging\r\n# with this trick, we turn them into proper logs\r\nbrping.device.print = brping_muted_print\r\n```\r\n\r\nThanks","author":{"url":"https://github.com/gowhari","@type":"Person","name":"gowhari"},"datePublished":"2024-08-19T15:06:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/141/ping-python/issues/141"}
| 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:8ddd0ed7-ea8e-a774-deae-54490fb1eca0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BA0C:B33E:2FE3BB8:41AE026:698C9D41 |
| html-safe-nonce | b1b0e580e2861b299848ee8207fec57e2bdba5aa618173d2f7458344389aa175 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTBDOkIzM0U6MkZFM0JCODo0MUFFMDI2OjY5OEM5RDQxIiwidmlzaXRvcl9pZCI6IjUyNDY1MzYyOTg4Mzk5NzMxODUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | dfe726d6c3f0b2a6103acdb790955ad6d166638867f71ce9257c154099833983 |
| hovercard-subject-tag | issue:2473591992 |
| 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/bluerobotics/ping-python/141/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8116cc8df55a1eeb4f1fa81960dd37021bd9aadf6e25ae11ecfc03803c8b8760/bluerobotics/ping-python/issues/141 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8116cc8df55a1eeb4f1fa81960dd37021bd9aadf6e25ae11ecfc03803c8b8760/bluerobotics/ping-python/issues/141 |
| og:image:alt | This is just a copy of connect_serial() method from brping/device.py (ver 0.1.5) def connect_serial(self, device_name: str, baudrate: int =115200): if device_name is None: print("Device name is req... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gowhari |
| hostname | github.com |
| expected-hostname | github.com |
| None | 640eeb7b6ff4d8d106235d228c0c286e82592d4d2403227b5b2b4fc5832297a4 |
| turbo-cache-control | no-preview |
| go-import | github.com/bluerobotics/ping-python git https://github.com/bluerobotics/ping-python.git |
| octolytics-dimension-user_id | 7120633 |
| octolytics-dimension-user_login | bluerobotics |
| octolytics-dimension-repository_id | 73196476 |
| octolytics-dimension-repository_nwo | bluerobotics/ping-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 73196476 |
| octolytics-dimension-repository_network_root_nwo | bluerobotics/ping-python |
| 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 | 3d444f0a47beeeac94cddbb51c91ab408befe8d4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width