本文整理汇总了Python中sys.stdin.read函数的典型用法代码示例。如果您正苦于以下问题:Python read函数的具体用法?Python read怎么用?Python read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: readpipe
def readpipe() -> str:
"""Read from a pipe"""
while True:
_input = ''
_data = stdin.read(1)
while _data:
_input += _data
_data = stdin.read(1)
return str(_input)
开发者ID:kaiHooman,项目名称:Pybooster,代码行数:9,代码来源:fs.py
示例2: readpipe
def readpipe() -> str:
"""Read from pipe"""
while True:
_input = ''
_character = stdin.read(1)
while _character:
_input += _character
_character = stdin.read(1)
return str(_input)
开发者ID:kaiHooman,项目名称:Pybooster,代码行数:9,代码来源:ezdisplay.py
示例3: read
def read(self):
self.alive = True
self.writer_thread.start()
ch = stdin.read(1)
while ch != '#':
self.sp.write(ch)
ch = stdin.read(1)
self.alive = False
self.sp.write(' ')
self.writer_thread.join()
开发者ID:jisanch1,项目名称:sepial,代码行数:10,代码来源:terminal.py
示例4: alter
def alter(self, message, arguments):
"""
Performs operations specified in the arguments to modify the message in
whatever way.
"""
message = message.copy()
# Entity
if arguments.entity:
message["entity"] = arguments.entity
if arguments.readEntity:
message["entity"] = open(arguments.readEntity, "r").read()
if arguments.entityStdin:
message["entity"] = stdin.read()
if arguments.appendEntity:
message["entity"] += arguments.appendEntity
if arguments.appendEntityStdin:
message["entity"] += stdin.read()
if arguments.appendEntityFile:
message["entity"] += open(arguments.appendEntityFile, "r").read()
# Top-line
if arguments.version:
message["version"] = arguments.version
if arguments.method:
message["method"] = arguments.method.upper()
if arguments.path:
message["path"] = arguments.path
if arguments.status:
message["status"] = arguments.status
if arguments.reason:
message["reason"] = arguments.reason.upper()
# Headers
for header in arguments.header:
message["headers"] = setValuesByName(message["headers"], *header)
if arguments.host:
message["headers"] = setValuesByName(message["headers"], "Host", arguments.host)
if arguments.auto: # obviously must come after entity
message["headers"] = setValuesByName(
message["headers"],
"Content-length",
str(len(message["entity"]))
)
return message
开发者ID:xmnr,项目名称:atk,代码行数:50,代码来源:command.py
示例5: getch
def getch():
stdout.flush()
fd=stdin.fileno()
if isatty(fd):
oldset=tcgetattr(fd)
newset=oldset[:]
try:
newset[3]&=-11
tcsetattr(fd, TCSANOW, newset)
return ord(stdin.read(1))
finally:tcsetattr(fd, TCSANOW, oldset)
else:
fd=stdin.read(1)
return ord(fd) if fd else -1
开发者ID:serprex,项目名称:Befunge,代码行数:14,代码来源:funge.py
示例6: _windows_shell
def _windows_shell(self, chan):
import threading
stdout.write("Line-buffered terminal emulation. Press F6 or ^Z to send EOF.\r\n\r\n")
def writeall(sock):
while True:
data = sock.recv(256)
if not data:
stdout.write("\r\n*** EOF ***\r\n\r\n")
stdout.flush()
break
stdout.write(data)
stdout.flush()
writer = threading.Thread(target=writeall, args=(chan,))
writer.start()
try:
while True:
d = stdin.read(1)
if not d:
break
chan.send(d)
except EOFError:
# user hit ^Z or F6
pass
开发者ID:roadlabs,项目名称:buildozer,代码行数:27,代码来源:__init__.py
示例7: main
def main():
answers = ans
def ansans(n):
return answers[n - 1]
print '\n'.join(map(ansans, map(int, stdin.read().split())))
开发者ID:eightnoteight,项目名称:compro,代码行数:7,代码来源:qcj2.py
示例8: write_command
def write_command(server, command):
# write the command
server.stdin.write('runcommand\n')
writeblock(server, command)
# receive the response
while True:
channel, val = readchannel(server)
if channel == 'o':
print val.rstrip()
elif channel == 'e':
print 'error: %s' % val.rstrip()
elif channel == 'r':
r = unpack(">l", val)[0]
if r is not 0:
print 'ERROR %s' % r
break
elif channel == 'L':
print '(line read request)'
writeblock(server, stdin.readline(val))
elif channel == 'I':
print '(block read request)'
writeblock(server, stdin.read(val))
else:
print 'unexpected channel: %s %s' % (channel, val)
if channel.isupper(): # required?
break
开发者ID:brachior,项目名称:Android-292,代码行数:27,代码来源:aosp.py
示例9: main
def main():
dstream = imap(float, stdin.read().split())
try:
for a, b, s, m, n in izip(dstream, dstream, dstream, dstream, dstream):
print "%.2f %.2f" % (degrees(atan2(n*b, m*a)), sqrt((m*a / s)**2 + (n*b / s)**2))
except ZeroDivisionError:
pass
开发者ID:eightnoteight,项目名称:compro,代码行数:7,代码来源:billiard.py
示例10: main
def main():
fpp = [
0, 3, 5, 11, 17, 2, 2, 5, 11, 19, 23, 23, 197, 307, 359, 521, 1553,
2693, 3083, 419, 953, 5, 11, 13, 5, 7, 53, 107, 131, 103, 359, 419, 223,
613, 541, 691, 151, 593, 1069, 1321, 1193, 3083, 311, 1619, 1543, 4813,
5519, 23, 61, 151, 307, 359, 23, 197, 593, 827, 2789, 5443, 9311, 1427,
1427, 5039, 13249, 4813, 13697, 6857, 19447, 4211, 4211, 38197, 12197,
521, 1553, 1931, 853, 3083, 2693, 11353, 3083, 6857, 23789, 6007, 53881,
60761, 51713, 111599, 72871, 100169, 244691, 134587, 248851, 288359,
127081, 272141, 424243, 4127, 419, 5519, 12197, 49681, 10627, 36677,
79349, 109037, 124181, 202987, 57559, 124181, 229727, 127081, 222863,
373019, 170627, 364523]
pp = [
0, 2, 3, 5, 7, 11, 101, 131, 151, 181, 191,
313, 353, 373, 383, 727, 757, 787, 797, 919, 929, 10301, 10501, 10601, 11311,
11411, 12421, 12721, 12821, 13331, 13831, 13931, 14341, 14741, 15451, 15551,
16061, 16361, 16561, 16661, 17471, 17971, 18181, 18481, 19391, 19891, 19991,
30103, 30203, 30403, 30703, 30803, 31013, 31513, 32323, 32423, 33533, 34543,
34843, 35053, 35153, 35353, 35753, 36263, 36563, 37273, 37573, 38083, 38183,
38783, 39293, 70207, 70507, 70607, 71317, 71917, 72227, 72727, 73037, 73237,
73637, 74047, 74747, 75557, 76367, 76667, 77377, 77477, 77977, 78487, 78787,
78887, 79397, 79697, 79997, 90709, 91019, 93139, 93239, 93739, 94049, 94349,
94649, 94849, 94949, 95959, 96269, 96469, 96769, 97379, 97579, 97879, 98389,
98689]
print '\n'.join(["%s %s" % (pp[n], fpp[n]) for n in map(int, stdin.read().split()[1:])])
开发者ID:eightnoteight,项目名称:compro,代码行数:25,代码来源:mb1.py
示例11: main
def main():
nextint = iter(map(int, stdin.read().split())).next
# next = iter(stdin.read().split()).next
nk, q = nextint(), nextint()
temp = 0
Qu = [(nextint(), nextint() + 1, nextint()) for _ in xrange(q)]
ends = []
temps = {}
for k, it in groupby(sorted(Qu), key=itemgetter(0)):
while ends and ends[0][0] <= k:
e = heappop(ends)
temp -= e[1]
temps[e[0]] = temp
for _, y, i in it:
temp += i
heappush(ends, (y, i))
temps[k] = temp
while ends:
e = heappop(ends)
temp -= e[1]
temps[e[0]] = temp
assert temp == 0
tot = 0
xxx = sorted(temps.items())
for (x1, y1), (x2, y2) in zip(xxx, xxx[1:]):
if y1 >= nk:
tot += x2 - x1
print tot
开发者ID:eightnoteight,项目名称:compro,代码行数:28,代码来源:4.py
示例12: main
def main():
out = bytearray()
try:
dstream = imap(int, stdin.read().split())
for _ in xrange(1000000000):
n = next(dstream)
arr = [(0, next(dstream)) for _ in xrange(n)]
dp = [[(float('inf'), float('inf'))]*x for x in xrange(1, len(arr))]
dp.append(arr)
for x in xrange(n - 2, -1, -1):
for y in xrange(x + 1):
lo, hi = y, y + n - x
for lhi in xrange(lo + 1, hi):
dp[n - (hi - lo)][lo] = min(
dp[n - (hi - lo)][lo],
(
dp[n - (lhi - lo)][lo][0] +
dp[n - (hi - lhi)][lhi][0] +
(
dp[n - (lhi - lo)][lo][1] *
dp[n - (hi - lhi)][lhi][1]),
(
dp[n - (lhi - lo)][lo][1] +
dp[n - (hi - lhi)][lhi][1]) % 100
)
)
out.extend(bytes(dp[0][0][0]))
out.append('\n')
except StopIteration:
print out
开发者ID:eightnoteight,项目名称:compro,代码行数:32,代码来源:mixtures.py
示例13: main
def main():
nextint = map(int, stdin.read().split()).__next__
n, m = nextint(), nextint()
graph = [defaultdict(int) for _ in range(n)]
for _ in range(m):
graph[nextint() - 1][nextint() - 1] += 1
print(" ".join(map(str, topological_sort(graph))))
开发者ID:eightnoteight,项目名称:compro,代码行数:7,代码来源:toposort.py
示例14: main
def main():
fibs = [
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584,
4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811,
514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352,
24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437,
701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049,
12586269025, 20365011074, 32951280099, 53316291173, 86267571272,
139583862445, 225851433717, 365435296162, 591286729879, 956722026041,
1548008755920, 2504730781961, 4052739537881, 6557470319842, 10610209857723,
17167680177565, 27777890035288, 44945570212853, 72723460248141, 117669030460994,
190392490709135, 308061521170129, 498454011879264, 806515533049393, 1304969544928657]
def nbin(n):
if n == 0:
return '0'
num = bytearray()
for x in xrange(bisect(fibs, n - 1), -1, -1):
if fibs[x] <= n:
num.append('1')
n -= fibs[x]
else:
num.append('0')
return str(num).lstrip('0')
dstream = map(int, stdin.read().split())
print '\n'.join([nbin(dstream[x]) for x in xrange(1, dstream[0] + 1)])
开发者ID:eightnoteight,项目名称:compro,代码行数:27,代码来源:nbin.py
示例15: main
def main():
def extended_gcd(aa, bb):
lastr, remainder = abs(aa), abs(bb)
x, lastx, y, lasty = 0, 1, 1, 0
while remainder:
lastr, (quotient, remainder) = remainder, divmod(lastr, remainder)
x, lastx = lastx - quotient * x, x
y, lasty = lasty - quotient * y, y
return lastr, lastx * (-1 if aa < 0 else 1), lasty * (-1 if bb < 0 else 1)
def modinv(a, m):
g, x, _ = extended_gcd(a, m)
if g != 1:
raise ValueError
return x % m
dstream = map(int, stdin.read().split())
dstream.pop()
dstream.pop()
dstream = iter(dstream)
out = []
m = 1000000007
for n, l in zip(dstream, dstream):
out.append(str((n*(pow(n, l, m) - 1)*modinv(n - 1, m)) % m))
print '\n'.join(out)
开发者ID:eightnoteight,项目名称:compro,代码行数:25,代码来源:ucv2013a.py
示例16: main
def main():
# Read the file in through standard input
f = stdin.read()
# Use regex to find text
n = re.findall(r'[a-zA-Z0-9]{3,}', f)
wordList = []
# Read in each line of the file and print out the words that are found
for line in n:
# If words found, save to a string var and print them
if line:
words = str.split(line)
for word in words:
if not word.isdigit() and not word=="" and not word==" ":
for char in badchars:
if char in word:
break
else:
wordList.append(word)
for i in range(len(wordList)-1):
print wordList[i] + ',' + wordList[i+1] + '\t' + '1'
开发者ID:tDeranek117,项目名称:CSE-Notre-Dame,代码行数:27,代码来源:BigramsMapper.py
示例17: main
def main(compiler):
text = stdin.read().decode('utf8')
parser = Parser(text, compiler)
try:
parser()
except LexError as e:
print >>stderr, e.pprint()
开发者ID:xiaq,项目名称:jadepy,代码行数:7,代码来源:parse.py
示例18: main
def main():
dstream = imap(int, stdin.read().split())
mod = 1000000007
for case in xrange(1, next(dstream) + 1):
m, l = next(dstream), next(dstream)
print "Case %s: %s" % (case,
((((pow(m, l + 1, mod) - 1) % mod)*(pow(m - 1, mod - 2, mod))) % mod) if m != 1 else l + 1)
开发者ID:eightnoteight,项目名称:compro,代码行数:7,代码来源:najtree.py
示例19: main
def main():
nextitem = iter(stdin.read().split()).next
n, m = int(nextitem()), int(nextitem())
regs = [[] for _ in xrange(m)]
for _ in xrange(n):
sur, r, s = nextitem(), int(nextitem()), int(nextitem())
regs[r - 1].append((s, sur))
out = []
for x in xrange(m):
regs[x].sort(reverse=True)
for i, (x, it) in izip((0, 1), groupby(regs[x], key=itemgetter(0))):
if i == 0:
items = list(it)
k = len(items)
if k > 2:
out.append('?')
break
elif k == 2:
out.append(items[0][1] + ' ' + items[1][1])
break
else:
out.append(items[0][1])
else:
items = list(it)
k = len(items)
if k > 1:
out[-1] = '?'
break
else:
out[-1] += ' ' + items[0][1]
print '\n'.join(out)
开发者ID:eightnoteight,项目名称:compro,代码行数:31,代码来源:b.py
示例20: test_some_datasets
def test_some_datasets(self):
'''query the datasets defined im commands'''
commands = ['CPU_CORE_COUNT', 'CPU_SPEED', 'CPU_TYPE']
for i in commands:
self.assertTrue(i in self.c.list_available_dataitems())
self.commands = commands
def callback(result):
print("test_some_datasets callback function: %s" % result)
self.assertEquals(result['identifier1'], self.localip)
self.assertEquals(result['identifier2'], self.remoteip)
found = False
for i in self.commands:
if i in result:
self.commands.remove(i)
found = True
if not found:
print("unknown field in result %s" % result)
self.assertTrue(False)
for i in commands:
#invalid orderird fixed in Client
order = {'orderid': 'invalid', 'identifier1':self.localip,
'identifier2':self.remoteip, 'type':'oneshot',
'dataitem':i}
self.c.commit_order(order, callback)
print("press any key ....")
ch = stdin.read(1)
self.assertEquals(self.commands, [])
开发者ID:e110c0,项目名称:unisono,代码行数:32,代码来源:connection_interactive_test.py
注:本文中的sys.stdin.read函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论