小编dra*_*234的帖子

如何将类属性转换为整数

我有以下课程:

class temp_con():
    def __init__(self):
        self.t = 0
    @property
    def t(self):
        return self.t
    @t.setter
    def t(self,value):
        self.t = value
Run Code Online (Sandbox Code Playgroud)

我需要使用它来比较遵循这个逻辑的数字:

if num <= temp_con.t - 2:
    #dothing
Run Code Online (Sandbox Code Playgroud)

但是我得到错误:

输入错误:不支持的操作数类型 - :'property'和'int'<

我试过了int(temp_con.t),getattr(temp_con, t)但那些没用.

我如何将该属性用作int?

python properties class

2
推荐指数
1
解决办法
1910
查看次数

String.Split创建所有空数组值

我的代码使用StringBuilder从网络流构建一个字符串.

然后我将生成的StringBuilder(myCompleatMessage)转换为一个字符串ToString.

此时字符串很好.

然后我尝试使用.Split()'〜'分隔字符串

当我尝试用控制台显示结果字符串或将其写入文件时,我得到:"System.String []"一遍又一遍地重复.

我的代码是:

byte[] myReadBuffer = new byte[3000];
StringBuilder myCompleteMessage = new StringBuilder();
int numberOfBytesRead = 0;
char[] separatingChars = {'~'};
// Incoming message may be larger than the buffer size.
do
{
    numberOfBytesRead = stream.Read(myReadBuffer, 0, myReadBuffer.Length);

    myCompleteMessage.AppendFormat("{0}", Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead));

}
while (stream.DataAvailable);
string tosep = myCompleteMessage.ToString();

string[] words = tosep.Split(separatingChars);
Console.Write(tosep);

StreamWriter file = File.AppendText("c:\\Users/edegraaf/Desktop/test.txt");
foreach(string i in words)
{
    file.WriteLine(words);
} 
file.Close();
Run Code Online (Sandbox Code Playgroud)

字符串示例:

24.062C 2017-05-31 19:36:20.143767~24.125C 2017-05-31 19:37:21.075028~30.25C …

c# arrays string

-1
推荐指数
1
解决办法
41
查看次数

标签 统计

arrays ×1

c# ×1

class ×1

properties ×1

python ×1

string ×1