July 26th, 2013, 03:01 PM
Questions from a beginner.
I'm learning from "Learn Python the hard way". I'm using python 3.1, although he says to use python 2.
1. In the exercise 12 he says to use the raw_input function. This function isn't in python 3, and google says that eval(input()) is the same thing as raw_input. But in the "What You Should See" box on the webpage, it says 6'2" in the 3rd line. My programme messes up at that line if the user tries to input ' or " in to the programme. Why is this, and what is the best way to emulate raw_input in python 3?
2. Before all of the lessons, he says to install and use microsoft powershell and notebook+ and use them together in some way. I didn't figure out how to do this. Is it essential?
July 26th, 2013, 03:13 PM
1) python 3 eval(input()) does replace python 2 input()
If you typed ' " into the interpreter, would you not be charmed with the error? The same rules apply to using either. You must use eval(input()) within a try except block, which is ok for toy problems. Commercially you need to parse the input before using eval. Consider
eval(input('5 + 2 = ? '))
given a response of
os.system('delete wild_card_pattern_for_all_files || rm wild_card')
2) A good python program editor is next to essential. I use emacs.
[/code] are essential for python code and Makefiles!
July 27th, 2013, 11:19 AM
Python3 has changed the raw_input() to input()
input("Enter your whatever:")
July 27th, 2013, 12:38 PM
Yeah, you may have read the raw_input thing backwards: eval(input()) is equivalent to Python 2's input(), whereas just plain input() is equivalent to raw_input().
It's not essential to use that editor, and it's definitely not essential to use PowerShell. In fact if you're only using it for Python and not for other command line stuff, there's no difference between PowerShell and cmd.exe (the basic built-in command prompt) at all. Notepad++ is a pretty good editor, but it's certainly not the only one. Just as long as you don't use Windows Notepad you should be fine.
Also, why 3.1? You should be using 2.7 or 3.3.
Last edited by Nyktos; July 27th, 2013 at 12:40 PM.
July 27th, 2013, 03:54 PM
I have a stupid question though. How do I start programmes on python from the idle?
I'm on lesson thirteen of learn python the hard way. How do I play a programme from idle? The lesson says to do:
python ex13.py first 2nd 3rd
(where "first 2nd and 3rd" are input arguments) but it doesn't work. I'm now using python 2.7.5, and I've tried lots of different combinations of brackets and no brackets etc but can't do it.
July 28th, 2013, 07:09 AM
is intended to be run from the command line; not from within IDLE (or any other IDE). You could cheat the program by editing it and appending the intended arguments to sys.argv, but you should really probably just run it from command line.
python ex13.py first 2nd 3rd