"raw_input" For ALL Versions Of Python...

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

"raw_input" For ALL Versions Of Python...

Postby Bazza » Wed Aug 10, 2011 7:23 pm

Hi all...

A simple quicky...

Add these two lines to ANY python code from Python 1.4.0 to 3.2.x, and
have universal KB entry for ALL versions...

(C)2011, B.Walker, G0LCU...

Issued under the MIT licence.

<CODE>

import sys
if sys.version[0]=="3": raw_input=input

</CODE>

Test procedure below for Python 3.x.x...


Code: Select all
Python 3.1.3 (r313:86834, Nov 28 2010, 10:01:07)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> if sys.version[0]=="3":
...     raw_input=input
...
>>> test=raw_input("Some Prompt:- ")
Some Prompt:- qwertyuiop
>>> print(test)
qwertyuiop
>>>
73...

Bazza, G0LCU...

Team AMIGA...
User avatar
Bazza
LXF regular
 
Posts: 1483
Joined: Sat Mar 21, 2009 11:16 am
Location: Loughborough

Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron