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

Pages: 1-

Python novice

Name: Anonymous 2011-09-29 17:35


class tic:
  turn = "x"
  def changeturn(self, y = turn):
    if y == "x":
      self.turn = "o"
    if y == "o":
      self.turn = "x"

'''WHY THE FUCK ISN'T this working? The changeturn(), I mean, it only works once!'''

Name: Anonymous 2011-09-29 17:39

It's a matter of sequentiality.

Name: Anonymous 2011-09-29 21:51

from itertools import cycle

class Tic():
    turn = cycle(['x', 'y'])

    def get_turn(self):
        return self.turn.next()

Name: Anonymous 2011-09-29 21:51

from itertools import cycle

class Tic():
    turn = cycle(['x', 'y'])

    def get_turn(self):
        return self.turn.next()

Name: Anonymous 2011-09-29 21:56

Event better
------------

from itertools import cycle

turn = cycle(['x', 'y'])

turn.next()
turn.next()
turn.next()
for t in turn:
    print t

Name: Anonymous 2011-09-30 4:03

>>1
take a loot at the error messages in the interpreter

Name: Anonymous 2011-10-01 8:01

one word: THE FORCED INDENTATION OF CODE!!!!!!!!

Name: Anonymous 2011-10-01 8:17

Today is useful Anonymous day.

>>1
Default parameters are read and evaluated only once, at definition time. As Python defines changeturn, y is bound to the default value of "x", forever.

In order to implement your desired behaviour, do as follows:

class tic(object):
  turn = "x"
  def changeturn(self, y = None):
    if not y:
      y = self.turn
    if y == "x":
      self.turn = "o"
    if y == "o":
      self.turn = "x"


Also, please inherit from Object in your classes: class tic(object).

Name: Anonymous 2011-10-01 12:39

>>8
Default parameters are read and evaluated only once, at definition time.
I fell victim to this more than once. def function(x=[]), for example. Changing this list afterwards and calling the function again is bad news. Fucking bad news.

Name: Anonymous 2011-10-01 16:29


(define (make-tic)
  (let ((turn 'x))
    (lambda (message . args)
      (case message
        ((turn) turn)
        ((changeturn) (define t
                        (if (null? args) turn (car args)))
                      (set! turn (case t ((x) 'y) ((y) 'x))))))))

(define tic (make-tic))

(tic 'turn)
x

(tic 'changeturn)
(tic 'turn)
y

;; This is stupid IMO but your code does the same so i supported it:
(tic 'changeturn 'x)
(tic 'turn)
y

Name: Anonymous 2011-10-01 17:12

>>8
Default parameters are read and evaluated only once, at definition time

Yo homegirl, there is only "compile time" and "run time".

As Python defines changeturn, y is bound to the default value of "x", forever

Not really. Reread the python docs again you jew.

Name: John Carmack 2011-10-01 17:20

Focused, hard work is the real key to success. Keep your eyes on the goal, and just keep taking the next step towards completing it. If you aren't sure which way to do something, do it both ways and see which works better.

Name: Anonymous 2011-10-01 18:50

>>8
Also, please inherit from Object in your classes: class tic(object).
What's the purpose of this?

Name: Anonymous 2011-10-01 19:01

>>11

Yo homegirl, there is only "compile time" and "run time".

In Python, definition happens dynamically (i.e. in run time) as the program reaches defs and classes. Definition time is the point in run time at which a function or a class is defined, you faggot.

>>13
Make it a new-style class. Just do it.

Name: Anonymous 2011-10-01 20:35

happens

Name: Anonymous 2011-10-01 20:49

>>14
The point being, there is no such thing as "definition time".

Name: Anonymous 2011-10-01 20:59

>>16
shut up queer

Name: Anonymous 2011-10-02 2:01

>>16
You define something right the moment you write it!

Name: Anonymous 2011-10-02 12:10

>>18
No you don't. Go take a CS class you fucktard.

Name: Anonymous 2011-10-02 13:43

>>19
Clearly your thoughts lack focus. Have you ever read an academic paper containing a definition? (Hahaha, who am I kidding, you probably can't even read.) When do you think this agglomeration of big words came to be a ``definition''? When the author thought of it? When he wrote it down? When he refined it? After the paper was published? After it was reviewed? After it became popular?

You see, this is quite an interesting situation that warrants deeper discussion.

Name: Anonymous 2011-10-02 13:56

Theorem 2.6.3
Let $P_i$ denote the $P$th poster in this thread.
Let $f(x)$ denote his faggotry.
Then,
$$ \forall P_i, f(x) > 9000 $$

Name: Anonymous 2011-10-02 15:56

>>20
Clearly your thoughts lack focus.

That's not what my graduate advisor at UC Berkeley told me back in 2001.

Have you ever read an academic paper containing a definition?
Yes. It's called the lower division classes you moron.

When do you think this agglomeration of big words came to be a ``definition''? When the author thought of it? When he wrote it down? When he refined it? After the paper was published? After it was reviewed? After it became popular?

Okay, I really can't tell if you're trolling or if you're just plain fucking stupid. Either way, go run off and scrub another toilet you fucking mental midget.

Name: Anonymous 2011-10-02 16:32

>>22
Go suck another midget you fucking human toilet.

Name: Anonymous 2011-10-02 17:15

>>22

Clearly your thoughts lack focus.

That's not what my graduate advisor at UC Berkeley told me back in 2001.

Your thoughts lack focus.

Have you ever read an academic paper containing a definition?

Yes. It's called the lower division classes you moron.

It's called it.

When do you think this agglomeration of big words came to be a ``definition''? When the author thought of it? When he wrote it down? When he refined it? After the paper was published? After it was reviewed? After it became popular?

Okay, I really can't tell if you're trolling or if you're just plain fucking stupid. Either way, go run off and scrub another toilet you fucking mental midget.

The mental midgets will be the only survivors when a piece of razor wire whips through the room.

Name: Anonymous 2011-10-02 17:42

>>22
Okay, I really can't tell if you're trolling or if you're just plain fucking stupid.
Isn't that proof of your insufficiency as a human being?

Name: Anonymous 2011-10-02 17:43

Pythoners are this retarded.

Name: Anonymous 2011-10-02 23:30

LOLOL WHAT THE FUCK ARE YOU DOING PROG

Name: Anonymous 2011-10-03 3:04

I just took the biggest shit ever. It weighed in at 9 pounds 4 ounces... I named it Brianna.

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