On Aug 9, 12:00 pm, Irish <[EMAIL PROTECTED]> wrote:
> Hey everybody!

Firstly, welcome to Python, and Turbogears! Python's a great language,
in addition to being a great language to start in.

> def worldbuilder(xspan, yspan):
>         for ycoord in range(yspan):
>                 print ycoord
>                 for xcoord in range(xspan):
>                         print xcoord
>                         BuildingLot=(xcoord, ycoord)
>
> and I'm calling it by using the tg-admin toolbox, in the WebConsole by
> typing:
>
> >>> from controllers import *
> >>> worldbuilder(xspan=2, yspan=8)

I can't reproduce this (I haven't tried in tg-admin, since there are
problems you need to address before even getting that far...)

A major problem with what you are doing here lies in the last line.
You are not creating a new BuildingLot instance, but rather
reassigning the name BuildingLot to the tuple (xcoord, ycoord). That
is, BuildingLot no longer refers to the class in your model - it now
points at the last tuple built - in the first iteration (0, 0).

In general, new objects are created using parentheses: Address("Bob",
"112 Dingo Way")  for example. in the specific case of your class, it
subclasses SQLObject and provides no constructor of itself (i.e. a
method called __init__ of the class), and so you need to pass in
values to the constructor as key-value pairs:

buildingLot = BuildingLot(xcoord=xcoord, ycoord=ycoord)

It would be worth spending a bit of time in the Python console (the tg-
admin shell woould be fine) and try playing with classes to see how
they work. For example:

>>> class Test(object):
...   pass
...
>>> x = Test()
>>> x = Test(1,2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: default __new__ takes no parameters
>>> class Test(object):
...   def __init__(self, x, y):
...     self.x = x
...     self.y = y
...
>>> def printxy(obj):
...   print "X:", obj.x, "Y:", obj.y
...
>>> printxy(Test())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() takes exactly 3 arguments (1 given)
>>> printxy(Test(1,2))
X: 1 Y: 2
>>> printxy(Test(y=1,x=2))
X: 2 Y: 1
>>>

It will give you a better understanding of how it all hangs together.

Cheers,

--
Ant...

http://antroy.blogspot.com/





































--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to