小编pyl*_*ner的帖子

将来运行python脚本

我有一个需要在用户输入上运行的python脚本.我将从用户那里获得日期和时间,脚本将在该日期运行.

import time
from datetime import datetime

today = datetime.today() 
enter_date = raw_input("Please enter a date:(2017-11-28): ")
enter_time = raw_input("What time do you want to start the script? ")

difference = enter_date - today

time.sleep(difference)
Run Code Online (Sandbox Code Playgroud)

在此之后,main()函数将运行.

我无法让它运行.有没有更好的方法来完成这项任务?谢谢

python time datetime

5
推荐指数
1
解决办法
438
查看次数

在另一个函数中使用返回值

我有两个功能.请参阅以下功能;

 def check_channel_number(self):

    print "***************Channel Checker *********************" 

    print ''

    user_channel_number = int(re.sub('\D', '', raw_input("Enter a channel number, (3digit): "))[:3]);

    channel = ("channelNr= '%d'") % (user_channel_number)

    print channel

    # channel_search = channel + str(user_channel_number)

    datafile = file('output.txt')

    found = False

    for line in datafile:

        if channel in line:

            found = True 
            print 'The channel number you entered is correct and will be deleted'
            return user_channel_number

    print 'The channel number you entered is not on the planner'
    return False
Run Code Online (Sandbox Code Playgroud)

只想在以下函数中使用(user_channel_number)的返回值.

   def delete_events(self): …
Run Code Online (Sandbox Code Playgroud)

python python-2.7

3
推荐指数
2
解决办法
2万
查看次数

获取Django模板中for循环的第一个元素

模板:

{% for code in group_codes %}
        *_{{ code.build }}_*<br />
        {% if test_info.test_type = 0 %}
            {{ code.pre_testing_fail }}/{{ code.pre_testing_total }} failed pre-test<br />
        {% else %}

        {% for shelf in final_shelf_info %}

        {{ shelf.build }} <br/>

           {% if shelf.build = code.build %}

            {{ mr_script_count_func }}/{{ code.script_total }} 
            <span>MR</span> failed during script<br />
            {{gw_script_count_func}}/{{ code.script_total }} 
            <span>GW</span> failed during script<br />
            {{ mr_post_count_func }}/{{ code.post_testing_total }} 
            MR failed during post-test<br/>
            {{ gw_post_count_func }}/{{ code.post_testing_total }}
             GW failed during post-test<br/> …
Run Code Online (Sandbox Code Playgroud)

django django-templates django-views

2
推荐指数
1
解决办法
8045
查看次数

TypeError:'long'对象不可迭代

我刚刚在python中创建了一个字典.

stb_info = self.stb_type()
print type(stb_info) #The output gives me dict
Run Code Online (Sandbox Code Playgroud)

当我想为每个小组运行我的胎面功能时

for group_no, shelves in stb_info:
    self.thread_function(group_no, shelves)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

TypeError: 'long' object is not iterable
Run Code Online (Sandbox Code Playgroud)

那么,我怎么能解决这个bug呢?

python python-2.7

1
推荐指数
1
解决办法
6563
查看次数