我正在尝试使用Python制作程序。
我希望能够通过其他程序管道程序:
" #EXAMPLE " ./my_python | another programme "
这是我到目前为止的代码。
此代码将输出保存到文件:
#!/usr/bin/env python
import os, random, string
# This is not my own code
''' As far asi know, It belongs to NullUserException. Was found on stackoverflow.com'''
length = 8
chars = string.ascii_letters.upper()+string.digits
random.seed = (os.urandom(1024))
# my code
file_out = open('newRa.txt','w') # Create a 'FILE' to save Generated Passwords
list1=[]
while len(list1) < 100000:
list1.append(''.join(random.choice(chars) for i in range(length)))
for item in list1:
file_out.write('%s\n' % item)
file_out.close()
file_out1=open('test.txt','w')
for x in list1:
file_out1.write('%s\n' %x[::-1])
这是我试图通过另一个程序管道的代码:
#!/usr/bin/env python
import os,string,random,sys
length = 8
chars = string.ascii_letters.upper()+string.digits
random.seed = (os.urandom(1024))
keep=[]
keep1=[]
while len(keep)<1000:
keep.append(''.join(random.choice(chars) for i in range(length)))
print '\n',keep[::-1]
for x in keep:
keep1.append(x[::-1])
while len(keep1) < 1000:
print keep1
我尝试过chmod并将脚本用作可执行文件。
答案 0 :(得分:0)
很抱歉我没有谷歌搜索。
sys.stdout就是答案
#!/usr/bin/env python
import os,string,random,sys
length = 8
chars = string.ascii_letters.upper()+string.digits
random.seed = (os.urandom(1024))
keep=[]
while len(keep)<1000:
keep = (''.join(random.choice(chars) for i in range(length)))
print sys.stdout.write(keep)
sys.stdout.flush()
我删除了我的代码(因为它使得它更快,但我在执行时得到了这个 我的代码........ P5DBLF4KNone
DVFV3JQVNone
CIMKZFP0None
UZ1QA3HTNone
如何摆脱“无”&#39;最后?
我做了什么导致这个?
Should This Be A Seperate Question??