#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0

    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?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,955
    Rep Power
    481
    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
    Code:
    os.system('delete wild_card_pattern_for_all_files || rm wild_card')
    Get it?

    2) A good python program editor is next to essential. I use emacs.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    14
    Rep Power
    0
    Python3 has changed the raw_input() to input()

    Code:
    input("Enter your whatever:")
    Like this
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    114
    Rep Power
    3
    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.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0
    Thanks guys.

    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.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    194
    Rep Power
    3
    The command:
    Code:
    python ex13.py first 2nd 3rd
    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.

    -Mek

IMN logo majestic logo threadwatch logo seochat tools logo