我正在http://www.sthurlow.com/python/lesson08/上在线阅读教程,我相信我理解类在python中是如何工作的,至少在某种程度上,但是当我运行这段代码时:
class Shape:
def __init__(self,x,y):
self.x = x
self.y = y
description = "This shape has not been described yet"
author = "Nobody has claimed to make this shape yet"
def area(self):
return self.x * self.y
def perimeter(self):
return 2 * self.x + 2 * self.y
def describe(self,text):
self.description = text
def authorName(self,text):
self.author = text
def scaleSize(self,scale):
self.x = self.x * scale
self.y = self.y * scale
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Traceback (most recent call last):
File "Y:/python/Shape.py", line 1, …Run Code Online (Sandbox Code Playgroud) 我只是想知道是否有一种方法可以在IDLE中添加断点,以便我可以在脚本中的某个点停止并在空闲shell中写入其他行进行测试.如果没有,是否有其他软件可以做到这一点?
我有一个非常大的数据库,我正在使用,我需要知道如何选择一组没有任何实际模式的id.这是我到目前为止的代码段:
longIdList = [1, 3, 5 ,8 ....................................]
for id in longIdList
sql = "select * from Table where id = %s" %id
result = cursor.execute(sql)
print result.fetchone()
Run Code Online (Sandbox Code Playgroud)
我在想,必须有一个更快的方法来做到这一点......我的意思是我的脚本需要搜索一个拥有超过400万id的数据库.有没有办法可以使用select命令一次性抓取它们.我可以使用带有id列表的where语句吗?谢谢
我已经粘贴了下面的代码片段,当我在缓冲区中有数据时,它会从串口读取一行数据,但是我打印的是我不想要的额外空白行.任何想法我做错了什么?
static void Port1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int i = 0;
int end = -1;
SerialPort Port1 = (SerialPort)sender;
String GPSMessage = "";
while (end == -1)
{
int GPStoRead = Port1.BytesToRead;
byte[] GPSbuffer = new byte[GPStoRead];
Port1.Read(GPSbuffer, 0, GPSbuffer.Length);
buffer = Utility.CombineArrays(buffer, GPSbuffer);
for (i = 0; i < buffer.Length; i++)
{
if (buffer[i] == '\r')
{
end = i;
}
}
}
GPSMessage += new String(System.Text.Encoding.UTF8.GetChars(Utility.ExtractRangeFromArray(buffer, 0, end)));
GPSMessage.TrimEnd();
if (GPSMessage != "")
{
Debug.Print(GPSMessage);
}
buffer …Run Code Online (Sandbox Code Playgroud)