Setting out to learn Python. Anyone wanna join?

Hi again everyone,

How's your work coming? I've gotten to the point on the game I'm making where I *need* some sort of GUI for me to make sure everything is working properly (stats are what they're supposed to be depending on what's going on, etc.). With everything just running through the terminal, I was having to input all these manual stat checks like:

print '------- %s\'s DEXTERITY IS: %s ---------' % (character.name, character.dex)

print '------- %s HAS %s BUFFS ------------' % (character.name, str(len(character.buff_list)))

They were all over the place. It was really getting out of hand.

So I'm just getting into learning how to display things outside of the terminal. So far it's going well. I've played around with both Tkinter (a plain old GUI for text fields, radio buttons, etc.) and pygame (which handles graphics rather than text-based input/output). In pygame I had some fun creating epilepsy-inducing screens just to see how crazy I could get it to go. Then I got a headache.

In going through a snow animation tutorial for pygame, I also managed on accident to create a pretty cool animation that basically made it look like the window was bleeding from tons of different spots. Basically, the snow was going staight down, and I misplaced the command that clears the screen every frame before the new positions of the graphical items were displayed.

Anyway, now I'm back on Tkinter messing around with that a little. I want a text-based game with graphics in a couple ancillary windows. I'm really looking forward to putting this together based on the mechanics of the game. I think it will also help me continue to program the game faster, since, again, I'll be able to have a display that shows me what's going on at all times, so I don't have to scroll up and down the terminal looking for silly print commands that show me all the numbers, etc., I want to know.

How's everyone else's stuff coming along?

I'm working my way through the last week of Coursera, but I haven't started the mini-project yet. So far it's all been working out smoothly every week, and I don't expect any major issues this time either

When that is done I'll go back and finish Codecademy, read through a bunch of links I saved earlier, and then probably start a roguelike with libtcod (found a tutorial on RogueBasin). Or maybe I'll also go look at pygame and/or Tkinter and make some other type of game.

I would have really liked to go on with Coursera and do the three-course Rice specialization, but I'll be away for half of the next course so it's a no-go. Hopefully I can join in the next session this autumn. Liquidmantis maybe you can let us know if it's any good!

il dottore wrote:

I'm working my way through the last week of Coursera, but I haven't started the mini-project yet. So far it's all been working out smoothly every week, and I don't expect any major issues this time either

When that is done I'll go back and finish Codecademy, read through a bunch of links I saved earlier, and then probably start a roguelike with libtcod (found a tutorial on RogueBasin). Or maybe I'll also go look at pygame and/or Tkinter and make some other type of game.

I would have really liked to go on with Coursera and do the three-course Rice specialization, but I'll be away for half of the next course so it's a no-go. Hopefully I can join in the next session this autumn. Liquidmantis maybe you can let us know if it's any good!

I actually dropped the intro to Python course that's I was doing on Coursera (that's the one you can only do through a certain period, right?). I had to drop something, and I didn't really have time to finish it, so I figured I'd stick to some other basic comp sci intros and then learn my Python stuff through other resources as I move forward. I would have liked to stick with Coursera's intro to Python, but I just didn't have the time.

Some basic CS intro is probably what I would need actually, at times it feels like I started at the wrong end, meaning the fun one
Which one(s) did you take? We were talking MITx 6.00.1x earlier in the thread, was that the one you took?

And that's a wrap. Now to wait for the results and next class. I'm annoyed because I'd have finished this with a 100% except I missed the deadline for the Week 1 quiz. I wish there were reminders.

You know what I'm annoyed at? Not getting explosions to work in RiceRocks! Stayed up late and couldn't figure it out. If I hadn't seen someone else's code I'd never have guessed the solution.
I wrote:

Spoiler:

if self.animated:
self.image_center[0] += self.image_size[0] * self.age

which apparently is not enough. I should have written:

Spoiler:

if self.animated:
self.image_center = [self.image_center[0] + self.image_size[0] * self.age, self.image_center[1]]

WHY?

Anyhow, a bit sad it's over and that I can't jump straight into the next course, but I sure won't miss clicking all those drop-down menus for grading.

Oh by the way, they provide a .ics file with all the deadlines, saved my bacon a few times in the first two weeks or so.

il dottore wrote:
if self.animated: self.image_center = [self.image_center[0] + self.image_size[0] * self.age, self.image_center[1]]

WHY?

Anyhow, a bit sad it's over and that I can't jump straight into the next course, but I sure won't miss clicking all those drop-down menus for grading.

Huh, that works in Python:

>>> foo = [5, 10] >>> foo[0] += foo[0] * 3 >>> foo [20, 10]

I did just that but I did put it in parentheses.

def update(self): # update age self.age += 1 if self.animated: self.image_center[0] += (self.image_size[0] * self.age)

However I repeated my above foo test in Codeskulptor and it worked. Here is my version. I realized I left an Explosion class I created to overload some of the Sprite stuff when I was using the explosion from the video. For some reason that explosion was killing the framerate and I have no idea why.

Yeah, the peer-evaluation format is annoying, radio selectors would be nicer. The continuing classes still use Codeskulptor but I guess that's the best solution for code that can't be machine graded.

I made it a slightly more general solution:

if self.animated: x_offset = self.image_size[0] * (self.age % self.anim_frames) else: x_offset = 0

and put anim_frames into the Image and Sprite classes. The actual draw command just added x_offset to the base X value.

edit: I also did a version with rocks that split, by adding in a scale value and a splitting boolean... scale started at 1, and on collision, if a sprite was splitting, and scale was less than 4, it would create two more sprites at the current scale * 2. Then the draw method and the collision routines divided by scale. So the first generation of rocks were full size (scale 1), the second generation was quarter size (half size in both directions, scale 2), the third generation was 1/16th (scale 4), and those rocks just disappeared when shot.

Problem was, it wasn't very much fun. I didn't come up with a good algorithm for the velocities of the smaller rocks... I wanted it to feel like Asteroids, but it really didn't, and it ended up just being tedious, trying to chase down all the small ones. So I ended up sticking with the basic version.

I'm going through Python the Hard Way and up to the point of creating my first text based adventure game.

interaction() gets the interaction.

def interaction(): global act act = None # resets the response print "What would you like to do?" act = raw_input ("> ") act = act.lower() if "quit" in act: dead("Goodbye.") # function dead() exits the game return act

Each room is it's own function that uses act to determine what happens next. The code below works, but seems pretty clunky.

Is there a way to streamline the if statement below?

if "look" in act: print "There is a large crystal chandelier here." elif "kitchen" in act: print "You enter the kitchen." kitchen() elif "hang" in act: print "You grab the chandelier with both arms and swing around like Tarzan." print "Whee!" elif "swing" in act: print "You grab the chandelier with both arms and swing around like Tarzan." print "Whee!" elif "chandelier" in act: print "You grab the chandelier with both arms and swing around like Tarzan." print "Whee!"

I tried to streamline it like what I typed below but it would not work. I just don't know enough to know why.

elif "hang" in act or "swing" in act or "chandelier" in act: print "You grab.."

I know you can have 'or' conditions in if statements, so I don't get it. Can someone explain or point me to a place I can learn it better?

I'm otherwise pretty proud that I've gone from zero programming knowledge to enough to make a working infocom-type text adventure.

It works for me in Python 2.7.

>>> act = 'hang from the chandelier' >>> if "look" in act: ... print "There is a large crystal chandelier here." ... elif "hang" in act or "swing" in act or "chandelier" in act: ... print "You grab.." ... else: ... print 'Nothing' ... You grab..

What version of Python are you using?

2.7.5

Tried it again and it works. No idea what I did wrong (or differently) before.

Thanks for your help.

edit: Wait. Found what I was asking about.

if "look" in act: print "You look around." elif "hang" in act or "swing" in act or "chandelier" in act": print "You grab the chandelier.." elif "crawl" in act: print "You crawl under the table." else: print "something else"

then when I run it, if I type 'crawl' I get back "You grab the chandelier.."

edit again:
OK, I'm an idiot. Missed a " mark and that caused the issue.

There are alternative ways to do this that lead to a more object-oriented design. Let me know if you are interested.

I'm going to hold off for now. I see objects and classes are coming in the next few lessons.

Fair enough. Have fun!

So, at Coursera's suggestion, I figured I'd take a peek at R, just to see what was up with it. There are two closely related "4-week" courses:

The Data Scientist’s Toolbox and
R Programming

I was able to do the entire "month-long" first course in maybe six hours, including all the quizzes and the 'final project', which is so simple it's laughable. It's basically getting you set up for the second course, which is where the actual meat is.

The second course has bent my brain somewhat. They sort of throw you in the deep end there. R is a weird language, with very strange data types and fairly bizarre syntax (it's not deliberately obfuscated, but things combine in weird ways), and they don't really give you concrete examples of solving actual problems in the lectures. But then, in Quiz 1, you actually have to solve real problems using a sample data set, and I definitely floundered for awhile. I knew what I needed to do, and roughly how the language did it, but I had a hell of a time figuring out the exact syntax I needed. I was eventually able to muddle through, and got all the points, but it took quite a bit of fiddling in RStudio to do it.

I am, however, seeing a little bit of the power of R. It appears that much of what you're doing is similar to list comprehensions in Python, where you extract data from a set using a test of some kind, and the language does the iteration for you. And it appears very highly tuned to doing matrix operations, which are awkward in Python; that base language, for instance, can't add two tuples, you have to add each part of the tuple yourself. In R, one of the fundamental data types is a vector, which is basically a one-dimensional array of values of the same type, all integer, say, or all character, or all Boolean. You can say things like (vector + 3), and it adds 3 to every element of the vector. If you add two vectors of the same size, it adds each element to the corresponding one in the other vector... if they're not the same size, but one is a multiple of the other, then it repeats the smaller vector over and over as it does the operation. (so a vector of 1,2,3,4 added to a vector of 2,3 will come back as 3,5,5,7.)

And it's got lots of stuff for gluing vectors together, and splitting them apart, and it has the ability to name parts of variables.... a matrix, for instance, is a two-dimensional array, and you can actually name the rows and columns, almost like a database, and then access them by name instead of number.

I've only just stuck my toe in the water, but it looks like a good tool, although you can feel its roots in the dark ages of computing. It's quite Unixy, with all the advantages and drawbacks that implies. The course is nice and short, and it looks like they make the whole thing available right away, so you can work through it quickly if you want to.

Both classes just started today, so hopping in anytime in the next few days should work out fine.... the first deadlines look to be the 8th.

So is there a dvd I can buy with all of the coursera python videos on it? I totally blew it and never logged in.

You should be able to get to the class still and download the videos.

Thank you for that! Whew, saved them all.

Certified with Distinction! Woot!

...

So now what?
I really have no plan or idea why I did this, other than it's fun. I can pretend I did it so I can script macros to use in Revit (the architecture CAD program we use), but that would be a complete lie. Though there is a cool parametric modelling plugin which explicitly uses Python to program complex geometries (it's called Dynamo in case anyone is interested).

Why are you guys doing this? Some of you seem to have quite a lot of programming experience already, are you hoping to open up new career paths this way?

Why are you guys doing this? Some of you seem to have quite a lot of programming experience already, are you hoping to open up new career paths this way?

I just wanted to use Python better, and thought that course focus would be a fun way to learn. I went ahead and signed up for the next two classes too, as I quite like most of the instructors.

It definitely seems to have helped... I've been working my way through some of the Project Euler stuff (up to question 39, though I skipped one), and I'm finding that I can organize my approach to problems much better. It's easier for me to think in terms of Python data structures now... the focused practice, as opposed to just dinking around on little projects, seems to have worn some new grooves in my brain.

Malor wrote:
Why are you guys doing this? Some of you seem to have quite a lot of programming experience already, are you hoping to open up new career paths this way?

I just wanted to use Python better, and thought that course focus would be a fun way to learn. I went ahead and signed up for the next two classes too, as I quite like most of the instructors.

This. All of it.

il dottore wrote:

Why are you guys doing this? Some of you seem to have quite a lot of programming experience already, are you hoping to open up new career paths this way?

The same reason I have a toolbox full of tools and a workbench in the garage. I like making stuff. I'd like to see what I can do at a basic level, and perhaps build from there.

This. All of it.

I am about 8-10 videos in and I agree with this as well. I have some programming/scripting experience but didn't know a lick about python so this looked like it fit the bill.

They spend a bit of time early on explaining codeskulptor and promoting it. But I actually think codeskulptor is pretty darn cool so it isn't a big deal. And the instructors are good enough that I don't feel the need to skip over a lot of the basic stuff I already know.

I was more wondering what is your goal with this, why you want to learn Python. Is it something you use in your day job? Or like DonD you just like to tinker? Or maybe like KingOctavious you're thinking about making your own games (I am)?

No need to sell me on the course, I completed it already and loved it! Great instructors and fun projects.

you're thinking about making your own games (I am)?

BINGO. Or at least flesh out some time wasters I have been mulling over. Also, I have been thinking of little apps to write and highly interactive GUI templates.

I have a thing I have made in Multimedia Fusion that I like to call spaciablo. It is very basic asteroids with diablo mouse movement and screen scrolling. It is a testbed for things like dropped turrets which is a surprisingly cool feature for asteroids.

I am hoping to grow it more into a fuller fledged Diablo clone with tile sets and cloud nebulae or giant asteroids (dungeons). Boss monsters would be capital ships with multiple hardpoints and weapons like any of your typical side scrolling shooters (but in a top down perspective)

I know SPAZ (space pirates and zombies) exists but I had the idea first and made that prototype in MMF round a decade ago. Also, my idea is slower paced and more strategic. But MMF is way too much of a performance hog so development stalled. And I'd also like to migrate to 3d graphics for it.

I was more wondering what is your goal with this, why you want to learn Python.

Well, in my case, I already know Python to some degree, but I wanted to get better with it. I do quite a lot of scripting on Unix machines, and while I'm proficient with bash, there are times when its complex syntax and simple data structures become a real hindrance. It's a complete language, and you can do almost anything with it, but it can easily turn awkward, or even dangerous, as soon as you go past simple automation of things you'd normally type.

Python is a nice step up from there, and getting better at it gives me a great tool for more advanced projects. I think of it as a tool without many sharp edges, unlike bash, which has razorlike dangly bits everywhere.

As far as why to take it in a class.... I have two reasons there. First, I'd never tried an online class before, and thought it would be interesting. (it was!) Second, I just don't learn as fast as I used to, so the focused structure helps me hammer the stuff into my head that would once have been nearly instant. I need more exposure to different thought processes than I used to; without guidance, I end up rehashing what I already know, repeatedly, rather than coming up with as many genuine breakthroughs.

The object-oriented stuff in this class is a good example... I still don't really think that way, but it's a lot easier now than it was.

You guys have gotten me interested in trying the course out on coursera. I've taught myself a little Python a while back but really need a structured course to keep me going. What did you guys think of the Coursera experience? How much does the class teach you of Python? What are you going to do after the course is finished to keep learning more? Are there more advanced python classes offered?

Well, I thought it worked very well. I don't think this class will run again for about four more months, though. It's part of a three-course cycle, each of which is 8 weeks long.

As far as what it covers, it goes over the major data types, and gives you a lot of practice with lists, some with sets, and I think maybe one exercise uses dicts, briefly. It gives you solid basics in event-driven programming, and some exposure to object-oriented programming, although that part is mostly fleshing out designs that they've already done, rather than doing your own. (which is probably better, to help get the patterns into your head.)

It looks like the later classes get much more advanced, but as I haven't taken them yet, I don't know for sure.

This first class really covers a lot of ground in eight weeks. If you already know programming, it's fairly easy, but if you're a near-total noob, you'll definitely need to pay close attention. You'll probably want to work through the optional exercises they offer.

Be aware that they use the quizzes to teach; they will ask you questions that are implications of what they covered in lecture, and you have to answer them yourself. And they get kind of tricky, sometimes. You get 5 tries on each quiz, so this isn't particularly onerous, but you can expect to miss some questions, and need to retake it if you want a better score. The quizzes are not mean, but they are trying to trip you up and make you think, so be aware of that.

I ended up dropping out of those R courses. The first was ridiculously easy, and the second went almost immediately into using a ton of stuff that they never really defined. The lectures were very poor, going on at great length about abstract ideas with no application to what they're asking you to do, and then the programming assignments have a bunch of unrelated, concrete requirements, like determining correlations... and they never even vaguely described the correlation function, or what it does. Even mentioning the function seems to have been a total afterthought, an 'oh, yeah, you might need this, go look it up in help.'

In other words, they wasted like an hour telling me about lexical versus dynamic scoping, and didn't spend even one minute telling me how the correlation function works, yet I'm supposed to be using it to read through literally hundreds of data files, producing correct answers. In the second week.

If you don't already know statistics, I don't think it's a good course at all.