Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 211 212 [213] 214 215 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 886510 times)

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3180 on: October 22, 2012, 05:05:05 pm »

That gave me this:
Quote
TypeError: Can't convert 'bool' object to str implicitly

Which is kinda odd, as there is no boolean >.>

edit: the second one worked. Which I find odd. Why should it matter?
edit: Nevermind, I am an idiot. s.split() doesn't actually change the variable. I ALWAYS forget this...
« Last Edit: October 22, 2012, 05:09:05 pm by Dutchling »
Logged

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3181 on: October 22, 2012, 05:08:15 pm »

As Siquo said, pretty sure split just /returns/ the split string - it's not an in place operation.

Try:
Code: [Select]
s = 'aa>bb>cc'

print(s.split('>'))

Does that work for you?
Logged

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3182 on: October 22, 2012, 05:10:25 pm »

Yeah that worked. You ninja'ed my edit. I should probably write that down sometime, as I keep forgetting that a lot of stuff just return something instead of actually changing a variable.
Logged

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3183 on: October 22, 2012, 05:13:03 pm »

I'm pretty sure you don't even WANT it to be an in-place operation here, I'd imagine. :P

Remember that Python passes by reference, so you would have permanently changed 's' to an array.
Logged

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3184 on: October 22, 2012, 07:25:49 pm »

Argh. In Code::Blocks, I have a static library project linked to an executable project. Whenever I change files in the static library project and recompile, the .o file for the executable project isn't updated. So nothing changes when I compile, I have to choose to rebuild everything. Annoying. Luckily, Code::Blocks allows me to specify a pre build command, so I just made it do "cmd /c del /q /s obj".
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3185 on: October 22, 2012, 10:03:50 pm »

Crash course on prototype based OOP in js.

Basic demonstration of prototype features.

Part 1:
Spoiler: the prototype (click to show/hide)
« Last Edit: October 23, 2012, 08:29:04 pm by Nadaka »
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3186 on: October 23, 2012, 01:18:00 am »

Yeah that worked. You ninja'ed my edit. I should probably write that down sometime, as I keep forgetting that a lot of stuff just return something instead of actually changing a variable.

In Java and Python, there are no mutator methods for (String/str) objects. Every method that seems like it would change the contents of the object will instead return a new object without changing the original object.

Spoiler: Long Explanation (click to show/hide)

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3187 on: October 23, 2012, 07:30:33 am »

Thanks, Nadaka! That was pretty thorough - I think I understand how it works now, which means I'll feel comfortable using it.

I'm not quite sure to the extent I /will/ use it, mind you. :P Probably be limited to going back at the end and doing an efficiency run once the shape of everything is in place, since it's basically just shifting out the methods that only ever get defined once and for inheritance stuff which I might not need for my current project.

Thanks though, good explanation.
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3188 on: October 23, 2012, 07:45:41 am »

there is slightly more to it,  there are ways to create private members/methods by declaring them  inside the constructor, and a few other things but that was the basics for using  the prototype itself though i didnt get around to multiple inheritance.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3189 on: October 23, 2012, 05:35:21 pm »

Is there a way in Python to go through each key : value pair in a dictionary? I can't do it the way I do it with lists / strings because dict_var[x:y] gives an error. I know why it doesn't work that way, I just don't know any other way to do it.
Logged

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3190 on: October 23, 2012, 05:43:22 pm »

dict.items() turns it into a list of 2-element lists.  Or you can get an iterator with dict.iteritems()
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3191 on: October 23, 2012, 05:57:32 pm »

Code: [Select]
for x in dict.keys():
   #do whatever using dict[x] to reference each item in the dict individually
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3192 on: October 23, 2012, 06:33:17 pm »

Thank you both!
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3193 on: October 23, 2012, 08:29:43 pm »

...

I updated that, made one mistake that needed fixing, and I added a bit more stuff.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3194 on: October 23, 2012, 08:43:38 pm »

Code: [Select]
for x in dict.keys():
   #do whatever using dict[x] to reference each item in the dict individually
IIRC, in newer versions of Python 3 and 2.X, you don't need to call keys().
Logged
Pages: 1 ... 211 212 [213] 214 215 ... 796