Setting out to learn Python. Anyone wanna join?

Pages

I've begun learning Python, and it occurred to me that it would be helpful to do it along with others who are also interested in learning. This will be my first programming language.

I've actually gotten a good way through Learn Python the Hard Way, but I recently discovered Codeacademy, and it's more my style, so I may switch primarily to CA.

Anyone care to start learning it along with me?

I'm in the middle of a learning-Python journey. So far my projects have been using pygame to make weird little math demos and toys, and I've been working through the problems at projecteuler.net. Level 2, wooo!

Today I took another shot at pyopengl, but I'm finding setting up an environment that's actually happy to dig into the opengl part really frustrating:
To install pyopengl, you need pip.
To install pip you need setuptools.
To install setuptools you need ezsetup.
Do all that and you still need other dependencies, one of which refuses to install.

WTF, people? This is a joke or a sociological experiment, right? I accept that there's some mental overhead necessary to tackle a new aspect of programming, but damn this seems purposefully, needlessly obtuse. Up to this point I've been using Portable Python, which installs with a lot of useful modules ready to go, so I've been avoiding this setup headaches. (I'm sure the master programmers are chuckling at my amateur gripes! :wink:)

I'm really interested in hearing about the neato things you learn how to do. The Joys of Programming thread is fun to read, but it's mostly Goodjers complaining about the pains of coding cooperatively within a corporate structure, which sounds like a special pit of hell.

I'm in, thanks for the heads up about codeacademy; seems like a great little site so far.

I'm not a developer, but I've just this week started trying to learn Python as well.

So far I've started down the path of trying to refactor some perl scripts I've written for work, and surprisingly have had pretty good success so far. I'll try running through some of the codeacademy stuff, too.

I've been doing Learn Python the Hard Way for a bit, but I've been having some trouble finding the time with university and homework taking priority. And when I'm done with that I just want to lie face down on the couch.

I'm gonna give Codeacademy a shot, though, and maybe try to set aside a few hours every week. : )

Danjo Olivaw wrote:

To install pyopengl, you need pip.
To install pip you need setuptools.
To install setuptools you need ezsetup.
Do all that and you still need other dependencies, one of which refuses to install.

Haha, wow. Yeah, that's one of the things I really like about Codeacademy. Everything is contained in the browser--the code and the output. I got VMWare installed and put Ubuntu on it to get a slightly more authentic programming experience (I'm new to Linux as well), but it's just so damned convenient to pull up Codeacademy, and everything is right there and works very smoothly.

As for the "neato" things, while I'm learning, I'm also working on a game that's very basic but also, I think, reasonably fun. Basically it's going to be a one-on-one multiplayer text RPG, where you choose a character, equip him/her with a weapon, and fight an opponent. Of course my biggest problem so far is syntax. But one of the things that I quickly discovered was that knowing the programming code has really only been about 50% of what it takes to make a game--or at least a game like this. The rest of it is stuff you don't so much have to learn as simply work out in your head: how do the formulas for damage/dodge/crit/etc. work while taking into account stats like character strength, weapon strength, armor, etc. This has been fun to me because it's not just about knowing the code--it's equally about problem solving. May sound obvious, but I had never really considered that before I actually got started working on a project that I wanted to do for its own sake.

I'll keep everyone posted on my progress and issues I encounter here. You guys should do the same.

FeralMonkey wrote:

I'm not a developer, but I've just this week started trying to learn Python as well.

So far I've started down the path of trying to refactor some perl scripts I've written for work, and surprisingly have had pretty good success so far. I'll try running through some of the codeacademy stuff, too.

Same here. The closest thing I've done to development is HTML, which isn't really programming, though I have also recently started trying to learn PHP. That's why I started this thread--most of the other ones I've see on GWJ, like Danjo said, are for people who already have programming experience.

Eva Earlong wrote:

I've been doing Learn Python the Hard Way for a bit, but I've been having some trouble finding the time with university and homework taking priority. And when I'm done with that I just want to lie face down on the couch. f

I'm gonna give Codeacademy a shot, though, and maybe try to set aside a few hours every week. : )

I hear you 100%. After waking up, getting some exercise in, going to work for 8 hours, coming home, helping fix dinner, then hanging out with the wife and daughter for a couple hours, I usually have VERY little energy left. Usually I just want to play some games or read. I try to make it a habit to at least do 30 minutes of learning and/or actual programming just so I'm continually making some progress, even if it's not much. And then not even that always happens.

EDIT: I'll add that I think you'll like Codeacademy. One of the things that I struggled with on Learn Python the Hard Way is how often he goes, "Now go Google this and learn about it on your own." I can understand his reason for doing so, but with all I have going on on a daily basis, I reeeaaaally struggle to go off and do my own research on things like that.

Gem of the day: Python Decorators in 12 Steps

Triumph of the day: I got something in pyglet to work! Woo!

Please be using virtualenvs, for all the wit in Odin's one eye please use virtualenv and virtualenvwrapper.

Don't use python without virtualenv, got it. To install virtualenv, use pip. To install pip, use python. Kill all humans.

I use VMware. Danjo, maybe give that a shot. I found it pretty easy to install.

How's everyone's progress coming along? I've hit a point right now where I need to map some stuff out on paper before I start getting into the meat of my game. Namely, I'm trying to work out exactly how the object aspects of it need to work. The two main objects in play at this point are objects of Character class and of Weapon Class.

I could have it where the player sort of takes control of one Character and of one Weapon, and those two things work together. What I think will be better, though, especially if I want to alter things at some point so that players control parties, is that instead of the player simply working with a character and a weapon, the characters can have weapons assigned specifically to them.

So now I need to figure how to let an object of one class sort of own an object of an entirely different class.

I'm in the middle of the Coursera Python course.

I'm coding Pong! The final assignment is an asteroids clone! It's totally fun!

Maq wrote:

I'm in the middle of the Coursera Python course.

I'm coding Pong! The final assignment is an asteroids clone! It's totally fun!

Wow, that's actually pretty awesome! About how long do you think Pong is going to take?

I decided to take a look at the Codeacademy Python course. I've never used Python, but I have a degree in computer science -- in other words, I know enough to be dangerous. I just finished the PygLatin (part 2) example, which left me with some hanging questions and observations which may or may not be answered later on. If any experienced Python programmer wants to jump in, I'm all ears.

  • "always use four spaces". CodeAcademy, you are not the boss of me. What if I want to use 3? or 5? or a tab?
  • This is not the version of Pig Latin I was taught as a kid, where you removed all the consonants at the beginning of the word, not just the first consonant. They must not want to introduce loops quite yet.
  • There has got to be a better way to check if the first letter of a word falls within a subset of other letters than a long string of tests. I should find a function reference -- the only string operations I know are the few they've dribbled out to me. Does Python have sets and set operations built in? What about dictionaries or enumerated types?
  • I can already see that I am likely to keep screwing up function calls vs. dot notation until I get a lot more information stored in my head. Right now I don't have a model in my head that tells me when to use which.
  • are all these variables global in scope? That, alongside with not declaring variable types, is making me twitchy (but not to the extent where I've started adding type warts to my variables)
  • Does common Python practice in variable names use underscores in preference to CamelCase? What's the most widely accepted house rule?
  • We haven't talked memory management at all (no surprise in an intro-to-programming course, since it can be tricky). What will I eventually need to know about heap management or garbage collector speed?

Oh, and the introduction to functions... having one branch of the function return False, and the other branch return some_number ? Bleargh. Why would you DO that?

Ahem.

1.) Because standards are nice when reading code. Readability always.
2.) Could be done without a loop structure, but I'm assuming they are baby gating out more of the functional stuff
3.) There for sure is. Python has sets and dicts (which are used as enums when needed). Normally I would use "if var in collection_of_things" which if the collection is a dict or set (with the corresponding __hash__ method) should be snappy.
4.) I personally avoid dot notation, but due to the polyglot nature of python this is a personal choice.
5.) Namespacing in python http://bytebaker.com/2008/07/30/python-namespaces/
6.) Underscores.
7.) I would doubt you would need to learn about that.

addendum: Truthy/Falsey stuff (like that func return being used I assume) can be weird. Just flow with it and remember that everything is just a thing with a name attached.

Some successes. Lots of banging my head against a wall. I think I'm about to give up on doing anything python-related at work, at least for now, because I need to be in an environment that I control completely, instead of hamstrung by outdated installations and missing packages.

I also learned that one of the authors of the Docstring Conventions (PEP-257) is David Goodger.

Katy wrote:
  • This is not the version of Pig Latin I was taught as a kid, where you removed all the consonants at the beginning of the word, not just the first consonant. They must not want to introduce loops quite yet.

Probably not, and they probably want you to do it a certain way. Depends how fancy you want to get.

Using "in":

s[0] in "aeiou"

Using regular expressions:

import re def pig_latin(word): reg = r'^([aeiou]+)(.*)$' match = re.match(reg, word) if match: matches = match.groups() return "%s-%say" % (matches[::-1]) return word
"always use four spaces". CodeAcademy, you are not the boss of me. What if I want to use 3? or 5? or a tab?

I've always been fond of tabs, but the size of a tab is not defined. Every editor handles it differently. So, in any file that gets touched by more than one person, it's really, really common to end up with a mix of spaces and tabs, and the more people are touching it, the worse it gets. So it's typically better to always use spaces, since spaces are defined things, and always come out the same, no matter what. Most editors will let you redefine the tab key as a certain number of spaces.

Why four? Well, as far as I can tell, that comes from the Linux kernel coders, and has sort of spread by osmosis into the larger open source community. It doesn't have to be four at all, but when everyone's doing that, it improves readability a little, and it also means that the macros and/or redefinitions of 'tab = 4 spaces' will work on any file to that standard.

There's nothing special, in other words, about 4, except the network effect. If you plan to work with other people, it's nice. If you're working alone, it doesn't matter in the least.

I'll skip numerous questions that I'm not really qualified to answer, down to:

Does common Python practice in variable names use underscores in preference to CamelCase? What's the most widely accepted house rule?

Well, I don't know what's common, but they did a study not long ago that showed that programmers can read variable names with underscores faster, and they make fewer mistakes than with CamelCase. AFAIK, it's objectively better to do it that way. Whether or not the Python community does so, I have no idea, as I just mostly write scripts with it, not Real Programs.

We haven't talked memory management at all (no surprise in an intro-to-programming course, since it can be tricky). What will I eventually need to know about heap management or garbage collector speed?

Well, I suspect that for any program where you'd be worried about GC speed, you probably don't want Python in the first place. It's such a terribly slow language that if you're that performance sensitive, you probably want to start out in one that runs faster, like Java, C#, or even C. Python is a reasonably fast language in the interpreted space, but it's about an order of magnitude slower than the JIT languages, and those, in turn, are usually about half as fast as C.

Oh, if you use vim, this is the relevant section of my .vimrc:

set tabstop=4 set shiftwidth=4 set softtabstop=4 set expandtab
Malor wrote:
"always use four spaces". CodeAcademy, you are not the boss of me. What if I want to use 3? or 5? or a tab?

I've always been fond of tabs, but the size of a tab is not defined. Every editor handles it differently. So, in any file that gets touched by more than one person, it's really, really common to end up with a mix of spaces and tabs, and the more people are touching it, the worse it gets. So it's typically better to always use spaces, since spaces are defined things, and always come out the same, no matter what. Most editors will let you redefine the tab key as a certain number of spaces.

I forget how difficult it is to convey tone of voice in plain text. I tried to highlight "tab" with sarcastic italics, but it was too subtle. (And the explanation is worth revisiting, anyhow.)

Malor wrote:

Well, I don't know what's common, but they did a study not long ago that showed that programmers can read variable names with underscores faster, and they make fewer mistakes than with CamelCase. AFAIK, it's objectively better to do it that way.

I'd be interested to see that study. It's been a long time since I was actively keeping my eye on current best practices.

It's such a terribly slow language that if you're that performance sensitive, you probably want to start out in one that runs faster.

Memory management vs. garbage collection is one of those issues I have heightened awareness of -- back when I was working in the industry, I was working alongside a team doing real-time motion control, so both speed of execution and memory footprint came up regularly.

This week I had to rip apart a Bluetooth steamer and plotter to remake it. This evening I finally got a blank plot up on the screen. Next step, put some lines in it.

I'm pretty slow:( using gtk and matplotlib for the plotting parts.

As far as speed/performance goes, I can tell you from recent experience that the algorithm you choose is almost infinitely more important than the language. Python is more than fast enough for almost anything you want to do. If you wanted to squeeze extra performance out of a web server or router, it'd be your bottleneck. Same if you wanted to code a AAA game. If you're just learning, it's perfect.

I forget how difficult it is to convey tone of voice in plain text. I tried to highlight "tab" with sarcastic italics, but it was too subtle.

Sorry, I took you semi-seriously because this was an issue in my head until the last year or two. I *like* tabs. Always have, always will. But I've been bludgeoned into the spaces religion, so of course I have to evangelize the new faith.

And as far as 'four' goes, I think that's just the network effect.. it's four because it's four, not because that's intrinsically better.

I'd be interested to see that study.

It was linked on Reddit about a year ago, probably. You could try searching the /r/programming subreddit for CamelCase and see what you find. I'm much too lazy to do it myself.

Python is more than fast enough for almost anything you want to do.

This is very true, but if you're worried about garbage collection, then it may not be a good choice: you're probably going to want a language with tighter controls and less flexibility. It sounds like Katy is more sensitized by old reflex than actually worried, though.

For just, you know, making a tool, almost everything on a computer is I/O bound anyway, so a "fast" language won't run any faster than a "slow" one. We're mostly waiting on the hard disk, so a fast language just, well, waits faster.

My big caveat with Python remains forever this: variant data types are hard to code for safely. Python is maybe the best prototyping language ever, and it's awesome for scripts for system administration, but making a Python program safe to expose to the general public takes a mountain of work and unit testing. I *really* prefer strong static typing, running on the assumption that I'm a complete idiot, and need the help. I think I would want that even if I programmed professionally, because, while I would undoubtedly become much more skilled, I would also have many more opportunities to be stupid.

KingOctavious wrote:
Maq wrote:

I'm in the middle of the Coursera Python course.

I'm coding Pong! The final assignment is an asteroids clone! It's totally fun!

Wow, that's actually pretty awesome! About how long do you think Pong is going to take?

Knocked it over in a couple of hours, then added a bunch of extra-credit stuff. It's actually fun to play.

Katy wrote:

[*] I can already see that I am likely to keep screwing up function calls vs. dot notation until I get a lot more information stored in my head. Right now I don't have a model in my head that tells me when to use which.

I've been out of internet for a few days, so I'm a little behind, but that's one of the things I'm struggling with this point right now as well. I know there's logic for when to use which, but I don't see what that logic is right now. At this point, I'm pretty much guessing at it every time. But I bet it's going to be one of those things that eventually makes legit logical sense after you do over and over.

KingOctavious wrote:
Katy wrote:

[*] I can already see that I am likely to keep screwing up function calls vs. dot notation until I get a lot more information stored in my head. Right now I don't have a model in my head that tells me when to use which.

I've been out of internet for a few days, so I'm a little behind, but that's one of the things I'm struggling with this point right now as well. I know there's logic for when to use which, but I don't see what that logic is right now. At this point, I'm pretty much guessing at it every time. But I bet it's going to be one of those things that eventually makes legit logical sense after you do over and over.

Not sure I understand what you mean by"function calls vs. dot notation". Is it when to use object orientation vs when to use functions? If so, use what seems right, Python supports both imperative and object oriented styles equally well. Once you get something working, you can change things around.

It's mostly getting to know my way around the library and the available types. I understand why the codeacademy class introduces methods and function calls at the same time, but because it's set up to introduce things on a just-in-time basis, it's a little harder for me to build the appropriate mental model of the library.

The early lessons go through the basic data types, and introduce some methods of the string class as well as some general-purpose functions that take a string as input. (e.g. string.upper() and len(string) ). I keep mixing them up, and trying to call string.len() or upper(string). At some point I need to spend a little more time looking over the documentation and getting a bit more of it inside my head.

Yeah, I always have to look that stuff up, too. If there's an underlying theme for when things are methods and when they're built-in language functions, I haven't sussed it out. I don't do a lot of Python, so it never fully sticks, and I'm constantly referring to the docs.

tboon wrote:
KingOctavious wrote:
Katy wrote:

[*] I can already see that I am likely to keep screwing up function calls vs. dot notation until I get a lot more information stored in my head. Right now I don't have a model in my head that tells me when to use which.

I've been out of internet for a few days, so I'm a little behind, but that's one of the things I'm struggling with this point right now as well. I know there's logic for when to use which, but I don't see what that logic is right now. At this point, I'm pretty much guessing at it every time. But I bet it's going to be one of those things that eventually makes legit logical sense after you do over and over.

Not sure I understand what you mean by"function calls vs. dot notation". Is it when to use object orientation vs when to use functions? If so, use what seems right, Python supports both imperative and object oriented styles equally well. Once you get something working, you can change things around.

I may have worded it wrong. What I mean, is I'm having trouble working out in my head when something should be variable.do_something as opposed to do_something(variable). Does that make sense?

Though I think I'm slowly starting to get the hang of it.

Ping, I'm in. When last I looked at Code Academy, it was JavaScript-only. I endorse the Coursera course, and enjoyed my version of Asteroids. That course has a nicely constructed browser-based IDE, including graphics and reference. I sense it's pretty popular so it should come around again in a few months.

Pages