Invalid Syntax using @app.route

2024/11/15 0:44:49

I'm getting a Invalid Syntax in line 22 @app.route('/start') and really don't know why... I'm developing it under a Cloud9 server https://c9.io , maybe that has something to do with it... I tried it in two virtual enviroments with python versions 2.7.3 and 3.4.3. It's exactly the same syntax of a hello.py that actually does work...

#import random
import string
import hangman
import os
from flask import Flask, \request, \render_template, \url_for, \redirect, \flashapp = Flask(__name__)@app.route('/')
@app.route('/index')
def initialize():WORDLIST_FILENAME = "./resources/words.txt"wordlist = hangman.loadWords(WORDLIST_FILENAME)return redirect(url_for('start_game', wordlist=wordlist)@app.route('/start')
def start_game(wordlist):secretWord = hangman.chooseWord(wordlist).lower()hangman.hang(secretWord)return Noneif __name__ == '__main__':
#app.debug = True
app.secret_key = 'MySecretKey'
app.run(host=os.getenv('IP', '0.0.0.0'), port=int(os.getenv('PORT',5000)))

feel free to colaborate branching this project at https://github.com/leomagal/hangman

Answer

Missing a closing parenthesis on:

return redirect(url_for('start_game', wordlist=wordlist)

If you get a syntax error, if the problem isn't obvious in the line the error reports, look at previous lines for issues like missing parenthesis.

https://en.xdnf.cn/q/119739.html

Related Q&A

How do I count unique words using counter library in python?

im new to python and trying various librariesfrom collections import Counter print(Counter(like baby baby baby ohhh baby baby like nooo))When i print this the output I receive is:Counter({b: 10, : 8, …

Need some debugging in my program: filling up SQL tables with data retrieved from a Python program

I am filling up SQL tables with data that I have retrieved from a Python program. I am using Visual Studio Code for the Python program and MySQL Workbench 8.0 for SQL. There are some errors in it that …

How do I create a magic square matrix using python

A basket is given to you in the shape of a matrix. If the size of the matrix is N x N then the range of number of eggs you can put in each slot of the basket is 1 to N2 . You task is to arrange the egg…

Ensuring same dimensions in Python

The dimensions of P is (2,3,3). But the dimensions of M is (3,3). How can I ensure that both P and M have the same dimensions i.e. (2,3,3). import numpy as np P=np.array([[[128.22918457, 168.52413295,…

how to stop tkinter timer function when i press button one more times?

id tried to use root.after_cancel(AFTER), but i dont know how.root.after_cancel(AFTER) AFTER = None def countdown(count,time,name):global AFTERtime[text] =name,":",datetime.fromtimestamp(cou…

Read csv into database SQLite3 ODO Python

I am trying to read in a csv into a new table in a new databased using ODO, SQLite3 and Python.I am following these guides:https://media.readthedocs.org/pdf/odo/latest/odo.pdf http://odo.pydata.org/en/…

netmiko cant execute sh run | i host

I notice that my netmiko code cant run sh run | i host which is a legitimate Cisco command.When I replace sh run with other command such as sh clo, or show ip interface brief, it works perfectly.from n…

How to dump the data from file to an excel sheet

I want to dump [3-4 lines together] some data to an excel sheet. I could able to dump single line based on some criteria [like if line is getting start with // or /* ], but in case of when lines starts…

I dont understand why my script is not iterating through all string.split elements?

The objective of this python exercise is to build a function that turns text into pig latin, a simple text transformation that modifies each word by moving the first character to the end and appending …

Unable to change the tick frequency on my chart

I have seen many questions on changing the tick frequency on SO, and that did help when I am building a line chart, but I have been struggling when its a bar chart. So below are my codes import numpy a…