2012-02-11 18 views
7

मैं निम्नलिखित कोड है: जब मैं python ./pypy/pypy/translator/goal/translate.py t.py चलानेRPython sys विधियां काम नहीं करती

import sys 

def entry_point(argv): 
    sys.exit(1) 
    return 0 

def target(*args): 
    return entry_point, None 

हालांकि, मैं प्राप्त निम्न त्रुटि:

... 
[translation:ERROR] Exception: unexpected prebuilt constant: <built-in function exit> 
[translation:ERROR] Processing block: 
[translation:ERROR] [email protected] is a <class 'pypy.objspace.flow.flowcontext.SpamBlock'> 
[translation:ERROR] in (t:3)entry_point 
[translation:ERROR] containing the following operations: 
[translation:ERROR]  v0 = simple_call((builtin_function_or_method exit), (1)) 
[translation:ERROR] --end-- 

था वास्तव में त्रुटि के लिए और अधिक लेकिन मैंने सोचा कि केवल यह अंतिम हिस्सा प्रासंगिक था। यदि आपको लगता है कि इससे अधिक उपयोगी हो सकता है, तो कृपया टिप्पणी करें और मैं संपादित करूंगा।

वास्तव में, जब मैं sys.exdit को sys.stdout.write की तरह कुछ भी सरल के साथ बदलता हूं तो मुझे एक और त्रुटि मिलती है।

import sys 

def entry_point(argv): 
    sys.stdout.write('some mesg\n') 
    return 0 

def target(*args): 
    return entry_point, None 

मुझे देता है:

... 
[translation:ERROR] AnnotatorError: annotation of v0 degenerated to SomeObject() 
[translation:ERROR] v0 = getattr((module sys), ('stdout')) 
[translation:ERROR] 
[translation:ERROR] In <FunctionGraph of (t:3)entry_point at 0x10d03de10>: 
[translation:ERROR] Happened at file t.py line 4 
[translation:ERROR] 
[translation:ERROR] ==>  sys.stdout.write('some mesg\n') 
[translation:ERROR] 
[translation:ERROR] Previous annotation: 
[translation:ERROR] (none) 
[translation:ERROR] Processing block: 
[translation:ERROR] [email protected] is a <class 'pypy.objspace.flow.flowcontext.SpamBlock'> 
[translation:ERROR] in (t:3)entry_point 
[translation:ERROR] containing the following operations: 
[translation:ERROR]  v0 = getattr((module sys), ('stdout')) 
[translation:ERROR]  v1 = getattr(v0, ('write')) 
[translation:ERROR]  v2 = simple_call(v1, ('some mesg\n')) 
[translation:ERROR] --end-- 

sys तरीकों बस RPython के लिए सीमा बंद कर रहे हैं? ऐसा लगता है कि मेरे लिए अजीब लगता है क्योंकि बाहर निकलने और stdout सी में इतनी आसानी से उपलब्ध हैं। हालांकि, त्रुटि संदेशों की तरह दिखती है कि वे अलग-अलग चीजों के बारे में हो सकते हैं, इसलिए मैं सिर्फ गलत पेड़ को भौंकने वाला हो सकता हूं।

वर्तमान में मैं this का उपयोग कर रहा हूं ताकि यह पता लगाया जा सके कि RPython में क्या अनुमति है और अनुमति नहीं है। क्या अन्य जानकारी के लिए मैं अन्य सुलभ संदर्भों का उपयोग कर सकता हूं?

+2

क्षमा करें, मैं आगे की मदद नहीं कर सकता, लेकिन मुझे यह इंगित करने की अनुमति देता है कि आखिरी उदाहरण गलत है जिसे आपको प्रतिस्थापित करना चाहिए: 'sys.std.write'' sys.stdout.write' द्वारा, कोई 'sys.std नहीं है पाइथन में – mouad

+0

@mouad इसे इंगित करने के लिए धन्यवाद। मैंने इसे फिर से कोशिश की और अद्यतन त्रुटि संदेश पोस्ट किया। – math4tots

उत्तर

9

sys मॉड्यूल RPython नहीं है, आप इसे RPython प्रोग्राम में उपयोग नहीं कर सकते हैं। एक स्टेटस कोड वापस करने के लिए आपको इसे सीधे एंट्री_पॉइंट फ़ंक्शन से वापस करना होगा।

आप sys.stdout/sys.stdin/sys.stderr का भी उपयोग नहीं कर सकते हैं, आपको फ़ाइल विवरणकर्ता के साथ os.read/os.write फ़ंक्शंस का उपयोग करके पढ़ने/लिखने की आवश्यकता होगी।

+0

यदि sys उपलब्ध नहीं है, तो मैं stdin/stdout फ़ाइल डिस्क्रिप्टर कैसे प्राप्त करूं ताकि मैं उन्हें os.read पर पास कर सकूं? कच्चे_इनपुट/प्रिंट के माध्यम से stdin/stdout प्राप्त करने का एकमात्र तरीका हैं? – math4tots

+0

stdin = 0, stdout = 1, stderr = 2. आप उन पूर्णांक तर्कों के साथ os.write/os.read को कॉल कर सकते हैं। –

संबंधित मुद्दे