Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Python objects

Name: Anonymous 2010-10-30 18:53

Why is oStarSpeck[i] not a point object and instead is
<class 'NoneType'>
<class 'NoneType'>
<class 'NoneType'>
<class 'NoneType'>

info about graphics.py
http://mcsp.wartburg.edu/zelle/python/graphics/graphics/index.html

from graphics import *
import random

WINDOW_SIZE = 300
NUMBER_OF_STARS = 100
oStarSpeck = [Point(0, 0) for _ in range(NUMBER_OF_STARS)]
def main():

    formMain = GraphWin("stars", WINDOW_SIZE, WINDOW_SIZE)
    for i in range(NUMBER_OF_STARS):
        oStarSpeck[i] = Point(random.randint(1, WINDOW_SIZE), random.randint(1,WINDOW_SIZE)).draw(formMain)
        print(type(oStarSpeck[i]))
    iStarCount = NUMBER_OF_STARS
    while (iStarCount > 5):
        print(type(oStarSpeck[random.randint(0, NUMBER_OF_STARS)]))
       
       
           
              
    formMain.getMouse()
   
main()

Name: Anonymous 2010-10-30 18:55

.draw

Name: Anonymous 2010-10-30 19:14

so

oStarSpeck[i] = Point(random.randint(1, WINDOW_SIZE), random.randint(1,WINDOW_SIZE)).draw(formMain)

should be

oStarSpeck[i] = Point(random.randint(1, WINDOW_SIZE), random.randint(1,WINDOW_SIZE))
oStarSpeck[i].draw(formMain)

Is there some rule that I should know about to avoid this in the future?

Name: Anonymous 2010-10-30 19:24

>>3
Yes, learn to program. When you assign something to something, look at what you're assigning.

Name: Anonymous 2010-10-30 19:29

It might be obvious to you that I can't call a method and assign to the object I'm calling the method on but I don't code much so this is the sort of thing I'm trying to figure out, why else would I make a program like this?

Name: Anonymous 2010-10-30 19:39

>>5
I don't know, you tried to optimise something you didn't quite know about instead of doing what I'd have done as a beginner. I thought Python was meant for this type of program anyway. You could probably also do
(oStarSpeck[i] = Point(random.randint(1, WINDOW_SIZE), random.randint(1,WINDOW_SIZE))).draw(formMain) if that was your intention.

Name: Anonymous 2010-10-30 20:08

>>5
The result of a function call is the return value of the function, which is None if the function does not explicitly return a value.
Understanding how expressions are evaluated is fairly critical to writing cohesive code, as are most other aspects on how the code will get evaluated. People with a programming bent often find it easiest to learn a language bottom-up starting with the specifications.

>>6
Not in Python you couldn't.

Name: Anonymous 2010-10-30 21:08

Alright guys thanks # 7 for spelling it out and thanks #2 for helping me even if you are a little sassy, you've both been great help.

Name: Anonymous 2010-12-17 1:40

Erika once told me that Xarn is a bad boyfriend

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List