Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
checking username
#4
They should have written usernames, that would be less confusing for you perhaps.

Try like this maybe? Make your own file, then save it and then open it.

Of course, you need to set your own path, don't try to use my path!

import json
from pathlib import Path

path2json = '/home/pedro/temp/usernames.json'
mypath = Path(path2json)
data = []
username = 'X'
# enter usernames and emails
while not username == 'q':
    users_dict = {}
    username = input(f'Enter your username, enter q to quit ... ')
    if username == 'q':
            break
    email = input('enter your email ... ')
    users_dict['user name'] = username
    users_dict['user email'] = email
    data.append(users_dict)

# save the data
with open(mypath, 'w', encoding='utf-8') as fp:
    json.dump(data, fp, ensure_ascii=False, indent=4)

# open the data to inspect it
with open(mypath) as fp:
    data_list = json.load(fp)

# find Tarzan
for d in data_list:
    if d['user name'] == 'Tarzan':
        print(d)
        print(d['user name'])

Output:
{'user name': 'Tarzan', 'user email': '[email protected]'} Tarzan
Reply


Messages In This Thread
checking username - by newbexx - Jun-17-2024, 05:10 AM
RE: checking username - by menator01 - Jun-17-2024, 05:34 AM
RE: checking username - by newbexx - Jun-17-2024, 05:58 AM
RE: checking username - by Pedroski55 - Jun-17-2024, 11:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 2,331 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Hiding username and password on sql tantony 10 3,418 Oct-21-2022, 07:58 PM
Last Post: wavic
  Pulling username from Tuple pajd 21 4,141 Oct-07-2022, 01:33 PM
Last Post: pajd
  Trying to create a conditional with a username Realen 2 1,942 Jun-20-2020, 12:44 AM
Last Post: Realen
  Client OS username ImPyBoy17 5 2,880 Sep-24-2019, 10:18 AM
Last Post: buran
  creating a username and pword program using a #def statement and #dictionary zcode12 3 3,305 Oct-14-2018, 04:41 AM
Last Post: volcano63

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020