Search code examples
python-2.7pseudocodewith-statement

replacing "with" statement in Python code


import json
with open("login_data.txt", "r") as login_file:
    try:
        users = json.load(login_file)
    except:
        users = {}

Recently, I'm doing a presentation for my code. However, my lecturer requires me to break down the code into pseudocode.

I can't find any pseudocode terms that fit in the with statement. I need to find alternative solution that can replace the with statement above.

 #i suppose it should look like this:...
def dummyname(login_file):
    login_file = process open("login_data.txt","r")
    while
        users != {}
    do
        users = process json.load(login_file)
process dummyname(login_file)
#is it something like this?

Solution

  • If you don't mind to write less safe pseudo-code ( and write safe after ) you could open-close.

    login_file = open "login_data.txt" in text reading mode
    users = load_json( login_file )
    if load_json failed,
        users = {}
    close( login_file )