Title: py.RunFile / RunCode doesn't handle a nil module pointer · Issue #249 · go-python/gpython · GitHub
Open Graph Title: py.RunFile / RunCode doesn't handle a nil module pointer · Issue #249 · go-python/gpython
X Title: py.RunFile / RunCode doesn't handle a nil module pointer · Issue #249 · go-python/gpython
Description: Hey, there. It's really cool to be able to run Python in Go! I'd like to congratulate you on this project, it might be exactly what I've been looking for when it comes to an easily embeddable scripting language. I just noticed that py.Ru...
Open Graph Description: Hey, there. It's really cool to be able to run Python in Go! I'd like to congratulate you on this project, it might be exactly what I've been looking for when it comes to an easily embeddable scrip...
X Description: Hey, there. It's really cool to be able to run Python in Go! I'd like to congratulate you on this project, it might be exactly what I've been looking for when it comes to an easily embe...
Opengraph URL: https://github.com/go-python/gpython/issues/249
X: @github
Domain: redirect.github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"py.RunFile / RunCode doesn't handle a nil module pointer","articleBody":"Hey, there. It's really cool to be able to run Python in Go! I'd like to congratulate you on this project, it might be exactly what I've been looking for when it comes to an easily embeddable scripting language.\n\nI just noticed that `py.RunFile()` and `py.RunCode()` don't handle a `nil` `py.Module` pointer when deciding to create a new module. I feel like that would lessen the friction on using it, since if you run multiple files and want them to be in a single module you currently have to call two different `RunFile() / RunCode()` calls that are essentially the same (just with `nil` as the `inModule` argument the first time).\n\nBasically, currently I'm doing this:\n\n```go\nvar mod *py.Module\n\n...\n\n// In a for loop for mutliple .py files\n\nif mod == nil {\n\tmod, err = py.RunFile(context, fpath, py.CompileOpts{UseSysPaths: true}, nil) // Returns a new module\n} else {\n\tmod, err = py.RunFile(context, fpath, py.CompileOpts{UseSysPaths: true}, mod) // Adds onto the existing one\n}\n```\n\nand it would be easier to just do this:\n\n```go\nvar mod *py.Module\n\n...\n\nmod, err = py.RunFile(context, fpath, py.CompileOpts{UseSysPaths: true}, mod) // Returns a new module on first run because 'mod' is nil, adds onto the existing module afterwards\n```\n\nI believe to implement this I would just need to modify `RunCode()` to check for `nil` in the `case *Module` part of the inModule type check. Does this sound OK?","author":{"url":"https://github.com/SolarLune","@type":"Person","name":"SolarLune"},"datePublished":"2025-10-23T10:53:05.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/249/gpython/issues/249"}
| 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:1f6d6143-7b50-352c-42ab-4c4287eb2623 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B6E2:270B7A:88E101:BC84D3:6969E96C |
| html-safe-nonce | 223b07b90c2125aeb0ccd3f166a7cb50b23a8c5f6cfb599d9561ec862d97bac4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNkUyOjI3MEI3QTo4OEUxMDE6QkM4NEQzOjY5NjlFOTZDIiwidmlzaXRvcl9pZCI6IjI4MjA1NjQ0NzA2ODY3NTY0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bcc9c5be9b5b11182887e5741fb8e346926bc04148766fcb92d06e63b7ea0cbb |
| hovercard-subject-tag | issue:3544168117 |
| 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/249/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9fe9a2f69d8618b3b266c1a784b66dca5e4b84ecb539b428c0d22183c2b1b166/go-python/gpython/issues/249 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9fe9a2f69d8618b3b266c1a784b66dca5e4b84ecb539b428c0d22183c2b1b166/go-python/gpython/issues/249 |
| og:image:alt | Hey, there. It's really cool to be able to run Python in Go! I'd like to congratulate you on this project, it might be exactly what I've been looking for when it comes to an easily embeddable scrip... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SolarLune |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7b32f1c7c4549428ee399213e8345494fc55b5637195d3fc5f493657579235e8 |
| 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 | bdde15ad1b403e23b08bbd89b53fbe6bdf688cad |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width