コード例 #1
0
ファイル: fterm.py プロジェクト: Ninja-1/Circle2
    def on_key_release(self, _w,_e):
        if not self.app.config['augmented_text']:
            return

        if not self.key_presses.has_key(_e.keyval):
            return

        press_time, offset = self.key_presses[_e.keyval]
        del self.key_presses[_e.keyval]

        string = utility.force_unicode(_e.string)
        if not string or \
           ord(string) < 32:
             return

        if offset < 0 or offset >= len(self.augmentation):
            return

        if string.isalpha():
            interval = (_e.time - press_time) / 1000.0
            level = int( interval*4 *255)
            if level < 0: level = 0
            if level > 255: level = 255
        else:
            level = 128

        tag = "aug" + str(level/16)
        iter1 = self.buffer.get_iter_at_offset(self.prompt_end+offset)
        iter2 = iter1.copy()
        iter2.forward_char()
        self.augmentation = self.augmentation[:offset] + \
                            chr(level) + \
                            self.augmentation[offset+1:]
        self.buffer.remove_all_tags(iter1,iter2)
        self.buffer.apply_tag_by_name(tag,iter1,iter2)
コード例 #2
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()
コード例 #3
0
def string_run_compress(strings):
    curr = ""
    out = ""
    for string in strings:
        assert string.isalpha() and string.lower() == string
        d = 0
        while not string.startswith(curr):
            curr = curr[:-1]
            d += 1
        assert d <= 32
        out += b64[d]
        for i in range(len(curr), len(string)):
            curr += string[i]
            out += string[i]
    return out.strip()
コード例 #4
0
def generate_alphanumerics():
    """Utilize uuid4, then stripping all "-" and slicing the string randomly
    Returns:
        string: an alphanumeric string
    """
    length_of_string = generate_random_integer(MIN_LENGTH_OF_ALPHANUMERIC,
                                               MAX_LENGTH_OF_ALPHANUMERIC)

    string = str(uuid4()).replace("-", "")[:length_of_string]

    # Handle case if the uuid output is not alphanumeric after slicing else just return
    if string.isdigit():
        return string + generate_alphabetical_strings()
    elif string.isalpha():
        return string + str(generate_random_integer(MIN_LENGTH, MIN_LENGTH))
    else:
        return string
コード例 #5
0
reviewWords.index("pickle")
-46 # the word position
review.find("pickle")
-238 #charactersinto review that the word appears
review.count("love")
-2
review.lower().count("love")
-3

string.punctuation
[x for x in review if not x in string.punctuation]
''.join([x for x in review if not x in string.punctuation])

string.startswith()(etc.)
string.endswith()(etc.)
string.isalpha()
string.strip()
string.lstrip()
string.rstrip()

#L3 Processing Times and Dates in Python
# Time.strptime : convert a time string to a structured time object
# Time.strftime : convert a time object to a string
# Time.maketime/calendar.timegem: convert a time object to a number
# Time.gmtime: convert a number to a time object
import time
import calendar
timeString = "2018-07-26 01:36:02"
timeStruct = time.strptime(timeString, "%Y-%m-%d %H:%M:%S")
timeStruct
[out]:time.struct_time(tm_year=2018, tm_mon=7, tm_mday=26, tm_hour=1,tm_min=36, tm_sec=2, tm_wday=3, tm_yday=207, im_isdst=-1)
コード例 #6
0
ファイル: rotate_word.py プロジェクト: clara0/learn-python
alphabet = string.ascii_lowercase


def rotateLetter(letter, rotateNum):
    if letter in alphabet:
        newLetterIndex = alphabet.find(letter) + rotateNum
        finalNewLetterIndex = newLetterIndex - (newLetterIndex //
                                                len(alphabet)) * len(alphabet)
        return alphabet[finalNewLetterIndex]


def rotate(word, rotateNum):
    newWord = ''

    for letter in word.lower():
        newWord = newWord + (rotateLetter(letter, rotateNum))

    return newWord


if __name__ == '__main__':
    while True:
        string = input('Enter a word: ').strip()
        if string.isalpha():
            num = input('Enter a number: ').strip()
            try:
                result = rotate(string, int(num))
                print(result)
            except:
                continue
コード例 #7
0
# isalpha()
'''
 |  isalpha(...)
 |      S.isalpha() -> bool
 |      
 |      Return True if all characters in S are alphabetic
 |      and there is at least one character in S, False otherwise.
'''
# Alphabetic: abc...zABC...Z
import string
print(string.ascii_letters)
string = "This"
print("Is all alphanumeric in the string '%s'? %s" %
      (string, string.isalpha()))
string = "This123"
print("Is all alphanumeric in the string '%s'? %s" %
      (string, string.isalpha()))
string = "This@"
print("Is all alphanumeric in the string '%s'? %s" %
      (string, string.isalpha()))
string = ""
print("Is all alphanumeric in an empty string '%s'? %s" %
      (string, string.isalpha()))
string = "123@"
print("Is all alphanumeric in the string '%s'? %s" %
      (string, string.isalpha()))
string = "1 2 3"
print("Is all alphanumeric in the string '%s'? %s" %
      (string, string.isalpha()))
string = " "
print("Is all alphanumeric in the string '%s'? %s" %
コード例 #8
0
def isAlphaLower(string):
    """Return True if string only contains lower case letters."""
    return string.islower() and string.isalpha()
コード例 #9
0
def isAlphaUpper(string):
    """Return True if string only contains capital letters."""
    return string.isupper() and string.isalpha()
コード例 #10
0
def isAlpha(string):
    """Return True if string only contains letters."""
    return string.isalpha()
コード例 #11
0
def check_name(string):
    if string.isalpha():
        return 1
    else:
        return 0