Python新手:我们在Python中有Hash的概念吗? [英] New to Python: Do we have the concept of Hash in Python?

查看:84
本文介绍了Python新手:我们在Python中有Hash的概念吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我是Python新手,有C#/ Java背景


Python中是否有任何内置的Hash实现?我正在寻找一个

容器,我可以按名称访问它的项目。这样的事情:


打印容器[" memeberName"]


我问这个是因为我了解到Python中的DB-API没有按名称提供

访问游标列。唯一的选择是索引访问。我希望

我错了!


我学会了Ruby完全支持它。


谢谢,


Alan

Hi,

I am new to Python, with C#/Java background

Is there any built-in Hash implementation in Python? I am looking for a
container that I can access to it''s items by name. Something like this:

Print container["memeberName"]

I am asking this because I learned that DB-API in Python doesn''t offer
access to cursor columns by name. The only option is access by index. I hope
that I''ve got it wrong!

I learned Ruby perfectly supports that.

Thank you,

Alan

推荐答案

> Python中是否有任何内置的Hash实现?我正在寻找一个
> Is there any built-in Hash implementation in Python? I am looking for a
容器,我可以按名称访问它的项目。这样的事情:

打印容器[" memeberName"]


你显然没有阅读教程,他们被称为字典 ;

in Python

我问这个是因为我了解到Python中的DB-API并没有按名称提供对游标列的访问。唯一的选择是索引访问。我希望我错了!


那是因为DB-API使用元组来表示记录。

我学会了Ruby完全支持它。
container that I can access to it''s items by name. Something like this:

Print container["memeberName"]
You obviously haven''t read the tutorial, they''re called "dictionaries"
in Python
I am asking this because I learned that DB-API in Python doesn''t offer
access to cursor columns by name. The only option is access by index. I hope
that I''ve got it wrong!
That''s because the DB-API uses tuples to represent records.
I learned Ruby perfectly supports that.




适用于Ruby。



Yay for Ruby.


AM写道:
是否有任何内置的Hash实现在Python?我正在寻找一个
容器,我可以按名称访问它的项目。这样的事情:

打印容器[" memeberName"]


d = {" memberName" :某些值}

打印d [" memberName"]

我问这个是因为我了解到Python中的DB-API没有提供
按名称访问游标列。唯一的选择是索引访问。我希望
我错了!

我学会了Ruby完全支持它。
Is there any built-in Hash implementation in Python? I am looking for a
container that I can access to it''s items by name. Something like this:

Print container["memeberName"]
d = {"memberName" : "some value"}
print d["memberName"]
I am asking this because I learned that DB-API in Python doesn''t offer
access to cursor columns by name. The only option is access by index. I hope
that I''ve got it wrong!

I learned Ruby perfectly supports that.




Python不使用默认情况下列名称,因为它们不是跨数据库实现可移植的。话虽如此,如果你愿意,你可以轻松获得
。看一下描述。你的

游标实例的属性。


干杯,

Brian



Python does not use column names by default because they are not
portable across database implementations. That being said, you can get
them easily, if you want. Look at the "description" attribute of your
cursor instance.

Cheers,
Brian


AM写道:
A.M wrote:
我问这个是因为我了解到Python中的DB-API没有按名称提供对游标列的访问权限。唯一的选择是索引访问。我希望我错了!
I am asking this because I learned that DB-API in Python doesn''t offer
access to cursor columns by name. The only option is access by index. I
hope that I''ve got it wrong!




虽然据我所知,它不是DB-API的一部分, MySQLdb包(和

也许其他数据库访问模块,我不知道)提供了

aDictCursor将查询结果作为列键控的元组返回的类

词典(哈希已经演示过哈希)。

Jeffrey



While it''s not part of the DB-API as far as I know, the MySQLdb package (and
perhaps other DB access modules as well, I don''t know) provides
a "DictCursor" class that returns query results as a tuple of column-keyed
dictionaries (hashes, already demonstrated by Brian).
Jeffrey


这篇关于Python新手:我们在Python中有Hash的概念吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆