Python Forum
function that returns a list of dictionaries
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function that returns a list of dictionaries
#1
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.
Reply
#2
# result.py
from my_record import foo

def bar():
    print(f'The car vaules is <{foo()[1].get("car")}>')

bar()
Output:
The car vaules is <641>
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_lst
Here a post where explain more a packages(a way to organize more files/folders).
Reply
#3
(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()
Output:
The car vaules is <641>
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_lst
Here a post where explain more a packages(a way to organize more files/folders).


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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  convert List with dictionaries to a single dictionary iamaghost 3 1,074 Jan-22-2021, 03:56 PM
Last Post: iamaghost
  Creating a list of dictionaries while iterating pythonnewbie138 6 1,460 Sep-27-2020, 08:23 PM
Last Post: pythonnewbie138
  Recursive function returns None, when True is expected akar 0 1,482 Sep-07-2020, 07:58 PM
Last Post: akar
  Help accessing elements of list of dictionaries Milfredo 6 1,203 Sep-07-2020, 01:32 AM
Last Post: Milfredo
  Accessing values in list of dictionaries pythonnewbie138 2 829 Aug-02-2020, 05:02 PM
Last Post: pythonnewbie138
  how does .join work with list and dictionaries gr3yali3n 7 1,356 Jul-07-2020, 09:36 PM
Last Post: bowlofred
  creating a list of dictionaries from API calls AndrewEnglsh101 5 1,243 Apr-03-2020, 02:21 PM
Last Post: AndrewEnglsh101
  Python function returns inconsistent results bluethundr 4 1,535 Dec-21-2019, 02:11 AM
Last Post: stullis
  I created a function that generate a list but the list is empty in a new .py file mrhopeedu 2 1,082 Oct-12-2019, 08:02 PM
Last Post: mrhopeedu
  Inspect.getmembers with isclass returns an empty list Aldar 1 1,239 Oct-02-2019, 01:48 PM
Last Post: Aldar

Forum Jump:

User Panel Messages

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