0
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?
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

2 Answers2

3

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 )
Lærne
  • 3,010
  • 1
  • 22
  • 33
1

Instead of replacing with statements, describe what is going on in pseudocode. Context managers are fundamental programming elements.

Neil G
  • 32,138
  • 39
  • 156
  • 257