Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Invalid Syntax

Hi, I am using a script for a school project but as soon as I try to execute it I get this error :
File "python", line 47
print "Block #{}\n has been added to the blockchain" .format(block_to_add.index)

SyntaxError: invalid syntax

*this being pointed to be wrong

Python Says theres something wrong with the following 2 lines :
print "Block #{}\n has been added to the blockchain" .format(block_to_add.index)
print "Hash: {}\n " .format(block_to_add.hash)
[/b]

Someone who can help me out? Thanks!
Mind pasting the whole stacktrace?
-Probably- you are using python3 and on the example you are using python2 syntax.On python2 print is statement and on python3 its function you should use brackets.
you forgot the index value
print "Block #{0}\n has been added to the blockchain" .format(block_to_add.index)
print "Hash: {0}\n " .format(block_to_add.hash)
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP
Check which version of Python you're using.
he is using python 2 cant you see
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP
(Aug 20, 2017 11:49 AM)HFDone Wrote:  you forgot the index value
print "Block #{0}\n has been added to the blockchain" .format(block_to_add.index)
print "Hash: {0}\n " .format(block_to_add.hash)

Format indexes are optional, actually.

OP:
Code
print("Block #{}\n has been added to the blockchain" .format(block_to_add.index))
print("Hash: {}\n " .format(block_to_add.hash))

In Python 3.x `print` is a function so you have to call it as such.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by 2xTheTap115May 23, 2020 12:11 PM 5 148 May 23, 2020 12:11 PM
Last Post: Athr
[Python] by ZakMay 2, 2018 05:26 AM 2 116 May 2, 2018 05:26 AM
Last Post: F.A.S.T
[Python] by M O D E R NDec 13, 2017 04:14 PM 2 169 Dec 13, 2017 04:14 PM
Last Post: M O D E R N