简体   繁体   English

来自拆分或输入法的无效令牌

[英]Invalid token from split or input method

I'm currently constructing a little python script and for some reason, I'm receiving an invalid token after I input my value. 我目前正在构建一个小的python脚本,由于某种原因,我在输入值后收到了无效的令牌。

Code: 码:

#!/usr/bin/python

def main():
    frankOceanRelease()

def frankOceanRelease():
    info = str(input('Enter the date in which Frank will drop his album (MM/DD/YYYY):')).split("/")
    if info[1] == "13" and info[0] == "11":
        return('Let\'s hope he doesn\'t flake')
    elif info[2] == "3005":
        return('This might happen, but no guarantee')
    else:
        return('Nah man, this album ain\'t out yet!')

if __name__ == "__main__":
    main()

Error: 错误:

File "./frankOceanRelease.py", line 16, in <module>
    main()
File "./frankOceanRelease.py", line 4, in main
    frankOceanRelease()
File "./frankOceanRelease.py", line 7, in frankOceanRelease
    info = input('Enter the date in which Frank will drop his album (MM DD YYYY):').split()
File "<string>", line 1
    08 07 2016
     ^
SyntaxError: invalid token

If you're on Python 2, then entering the items with input separated by / (ie 'MM/DD/YYYY)' ) will perform multiple integer divisions. 如果您使用的是Python 2,则输入的input/分隔(即'MM/DD/YYYY)' )将执行多个整数除法。 You will almost always get a 0 since the year will be far larger than the two others. 您几乎总是会得到0因为年份将远远大于其他两个年份。

On the other hand, entering without the separator will raise the error you see since that input cannot be evaluated. 另一方面,如果输入不带分隔符,则会引起错误,因为该输入无法评估。

What you want is raw_input : 您想要的是raw_input

>>> info = raw_input('Enter the date in which Frank will drop his album (MM/DD/YYYY):').split("/")
Enter the date in which Frank will drop his album (MM/DD/YYYY):11/06/2016
>>> info
['11', '06', '2016']

未捕获的 SyntaxError:无效或意外的令牌<input id="{{" vendor.id }}< div><div id="text_translate"><p> 我正在尝试在 input[type='checkbox'] 上单击 function 提交表单,而不使用 ajax-jquery 刷新页面。 顺便说一句,我正在开发一个 Django web 应用程序。</p><p> 这是我的表单元素代码-</p><pre> {% if vendor.accountEnabled %} &lt;form id="form" action="{% url 'change_account_switch' vendor.id %}" method="post"&gt; {% csrf_token %} &lt;div class="custom-control custom-switch"&gt; &lt;input onclick="switchAcc('{{ vendor.id }}customSwitch1');" type="checkbox" name="switch" class="custom-control-input" id="{{ vendor.id }}customSwitch1" checked&gt; &lt;label class="custom-control-label" for="{{ vendor.id }}customSwitch1"&gt;Enable&lt;/label&gt; &lt;/div&gt; &lt;/form&gt; {% else %} &lt;form id="form" action="{% url 'change_account_switch' vendor.id %}" method="post"&gt; {% csrf_token %} &lt;div class="custom-control custom-switch"&gt; &lt;input onclick="switchAcc('{{ vendor.id }}customSwitch1');" type="checkbox" name="switch" class="custom-control-input" id="{{ vendor.id }}customSwitch1"&gt; &lt;label class="custom-control-label" for="{{ vendor.id }}customSwitch1"&gt;Enable&lt;/label&gt; &lt;/div&gt; &lt;/form&gt; {% endif %}</pre><p> 这是我的JS代码-</p><pre> function switchAcc(cb_id) { let switchBtn = $('#' + cb_id).is(':checked'); console.log(switchBtn) console.log(cb_id) $.ajax({ url: $('#form').attr('action'), data: { 'status': switchBtn }, dataType: 'json', success: function (data) { console.log(data) if (data.is_done) { alert("A user with this username already exists."); } }, error: function (e) { console.log(e.message); } }); }</pre><p> Django views.py ----</p><pre> @login_required(login_url='/login/') def change_account_switch(request, doc_id): ref = db.collection('vendorUsers').document(doc_id) switch = request.GET.get('status', None) if switch == 'true': switch = True elif switch == 'false': switch = False ref.update({ 'accountEnabled': switch, }) data = { 'is_done': ref.get().to_dict()['accountEnabled'], } return JsonResponse(data)</pre><p> 我还有一个问题。 看看我的表单元素代码,我正在显示多个用户,每个用户在他们的个人资料数据库中都包含 accountEnabled 字段。 . . .</p><p> 现在,看看我的views.py 代码。 在该文件中,我根据切换按钮(复选框)更新 accountEnabled 字段。 . . .</p><p> 但问题是,只有第一个用户的 accountEnabled 字段在列表中更新。 –</p></div> - Uncaught SyntaxError: Invalid or unexpected token in <input id={{ vendor.id }}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Braintree 中的付款方式令牌无效 - Payment method token is invalid in Braintree Function 将输入表达式拆分为令牌单元(python) - Function to split the input expression into token units(python) sklearn.model_selection.train_test_split 中分层方法的(无效参数)错误 - error of (Invalid parameters) from stratify method in sklearn.model_selection.train_test_split 同一变量的多个输入 split() 方法类型 - Multiple input split() method types for the same variable 从 tweepy 获取“无效或过期的令牌” - Getting "Invalid or expired token" from tweepy 未捕获的 SyntaxError:无效或意外的令牌<input id="{{" vendor.id }}< div><div id="text_translate"><p> 我正在尝试在 input[type='checkbox'] 上单击 function 提交表单,而不使用 ajax-jquery 刷新页面。 顺便说一句,我正在开发一个 Django web 应用程序。</p><p> 这是我的表单元素代码-</p><pre> {% if vendor.accountEnabled %} &lt;form id="form" action="{% url 'change_account_switch' vendor.id %}" method="post"&gt; {% csrf_token %} &lt;div class="custom-control custom-switch"&gt; &lt;input onclick="switchAcc('{{ vendor.id }}customSwitch1');" type="checkbox" name="switch" class="custom-control-input" id="{{ vendor.id }}customSwitch1" checked&gt; &lt;label class="custom-control-label" for="{{ vendor.id }}customSwitch1"&gt;Enable&lt;/label&gt; &lt;/div&gt; &lt;/form&gt; {% else %} &lt;form id="form" action="{% url 'change_account_switch' vendor.id %}" method="post"&gt; {% csrf_token %} &lt;div class="custom-control custom-switch"&gt; &lt;input onclick="switchAcc('{{ vendor.id }}customSwitch1');" type="checkbox" name="switch" class="custom-control-input" id="{{ vendor.id }}customSwitch1"&gt; &lt;label class="custom-control-label" for="{{ vendor.id }}customSwitch1"&gt;Enable&lt;/label&gt; &lt;/div&gt; &lt;/form&gt; {% endif %}</pre><p> 这是我的JS代码-</p><pre> function switchAcc(cb_id) { let switchBtn = $('#' + cb_id).is(':checked'); console.log(switchBtn) console.log(cb_id) $.ajax({ url: $('#form').attr('action'), data: { 'status': switchBtn }, dataType: 'json', success: function (data) { console.log(data) if (data.is_done) { alert("A user with this username already exists."); } }, error: function (e) { console.log(e.message); } }); }</pre><p> Django views.py ----</p><pre> @login_required(login_url='/login/') def change_account_switch(request, doc_id): ref = db.collection('vendorUsers').document(doc_id) switch = request.GET.get('status', None) if switch == 'true': switch = True elif switch == 'false': switch = False ref.update({ 'accountEnabled': switch, }) data = { 'is_done': ref.get().to_dict()['accountEnabled'], } return JsonResponse(data)</pre><p> 我还有一个问题。 看看我的表单元素代码,我正在显示多个用户,每个用户在他们的个人资料数据库中都包含 accountEnabled 字段。 . . .</p><p> 现在,看看我的views.py 代码。 在该文件中,我根据切换按钮(复选框)更新 accountEnabled 字段。 . . .</p><p> 但问题是,只有第一个用户的 accountEnabled 字段在列表中更新。 –</p></div> - Uncaught SyntaxError: Invalid or unexpected token in <input id={{ vendor.id }} 在Braintree中创建订阅时,付款方式令牌无效 - Payment method token is invalid when I create subscription in Braintree 无效的令牌和无效的语法 - Invalid token and Invalid syntax 从拆分方法中拉出某些字符串 - Pulling out certain strings from split method 使用拆分方法从文本文件预处理数据 - Preprocessing the data from a text file with a split method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM