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
ファイル: processor.py プロジェクト: gaphex/Oracle
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
ファイル: bibutils.py プロジェクト: mjpost/bibsearch
 def priority(string):
     if not string:
         return 0
     elif string.isspace():
         return 1
     return 2
コード例 #10
0
ファイル: algo.py プロジェクト: aclements/biblib
 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()))