Sign in to follow this  
Splinter of Chaos

Classes? :Python

Recommended Posts

I'm looking for a good project to work on involving classes. I thought of an address maker, but that isn't really anything practical for practice. I'm looking for something to gain experience in many areas with a focus on class work and how to tie it to different things. I tried doing a text adventure, but found Python's lack of two dimensional arrays a difficult problem. So does any one know a good project?

Share this post


Link to post
Share on other sites
*What* lack of two-dimensional arrays?

(Seriously. A Python list can hold anything. Did you *try* holding lists?)

Share this post


Link to post
Share on other sites
Numpy is great, but what's wrong with something like:


def array2d(w,h,init_value=None):
return [[init_value]*w for i in range(0,h)]




What does it mean "lists are too general"? Usually we complain when something doesn't meet our requirements, not when it exceeds them.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
*What* lack of two-dimensional arrays?

(Seriously. A Python list can hold anything. Did you *try* holding lists?)


Holding lists? I no not wut meen. Sorry.


And about Numpy:
Looking into it, looks awsome.

Share this post


Link to post
Share on other sites
Quote:
Original post by Splinter of Chaos
Holding lists? I no not wut meen. Sorry.


He simply meant whether you tried using lists. If you put lists within a list as mikeman demonstrated, you have something similar to a 2D array.

Quote:
And about Numpy:
Looking into it, looks awsome.


You'll probably want to use its record arrays and the element type 'object'.

Share this post


Link to post
Share on other sites
Ah, now I see. Yes, I tried. The problem came from lack of experience and thus not knowing how arrays much work, that is withought creating my own array. And what I came up with was difficult to read.

Share this post


Link to post
Share on other sites
Mikeman, I've learnt programming in Python just a few months ago, and I have been using C++ for years. I couldn't yet get used to Pythons powerful constructs, so I missed the vectors, lists, deques etc., but your code showed me how to think in a Pythonic way.

Share this post


Link to post
Share on other sites
Before this thread becomes unused and thus worthless, I would like to jeer it back to the crux: A good exercise for working with and understanding classes, what is?

Is a text adventure a good starter?
Is it too advanced (or, is it a good starting ground for learning procedural progamming or isn't it)?
Are there other, simpler programms that use classes that are much better introductions?

Thanks in advance.

EDIT:
I know I said above that I'd like to get back to the main point, but can any one tell me what you have to do to make NumPy work? I tried put it in Python 2.5/lib/sit-packages and it didn't work when I imported Numpy, NumArray or a few other tries, and I even tried running the installer in its file. The NumPy website didn't seem to have suffician advice.

Anyone know what I should do?
(Wow I feel extra noobish right now :]

[Edited by - Splinter of Chaos on October 22, 2006 4:12:46 PM]

Share this post


Link to post
Share on other sites
I wouldn't bother with NumPy for now. Lists and dictionaries should be more than enough for a simple game.

I would guess that a text adventure would be a good first project. You could probably make a very simple one, and you'd have a nice variety of classes to play with (Rooms, Items, Events, NPCs, etc.).

- Mike

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this