小编imy*_*suf的帖子

python - 为什么只读属性可写?

我试图在Python中定义一个只读属性的类; 我按照Python文档编写了以下代码:

#!/usr/bin/python

class Test:
        def __init__(self, init_str):
                self._prop = init_str

        @property
        def prop(self):
                return self._prop

t = Test("Init")
print t.prop
t.prop = "Re-Init"
print t.prop
Run Code Online (Sandbox Code Playgroud)

现在当我尝试执行代码虽然我期待错误/异常时,我看到它正常执行:

$ ./python_prop_test 
Init
Re-Init
Run Code Online (Sandbox Code Playgroud)

我的Python版本是2.7.2.我所看到的,是否有望?如何确保房产不可设置?

python properties readonly private-members python-2.7

16
推荐指数
1
解决办法
4587
查看次数

VS代码:文件结束新行不持久

我面临一个令人恼火的问题,即尽管明确规定应该完成这些操作,但没有为HTML和JavaScript保存新行.有人可以指导我做错了什么吗?

GitHub项目

Visual Studio代码版本详细信息:

Version 1.23.0
Commit 7c7da59c2333a1306c41e6e7b68d7f0caa7b3d45
Date 2018-05-03T15:23:19.356Z
Shell 1.7.12
Renderer 58.0.3029.110
Node 7.9.0
Architecture x64
Run Code Online (Sandbox Code Playgroud)

VS代码设置:

我的Visual Studio代码的设置

newline visual-studio-code vscode-settings

7
推荐指数
2
解决办法
2260
查看次数