0

I have a VS2015 solution with a large c# project and a python helper project. Is there a simple way to have solution-wide constants that I could access from both projects? If not, it would just hamper my maintainability, but I thought I'd ask.

UndeadBob
  • 1,110
  • 1
  • 15
  • 34
  • try locals() and globals() – polka Oct 21 '16 at 18:52
  • If you really do mean constants, I'd put them in a config file. – 15ee8f99-57ff-4f92-890c-b56153 Oct 21 '16 at 18:56
  • @EdPlunkett, Thanks, that's what I'm doing now – UndeadBob Oct 21 '16 at 18:59
  • 1
    In that case I'd retitle the question to "Solution wide constant constants" – 15ee8f99-57ff-4f92-890c-b56153 Oct 21 '16 at 19:04
  • 1
    Python doesn't have truly global (inter-module) variables or constants, and even if it did they would be defined differently since it's a different language that C#, The most portable way to do it is with a config file that can be read and processed by both Python and C#. On the Python side, if you really want things to available to to all modules without importing, you _could_ modify the `__builtin__` module (note the name has no `s` in it), although doing so might be a [bad idea](http://stackoverflow.com/a/6965111/355230). – martineau Oct 21 '16 at 19:29
  • @anonymous sorry, it's the weekend! Good thing I decided to get the app. – UndeadBob Oct 23 '16 at 23:49

1 Answers1

2

Create a separate file for maintaining your constants with some structure which could be accessed by both C# and Python. For example: JSON, YAML, etc. Read this file to load configuration from both projects

Moinuddin Quadri
  • 46,825
  • 13
  • 96
  • 126