![](/img/trans.png)
[英]How do I get a specific variable from another file if it is not defined in the constructor?
[英]How to access variable defined in constructor from another file in python
我有一個python文件file1
,其中包含以下代碼
Class myClass():
def __init__(self):
self._variable1 = 2
現在如何從另一個python文件訪問variable1
from file1 import myClass
class = myClass()
class._variable1 ??
如何訪問這些變量。
一切都很好,除了變量的名稱class
試試吧
from file1 import myClass
cl = myClass()
cl.variable1
較新的用戶python關鍵字作為變量名,您可能會看到它的列表
import keyword
keyword.kwlist
更多細節lexical_analysis
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.