python程式設計的糾結

2021-09-01 09:54:04 字數 4336 閱讀 7535

場景:

1. 定義乙個物件

class strategy:

"""attributes:

- version

- inteval

- period

- validday

- onnetbeg

- circletype

"""thrift_spec = (

none, # 0

(1, ttype.string, 'version', none, none, ), # 1

(2, ttype.string, 'inteval', none, none, ), # 2

(3, ttype.string, 'period', none, none, ), # 3

(4, ttype.string, 'validday', none, none, ), # 4

(5, ttype.string, 'onnetbeg', none, none, ), # 5

(6, ttype.i32, 'circletype', none, 1, ), # 6

) def __init__(self, version=none, inteval=none, period=none, validday=none, onnetbeg=none, circletype=thrift_spec[6][4],):

self.version = version

self.inteval = inteval

self.period = period

self.validday = validday

self.onnetbeg = onnetbeg

self.circletype = circletype

def read(self, iprot):

if iprot.__class__ == tbinaryprotocol.tbinaryprotocolaccelerated and isinstance(iprot.trans, ttransport.creadabletransport) and self.thrift_spec is not none and fastbinary is not none:

fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))

return

iprot.readstructbegin()

while true:

(fname, ftype, fid) = iprot.readfieldbegin()

if ftype == ttype.stop:

break

if fid == 1:

if ftype == ttype.string:

self.version = iprot.readstring();

else:

iprot.skip(ftype)

elif fid == 2:

if ftype == ttype.string:

self.inteval = iprot.readstring();

else:

iprot.skip(ftype)

elif fid == 3:

if ftype == ttype.string:

self.period = iprot.readstring();

else:

iprot.skip(ftype)

elif fid == 4:

if ftype == ttype.string:

self.validday = iprot.readstring();

else:

iprot.skip(ftype)

elif fid == 5:

if ftype == ttype.string:

self.onnetbeg = iprot.readstring();

else:

iprot.skip(ftype)

elif fid == 6:

if ftype == ttype.i32:

self.circletype = iprot.readi32();

else:

iprot.skip(ftype)

else:

iprot.skip(ftype)

iprot.readfieldend()

iprot.readstructend()

def write(self, oprot):

if oprot.__class__ == tbinaryprotocol.tbinaryprotocolaccelerated and self.thrift_spec is not none and fastbinary is not none:

oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))

return

oprot.writestructbegin('circlestrategy')

if self.version is not none:

oprot.writefieldbegin('version', ttype.string, 1)

oprot.writestring(self.version)

oprot.writefieldend()

if self.inteval is not none:

oprot.writefieldbegin('inteval', ttype.string, 2)

oprot.writestring(self.inteval)

oprot.writefieldend()

if self.period is not none:

oprot.writefieldbegin('period', ttype.string, 3)

oprot.writestring(self.period)

oprot.writefieldend()

if self.validday is not none:

oprot.writefieldbegin('validday', ttype.string, 4)

oprot.writestring(self.validday)

oprot.writefieldend()

if self.onnetbeg is not none:

oprot.writefieldbegin('onnetbeg', ttype.string, 5)

oprot.writestring(self.onnetbeg)

oprot.writefieldend()

if self.circletype is not none:

oprot.writefieldbegin('circletype', ttype.i32, 6)

oprot.writei32(self.circletype)

oprot.writefieldend()

oprot.writefieldstop()

oprot.writestructend()

def validate(self):

return

def __repr__(self):

l = ['%s=%r' % (key, value)

for key, value in self.__dict__.iteritems()]

return '%s(%s)' % (self.__class__.__name__, ', '.join(l))

def __eq__(self, other):

return isinstance(other, self.__class__) and self.__dict__ == other.__dict__

def __ne__(self, other):

return not (self == other)

2. 當例項化物件時

strategy = strategy()

strategy.interval = str(a.timeinterval)

3. 取值發現

strategy.inteval 取不到!

4. 糾結是

賦值的屬性是strategy.interval 

原來是物件定義是屬性名稱寫錯了。

但是python語義是不會報錯,只會給物件多增加乙個屬性!

5.解決辦法

1.細心

2.再細心

3.還有就是帶著放大鏡找問題!

糾結的難題

不知道各位在使用oracle時,有木有遇上這麼個情況 相同的資料庫連線,使用者密碼均相同的情況下 在別人機器上,查詢所有的表或者檢視都是有資料的。而在你自己的機器上,並不能查詢到所有的表或檢視均有資料。尤其是那些你需要用到的檢視,那個莫名的火呀!o o 解決方案如下 通過regedit 修改登錄檔 ...

糾結的內心

糾結的內心 現在天就要亮了,我還沒有睡意,現在心裡面非常平靜。2012 年10 月5 號下午吃晚飯的時候,路邊有人給了我一本廣告紙,是關於女性健康的,一共三四十頁,我想大家也都收到過,閒來無事我就翻起來看,也算是為我未來的老婆。沒想到竟然幫了我的大忙。怎麼說呢,我把這本書從頭到尾翻了一遍。在這期間,...

糾結的離職

5月5日提出的離職申請,目前申請已經被批下來了,交接已經完成了。此後經歷了數次面試後,拒絕了乙個6.4k,最後選擇了千橡。千橡那邊就等我確定最後入職時間,而我的入職時間也是我最糾結的地方。本來我以為交接完了就差不多了。可是領導意猶未盡,說一定要我完成他給的任務才能放人,還暗示說如果沒幹完的話就6月4...