# Classes? :Python

This topic is 4106 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
*What* lack of two-dimensional arrays?

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

##### Share on other sites
Hi
I think you should try Numpy.
Here is the doc.
BTW, I also found the lack of arrays disturbing, those lists are too general.

##### 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 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.

Looking into it, looks awsome.

##### Share on other sites
Quote:
 Original post by Splinter of ChaosHolding 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 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 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 on other sites
What do you want to store?

##### 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?

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 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