Re: [Tutor] syntax error with raw input

2014-11-12 Thread Chris Warrick
On Wed, Nov 12, 2014 at 12:08 PM, Vaibhav Banait
 wrote:
> Hi
> I am new to python. I learnt (!) using  raw_input a day back. Attempt to use
> has resulted in error. I am not able to spot a problem in syntax. I am using
> python 3.4.2. Kindly help
>
>
> a = raw_input("Write down your name: ")
>
> Output:
>
>
> Traceback (most recent call last):
>   File "", line 1, in 
> a = raw_input("Write down your name: ")
> NameError: name 'raw_input' is not defined
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

In Python 3, raw_input() was renamed to input().

a = input("Write down your name: ")

Note that input() is also a thing in Python 2, but you shouldn’t use
that one for security reasons.  Python 3’s is fine though.

-- 
Chris Warrick 
PGP: 5EAAEA16
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error with raw input

2014-11-12 Thread Alan Gauld

On 12/11/14 11:08, Vaibhav Banait wrote:

Hi
I am new to python. I learnt (!) using  raw_input a day back. Attempt to
use has resulted in error. I am not able to spot a problem in syntax. I
am using python 3.4.2. Kindly help


Looks like you are reading a v2 book/tutorial but using v3.

In v3 several key changes were made to Python including the renaming of 
raw_input() to input().


The other big change was making print a function so you now *must* put 
parentheses around anything you want to print.


ie

print 'hello'  # Python v2

becomes

print('hello')   # python v3

There are numerous other small changes so it would be better for you to 
either find a v3 tutorial (you could try mine! :-) or install Python 
v2.7 while you are learning.



--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error with raw input

2014-11-12 Thread wesley chun
Slightly hijacking this thread a bit, specifically Alan's reply, if anyone
is averse to installing multiple versions of Python on their computers, you
can always access a Python interpreter from a browser window.

Here are a collection I've put together. Most are Python 2, but the top
pair also support Python 3:

   - http://ideone.com (2.x & 3.x)
   - http://colabv6.dan.co.jp/lleval.html (2.x & 3.x)
   - http://doc.pyschools.com/console
   - http://repl.it/languages/Python
   - http://skulpt.org (pure JS implementation; allows turtle)
   - http://pythonwebconsole.thomnichols.org
   - http://shell.appspot.com (Google App Engine + libraries)
   - http://codepad.org
   - http://lotrepls.appspot.com
   - http://datamech.com/devan/trypython/trypython.py

Cheers,
--Wesley

On Wed, Nov 12, 2014 at 9:11 AM, Alan Gauld 
wrote:

> On 12/11/14 11:08, Vaibhav Banait wrote:
>
>> Hi
>> I am new to python. I learnt (!) using  raw_input a day back. Attempt to
>> use has resulted in error. I am not able to spot a problem in syntax. I
>> am using python 3.4.2. Kindly help
>>
>
> Looks like you are reading a v2 book/tutorial but using v3.
>
> In v3 several key changes were made to Python including the renaming of
> raw_input() to input().
>
> The other big change was making print a function so you now *must* put
> parentheses around anything you want to print.
>
> ie
>
> print 'hello'  # Python v2
>
> becomes
>
> print('hello')   # python v3
>
> There are numerous other small changes so it would be better for you to
> either find a v3 tutorial (you could try mine! :-) or install Python v2.7
> while you are learning.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"A computer never does what you want... only what you tell it."
+wesley chun  : wescpy at gmail : @wescpy

Python training & consulting : http://CyberwebConsulting.com
"Core Python" books : http://CorePython.com
Python blog: http://wescpy.blogspot.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] syntax error with raw input

2014-11-12 Thread Steven D'Aprano
On Wed, Nov 12, 2014 at 04:38:51PM +0530, Vaibhav Banait wrote:
> Hi
> I am new to python. I learnt (!) using  raw_input a day back. Attempt to
> use has resulted in error. I am not able to spot a problem in syntax.

What makes you think it is a problem with syntax?

This is what happens when you have a syntax error:

py> 23 42 +
  File "", line 1
23 42 +
^
SyntaxError: invalid syntax


Look at the error you get instead: it doesn't say "SyntaxError", does 
it? It says "NameError".

NameError: name 'raw_input' is not defined


The reason is that in Python 3, "raw_input" has been renamed to just 
"input".



-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor