我正在从CSV导入并大致以格式获取数据
{ 'Field1' : 3000, 'Field2' : 6000, 'RandomField' : 5000 }
Run Code Online (Sandbox Code Playgroud)
字段的名称是动态的.(好吧,他们很有活力,因为可能会有超过Field1和Field2,但我知道Field1并且Field2总是会在那里.
我希望能够将这个字典传入我的班级,allMyFields以便我可以将上述数据作为属性访问.
class allMyFields:
# I think I need to include these to allow hinting in Komodo. I think.
self.Field1 = None
self.Field2 = None
def __init__(self,dictionary):
for k,v in dictionary.items():
self.k = v
#of course, this doesn't work. I've ended up doing this instead
#self.data[k] = v
#but it's not the way I want to access the data.
q = { …Run Code Online (Sandbox Code Playgroud) 我需要访问OpenSSL的加密函数来编码CBC流中的Blowfish数据.我用Google搜索并找到了一些Blowfish库(手写)和一些OpenSSL包装器(似乎没有一个完整的.)
最后,我需要访问某些OpenSSL函数,例如完整的blowfish.h 命令库.什么是pythonic /正确的访问方式?使用类似SWIG的东西来允许Python/C绑定,还是有更好的方法?
谢谢!
我似乎无法找到一种优雅的方式从t开始并导致s.
>>>t = ['a',2,'b',3,'c',4]
#magic
>>>print s
{'a': 2, 'c': 4, 'b': 3}
Run Code Online (Sandbox Code Playgroud)
我提出的解决方案看起来不那么优雅:
s = dict()
for i in xrange(0, len(t),2): s[t[i]]=t[i+1]
# or something fancy with slices that I haven't figured out yet
Run Code Online (Sandbox Code Playgroud)
它显然很容易解决,但是,似乎还有更好的方法.在那儿?