Python sys.stdin 模块,encoding() 实例源码
我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用sys.stdin.encoding()。
def _classify_many(self, featuresets, options):
# Make sure we can find java & weka.
config_weka()
temp_dir = tempfile.mkdtemp()
try:
# Write the test data file.
test_filename = os.path.join(temp_dir, 'test.arff')
self._formatter.write(test_filename, featuresets)
# Call weka to classify the data.
cmd = ['weka.classifiers.bayes.NaiveBayes',
'-l', self._model, '-T', test_filename] + options
(stdout, stderr) = java(cmd, classpath=_weka_classpath,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
# Check if something went wrong:
if stderr and not stdout:
if 'Illegal options: -distribution' in stderr:
raise ValueError('The installed version of weka does '
'not support probability distribution '
'output.')
else:
raise ValueError('Weka Failed to generate output:\n%s'
% stderr)
# Parse weka's output.
return self.parse_weka_output(stdout.decode(stdin.encoding).split('\n'))
finally:
for f in os.listdir(temp_dir):
os.remove(os.path.join(temp_dir, f))
os.rmdir(temp_dir)
def _classify_many(self, f))
os.rmdir(temp_dir)
def _classify_many(self, f))
os.rmdir(temp_dir)
def cat(lang):
"""
Translate any text into Greeklish by [typing + enter]
@param lang: a string to check which mode to activate {'greek',anything}
"""
if lang == 'greek':
while True:
try:
text = raw_input().decode(stdin.encoding
or locale.getpreferredencoding(True))
new_data = to_greeklish(list(text))
print ''.join(new_data)
except KeyboardInterrupt:
print '\nexit'
exit()
else:
while True:
try:
text = raw_input().decode(stdin.encoding
or locale.getpreferredencoding(True))
translated = Translator().translate(''.join(text), dest='el')
new_data = to_greeklish(list(unicode(translated.text)))
print ''.join(new_data)
except KeyboardInterrupt:
print '\nexit'
exit()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。