We use some essential cookies to make our website work.

We use optional cookies, as detailed in our cookie policy, to remember your settings and understand how you use our website.

katyp
Posts: 14
Joined: Sun May 07, 2017 1:40 pm
Location: London

input()

Wed May 31, 2017 9:15 pm

Suddenly Pythias 3 seems to want me to use raw_input not input()?
I don't see why?
thx

katyp
Posts: 14
Joined: Sun May 07, 2017 1:40 pm
Location: London

Re: input()

Thu Jun 01, 2017 7:02 am

Thanks but it will only work if I use raw_input() and yes it is Python 3. This is the mystery

katyp
Posts: 14
Joined: Sun May 07, 2017 1:40 pm
Location: London

Re: input()

Thu Jun 01, 2017 7:05 am

Code: Select all

from time import sleep, time
from random import randint
while True:
sleep(randint(1,5))
start = time()
print('Quick, hit the Enter key')
raw_input()       #had to change input() to raw_input() for it to work
reaction_time = time() - start
print('You took', reaction_time, 'seconds')

texy
Posts: 5174
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: input()

Thu Jun 01, 2017 9:05 am

katyp wrote:

Code: Select all

from time import sleep, time
from random import randint
while True:
sleep(randint(1,5))
start = time()
print('Quick, hit the Enter key')
raw_input()       #had to change input() to raw_input() for it to work
reaction_time = time() - start
print('You took', reaction_time, 'seconds')
You missed the CODE tags, which I have now added, but the formatting (indentation) is still missing.
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
Paeryn
Posts: 3608
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: input()

Thu Jun 01, 2017 10:37 am

katyp wrote:Thanks but it will only work if I use raw_input() and yes it is Python 3. This is the mystery
Are you absolutely sure you are running it with Python3? Python3 doesn't have raw_input() unless something else implements it. How are you running your program? You can add the following to the start of the program to print out which version of Python is running the program just to be sure.

Code: Select all

import sys
print(sys.version)
Above code saved as ver.py and run with both Python3 (first) and Python2 (second).

Code: Select all

pi@rpi3:~ $ python3 ver.py
3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1]
pi@rpi3:~ $ python ver.py
2.7.9 (default, Sep 17 2016, 20:26:04)
[GCC 4.9.2]
<Edit> Also, you can tell if Python2 or Python3 is running your code from the printing of the timing line, Python2 will print it as

Code: Select all

('You took', 0.6783080101013184, 'seconds')
Kira the Koding Kitty, R.I.P. 8/3/24

katyp
Posts: 14
Joined: Sun May 07, 2017 1:40 pm
Location: London

Re: input()

Thu Jun 01, 2017 2:45 pm

Texy
No sure what you mean by code tags? The programme has the indents and runs OK as is - just lost indent in copying and pasting Yes it is Python 3

katyp
Posts: 14
Joined: Sun May 07, 2017 1:40 pm
Location: London

Re: input()

Thu Jun 01, 2017 2:48 pm

texy wrote:
katyp wrote:

Code: Select all

from time import sleep, time
from random import randint
while True:
sleep(randint(1,5))
start = time()
print('Quick, hit the Enter key')
raw_input()       #had to change input() to raw_input() for it to work
reaction_time = time() - start
print('You took', reaction_time, 'seconds')
You missed the CODE tags, which I have now added, but the formatting (indentation) is still missing.
Texy

Texy
No sure what you mean by code tags? The programme has the indents and runs OK as is - just lost indent in copying and pasting Yes it is Python 3

User avatar
Paeryn
Posts: 3608
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: input()

Thu Jun 01, 2017 3:34 pm

katyp wrote:Texy
No sure what you mean by code tags? The programme has the indents and runs OK as is - just lost indent in copying and pasting Yes it is Python 3
Code tags are what you need to use to mark sections of your post as code so that it gets displayed exactly as given including all white space (multiple spaces, tabs). You can either insert the tags using the Code button which is the 5th button just above the text entry box, or you can type them in yourself. By pressing the button the start and end tags [­code] & [­/code] will be inserted for you with the cursor inbetween ready for you to put your code (or you can highlight a section of your post and press the button, the tags will then be placed either side of the highlighted section).

As to your program, as has been said, if your code uses raw_input() and runs then you are not using Python3 to run it, you are using Python2. Python3 does not have a function called raw_input unless you define it yourself (and your program doesn't do that). What makes you think that you are running it with Python3?
Kira the Koding Kitty, R.I.P. 8/3/24

Return to “General discussion”