Python Forum
How to use a module as dict ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use a module as dict ?
#4
If want to import can do it like this,remember a module is just a single Python file.
>>> from bar import mymodule
>>> mymodule('2 + 2')
'4'
>>> mymodule('os')
'fedora'
>>> mymodule('java')
'Not in record'
# bar.py
def mymodule(arg):
    return {
        "2 + 2": "4",
        "python": 3.4,
        "os": "fedora"
        }.get(arg, 'Not in record')
Reply


Messages In This Thread
How to use a module as dict ? - by harun2525 - May-15-2017, 04:58 PM
RE: How to use a module as dict ? - by micseydel - May-15-2017, 05:06 PM
RE: How to use a module as dict ? - by nilamo - May-15-2017, 05:24 PM
RE: How to use a module as dict ? - by snippsat - May-15-2017, 05:45 PM
RE: How to use a module as dict ? - by harun2525 - May-15-2017, 07:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort a dict in dict cherry_cherry 4 102,493 Apr-08-2020, 12:25 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

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