主文件.py
from resources import *
alist[0].update()
print (blist)
资源.py
class a:
def __init__(self):
self.x=0
def update(self):
global blist
blist=blist+[b()]
class b:
def __init__(self):
self.y=0
blist=[]
alist=[a()]
调用alist[0].update()时,此程序应在blist中创建类b的新实例,但在运行print(blist)后,它只显示一个空列表。我也尝试过同样的代码,其中类a的定义如下
class a:
def __init__(self):
self.x=0
global blist
blist=blist+[b()]
def update(self):
pass
它成功地在列表b中创建了一个实例。我真的需要它来用函数而不是构造函数创建另一个实例,我该怎么做?如有任何意见,我们将不胜感激
另外,只有在运行多个源代码文件时才会发生这种情况
Tags:
文件实例frompyself列表initdefupdateglobalclassresourcesprintalistblist1条回答网友
1楼 ·
发布于 2023-03-07 00:10:57
blist=blist+[b()]
重新定义了blist
。它不会修改原始对象,这就是另一个源文件中的blist
所指向的对象
您应该.append
到原始列表:
blist.append(b())
当用多个源文件运行python程序时,构造函数的行为与函数不同
http://www.vaticanhistory.de/wordpress/?p=6271
texas frenchies
[…]Every as soon as inside a when we select blogs that we study. Listed beneath are the most current sites that we opt for […]
cheap nude chat
[…]Every as soon as in a even though we select blogs that we study. Listed beneath are the latest websites that we pick […]
افضل جامعة يمنية
[…]here are some links to websites that we link to since we think they may be really worth visiting[…]
Queen Arwa University ROR ID: 03ygqq617
[…]please stop by the sites we follow, like this 1, as it represents our picks from the web[…]
Queen Arwa University uniRank
[…]below you will find the link to some web pages that we feel you ought to visit[…]
Kuliah Murah
[…]usually posts some incredibly exciting stuff like this. If you are new to this site[…]
918kiss
[…]Sites of interest we have a link to[…]
pg slot
[…]The information and facts talked about inside the write-up are some of the best readily available […]
918kiss
[…]here are some hyperlinks to web sites that we link to for the reason that we feel they’re really worth visiting[…]
当用多个源文件运行python程序时,构造函数的行为与函数不同
https://www.hotibau.ch/2014/01/13/basic-image-gallery-post/
当用多个源文件运行python程序时,构造函数的行为与函数不同
https://qadribearing.com/sweet-seat-functional-seat-for-it-folks/
当用多个源文件运行python程序时,构造函数的行为与函数不同
https://student.alsafwa.edu.iq/blog/2019/03/21/75445664/
当用多个源文件运行python程序时,构造函数的行为与函数不同
https://millerlab.ucsd.edu/project/plastic-credit-card-elementor/
当用多个源文件运行python程序时,构造函数的行为与函数不同
https://newsjagaban.blogspot.com/2016/05/democracy-or-kleptocracy-what-do-we.html
itme.xyz
[…]that will be the finish of this post. Right here youll come across some web sites that we assume youll appreciate, just click the hyperlinks over[…]
itme.xyz
[…]one of our visitors not too long ago recommended the following website[…]
Premium URL Shortener
[…]The information and facts talked about inside the post are a number of the most effective accessible […]
MasumINTL
[…]Here is a good Blog You may Obtain Intriguing that we Encourage You[…]
ItMe.Xyz
[…]The info talked about within the post are some of the best offered […]
itme.xyz
[…]below you will find the link to some web pages that we believe you’ll want to visit[…]
Best URL Shortener To Make Money
[…]one of our guests lately advised the following website[…]
masumintl.com
[…]Here is a good Weblog You may Uncover Interesting that we Encourage You[…]
itme.xyz
[…]always a large fan of linking to bloggers that I really like but really don’t get a whole lot of link appreciate from[…]
当用多个源文件运行python程序时,构造函数的行为与函数不同
https://www.mafiea.com/notorious-cavali/