# PS1 for Python3

DevFeed: [PS1 for Python3](<https://devfeed.tech/articles/ps1-for-python3-29447.md>)

Original publisher: [Read original article](<http://akaptur.github.com/blog/2014/10/23/ps1-for-python3/>)

Published: 2014-10-23T21:38:00Z

Content type: tutorial

Language: en

Sources: [Allison Kaptur](<https://devfeed.tech/sources/allison-kaptur.md>)

Topics: [Python](<https://devfeed.tech/topics/python.md>), [version](<https://devfeed.tech/topics/version.md>), [syntax](<https://devfeed.tech/topics/syntax.md>), [function](<https://devfeed.tech/topics/function.md>), [export](<https://devfeed.tech/topics/export.md>), [file](<https://devfeed.tech/topics/file.md>), [import](<https://devfeed.tech/topics/import.md>)

Tags: [export](<https://devfeed.tech/tags/export.md>), [file](<https://devfeed.tech/tags/file.md>), [function](<https://devfeed.tech/tags/function.md>), [import](<https://devfeed.tech/tags/import.md>), [python](<https://devfeed.tech/tags/python.md>), [syntax](<https://devfeed.tech/tags/syntax.md>), [version](<https://devfeed.tech/tags/version.md>)

## AI overview

A Python developer explains how to customize the interactive prompt with PYTHONSTARTUP so it clearly indicates whether a session is running Python 2 or Python 3. The article also shows how to use print_function from __future__ to adopt Python 3-style print syntax in Python 2.

## Source excerpt

I spend a lot of time flipping back and forth between Python 2.x and 3.x: I use different versions for different projects, talk to people about different versions, explore differences between the two, and paste the output of REPL sessions into chat windows. I also like to keep long-running REPL sessions. These two activities in combination became quite confusing, and I'd often forget which version I was using. 1 2 3 4 5 6 >>> print some_var File "<stdin>", line 1 print some_var ^ SyntaxError: invalid syntax >>> # *swears* After the hundredth time I made this mistake, I decided to modify my prompt to make it always obvious which version was which, even in long-running REPL sessions. You can do this by creating a file to be run when Python starts up. Add this line to your .bashrc: 1 export PYTHONSTARTUP=~/mystartupscript.py Then in mystartupscript.py: mystartupscript.py 1 2 3 4 import sys if sys.version_info.major == 3: sys.ps1 = "PY3 >>> " sys.ps2 = "PY3 ... " This makes it obvious when you're about to slip up: 1 2 3 PY3 >>> for value in giant_collection: PY3 ... print(value) PY3 ... I've also add this line to mystartupscript.py to bite the bullet and start using print as a function everywhere: mystartupscript.py 1 from __future__ import print_function This has no effect in Python3.x, but will move 2.x to the new syntax.