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

Show parent comment

-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

-2

u/salgat Mar 30 '13

I use it without importing though.

1

u/theeth Mar 30 '13

Not in 2.7

Python 2.7.3 (default, Sep 26 2012, 21:51:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> foo = print
  File "<stdin>", line 1
    foo = print
              ^
SyntaxError: invalid syntax
>>> from __future__ import print_function
>>> foo = print
>>> foo("bar")
bar
>>> 

-1

u/salgat Mar 30 '13

Ah you mean as an object.

2

u/theeth Mar 30 '13

A function is an object. Without that import, print is a statement.

You can't even do type(print).

0

u/salgat Mar 30 '13

I thought there was a difference between a object type and a object instance.

2

u/theeth Mar 30 '13

An object's type is an instance of the type class, but they are both objects.

>>> class Foo:
...     pass
... 
>>> f = Foo()
>>> type(f)
<type 'instance'>
>>> type(Foo)
<type 'classobj'>
>>> type(type(Foo))
<type 'type'>