-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseful_functions.py
More file actions
89 lines (71 loc) · 2.95 KB
/
useful_functions.py
File metadata and controls
89 lines (71 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# *arg - list format
# *kwarg dicitonary
# regular parameters
# *args
# **kwargs
def single_int_input(): #when you jsut want a number: 1234, 1, 9000 not 0009
while True:
user_input = input()
try:
user_input = int("".join(char for char in user_input if char != " ")) #gets rid of spaces and turns it into a string
return user_input
except ValueError: #if it become value error then do this instead
print("Please enter a string of numbers")
def clean_string(user_input):
user_input = "".join(char for char in user_input if char != " "); user_input.lower()
return user_input
#go trhough the string and if the word is in the long rando string then it works
#like virus question
#for i in word (word = "hugjdkslaujigkdsmbhgsioalchfdjkslfd")
#abcd is it in.
#lghsidjkhgdsjkähjgjdskhgsjkdtjgidoslkngldst
#hgsjdkghnjeskbgdlättbidhkghdsjihgsnd ___..--
def single_include_string_input(requirement, message):
#just enter with a list of the things you want the the string to be part of
while True:
user_input = input()
user_input = "".join(char for char in user_input if char != " "); user_input.lower()
#gone with all spaces. O(n) space.
if user_input in requirement:
return user_input
else:
print(message)
# def safe_input(user_input, *restrictions, **mode): #for now its just an input
# #restrictions should be in a list format.
# #input, restriction_list, Exclude = False, (String = False)
# #the input will be in string format
# ##if you want input as a word then String = True, If input as int then String = False (defult)
# #if you want exclude == True then the list is of stuff you wanan include, else it's Exclude = False (defult)
# #be in the format
# if len(mode) > 0: #you have some mode
# mode["Exclude"]
# print(user_input)
# print(restrictions)
# print(mode)
#safe_input(3, Exclude = True) #true means the thing has to be included
import sys
import threading
import time
def listen_for_enter():
global sleep_write_stopped
while True:
sys.stdin.read(1) #Looks for user input
sleep_write_stopped = True #returns that user input has been read
break
def sleep_write(word):
global sleep_write_stopped
sleep_write_stopped = False
listener = threading.Thread(target=listen_for_enter, daemon=True) #Points a thread to a function that waits for user input
listener.start() #Starts the thread
for i in word:
print(i, flush = True, end="") #Prints each letter in the string individually
if not sleep_write_stopped: #If the thread has recieved input: skips the following delay
time.sleep(0.03) #Creates a delay between each character
print("")
#
# # time.sleep(seconds)
# import messages
# word = messages.welcome_introduction
# for i in word:
# print(i, end="", flush = True)
# time.sleep(0.03)