Initialize a variable at python script initialization time.
Hello Community, Is there a method in python extension to load an external data structure?. I just need to initialize a large MAC address array from a JSON. And use it in all the auth requests without re-reading it from the file every time. Is there a way to achieve this? Thanks, -- *Anuruddha Premalala (MIEEE)Mobile : +94717213122E-mail : anuruddhapremalal@gmail.com <anuruddhapremalal@gmail.com>web : www.anuruddha.org <http://www.anuruddha.org>*
On Mar 12, 2017, at 3:26 AM, Anuruddha Premalal <anuruddhapremalal@gmail.com> wrote:
Hello Community,
Is there a method in python extension to load an external data structure?. I just need to initialize a large MAC address array from a JSON. And use it in all the auth requests without re-reading it from the file every time.
Is there a way to achieve this?
I'm sure there's a way to do that in Python... The Python interpreter isn't sandboxed, you can do anything you need to . -Arran
On 13/03/17 17:26, Arran Cudbard-Bell wrote:
On Mar 12, 2017, at 3:26 AM, Anuruddha Premalal <anuruddhapremalal@gmail.com> wrote:
Hello Community,
Is there a method in python extension to load an external data structure?. I just need to initialize a large MAC address array from a JSON. And use it in all the auth requests without re-reading it from the file every time.
Is there a way to achieve this?
I'm sure there's a way to do that in Python... The Python interpreter isn't sandboxed, you can do anything you need to .
A very quick & dirty solution is to use a module global: module.py: import json with open('macs.json') as f: macs = json.load(f) def authorize(...): global macs if 'blah' in macs: ...
participants (3)
-
Anuruddha Premalal -
Arran Cudbard-Bell -
Phil Mayers