I am having trouble trying to clone a tree i made. Any suggestions?
My Input: -
from cs1graphics import *
-
-
paper = Canvas(300, 200, 'skyBlue', 'My Forest')
-
-
grass = Rectangle(300, 80, Point(150,160))
-
grass.setFillColor('green')
-
grass.setBorderColor('green')
-
grass.setDepth(75)
-
paper.add(grass)
-
-
tree1 = ('tree', 'tree_bottom', 'tree_base')
-
tree = Polygon(Point(50,80), Point(30,125), Point(70,125))
-
tree.setFillColor('darkGreen')
-
paper.add(tree)
-
-
tree_bottom = Polygon(Point(50,80), Point(30,150), Point(70,150))
-
tree_bottom.setFillColor('darkGreen')
-
paper.add(tree_bottom)
-
-
tree_base = Polygon(Point(50,150), Point(45,165), Point(55,165))
-
tree_base.setFillColor('brown')
-
paper.add(tree_base)
-
-
tree2 = tree1.clone()
-
tree2.move(170,30)
-
tree2.scale(1.2)
-
paper.add(tree2)
-
Error: -
Traceback (most recent call last):
-
File "C:/Users/Robert/Documents/CSIS Projects/Ex3_8.py", line 30, in <module>
-
tree2 = tree1.clone()
-
AttributeError: 'tuple' object has no attribute 'clone'
-
I can see how you got the error. This will not work, because a tuple object has no method named clone: - tree1 = ('tree', 'tree_bottom', 'tree_base')
-
tree2 = tree1.clone()
What is tree2 supposed to be?
2 4460 bvdet 2,851
Expert Mod 2GB
I can see how you got the error. This will not work, because a tuple object has no method named clone: - tree1 = ('tree', 'tree_bottom', 'tree_base')
-
tree2 = tree1.clone()
What is tree2 supposed to be?
"clone" is too vague. You have at least 2 options with a tuple/list
tree2 = tree1
creates a reference to tree1, i.e. they both point to the same block of memory, so if you change one, you change both. For a copy, you have to convert to a list. - import copy
-
tree1 = ('tree', 'tree_bottom', 'tree_base')
-
tree2 = tree1
-
print tree2
-
print id(tree2), id(tree1) ## they are the same
-
-
tree3 = copy.copy(list(tree1)) ## shallow copy (look it up)
-
print tree3
-
print id(tree3), id(tree1) ## they are different
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jason Evans |
last post by:
Hi All,
I am writing my own implementation of queue via a linked list, note
not a LinkedList, and was running into trouble with the clone method.
I was wondering if anyone could point out some...
|
by: Vincent |
last post by:
Hey, I have a problem to understand the underlaying of
clone method. Hope someone can help me out.
Let's say,
clonedObject = originalObject.clone()
(syntax may be wrong, but you know what I...
|
by: Ryan Mitchley |
last post by:
Hi all
I have code for an object factory, heavily based on an article by Jim Hyslop
(although I've made minor modifications). The factory was working fine using
g++, but since switching to the...
|
by: ahaupt |
last post by:
Hi all,
I'm implementing the Clone() method through the ICloneable interface
and don't quite know how deep I need to go for a deep copy.
Example:
class A: ICloneable
{
object _val;
|
by: solex |
last post by:
Hello,
I am trying to use serialization to copy objects. The object in question
"Institution" inherits from a parent object "Party" both are marked as
<Serializable()>. Initially I can copy an...
|
by: Alex D. |
last post by:
hi guys.
I need to clone multiple times an object and I am succesfully cloning using
the regular serialization process, using a MemoryStream. My problem is that
after cloning the object more that...
|
by: Hamed |
last post by:
Hello
I am developing a utility to be reused in other programs. It
I have an object of type Control (a TextBox, ComboBox, etc.) that other
programmers use it in applications. they may set some...
|
by: Hamed |
last post by:
Hello
It seems that I should implement ICloneable to implement my own clone
object. the critical point for me is to make a control object based on
another control object that all of its event...
|
by: mark.norgate |
last post by:
Hello
I want to create a reference to an object, so that changes to the
referenced object are reflected in the other object. Like this:
object o = 123;
object p = o;
o = 456;
|
by: =?Utf-8?B?Sm9lbCBNZXJr?= |
last post by:
I have created a custom class with both value type members and reference type
members. I then have another custom class which inherits from a generic list
of my first class. This custom listneeds...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |