3
Contributors
3
Replies
12
Views
5 Years
Discussion Span
Last Post by Catchamouse
0

You can use

from time import sleep
sleep(1.5) # sleep 1.5 seconds

The precision of the sleep depends on your system (see timemodule.c for implementation details).

Also you may want to try

import os
os.system("pause")

Finally, if you want to wait until ENTER is pressed, simply use raw_input

raw_input("Press enter to continue")

This snippet could help you too http://snippets.dzone.com/posts/show/915

Edited by Gribouillis: n/a

0

Normally raw_input (Python 2) or input (Python 3) is enough. If you want to get fancy and have anyway in your module library my Tkinter getkey, you can utilize it also (for me input has been enough) You may want to make simple base class for it though as the snippet is reaction to key press for game use.

Notice also that many editors can pause the screen at end like ConText editor for Windows.

Edited by pyTony: n/a

0

I have this code

if __name__ == "__main__":

    def make_index(input, output):
        f_input = open(input, "rt")
        f_output = open(output, "wt")
        splitting_chars = (' ','.','!','?','\n',',','"')
        char_buffer = ""
        row_index = 0
        dict = {}

        for row in f_input:
            row_index += 1
            for char in row:
                if char not in splitting_chars:
                    char_buffer += char
                else:
                    if char_buffer is not "":
                        if not dict.has_key(char_buffer):
                            dict[char_buffer] = []
                        if row_index not in dict[char_buffer]:
                            dict[char_buffer].append(row_index)
                    char_buffer = ""
     
        keys = dict.keys()
        keys.sort()

        for key in keys:
            s = reduce(lambda a,b: str(a) + " " + str(b), dict[key])
            f_output.write(key + " "  +  str(s) + " \n")

        f_input.close()
        f_output.close()

    def search_by_index(input, index):
        file = open(input, "rt")
        rows = file.readlines()
        file.close()
        dict = {}
        for row in rows:
            lst = row.split(" ")
            dict[lst[0]] = map(lambda a: int(a), lst[1 : len(lst)-1])

        if dict.has_key(index):
            return dict[index]
        else:
            return []

    make_index("input.txt", "index.txt")
    print search_by_index("index.txt", "Python")
    print search_by_index("index.txt", "Kreatrix")

    raw_input("Press enter to continue")

In this case raw_input or import os does not work. Could you help me?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.