Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to skip over a environment variable when iterating over them

this is my code:

import os

def main():
  g = input("What's the password?\n")
  if g == os.environ['master-password']:
    for name, value in os.environ.items():
      if name == "master-password":
        break #obviously just ends the program
      else:  
        print("{0}: {1}".format(name, value))
      
main()

I want to skip the master password so it is not revealed.
The reason I want this is that I’m using replit

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use continue instead of break to skip to the next iteration of the loop.

g = input("What's the password?\n")
if g == os.environ["master-password"]:
    for name, value in os.environ.items():
        if name == "master-password":
            continue
        print(f"{name}: {value}")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading