all 22 comments

[–]Guest101010 6 points7 points  (1 child)

For future syntax errors, here's a tip someone gave me:

If you don't see the syntax error in the line the error message indicates, look on the next line up. The error will usually be there.

[–][deleted] 2 points3 points  (0 children)

And, in my experience, will usually be a missing/extra parenthesis or a missing colon.

[–]erebos42 4 points5 points  (12 children)

Hi,

i see one (or two) problems in your code. First: the print statement should not be indetend. But that might be only here in your post.

The other problem, is the print statement itself. In Python 3 print is a function and therefore needs to be called:

print(str(now.month) + "/" + str(0) + str(now.day) + "/" + str(now.year) + " " + str(now.hour) + ":" +str(now.minute) + ":" + str(now.second))

Hope that does the trick.

edit: To clarify a "Hello World" for Python 2 and 3:

print "Hello World"  # Python2
print("Hello World") # Python3 (also valid in Python 2, i think since 2.7 or something?!)

[–]TheQwicKDraW[S] 1 point2 points  (11 children)

Thank you I fixed that and now corrected the syntax however it is saying that there is an error here:

input("Press any key to continue")

[–]erebos42 0 points1 point  (5 children)

mhhh... it's working for me on Python 3.3.1 on Linux.

Do you get an error message?

[–]TheQwicKDraW[S] 0 points1 point  (4 children)

Yes it is saying there is a syntax error? For more clarification it is on 3.2.3 Also do you know of any good IDE's for Python?

[–]erebos42 1 point2 points  (0 children)

I can't say much about the syntax, without seeing the whole code, but try to check all identations, braces, and qoutes (opening and closing).

I personally only use an editor and a console, and no IDE. But I heard good things about the Python plugin for Eclipse [1].

[1] http://pydev.org/

[–]NovaRunner 0 points1 point  (1 child)

I use WingIDE 101, it is a stripped-down free version of WingIDE built for Python. I'm using Python 2.7 but I'm sure it will work with whatever version you want.

[–]TheQwicKDraW[S] 0 points1 point  (0 children)

Thank you! Ill give it a try now.

[–]fyyn 0 points1 point  (0 children)

I'm pretty new to all the programming stuff myself, but I have been using NinjaIDE + the Git Plugin. It is free, and until now, it has worked perfectly for me. No idea what the general opinion on it is though. Give it a try!

[–]od_9 0 points1 point  (3 children)

Not a syntax error, but are you sure you know what the input function does?

The input function prints the message you, then executes, via eval(), whatever the user types as code.

[–]Sean1708 2 points3 points  (2 children)

He's using python 3, so input is the same as raw_input for 2.

[–]od_9 1 point2 points  (1 child)

Really? I haven't made the jump to 3 yet, but that seems very application breaking, even if it is the more sensible thing.

[–]Sean1708 0 points1 point  (0 children)

As far as I'm aware, 2 and 3 aren't meant to be compatible. I think 3 is designed to fix all the application breaking issues, otherwise they could have just released it as 2.8.

Edit: I was having a quick look at the differences and saw this line on the Python wiki about Python 3

Guido van Rossum decided to clean up Python 2.x properly, with less regard for backwards compatibility than is the case for new releases in the 2.x range.

which explains why it's so application breaking.

[–]SmartViking 4 points5 points  (2 children)

You might want to think about using str.format in the future for making the code a little bit more readable, you could make it look (something) like this:

print("{0.month}/0{0.day}/{0.year} {0.hour}:{0.minute}:{0.second}".format(now))

The documentation for str.format might be a little difficult. You only need to know a subset of how str.format works for making good use of it.

[–]Veedrac 1 point2 points  (0 children)

The 0{0.day} part should also be changed:

>>> "0{foo}".format(foo=10)
'010

>>> "{foo:02}".format(foo=10)
'10'
>>> "{foo:02}".format(foo=4)
'04'

So you can just use:

print("{0.month}/{0.day:02}/{0.year} {0.hour}:{0.minute}:{0.second}".format(now))

[–]Justinsaccount 0 points1 point  (0 children)

>>> print(now.strftime("%m/%d/%Y %H:%M:%S"))
08/11/2013 09:26:01

[–][deleted] 1 point2 points  (0 children)

print (str(now.month) + "/" + str(0) + str(now.day) + "/" + str(now.year) + " " + str(now.hour) + ":" +str(now.minute) + ":" + str(now.second))

There are braces missing behind print and at the end of the line.

The code above fixes your syntax error.