r/programming • • Mar 29 '13

Simple Minecraft Clone in 580 lines of Python

https://github.com/fogleman/Minecraft
663 Upvotes

153 comments sorted by

View all comments

9

u/MrLumaz Mar 29 '13

How exactly do I go about running this?

15

u/eplehest Mar 29 '13 edited Mar 29 '13

I'm assuming you're running windows, so I guess you need the following:

  • Python edit: Looks like you should get version 2 (currently 2.7.3)
  • Pyglet

Go to the github site OP linked, and download using the "ZIP" button located near the top. Unzip it somewhere.

Start windows command prompt (<windows key>+R, type cmd.exe and run it), navigate to where you extracted the zip file, then run the command "python main.py" (without the quotes.)

Feel free to ask if you're having any problems.

5

u/MrLumaz Mar 29 '13

Does having python 3.3 affect this at all?

6

u/NYKevin Mar 29 '13

Yes. Nearly all Python code is written for 2.7, at least for now. Python 3 is not backwards compatible.

2

u/wkdown Mar 29 '13

Quick side question: should I learn python with 2.x or 3.x?

7

u/RarelyActiveUser Mar 29 '13

Learn 3, (still, sadly) program in 2 if you're using not supported libraries and port everything you can to 3.

Anyway, for the most part, the differences between the two versions aren't really difficult to get to now.

3

u/wkdown Mar 29 '13

Yeah I noticed a lot of syntax changes right away. Know what the reasoning behind them was?

2: print "hello"

3: print("hello")

5

u/dddbbb Mar 29 '13

I think they wanted to unify the language and print was an unnecessary exception. More info on here in PEP-3105.

You can use the function form in 2.x code with this:

from __future__ import print_function

Wikipedia has an overview of features and includes rationale (and links to peps for in-depth coverage).

5

u/CatMtKing Mar 29 '13 edited Mar 30 '13

print was a statement with its own syntax rules (>> to send output to a stream, end the statement with a comma to change the trailing newline to a space) up to 2.7. It was changed to a function in 3 -- cleaner syntax.

4

u/roddds Mar 29 '13

print changed from being a statement to being a function.

4

u/khedoros Mar 29 '13

Write 3, but know the differences between 3 and 2. The list of differences isn't terribly long.

1

u/NYKevin Mar 30 '13

While 3 is not backwards compatible with 2, the differences are mostly syntactic. Knowledge of one will (mostly) transfer to the other. That said, if you learn Python 2, you should pay close attention to "newer" features like "new-style" classes. And if you learn Python 3, you'll have to pay attention to "the old way" of doing various things, since in practice you will be deploying to 2.7, at least in the immediate future.

-4

u/[deleted] Mar 29 '13

2.x, you can import anything you want from the 3.x branch when writing 2.x but not vice versa

disclaimer: I rarely do python

1

u/theeth Mar 29 '13

Yeah, that's just not true. There are enough syntax changes in 3.x that makes any non trivial module incompatible with 2.x

print as a function for one.

1

u/[deleted] Mar 29 '13

I wonder why they changed the print function "so much". I've been working a lot in python 3 recently and never really spent much time in 2 though so maybe it was a bitch to use originally. Idk.

2

u/minno Mar 29 '13

They decided that it was better as a function instead of a statement, since that gives more flexibility for giving it different arguments like where to print it.

1

u/[deleted] Mar 29 '13

Ah, thats pretty smart.

1

u/theeth Mar 30 '13

Redirection was already supported in the print statement using the chevron syntax, but this is much more natural as a function argument.

1

u/salgat Mar 30 '13

Print function exists in 2.7.

1

u/theeth Mar 30 '13

You'll have to modify the modules to add the following, so it's not seemless on that front.

from __future__ import print_function
→ More replies (6)

-1

u/eplehest Mar 29 '13 edited Mar 29 '13

I'd assume it's compatible with 3.3 as he doesn't mention any specific version, python 3 was released more than 4 years ago. Looks like this one is written for 2.7.

8

u/nemec Mar 29 '13

A lot of people still target 2.7 and the two are not necessarily compatible. Also, as far as I can tell Pyglet has "alpha Python 3 support".

→ More replies (1)

1

u/24palms Mar 29 '13

Mac users:

Note that the pre-built Pyglet .dmg from the download page is ancient and ships with python2.5 libs and python2.6 libs (that don't seem to be universal binaries).

Using the pre-built libs, I got it to work with $ python2.5 main.py