我们从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 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()