当前位置: 首页>>代码示例>>Python>>正文


Python Stack.get方法代码示例

本文整理汇总了Python中stack.Stack.get方法的典型用法代码示例。如果您正苦于以下问题:Python Stack.get方法的具体用法?Python Stack.get怎么用?Python Stack.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stack.Stack的用法示例。


在下文中一共展示了Stack.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: FOG

# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import get [as 别名]
class FOG(object):

	# Main

	def __init__(self):
		self.reg = 0
		self.continue_count = 0
		self.idx = 0
		self.temp = None
		self.active = Stack()
		self.inactive = Stack()
		self.input_num = 1
		self.input = []
		self.exit = False
		self.implicit_output = False
		
		self.commands = {
			"^": self._input,#              ^_^
			"ಠ": self._swap_stacks,#        ಠ_ಠ
			".": self._swap_stacks,#        ._.
			"_": self._pop,
			":": self._print_all,#          :_:
			"o": self._peek,#               o_O
			";": self._print_register,#     ;_;
			"{": self._skip,#               {_{
			"@": self._exit,#               @[email protected]
			"+": self._increment,#          +_+
			"-": self._decrement,#          -_-
			"?": self._increment_register,# ?_?
			"c": self._clear,#              c_c
			'"': self._string_lit,#         "_
			"(": self._infinite_loop,#      (_(
			"[": self._for_loop,#           [_[
			"!": self._set_register,#       !_!
			"U": self._zero,#               U_U
			"N": self._none,#               N_N
			"K": self._unk,#                K_K
			"I": self._interleave,#         I_I
			")": self._noop,#               )_)
			"}": self._noop,#               }_}
			"]": self._noop,#               ]_]
			" ": self._noop,
			"'": self._string_lit2,#        '_'
			">": self._noop,#               >_>
			"🐐": self._goat,#             🐐 _🐐
			"g": self._goat,#               g_g
			"=": self._rocket,#             =_=
			"<": self._list,#               <_<
			"s": self._switch,#             s_s 
			"i": self._invert,#             i_i
			"e": self._error, #             e_e
			"r": self._clear_register,#     r_r
			"a": self._add,#                a_a
			"R": self._replace,#            R_R
			"C": self._copy,#               C_C
			"j": self._join,#               j_j
			"&": self._split,#              &_&
			"z": self._reverse,#            z_z
			"*": self._mult,#               *_*
			"S": self._subtract,#           S_S
			"Z": self._reverse_stack,#      Z_Z
			"p": self._power,#              p_p
			"d": self._dupe,#               d_d
			"t": self._push_temp,#          t_t
			"|": self._random,#             |_|
			"P": self._pi,#                 P_P
			"π": self._pi,#                 π_π
			"/": self._divide,#             /_/
			"T": self._trig,#               T_T
			"l": self._rotate_right,#       l_l
			"L": self._rotate_left,#        L_L
			"%": self._swap_two,#           %_%
			"X": self._print_top,#          X_X
			"$": self._range,#              $_$
			"#": self._comment,#            #_#
			"m": self._modulus,#            m_m
			"~": self._complement,#         ~_~
			"E": self._e,#                  E_E
			"O": self._log,#                O_O
			"o": self._assign,#             o_o
			"n": self._newline,#            n_n
			"D": self._noop,#               D_D
			"W": self._wipe,#               W_W
		}

	def get_code(self):
		if "--file" in sys.argv:
			code = open(sys.argv[sys.argv.index("--file") + 1]).read()

			input_index = sys.argv.index("--file")

			sys.argv.pop(sys.argv.index("--file") + 1)
			sys.argv.pop(sys.argv.index("--file"))

		elif len(sys.argv) >= 2:
			code = sys.argv[1]
			input_index = 2
		else:
			code = input("Code: ")

#.........这里部分代码省略.........
开发者ID:RikerW,项目名称:Fuzzy-Octo-Guacamole,代码行数:103,代码来源:main.py

示例2: Gaot

# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import get [as 别名]
class Gaot(object):
    def __init__(self):
        self.stack = Stack([])
        self.instructions = None
        self.ipointer = 0
        self.move = 1
        self.BAA = re.compile(r"ba{2,}")
        self.BLEET = re.compile(r"ble{2,}t")

        self.commands = [
            self._add,  # 2
            self._subtract,  # 3
            self._continue,  # 4
            self._exit,  # 5
            self._reverse,  # 6
            self._skiptrue,  # 7
            self._skipfalse,  # 8
            self._printnum,  # 9
            self._printchar,  # 10
            self._getnum,  # 11
            self._getchar,  # 12
            self._dupe,  # 13
            self._swap,  # 14
            self._reverse_stack,  # 15
            self._rotate_stack,
        ]  # 16
        self.ccount = 0

    def run(self, program):
        self.instructions = program.split()
        while self.ipointer < len(self.instructions):
            c = self.instructions[self.ipointer]

            if self.BAA.search(c):  # is a "baa" command
                self.stack.append(len(c) - 2)

            elif self.BLEET.search(c):  # is a "bleet" command
                n = len(c) - 3
                self.commands[n - 2]()
            self.ipointer += self.move

    def get_code(self):
        if "--file" in sys.argv:
            code = open(sys.argv[sys.argv.index("--file") + 1]).read()

            input_index = sys.argv.index("--file")

            sys.argv.pop(sys.argv.index("--file") + 1)
            sys.argv.pop(sys.argv.index("--file"))

        elif len(sys.argv) >= 2:
            code = sys.argv[1]
            input_index = 2
        else:
            code = raw_input("Code: ")

        try:
            self.input = sys.argv[input_index:]
        except:
            self.input = []
        return code

        # --------------------------------------

    def _add(self):
        self.stack.push(self.stack.pop() + self.stack.pop())

    def _subtract(self):
        self.stack.push(self.stack.pop() - self.stack.pop())

    def _continue(self):
        self.ipointer += self.move

    def _exit(self):
        exit()

    def _reverse(self):
        self.move *= -1

    def __skip(self, state):
        self.ipointer += self.move * (self.stack.pop() == state)

    def _skiptrue(self):
        self.__skip(True)

    def _skipfalse(self):
        self.__skip(False)

    def _printnum(self):
        sys.stdout.write(unicode(self.stack.pop()))
        sys.stdout.flush()

    def _printchar(self):
        sys.stdout.write(unicode(chr(self.stack.pop())))
        sys.stdout.flush()

    def _getnum(self):
        self.stack.push(float(raw_input()))

    def _getchar(self):
#.........这里部分代码省略.........
开发者ID:RikerW,项目名称:gaot,代码行数:103,代码来源:main.py


注:本文中的stack.Stack.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。