![]() |
|
[Python] Invalid Syntax - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Invalid Syntax (/showthread.php?tid=5699106) |
Invalid Syntax - Ricy - Aug 20, 2017 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! * - Hash G. - Aug 20, 2017 Mind pasting the whole stacktrace? * - SIM-1866423 - Aug 20, 2017 -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. * - HFDone - Aug 20, 2017 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) * - (╯°□°)╯︵ ┻━━┻ - Aug 20, 2017 Check which version of Python you're using. * - HFDone - Aug 20, 2017 he is using python 2 cant you see * - Vana - Aug 20, 2017 (Aug 20, 2017 11:49 AM)HFDone Wrote: you forgot the index value Format indexes are optional, actually. OP: Code print("Block #{}\n has been added to the blockchain" .format(block_to_add.index))In Python 3.x `print` is a function so you have to call it as such. |