python object类型转换_python对象类型转换

博主尝试搜索在Python中传递对象引用并进行类型转换,像Java那样操作却未成功。其问题是要将对象引用传递给类构造函数,不知如何将引用类型转换为对象,还给出了相关类的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我一直在尝试搜索如何在python中传递对象引用,并像Java一样对其进行类型转换,但没有成功。我不知道这个话题是否存在。

我的问题是必须将对象引用传递给类构造函数。但我不知道如何将引用类型转换为对象。在java中,虽然我已经完成了这个任务,但是我必须将代码传输到服务器端。

非常感谢,

杰克class SearchRectangle:

def __init__(self, lower_left_subgrid_x, lower_left_subgrid_y, rectangle_width, rectangle_height):

self.min_subgrid_x = int(lower_left_subgrid_x)

self.max_subgrid_x = int(self.min_subgrid_x + rectangle_width -1)

self.min_subgrid_y = int(lower_left_subgrid_y)

self.max_subgrid_y = int(self.min_subgrid_y + rectangle_height -1)

...blah

class SearchRectangleMultiGrid:

# parent rectangle should be a SearchRectangle instance

def __init__(self, parent_rectangle):

self.parent_rectangle = SearchRectangle()parent_rectangle

# test codes

test_rect = SearchRectangle(test_subgrid.subgrid_x, test_subgrid.subgrid_y, 18, 18)

print "\n\nTest SearchRectangle";

print test_rect.to_string()

print test_rect.sql_clause

test_rec_multi = SearchRectangleMultiGrid(test_rect)

print "\n\nTest SearchRectangleMulti"

test_rec_multi.parent_rectangle.to_string()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值