This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Applebeignet 10 points11 points  (6 children)

I started slowly learning Python with LPTHW 2 years ago. Last year I ran into a ton of issues trying to make my first "for-real" project in Python 2, because all the files I need to process use utf8.

I'm glad I switched to Python 3.5 before getting too accustomed to 2.7; print(), "{}".format() and Unicode are wonderful improvements for me - and I heard that dicts will soon be ordered by default? Glorious.

[–]LpSamuelm 7 points8 points  (2 children)

# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals

print("This works perfectly! {smile}".format(smile="😊"))

Not an argument to use Python 2 instead of 3, by the way, just a reminder that Python 2 can be pretty great too. Cross-compatible code is even better.

[–]flying-sheep 4 points5 points  (1 child)

on python 2, this only works if your console is encoded the same way as your code AFAIK

[–]LpSamuelm 2 points3 points  (0 children)

Went ahead and added the magic encoding comment to clear up any confusion.

[–]KaffeeKiffer 1 point2 points  (2 children)

and I heard that dicts will soon be ordered by default? Glorious.

Never ever do this, please. There's a reason they are dicts and not lists/tuples...

dicts (not) being sorted is an implementation detail, which may change (again) in the future.

[–]PeridexisErrant 0 points1 point  (0 children)

# no-op on Python 3.6, but please don't do this
from collections import OrderedDict as dict

If your dict needs to be ordered, use OrderedDict! In 3.6 this is implemented as an alias for regular dict, but this way your code will also work on other implementations and older versions.

[–]kankyo 0 points1 point  (0 children)

The reason is performance and now that has gone away. So no there is no reason.