Redian新闻
>
请帮我看一下这个很简单的python问题在哪里。
avatar
请帮我看一下这个很简单的python问题在哪里。# Programming - 葵花宝典
C*2
1
家住宾州长木头公园附近,邮编19317。现需聘请住家阿姨或是钟点工一名。主要负责
做饭清洁等家务。如有兴趣者,站内联系或请拨打610-388-1536联系,如无人接听,请
务必留下联系方式,因为每天家中都会有很多广告电话,不说明电话号码,实在是分不
清哪个电话是谁打的。谢谢!
avatar
l*7
2
最近总是 吃完饭 就难受 然后还有点痛 过2-3小时就饿
尤其是晚上 快睡觉时候更饿
白天最近发现 有时候胸部还有一点痛
查了下应该是溃疡
想去看 可是又没有保险 要怎么办呢?
最近是因为心情特别差,情绪波动很厉害
如果要是真看要花多少呢?如果自己吃药能吃什么药呢?
现在在吃lansoprazole 可是不怎么管用 不过也只是吃第2天
要怎么办呢?有人给点建议么?
感激不尽
avatar
M*P
3
这几个演员都不错,但是男的好像都没参加?
avatar
h*o
4
面临回国,有很多留学生担心自己成绩不好,或者因为特殊原因未能顺利毕业,不能取
得毕业证书。也有很多留学生担心自己的文凭得不到权威机构认证。我们将替您消除这
些顾虑,帮助您无忧发展,一展宏图。
本公司能最大程度减少中间环节成本的渠道服务机构,多年来以丰富的经验、负责的态
度、卓越的品质,真诚合作了大量海外中介机构、服务了大量的留学人员。专业快速办
理加拿大、澳洲、英国、新西兰、新加坡、美国、法国、德国等各大学校的毕业证。
微信/QQ:257.363.8246
主营项目:
◆办理真实使馆公证(即留学回国人员证明)
◆办理教育部国外学历学位认证。(网上可查、永久存档、快速稳妥,回国发展,考公
务员,落户,进国企,外企,创业,无忧愁)
◆办理各国各大学文凭(世界名校一对一专业服务,可全程监控跟踪进度)
◆提供整套申请学校材料
◆全套服务:毕业证、成绩单、真实使馆公证、真实教育部认证。让您回国发展信心十
足!
◆可以提供钢印、水印、烫金、激光防伪、凹凸版、最新版的毕业证、百分之百让您绝
对满意、设计,印刷,DHL快递;毕业证、成绩单7个工作日,真实大使馆教育部认证2
个月。
本公司长期和教育部以及各国使馆合作,拥有强大的背景与后台,保持着信誉优良的关
系网络。使馆回国人员留学证明和教育部认证完全按照正规程序、时间办理,客户可预
约来公司面谈,有专业的教育咨询顾问实行一对一服务!也可随我司工作人员一同前往
教育部窗口递交材料,更有保障,更放心。
承诺:
【一】高仿真
凭借多年的制作经验,本公司制作激光,水印,钢印,烫金,紫外线等防伪技术一流,
毕业证版本齐全,仿真的达100%。
【二】高效率
本公司承诺各位顾客在最短时间内制作完成并交货。不论您身在何处,只要您有需求,
我们便会以最高效的办事效率来满足您的需求。如果我们没有您所想办的学校,那么只
要你能提供版本,我们就可以为您专门开版办理,7-10天完成制作
【公司业务】
★办理加拿大、澳洲、英国、美国、新西兰。新加坡、法国、德国等各大学毕业证及成
绩单。从防伪到印刷,从水印到钢印,高精仿度几乎跟学校相似!让您绝对满意。(仿
真程度高达100%。)
★办理高仿地方教育部认证书
★提供制作学生卡、雅思等各种证明材料。
-------------拓展您前程,成就您梦想-------------
【咨询方式】
微信/QQ: 257.363.8246
(敬请保留此联系方式,以备用!如有不在线请给我们留言!我们将在第一时间给您回
复!)
【此贴长年有效——欢迎各位新老顾客咨询,我们将会竭诚为您服务!】
avatar
s*a
5
在靖安城下的开阔平原地带,包围与突围的战斗正进行荼。~~~~
魔族大军攻势如潮,对残余的靖安守军发动了一次又一次的猛攻。
溃败后,魔族骑兵抢先一步截断住了守军回城的道路,撤退中的靖安守军夺路不成
,被赶来的魔族主力追上,无奈之下,魏军部队唯有在原地组织抵抗。
包围圈中的兵马并不少,东平都督府的亲军和易小刀的横刀旅都在里面,更不要说
还有来自东陵卫、守备旅等各个部队的零散兵马。但是面对排山倒海的魔族斗铠,失去
斗志的各部魏军都成了惊弓之鸟,一击即溃。
黑风旅叛变,东陵卫旅至今未能突围,包围圈中的部队已是靖安最后的守军了。倘
若他们被歼灭,那魔族都用不着攻城了,直接派一队骑兵就能把防卫空虚的靖安城拿下
了。
易小刀和元义都明白,这是生死一刻。倘若再保存实力,大伙只有抱着一块死了。
他们派出了所有能战斗的斗铠部队,匆忙组建了一道不是很坚固的防线,抵挡着魔族斗
铠一波又一波的攻势。两军交战激烈,厮杀声一阵接着一阵,斗铠激烈冲撞的声音远远
传出,震撼大地。
此刻,魔族军阵中一处地较高的坡地上,银白色斗铠的武将和衣着华丽的贵族们侍
立如林。在
avatar
f*o
6
#!/usr/bin/python
import os;
import sys;
class Person:
''' Defines a Person class '''
population = 0
def __init__(self,name):
''' I really hate the indents. '''
self.name = name;
print 'The person'"'s"'name is %s' % self.name;
Person.population += 1;
def __del__(self):
print '%s says bye;' % self.name
Person.population -= 1
if Person.population == 0:
print 'I am the last one, now I am gone'
else:
print 'There are still %d people left;' % Person.
population
def howMany(self):
if Person.population == 1:
print 'I am the last one, but I am still here' ;
else:
print 'We have %d people here.' % Person.population ;
Ao = Person('Ao Liu');
Ao.howMany();
John = Person('John Bay');
John.howMany();
Chris = Person('Chris Tunnel');
Chris.howMany();
运行后得到
The person'sname is Ao Liu
I am the last one, but I am still here
The person'sname is John Bay
We have 2 people here.
The person'sname is Chris Tunnel
We have 3 people here.
Ao Liu says bye;
There are still 2 people left;
Chris Tunnel says bye;
Exception AttributeError: "'NoneType' object has no attribute 'population'"
in
> ignored
John Bay says bye;
Exception AttributeError: "'NoneType' object has no attribute 'population'"
in
> ignored
后面的两个成员为什么没法访问Person.population了呢? 第一个成员离开的时候不只
是将其减一而已吗?
谢谢~
avatar
Y*r
7
there are none prescription drugs for this, the important thing is relax
and don't eat greesy food
avatar
o*a
8
好看,尤其第一第二集,第三集节奏慢了点,等看第四集
avatar
p*2
9
python class那个self很恶心。
avatar
Y*r
10
I meant there are a lot of non prescription drugs for your symptoms
avatar
M*P
11
这几个演员都不错,但是男的好像都没参加?
avatar
f*o
12

是有点。但你没有告诉我具体问题出在哪里。

【在 p*****2 的大作中提到】
: python class那个self很恶心。
avatar
l*y
13
看症状像胃十二指肠溃疡,有条件的话最好做个胃镜确诊一下。
如果没有保险,暂时不想花钱,先吃一阵子PPI看看吧,两天时间太短了,看不出效果
来,lansoprazole就可以,类似的prilosec,prevacid药房都能买到,不需要处方。
但是要注意一点,如果是合并幽门螺杆菌,需要口服抗生素进行三联或者四联治疗,确
诊需要做检查,开抗生素要处方。
还有一点,情绪对胃溃疡的影响是很大的,放松,按时吃饭,尽量吃温和一点好消化的
东西,不要喝酒,不要喝茶喝咖啡,不要吃辛辣刺激的东西。

【在 l********7 的大作中提到】
: 最近总是 吃完饭 就难受 然后还有点痛 过2-3小时就饿
: 尤其是晚上 快睡觉时候更饿
: 白天最近发现 有时候胸部还有一点痛
: 查了下应该是溃疡
: 想去看 可是又没有保险 要怎么办呢?
: 最近是因为心情特别差,情绪波动很厉害
: 如果要是真看要花多少呢?如果自己吃药能吃什么药呢?
: 现在在吃lansoprazole 可是不怎么管用 不过也只是吃第2天
: 要怎么办呢?有人给点建议么?
: 感激不尽

avatar
o*a
14
好看,尤其第一第二集,第三集节奏慢了点,等看第四集
avatar
h*s
15
http://docs.python.org/2/reference/datamodel.html
It is not guaranteed that __del__() methods are called for objects that
still exist when the interpreter exits.
第二次的时候Person这个符号已经没了

【在 f********o 的大作中提到】
: #!/usr/bin/python
: import os;
: import sys;
: class Person:
: ''' Defines a Person class '''
: population = 0
: def __init__(self,name):
: ''' I really hate the indents. '''
: self.name = name;
: print 'The person'"'s"'name is %s' % self.name;

avatar
l*7
16
谢谢大家!我今天去做了血检!还不知道要多少刀?
医生开了处方药,要200多啊!就2盒破药,而且我吃完胃就更难受了
我最近心情一直很差
因为男朋友的事情
很难过很难过 总哭
没想到竟成这样了
我现在真难受 我的胃一直不舒服 疼还烧的厉害 昨天晚上也一晚上都没睡 疼就去吃东
西吃了就不疼 然后又疼
我真不知道要怎么办 可以很快好么?
到底要怎么办呢
avatar
l*g
17
啥续集 不是演完了么
avatar
m*5
18
+1

【在 h*******s 的大作中提到】
: http://docs.python.org/2/reference/datamodel.html
: It is not guaranteed that __del__() methods are called for objects that
: still exist when the interpreter exits.
: 第二次的时候Person这个符号已经没了

avatar
l*7
19
要多久能好呢!我好难受啊!
avatar
m*5
20
welcome to python world! I provided a fix which can run flawless to your
class design. Seems like u r from java ;) We should always Keep
in mind that, unlike java, python is a dynamic language.
The counterpart of static class variable of java is class variable.
Using the class name as a reference to a class is very common outside the
class def. However, it is not a very good idea to do so within the class def
, because any class itself is an instance of `type`. The name space looking-
up can mess up when u do so. I recommend @
classmethod to handle all "static class variable"
import os
import sys
class Person(object):
''' Defines a Person class '''
population = 0
def __init__(self,name):
''' I really hate the indents. '''
self.name = name
print 'The person'"'s"'name is %s' % self.name
self.__addpopulation__()
super(Person, self).__init__()

@classmethod
def __addpopulation__(cls):
cls.population+=1

def __del__(self):
print '%s says bye;' % self.name
self.__poppopulation__()

@classmethod
def __poppopulation__(cls):
cls.population -= 1
if cls.population == 0:
print 'I am the last one, now I am gone'
else:
print 'There are still %d people left;' % cls.population

@classmethod
def howMany(cls):
if cls.population == 1:
print 'I am the last one, but I am still here'
else:
print 'We have %d people here.' % cls.population
Ao = Person('Ao Liu')
Ao.howMany()
John = Person('John Bay')
John.howMany()
Chris = Person('Chris Tunnel')
Chris.howMany()
Chris = Person('David')
Chris.howMany()
$./delproblem2.py
The person'sname is Ao Liu
I am the last one, but I am still here
The person'sname is John Bay
We have 2 people here.
The person'sname is Chris Tunnel
We have 3 people here.
The person'sname is David
Chris Tunnel says bye;
There are still 3 people left;
We have 3 people here.
Ao Liu says bye;
There are still 2 people left;
David says bye;
There are still 1 people left;
John Bay says bye;
I am the last one, now I am gone
BTW: U'd better lose all the ";"

【在 f********o 的大作中提到】
: #!/usr/bin/python
: import os;
: import sys;
: class Person:
: ''' Defines a Person class '''
: population = 0
: def __init__(self,name):
: ''' I really hate the indents. '''
: self.name = name;
: print 'The person'"'s"'name is %s' % self.name;

avatar
l*y
21
大夫给你开的什么药?
再说一遍,胃溃疡受情绪的影响非常大,你要是想快点好,那必须调整心情,这一点非
常关键。

【在 l********7 的大作中提到】
: 谢谢大家!我今天去做了血检!还不知道要多少刀?
: 医生开了处方药,要200多啊!就2盒破药,而且我吃完胃就更难受了
: 我最近心情一直很差
: 因为男朋友的事情
: 很难过很难过 总哭
: 没想到竟成这样了
: 我现在真难受 我的胃一直不舒服 疼还烧的厉害 昨天晚上也一晚上都没睡 疼就去吃东
: 西吃了就不疼 然后又疼
: 我真不知道要怎么办 可以很快好么?
: 到底要怎么办呢

avatar
l*a
22
不是说一般不建议自己写__del__()吗?
avatar
l*7
23
好像是 Omeprazole

【在 l*****y 的大作中提到】
: 大夫给你开的什么药?
: 再说一遍,胃溃疡受情绪的影响非常大,你要是想快点好,那必须调整心情,这一点非
: 常关键。

avatar
f*o
24
不应该啊,只是Person.population没有了,但还是say goodbye了啊?

【在 h*******s 的大作中提到】
: http://docs.python.org/2/reference/datamodel.html
: It is not guaranteed that __del__() methods are called for objects that
: still exist when the interpreter exits.
: 第二次的时候Person这个符号已经没了

avatar
f*o
25
谢谢你的建议。但我还是没弄明白为什么我的不可以用。Person是一个class,怎么会
由于一个成员的退出就没有了呢?你看,第二个person还是say了goodbye。只是没有访
问到Person.population 而已。

【在 m********5 的大作中提到】
: +1
avatar
m*5
26
This is dynamic language. `Person` is NOT a C++ or java like `class`. `
Person` is just a name in global scope referring to an instance of `type`.
In another word `Person` is nothing but a key in the global name dictionary.
During interpretor exiting, as @hatemaths pointing out, when __del__ get
called, there is no guarantee any referred global name still exists (
deleting order is unpredictable). In this case `Person` in the global scope
has already being destroyed. But in the local scope it still exist. That is
why if u use the reference in local scope: `cls` in @classmethod, it will
still work.
Here I will show some detail with examples:
try to modify my class as following:
@classmethod
def __poppopulation__(cls):
print "gloals: ", globals()
print "locals: ", locals()
cls.population -= 1
if cls.population == 0:
print 'I am the last one, now I am gone'
else:
print 'There are still %d people left;' % cls.population
Then modify the instantiation part:
Ao = Person('Ao Liu');
Ao.howMany();
John = Person('John Bay');
John.howMany();
Chris = Person('Chris Tunnel');
Chris.howMany();
David = Person('David');
David.howMany();
print globals()
what u will see is like this:
#############################
The person'sname is Ao Liu
I am the last one, but I am still here
The person'sname is John Bay
We have 2 people here.
The person'sname is Chris Tunnel
We have 3 people here.
The person'sname is David
We have 4 people here.
#############################
#Here is the global dict:
globals(): {'__builtins__': , '__file_
_': './delproblem2b.py', 'Ao': <__main__.person at="" object="">, '
__package__': None, 'sys': , 'Person': main__.Person'>, 'Chris': <__main__.person at="" object="">, '__
name__': '__main__', 'John': <__main__.person at="" object="">, 'os
': , '__doc__': None, 'David':
<__main__.person at="" object="">}
#############################
# so after Ao get del, still 'Person':
###
Ao Liu says bye;
gloals: {'__builtins__': , 'Ao': None,
'__package__': None, 'sys': , 'Person': main__.Person'>, 'Chris': <__main__.person at="" object="">, '__
name__': '__main__', 'John': <__main__.person at="" object="">, 'os
': , '__doc__': None, 'David':
<__main__.person at="" object="">}
locals: {'cls': }
There are still 3 people left;
#############################
# But when Chris get del, 'Person': None
###
Chris Tunnel says bye;
gloals: {'__builtins__': , 'Ao': None,
'__package__': None, 'sys': None, 'Person': None, 'Chris': None, '__name__'
module 'os' from '/usr/lib/python2.7/os.pyc'>, '__doc__': None, 'David': <__>main__.Person object at 0x7ff088126dd0>}
locals: {'cls': }
There are still 2 people left;
#############################
# because 'Person' is refer to None, Person.population is actually,
#None.population. This is why u get an error in ur code.
###
John Bay says bye;
gloals: {'__builtins__': , 'Ao': None,
'__package__': None, 'sys': None, 'Person': None, 'Chris': None, '__name__'
'__doc__': None, 'David': <__main__.person at="" object="">}
##But in the local scope of the instance of `Person class` is still ##exist.
locals: {'cls': }
There are still 1 people left;
David says bye;
gloals: {'__builtins__': , 'Ao': None,
'__package__': None, 'sys': None, 'Person': None, 'Chris': None, '__name__'
locals: {'cls': }
I am the last one, now I am gone
let's continue to play with the global name and demonstrate what the `
unpredictable` means. Create a new script with the *OP's* post as myscript1a.
py, with following modification:
add A to all the instances:
Ao = Person('Ao Liu');
Ao.howMany();
AJohn = Person('John Bay');
AJohn.howMany();
AChris = Person('Chris Tunnel');
AChris.howMany();
ADavid = Person('David');
ADavid.howMany();
###################
Chris Tunnel says bye;
There are still 3 people left;
David says bye;
There are still 2 people left;
Ao Liu says bye;
There are still 1 people left;
John Bay says bye;
Exception AttributeError: "'NoneType' object has no attribute '
population'" in 0x7f2f1f2e9ea8>> ignored
##we can see here the behavior changed!
So the behavior is not stable, it might related to the variable name, or to
other stuff, not for sure.
In certain cases, this will even create memory leak.
In general, as @libralibra said, we should avoid to use method __del__ with
global reference either explicitly or implicitly
I hope this will clear all the doubts u have. As I said, you should keep in
mind, Python is a dynamic language, which is nothing like the Java/C++, most
of the concepts you have learned in Java and C++ will surprise u in Python.
avatar
m*5
27
操, 楼主居然就这么消失了...
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。