0

I'm new to programming, and right now I'm working in a small personal project that uses environment variables to create global variables through classes, files, threads, and flask pages in a extremely easier way.

But I do have some questions about how it will work on mine and other computers.

  1. Do the "os.environ" and "os.getenv" work equally in all systems (windows, mac and linux)?
  2. How about the character limit? I'm using a single variable to keep a json dictionary, so how much info can I put in there?
  3. Is there a way to block the access to the environment variables? Is it normal in companies and universities to block the access to them?
ilke444
  • 2,641
  • 1
  • 17
  • 31

1 Answers1

0
  1. yes they work same, nothing different is mentioned in official documentation.
  2. char limit depends on your system specification. please refer: What is the max length of a python string?
  3. to block the access to the env var you can use "deny" eg.
    Deny from env="users"
yanxun
  • 566
  • 2
  • 10
classicdude7
  • 903
  • 1
  • 6
  • 23
  • Ok, i almost got it. So just to confirm, the environment variable content limit is in my harware, the OS doesnt narrow it, and i should not worry about store thousands of bytes in a single environment variable, right? – Matheus Menezes Apr 13 '20 at 17:59
  • Your second point is incorrect. The length limit of a Python string is going to be many orders of magnitude greater than the limit on an env var. The length of an env var is limited by the operating system limit on the total size of all env vars. This is configurable at the OS level. It is typically in the range of 64 KiB to 2 MiB for UNIX like operating systems. MS Windows apparently has a limit of 32 KiB based a a few minutes of googling. – Kurtis Rader Apr 13 '20 at 22:27
  • @MatheusMenezes see I had created an environment variable of 256 MB though it doesn't work very smoothly but the 8MB Environment variable work just fine for me on my linux. So if your limit is upto that level. It will be fine. – classicdude7 Apr 14 '20 at 05:44
  • 2
    @KurtisRader the thing is it depends on command which you want to execute. if you want to execute execve() it works fine till 8Mb but if you want to use exec() command it wont work as the argument list will be too long. So as long as the question is not detailed enough to tell what commands needed to be run .No one can be sure. – classicdude7 Apr 14 '20 at 05:51
  • @classicdude7 You missed my point. You cannot assume a 8 MiB limit. That might be the limit on the particular OS you're using but that is by no means universal. It is also an unusually high imit. It also has nothing to do with the length limit of a Python string. – Kurtis Rader Apr 14 '20 at 23:59