Title: How to get `globals()` inside Go bounded method? · Issue #211 · go-python/gpython · GitHub
Open Graph Title: How to get `globals()` inside Go bounded method? · Issue #211 · go-python/gpython
X Title: How to get `globals()` inside Go bounded method? · Issue #211 · go-python/gpython
Description: Simple description I cannot find a way to access globals() within a bounded method in GoLang. I expose a type into module, like moduleImpl.Globals["Foo"] = FooType, and add methods to FooType by FooType.Globals["bar"] = MustNewMethod(......
Open Graph Description: Simple description I cannot find a way to access globals() within a bounded method in GoLang. I expose a type into module, like moduleImpl.Globals["Foo"] = FooType, and add methods to FooType by Fo...
X Description: Simple description I cannot find a way to access globals() within a bounded method in GoLang. I expose a type into module, like moduleImpl.Globals["Foo"] = FooType, and add methods to Foo...
Opengraph URL: https://github.com/go-python/gpython/issues/211
X: @github
Domain: redirect.github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"How to get `globals()` inside Go bounded method?","articleBody":"## Simple description\r\n\r\nI cannot find a way to access `globals()` within a bounded method in GoLang.\r\n\r\nI expose a type into module, like `moduleImpl.Globals[\"Foo\"] = FooType`, and add methods to FooType by `FooType.Globals[\"bar\"] = MustNewMethod(..., someGoMethod, ...)`. \r\n\r\nI cannot access module's global variables inside `someGoMethod`.\r\n\r\n## Why I need this feature\r\n\r\nI just attach different `zap.Logger` to multiple `py.Context`s. I attach `logger` as a module's global variable, by using\r\n\r\n```\r\nctx.GetModule(\"name\").Globals[\"logger\"] = \u0026pyLoggerObject{logger}\r\n```\r\n\r\nbut I cannot find a way to use this logger inside bounded methods.\r\n\r\n\r\n---\r\n\r\nI found I can create a py.Type and attach the type to module global dynamically. I can somehow read module globals by this trick. But Is there a elegant way to archive that?\r\n\r\n```\r\nm = ctx.GetModule(\"module\")\r\nm.Globals[\"Foo\"] = NewFooType(m)\r\n```","author":{"url":"https://github.com/reyoung","@type":"Person","name":"reyoung"},"datePublished":"2022-12-13T08:03:17.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/211/gpython/issues/211"}
| 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:a2ec262f-b977-81c1-cf64-db794b4e08ea |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B954:1C7E2D:7DEDBE:AEA7C5:696A7E1D |
| html-safe-nonce | ee5fecf11b8ce8a0d90bccc7a2fcee59eb8fca5273b0ebd7eed479bd4df43f77 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTU0OjFDN0UyRDo3REVEQkU6QUVBN0M1OjY5NkE3RTFEIiwidmlzaXRvcl9pZCI6IjM3NTUxODQ3MDI4ODQ1NzY3OTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e57276e64f1c0a7f92f9f0bd6c7a6d8c7dbcaa0ba9aaf27a2dcf5a88038b026f |
| hovercard-subject-tag | issue:1493648286 |
| 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/go-python/gpython/211/issue_layout |
| twitter:image | https://opengraph.githubassets.com/75950f50f53836d9c9d7440372be9e03cc12c1dcfad9cf6bea804116988f2245/go-python/gpython/issues/211 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/75950f50f53836d9c9d7440372be9e03cc12c1dcfad9cf6bea804116988f2245/go-python/gpython/issues/211 |
| og:image:alt | Simple description I cannot find a way to access globals() within a bounded method in GoLang. I expose a type into module, like moduleImpl.Globals["Foo"] = FooType, and add methods to FooType by Fo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | reyoung |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5b774e44f85c14a75886edd04ddda4e5a25ddebbb241bcbb590b08a3048730e8 |
| turbo-cache-control | no-preview |
| go-import | github.com/go-python/gpython git https://github.com/go-python/gpython.git |
| octolytics-dimension-user_id | 7604679 |
| octolytics-dimension-user_login | go-python |
| octolytics-dimension-repository_id | 143203535 |
| octolytics-dimension-repository_nwo | go-python/gpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 143203535 |
| octolytics-dimension-repository_network_root_nwo | go-python/gpython |
| 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 | cc5f4eee261b3601c1e98e217ceaf28508b9567e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width