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

    Join Date
    Feb 2013
    Posts
    5
    Rep Power
    0

    Try except syntax error


    Dear all,
    I am new to python and trying to get a try...except part of a code to work but I always get an "invalid syntax" error
    this part of the code should read 2 files and if the user does not include the 2 files in his command line the except message will appear saying "please enter 2 file names, they were not entered properly" and exits.
    I am using Python 3.2
    the code is:
    Code:
    import sys, math
    try:
        r=input("where is file1") ; z = input("where is file2?")
        except:
            print("please enter 2 file names, they were not entered properly"); sys.exit(1)
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,995
    Rep Power
    481

    Indentation trouble!


    Code:
    import sys, math
    try:
        r = input("where is file1")
        z = input("where is file2?")
    except:
        print("please enter 2 file names, they were not entered properly")
        sys.exit(1)
    The semi-colons were okay. I removed them anyway.
    [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
    Mar 2013
    Posts
    16
    Rep Power
    0
    As it says b49P23TIvg, you must be careful with the indentation.

    PHP Code:
    try:
        
    # --- Some Code ----
    except:
        
    # --- More Code --- 
    finally:
        
    # --- More Code --- 
    etc.

IMN logo majestic logo threadwatch logo seochat tools logo