python从模块返回空字典

1 python dictionary

我正在尝试从模块返回一个字典,但无论在Windows 7上的Python2.7上是什么,字典都会返回空.例如:

test_dict.py

def get_dict():
    dictiom = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
    print dictiom['Name']
    return dictiom['Name']

if __name__ == '__main__':
    get_dict()
Run Code Online (Sandbox Code Playgroud)

get_dict.py

import test_dict

dict_test = test_dict.get_dict()
print dict_test
Run Code Online (Sandbox Code Playgroud)

独立运行test_dict.py,print语句返回

Zara
Run Code Online (Sandbox Code Playgroud)

从get_dict.py调用dict打印

{}
Run Code Online (Sandbox Code Playgroud)

这是一个简化的例子,但对于我尝试过的其他测试也是如此.

更新以更改我的示例错误.

好的,所以这是我实际代码的问题部分

Search.py

from Bio import Entrez


def search(query):

    Entrez.email = 'me@example.com'
    handle = Entrez.esearch(db='pubmed',
                        sort='relevance',
                        retmax='50',
                        retmode='xml',
                        term=query)
    results = Entrez.read(handle)
    return results
Run Code Online (Sandbox Code Playgroud)

main.py

import Search

query = 'cancer'
results = Search.search(query)
print(results)
Run Code Online (Sandbox Code Playgroud)

结果是一个空的字典,但无法解决原因.但运行Search.py​​本身是有效的.

Alt*_*yyr 5

给你的功能一个不同的名字!
dict是一个内置的功能.

test_dict.py

def get_dict():
    dictiom = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
    return dictiom #I think you want to return the whole dict?

if __name__ == '__main__':
    print get_dict() # print the dict as a test 
Run Code Online (Sandbox Code Playgroud)

然后你就可以做到这一点

main.py

import test_dict

dict_test = test_dict.get_dict()
print dict_test
Run Code Online (Sandbox Code Playgroud)