def hey (string):
    if string.isspace() or string == "":
        return "Fine. Be that way!"
    elif string.isupper():
        return "Whoa, chill out!"
    elif string.endswith("?"):
        return "Sure."
    else:
        return "Whatever."
def hey(string):
    if string.isspace() or string == "":
        return "Fine. Be that way!"
    elif string.isupper():
        return "Whoa, chill out!"
    elif string.endswith("?"):
        return "Sure."
    else:
        return "Whatever."
Пример #3
0
def is_num(number):
    """
    判断是否为数字
    :param number:
    :return:
    """
    string = str(number)
    print("判断所有字符都是数字或者字母: ", string.isalnum())
    print("判断所有字符都是字母: ", string.isalpha())
    print("判断所有字符都是数字: ", string.isdecimal())
    print("判断所有字符都是数字: ", string.isnumeric())  # 此方法只针对unicode对象
    print("判断所有字符都是小写: ", string.islower())
    print("判断所有字符都是大写: ", string.isupper())
    print("判断所有字符都是空白符: ", string.isspace())
    return string.isdigit()
Пример #4
0
def output(string, clear=True):
    global print_cache
    global log_runtime

    now = '[' + datetime.now().strftime('%Y-%m-%d %H:%M:%S') + ']'

    if string is None or string.isspace():
        return
    if (clear):
        print_cache += now + ' ' + string.replace(' ', '&nbsp;') + '<br/>\n'
        print string
    else:
        print_cache += now + ' ' + string.replace(' ', '&nbsp;')
        print string,

    log_runtime.log(logging.INFO, string)
Пример #5
0
def output(string, clear=True, timestamp=True):
    # global print_cache
    # global log_runtime

    if string is None or string.isspace():
        return

    if (timestamp):
        print '[' + datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S') + '] ',

    if (clear):
        print string
    else:
        print string,

    log_runtime.log(logging.INFO, string)
Пример #6
0
def text_process(obj, verbose=False):
    try:
        raw_text = obj['payload']['text']
        if verbose:
            print raw_text
        text, _ = extract_links(raw_text)
        cleantext = text.encode('ascii', 'ignore')
        words = []
        ws = re.findall(r'(?u)[@|#]?\w+', cleantext)
        if isinstance(ws, list):
            for word in ws:
                if not hasNumbers(word) and not hasBS(word):
                    words.append(word.lower().strip())
        else:
            return None

        htags = {}
        for i, word in enumerate(words):
            if word.startswith('#'):
                words[i] = ''  #word.split('#')[1]
                htags[i] = word

            if word.startswith('@'):
                words[i] = ''

        string = remove_punctuation(' '.join(words))
        wbag = string.split()

        if htags:
            for v in htags.keys():
                wbag.insert(v, htags[v])

        string = ' '.join(wbag)
        if string and not string.isspace():
            return string.strip()
        else:
            return None
    except Exception as e:
        print e
        return None
Пример #7
0
def text_process(obj, verbose = False):
    try:
        raw_text = obj['payload']['text']
        if verbose:
            print raw_text
        text, _ = extract_links(raw_text)
        cleantext = text.encode('ascii','ignore')
        words = []
        ws = re.findall(r'(?u)[@|#]?\w+', cleantext)
        if isinstance(ws, list):
            for word in ws:
                if not hasNumbers(word) and not hasBS(word):
                    words.append(word.lower().strip())
        else:
            return None
        
        htags = {}
        for i, word in enumerate(words):
            if word.startswith('#'):
                words[i] = '' #word.split('#')[1]
                htags[i] = word
                
            if word.startswith('@'):
                words[i] = ''
                    
        string = remove_punctuation(' '.join(words))
        wbag = string.split()
        
        if htags:
            for v in htags.keys():
                wbag.insert(v, htags[v])
            
        string = ' '.join(wbag)
        if string and not string.isspace():
            return string.strip()
        else:
            return None
    except Exception as e:
        print e
        return None
Пример #8
0
        ready_baby = ' '.join(cleaned_string)
        return ready_baby

result = string_cleaner(test_string)

print(' '.join([s for s in test_string.split(' ') if s and s not in string.whitespace]))



# -------------- Use Function isspace 
def string_cleaner(str):
    cleaned_string = []
    string_separated = str.split(' ')
    for word in string_separated:
        if word:
            if word.isspace():
                del word
            else:
                cleaned_string.append(word)

    ready_baby = ' '.join(cleaned_string)
    return ready_baby


result = string_cleaner(test_string)

print(result)

print(' '.join([string for string in test_string.split(' ') if string and not string.isspace()]))
Пример #9
0
 def priority(string):
     if not string:
         return 0
     elif string.isspace():
         return 1
     return 2
Пример #10
0
 def priority(string):
     if not string:
         return 0
     elif string.isspace():
         return 1
     return 2
Пример #11
0
# isspace()
'''
 |  isspace(...)
 |      S.isspace() -> bool
 |      
 |      Return True if all characters in S are whitespace
 |      and there is at least one character in S, False otherwise.
'''
# is space: ' ' Space, '\t' Horizontal Tab, '\n' New Line, '\r' Carriage Return, '\x0b' Vertical Tab, '\x0c' Vertical Tab, '\v' Vertical Tab
import string
print(repr(string.whitespace))
string = "     "
print("The string '%s' is space? %s" % (string, string.isspace()))
string = "\t"
print("The raw representation of the string is '%s'" % repr(string))
print("The string '%s' is space? %s" % (string, string.isspace()))
string = '\n'
print("The raw representation of the string is '%s'" % repr(string))
print("The string '%s' is space? %s" % (string, string.isspace()))
string = '\x0b'
print("The raw representation of the string is '%s'" % repr(string))
print("The string '%s' is space? %s" % (string, string.isspace()))
string = "\x0c"
print("The raw representation of the string is '%s'" % repr(string))
print("The string '%s' is space? %s" % (string, string.isspace()))
string = "a"
print("The string '%s' is space? %s" % (string, string.isspace()))
string = "1"
print("The string '%s' is space? %s" % (string, string.isspace()))
string = "@"
print("The string '%s' is space? %s" % (string, string.isspace()))