# 2to3
{id: 2to3}

## Convertig from Python 2 to Python 3
{id: converting-from-2-to-3}
{i: 2to3}


from __future__ import ...




## division
{id: division}
{i: division}
![](examples/2to3/div2.py)
![](examples/2to3/div3.py)


## print in Python 2
{id: print2}
![](examples/2to3/print2.py)
![](examples/2to3/print2.out)


## print in Python 3
{id: print3}
{i: print}

print now requires print()

![](examples/2to3/print3.py)
![](examples/2to3/print3.out)


## input and raw_input
{id: raw-input}
{i: raw_input}
{i: input}


`raw_input()` was renamed to `input()`

In Python 2 `raw_input()` returned the raw string. input(), on the other hand ran eval(raw_input())
which meant it tried to execute the input string as a piece of Python code. This was dangerous and was not really used.


In Python 3 raw_input() is gone. input() behaves as the old raw_input() returning the raw string. If you would like to get the old,
and dangerous, behavior of input() you can call eval(input()).


## Code that works on both 2 and 3
{id: dual-life-code}
![](examples/2to3/2and3.py)


## Compare different types
{id: compare-different-types-2to3}

![](examples/2to3/compare.py)


## Octal numbers
{id: octal-numbers}

Octal numbers in 2.x was `011` in 3.x is: `0o11`


## 2to3 Resources
{id: python3porting-resources}

* [python3porting book](http://python3porting.com/)
* [wiki](https://wiki.python.org/moin/PortingPythonToPy3k)
* [Dive into Python 3](http://www.diveintopython3.net/porting-code-to-python-3-with-2to3.html)
* [The __future__ module](http://docs.python.org/library/__future__.html)
* [The third-party future module](http://python-future.org/)
* [The six module](http://pythonhosted.org/six/)
* [docs of 2to3](http://docs.python.org/library/2to3.html)

