function that returns a list of dictionaries - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: function that returns a list of dictionaries (/thread-33567.html) |
function that returns a list of dictionaries - nostradamus64 - May-06-2021 Hello everyone, i want to create a function that returns a list of dictionaries with my users in Python. I dont want it to print out something, i want to use this module for another script. How do i go about it? thanks in advance. RE: function that returns a list of dictionaries - snippsat - May-06-2021 # result.py from my_record import foo def bar(): print(f'The car vaules is <{foo()[1].get("car")}>') bar() Look at at how modules work is the simplest way to use use import .So here is both files in same folder. This is file i import from. # my_record.py def foo(): my_lst = [ {"foo": 12, "bar": 14}, {"moo": 52, "car": 641}, {"doo": 6, "tar": 84}, ] return my_lstHere a post where explain more a packages(a way to organize more files/folders). RE: function that returns a list of dictionaries - nostradamus64 - May-06-2021 (May-06-2021, 09:42 PM)snippsat Wrote:# result.py from my_record import foo def bar(): print(f'The car vaules is <{foo()[1].get("car")}>') bar()Look at at how modules work is the simplest way to use use Thank you, and if i use the module pwd and systemd how could i get info about my users UID, name, shell(login) and if they are logged in or not with an asterisk symbol to symbolise it? |