Wednesday 13 December 2017

Stringio बाइनरी विकल्प


एक द्विपदीय ट्रेडिंग द्विआधारी विकल्प के लिए यूएस बाइनरी विकल्प में एक साधारण हां या कोई प्रस्ताव पर आधारित नहीं हैं: क्या किसी अंतर्निहित परिसंपत्ति किसी निश्चित समय पर एक निश्चित कीमत से ऊपर होगी, ट्रेडर्स स्थान ट्रेडों, चाहे वे मानते हों कि इसका उत्तर हां या नहीं है, यह व्यापार करने के लिए सरलतम वित्तीय संपत्तियों में से एक है इस सादगी के कारण व्यापारियों और नए लोगों के बीच वित्तीय बाजारों में व्यापक अपील हुई है। जैसा कि ऐसा लगता है कि सरल है, व्यापारियों को पूरी तरह से समझना चाहिए कि द्विआधारी विकल्प कैसे काम करते हैं, किस उत्पाद और समय के फ्रेम वे इन उत्पादों के द्विआधारी विकल्प, फायदे और नुकसान के साथ व्यापार कर सकते हैं, और कौन से कंपनियां कानूनी रूप से अमेरिकी निवासियों के लिए द्विआधारी विकल्प प्रदान करने के लिए अधिकृत हैं। यू.एस. के बाहर कारोबार किए जाने वाले द्विआधारी विकल्प आम तौर पर यूएस एक्सचेंजों पर उपलब्ध बायनेरिओ से अलग तरीके से संरचित होते हैं। सट्टेबाजी या हेजिंग पर विचार करने पर बाइनरी विकल्प एक विकल्प हैं, लेकिन केवल अगर व्यापारी इन विदेशी विकल्पों के दो संभावित परिणामों को पूरी तरह से समझता है (संबंधित पढ़ने के लिए, देखें: यूएस के बाहर द्विआधारी विकल्प के बारे में आपको क्या पता होना चाहिए) यू.एस. बाइनरी विकल्प समझाया गया है कि बाइनरी विकल्प हां या कोई प्रस्ताव के आधार पर आहरित जोखिम के साथ बाजारों को व्यापार करने का एक रास्ता प्रदान करते हैं। उदाहरण के लिए: क्या सोने की कीमत 1,250 से बढ़कर 1:30 बजे होगी? आज अगर आपको लगता है कि यह होगा, तो आप द्विआधारी विकल्प खरीद लेंगे। यदि सोचना है कि सोना 1:30 बजे से नीचे 1250 होगा तो आप इस द्विआधारी विकल्प को बेचते हैं द्विआधारी विकल्प की कीमत हमेशा 0 से 100 के बीच होती है, और अन्य वित्तीय बाजारों की तरह, बोली और पूछने की कीमत होती है उपरोक्त बाइनरी 42.50 (बीड) और 44.50 (ऑफर) पर 1 पीएम पर कारोबार कर सकते हैं। यदि आप द्विआधारी विकल्प खरीदते हैं, तो आप 44.50 का भुगतान करेंगे, यदि आप सही बेचने का निर्णय लेते हैं तो आप 42.50 में बेचना होगा। मान लेते हैं कि आप 44.50 में खरीदने का निर्णय लेते हैं। यदि 1:30 बजे तक सोने की कीमत 1,250 से ऊपर है, आपके विकल्प की समय सीमा समाप्त हो जाती है और यह 100 के बराबर हो जाता है। आप 100 - 44.50 55.50 (कम शुल्क) का लाभ कमाते हैं। इसे पैसों में कहा जाता है लेकिन अगर सोने की कीमत 1 से 22 बजे से कम 1:30 बजे है। विकल्प 0 पर समाप्त हो जाता है। इसलिए आप 44.50 का निवेश खो देते हैं। यह पैसे से बाहर बुलाया विकल्प समाप्त होने तक बोली और ऑफ़र में उतार-चढ़ाव होता है। आप लाभ में लॉक करने या हानि को कम करने की समाप्ति से पहले किसी भी समय अपनी स्थिति को बंद कर सकते हैं (धनराशि समाप्त होने की तुलना में)। आखिरकार हर विकल्प 100 या 0 100 पर होता है यदि द्विआधारी विकल्प का प्रस्ताव सही है, और 0 अगर यह झूठा होने का पता चला है। इस प्रकार प्रत्येक द्विआधारी विकल्प के पास 100 का कुल मूल्य संभावित होता है, और यह एक शून्य-सममूल्य गेम होता है जो आप किसी और को खो देता है, और जो आप किसी और को खो देते हैं प्रत्येक व्यापारी को अपने व्यापार के पक्ष में पूंजी लगाई जानी चाहिए। ऊपर दिए गए उदाहरणों में, आपने 44.50 में एक विकल्प खरीदा था, और किसी ने आपको यह विकल्प बेच दिया आपका अधिकतम जोखिम 44.50 है यदि विकल्प 0 पर स्थिर हो जाता है, इसलिए व्यापार की लागत 44.50 है। यदि आप को बेच दिया गया व्यक्ति का अधिकतम जोखिम 55.50 है, तो विकल्प 100 (100 - 44.50 55.50) पर हो जाता है। एक व्यापारी कई अनुबंध खरीद सकता है, अगर वांछित हो। एक अन्य उदाहरण: NASDAQ यूएस टेक 100 इंडेक्स gt 3,784 (11 एएम)। चालू बोली और पेशकश क्रमशः 74.00 और 80.00 है। यदि आपको लगता है कि सूचकांक 3,784 से 11 बजे से ऊपर होगा तो आप 80 पर बायर्न विकल्प खरीद सकते हैं (या कम कीमत पर बोली लगा सकते हैं और आशा है कि कोई आपके द्वारा उस कीमत पर बेचता है)। यदि आपको लगता है कि सूचकांक उस समय 3,784 से नीचे होगा, तो आप 74.00 पर बेचते हैं (या उस कीमत से ऊपर एक ऑफ़र देते हैं और उम्मीद है कि किसी ने इसे आप से खरीद लिया है)। आप 74.00 पर बेचने का फैसला करते हैं, विश्वास करते हुए सूचकांक 3,784 (स्ट्राइक प्राइस कहलाता है) से नीचे 11 डिग्री तक गिरने वाला है और अगर आप वास्तव में व्यापार पसंद करते हैं, तो आप कई अनुबंध बेच सकते हैं (या खरीद सकते हैं) चित्रा 1 में 74.00 पर पांच अनुबंध (आकार) बेचने के लिए एक व्यापार दिखाया गया है। नडेक्स प्लेटफार्म स्वचालित रूप से आपकी अधिकतम हानि की गणना करता है और जब आप कोई ऑर्डर बनाते हैं, जिसे टिकट कहा जाता है मैक्स प्रॉफिट और मैक्स लॉस के साथ एनडेक्स ट्रेड टिकट (चित्रा 1) इस टिकट पर अधिकतम लाभ 370 (74 x 5 370) है, और अधिकतम कॉन्ट्रैक्ट 130 (100 - 74 26 x 5 130) पांच कॉन्ट्रैक्ट और बिक्री पर आधारित है 74.00 की कीमत (इस विषय पर अधिक जानकारी के लिए, द्विआधारी विकल्प का परिचय देखें) बोली और पूछे जाने वाले निर्धारित कैसे होते हैं बोली और पूछे जाते हैं खुद को व्यापारियों द्वारा निर्धारित किया जाता है क्योंकि वे प्रस्ताव की सच्चाई की संभावना का आकलन करते हैं या नहीं। सरल शब्दों में, यदि द्विआधारी विकल्प पर बोली और मांग क्रमशः 85 और 89 है, तो व्यापारियों को बहुत ही उच्च संभावना माना जा रहा है कि बाइनरी विकल्प का परिणाम हां होगा, और विकल्प 100 की कीमत समाप्त हो जाएगा। यदि बोली और पूछने के करीब 50 हैं, व्यापारियों को अनिश्चित हैं यदि द्विआधारी 0 या 100 में इसकी बाधाओं का समय समाप्त हो जाएगा। यदि बोली और पूछना क्रमशः 10 और 15 पर है, तो इससे पता चलता है कि व्यापारियों का मानना ​​है कि विकल्प की कोई संभावना नहीं होगी और इस समय के मूल्य की अवधि समाप्त हो जाएगी। इस क्षेत्र में खरीदार एक बड़ी कमाई के लिए तैयार हैं। जबकि वे बिक्री बड़े जोखिम (उनके लाभ के सापेक्ष) के लिए एक छोटी लेकिन बहुत संभावना लाभ लेने के लिए तैयार हैं। जहां द्विआधारी विकल्प द्विआधारी विकल्प व्यापार Nadex विनिमय पर व्यापार करने के लिए। पहला कानूनी अमेरिकी विनिमय द्विआधारी विकल्प पर केंद्रित है। नॅडेक्स अपने स्वयं के ब्राउज़र-आधारित बाइनरी ऑप्शंस ट्रेडिंग प्लेटफॉर्म प्रदान करता है जो व्यापारियों को डेमो अकाउंट या लाइव अकाउंट के माध्यम से एक्सेस कर सकते हैं। ट्रेडिंग प्लेटफॉर्म, वास्तविक समय-समय प्रदान करता है, साथ ही वर्तमान बाइनरी विकल्प कीमतों तक प्रत्यक्ष बाजार पहुंच प्रदान करता है। बाइनरी विकल्प शिकागो बोर्ड ऑप्शन एक्सचेंज (सीबीओई) के माध्यम से भी उपलब्ध हैं। किसी भी विकल्प के साथ-अनुमोदित ब्रोकरेज खाता अपने पारंपरिक ट्रेडिंग खाते के माध्यम से सीबीओई बाइनरी विकल्प का व्यापार कर सकता है। सभी ब्रोकर द्विआधारी विकल्प ट्रेडिंग नहीं देते, हालांकि प्रत्येक एनएडएक्स अनुबंध में प्रवेश करने के लिए 0.90 दर्ज किए गए और 0.90 का कारोबार हुआ। शुल्क 9 पर आ गया है, इसलिए 15 लॉट क्रय करने के लिए केवल 9 प्रवेश करने होंगे और 9 बाहर निकलने होंगे। यदि आप अपने व्यापार को निपटारे तक और धन में खत्म करते हैं, तो बाहर निकलने का शुल्क समाप्ति पर आपको आकलन किया जाता है। यदि आप व्यापार को निपटारा तक पकड़ते हैं, लेकिन पैसे से बाहर निकलते हैं, तो बाहर निकलने के लिए कोई ट्रेड फीस का आकलन नहीं किया जाता है। सीबीओई बाइनरी विकल्प विभिन्न विकल्प दलालों के माध्यम से कारोबार किया जाता है, प्रत्येक अपने स्वयं के कमीशन फीस का भुगतान करते हैं। अपनी बाइनरी मार्केट उठाएं एकाधिक परिसंपत्ति वर्गों को द्विआधारी विकल्प के माध्यम से व्यापार किया जा सकता है नडेक्स प्रमुख बिंदुओं जैसे डो 30 (वॉल स्ट्रीट 30), एसएपीपी 500 (यूएस 500), नास्डैक 100 (यूएस टेक 100) और रसेल 2000 (यूएस स्मॉलकैप 2000) के प्रमुख सूचकांक में व्यापार करता है। यूनाइटेड किंगडम (एफटीएसई 100), जर्मनी (जर्मनी 30) और जापान (जापान 225) के लिए वैश्विक सूचकांक भी उपलब्ध हैं। नैडेक्स कच्चे तेल की कीमत से संबंधित वस्तु बाइनरी विकल्प प्रदान करता है प्राकृतिक गैस, सोना, चांदी, तांबा, मक्का और सोयाबीन। ट्रेडिंग समाचार इवेंट घटना बाइनरी विकल्प के साथ भी संभव है। खरीदें या बेचने के विकल्प के आधार पर कि क्या फेडरल रिजर्व दरें बढ़ेगी या घटाएगा, या क्या बेरोजगार दावे और गैरफार्म पेरोल आम सहमति अनुमानों के ऊपर या नीचे आएंगे। (इस विषय पर अधिक जानकारी के लिए, विदेशी विकल्प देखें: सामान्य व्यापार से एक भगदड़) सीबीओई व्यापार के लिए दो द्विआधारी विकल्प प्रदान करता है। एसएपीपी 500 इंडेक्स पर आधारित एक एसएम्पपी 500 इंडेक्स ऑप्शन (बीएसज़ड), और सीओबीईई वोल्टालिटी इंडेक्स (वीआईएक्स) के आधार पर एक वोल्टालिटी इंडेक्स ऑप्शन (बीवीजेड) है। अपना टाइम फ़्रेम चुनें एक व्यापारी नडेक्स बाइनरी विकल्प (उपरोक्त परिसंपत्ति वर्गों में) चुन सकता है जो प्रतिदिन, दैनिक या साप्ताहिक समाप्त होता है प्रति घंटा विकल्प दिन के व्यापारियों के लिए अवसर प्रदान करते हैं। यहां तक ​​कि चुप बाजार स्थितियों में, यदि वे समय सीमा पर बाजार की दिशा को चुनने में सही हैं तो एक स्थापित वापसी हासिल करने के लिए। दैनिक विकल्प ट्रेडिंग दिन के अंत में समाप्त हो जाते हैं, और दिन के व्यापारियों के लिए उपयोगी होते हैं या उन दिनों के आंदोलनों के खिलाफ अन्य स्टॉक, विदेशी मुद्रा या कमोडिटी होल्डिंग्स को हेज करने की तलाश करते हैं। साप्ताहिक विकल्प ट्रेडिंग सप्ताह के अंत में समाप्त हो जाते हैं, और इसलिए पूरे हफ्ते स्विंग व्यापारियों द्वारा कारोबार किया जाता है, और दिन के व्यापारियों द्वारा भी, विकल्प शुल्कों की समाप्ति के रूप में शुक्रवार दोपहर तक का कारोबार होता है। घटना-आधारित अनुबंध का आयोजन घटना के साथ जुड़े आधिकारिक समाचार रिलीज़ के बाद समाप्त हो जाता है, और इसलिए सभी प्रकार के व्यापारी पद के लिए अच्छी तरह से आगे ले जाते हैं - और समाप्ति के ठीक ऊपर। फायदे और नुकसान वास्तविक स्टॉक या विदेशी मुद्रा बाजारों के विपरीत जहां कीमत में कमी या गिरावट आ सकती है, द्विआधारी विकल्प के जोखिम को बंद किया गया है। व्यापार की लागत से अधिक खोना संभव नहीं है। बहुत ही शांत बाजारों में औसत से अधिक रिटर्न भी संभव है। यदि कोई शेयर इंडेक्स या विदेशी मुद्रा जोड़ी मुश्किल से बढ़ रहा है, तो इसकी कड़ी मेहनत होती है, लेकिन एक द्विआधारी विकल्प के साथ पेआउट जाना जाता है। यदि आप 20 में एक द्विआधारी विकल्प खरीदते हैं, तो यह या तो 100 या 0 में व्यवस्थित करेगा, आपको अपने 20 निवेश पर 80 कर देगा या आपको खो देगा 20. यह जोखिम अनुपात के लिए 4: 1 इनाम है। एक अवसर है जो बाइनरी विकल्प के वास्तविक बाजार में पाया जाने की संभावना नहीं है। इस का दूसरा पहलू यह है कि आपका लाभ हमेशा कैप्चर होता है। कोई फर्क नहीं पड़ता कि शेयर या विदेशी मुद्रा जोड़ी आपके पक्ष में कितना चलती है, एक द्विआधारी विकल्प विकल्प का मूल्य 100 हो सकता है। कई विकल्पों के अनुबंध खरीदना एक संभावित कीमत की चाल से संभावित लाभ का एक तरीका है। चूंकि द्विआधारी विकल्प अधिकतम 100 के लायक हैं, जो उन्हें सीमित व्यापारिक पूंजी के साथ व्यापारियों के लिए सुलभ बनाता है। जैसा कि पारंपरिक स्टॉक दिवस ट्रेडिंग की सीमाएं लागू नहीं होतीं ट्रेडिंग नडेक्स पर 100 जमा से शुरू हो सकता है। द्विआधारी विकल्प एक अंतर्निहित परिसंपत्ति के आधार पर एक व्युत्पन्न होता है, जिसे आप स्वयं नहीं करते हैं इसलिए, आप मतदान अधिकार या लाभांश के हकदार नहीं हैं जो कि आपके पास वास्तविक स्टॉक के स्वामित्व के लिए हकदार हैं। बाइनरी विकल्प हाँ या कोई प्रस्ताव पर आधारित हैं। आपका लाभ और हानि क्षमता आपके खरीद या बेचने की कीमत से निर्धारित होती है, और यह विकल्प 100 या 0 के बराबर होने की स्थिति में है। जोखिम और इनाम दोनों ही कैप्चर किए गए हैं, और आप लाभ में लॉक की समाप्ति से पहले किसी विकल्प से बाहर निकल सकते हैं या कम कर सकते हैं नुकसान। यूए में द्विआधारी विकल्प नडेक्स और सीबीओई एक्सचेंजों के माध्यम से कारोबार किया जाता है। विदेशी कंपनियों ने अमेरिकी निवासियों को अपने द्विआधारी विकल्पों के रूप में व्यापार करने के लिए अनुरोध किया है, जो आमतौर पर गैरकानूनी रूप से कार्य कर रहे हैं। बाइनरी ऑप्शन ट्रेडिंग में प्रवेश के लिए कम बाधा है लेकिन सिर्फ इसलिए कि कुछ सरल है इसका मतलब यह नहीं है कि पैसे कमाने के लिए आसान होगा। व्यापार के दूसरी तरफ हमेशा कोई और है जो सोचता है कि वे सही हैं और आप गलत हैं केवल पूंजी वाले व्यापार को आप खो सकते हैं, और एक डेमो खाते का व्यापार पूरी तरह से आरामदायक होने के साथ व्यापार करने से पहले बाइनरी विकल्प कैसे काम करते हैं। वास्तविक विकल्प के साथ व्यापार करने से पहले द्विआधारी विकल्प ट्रेडिंग। द्विआधारी विकल्प क्या है सबसे पहले, यह बहुत लाभदायक ऑनलाइन है व्यापार उपकरण जो आपको पहले से संभावित लाभ की मात्रा का अनुमान लगाने की अनुमति देता है। द्विआधारी विकल्प ट्रेडिंग संभवतः कम से कम समय में पर्याप्त आय ला सकता है। व्यापारी पूर्व निर्धारित मूल्य पर विकल्प खरीदते हैं। ऑनलाइन व्यापार लाभप्रद हो सकता है यदि व्यापारी सही ढंग से बाजार आंदोलन की पहचान करता है बाइनरी ऑप्शंस ट्रेडिंग का लाभ एक उच्च जोखिम वाले क्षेत्र है जहां आप या तो अपनी राजधानी को दोहरा कर सकते हैं या फिर ट्रिपल कर सकते हैं या कुछ मिनटों में इसे खो सकते हैं। द्विआधारी विकल्प के कई फायदे हैं जो अनुमानित जोखिम के साथ अधिक लाभ प्राप्त करना संभव बनाते हैं। एक निश्चित लाभ वाला एक विकल्प परंपरागत व्यापार से अलग है। शुरुआती IQ विकल्प के साथ-साथ अनुभवी व्यापारियों के साथ द्विआधारी विकल्प व्यापार कर सकते हैं। पूरी प्रक्रिया पूरी तरह से स्वचालित है। द्विआधारी विकल्प व्यापारियों को उनके मुनाफे से पहले से पता चल रहा है, उनका मुख्य उद्देश्य बाजार के आंदोलन की सही दिशा का चयन करना है। उन्हें केवल दो दिशाओं में से ऊपर या नीचे चुनने की ज़रूरत है ऑनलाइन ट्रेडिंग के दो प्रकार IQ विकल्प प्लेटफॉर्म आपको द्विआधारी विकल्पों के दो बुनियादी तरीकों में व्यापार करने की अनुमति देता है। प्रैक्टिस अकाउंट प्रशिक्षण के लिए है अभ्यास खाता खोलने के लिए और अपनी ताकत का परीक्षण करने के लिए, आपको जमा जमा करने की आवश्यकता भी नहीं है। असली व्यापार के लिए, आपको केवल 10 जमा करना होगा। यह 36 तक का बोनस सुनिश्चित करता है। जब एक बड़ी राशि (3,000 से) के लिए खाता खोलते हैं, तो एक निजी खाता प्रबंधक आपकी सेवा में होगा इस वेबसाइट पर दी गई व्यापारिक कार्रवाइयों को उच्च-जोखिम व्यापार संचालन माना जा सकता है और उनका निष्पादन बहुत जोखिम भरा हो सकता है। वेबसाइट पर उपलब्ध कराई गई वित्तीय उपकरणों या सेवाओं का उपयोग करने से आपके खाते में सभी हानियों की कुल हानि या हानि भी हो सकती है। वेबसाइट पर दी गई सेवाओं के संबंध में व्यक्तिगत और गैर-वाणिज्यिक उद्देश्यों के लिए इस वेबसाइट पर प्रदत्त आईपी का उपयोग करने के लिए सीमित गैर-विशिष्ट गैर-हस्तांतरणीय अधिकार दिए गए हैं कंपनी रूसी संघ के बाहर काम करती है eu. iqoption स्वामित्व और Iqoption यूरोप लिमिटेड द्वारा संचालित है IQ विकल्प, 20182017 पासवर्ड पुनर्प्राप्ति जानकारी सफलतापूर्वक आपके मेल पंजीकरण करने के लिए भेज दिया गया है वर्तमान में रूसी संघ में अनुपलब्ध है। अगर आपको लगता है कि आप इस संदेश को गलती से देख रहे हैं, तो कृपया समर्थन सहायता से संपर्क करें। क्या है 28217 नए पायथन 3.0 फरवरी 14, 2009 इस आलेख में 2.6 की तुलना में, Python 3.0 में नई सुविधाओं की व्याख्या की गई है। पायथन 3.0, जिसे 8220 पायथन 30008221 या 8220Py3K8221 के रूप में भी जाना जाता है, पहली बार जानबूझकर पीछे वाली असंगत पायथन रिहाई है। सामान्य रिलीज़ की तुलना में अधिक बदलाव हैं, और अधिक सभी पायथन उपयोगकर्ता के लिए महत्वपूर्ण हैं। फिर भी, परिवर्तनों को पचाने के बाद, you8217ll को पता चला है कि पायथन वास्तव में है 8217t बदल गया है कि सभी बहुत अधिक 8211 द्वारा और बड़े, we8217re ज्यादातर प्रसिद्ध annoyances और मौसा फिक्सिंग, और पुराने cruft बहुत दूर। इस आलेख में सभी नई विशेषताओं के पूर्ण विवरण प्रदान करने का प्रयास करता है, लेकिन इसके बजाय एक सुविधाजनक अवलोकन देने की कोशिश करता है। पूर्ण विवरण के लिए, आपको पायथन 3.0 के लिए प्रलेखन का उल्लेख करना चाहिए, और पाठ में संदर्भित कई पीईपी। यदि आप किसी विशेष सुविधा के लिए पूर्ण कार्यान्वयन और डिजाइन तर्क समझना चाहते हैं, तो आम तौर पर पीईपी सामान्य दस्तावेजों के मुकाबले अधिक विवरण देते हैं लेकिन ध्यान दें कि एक सुविधा पूरी तरह कार्यान्वित हो जाने पर पीईपी आमतौर पर अद्यतित नहीं रखी जाती है। समय की बाधाओं के कारण यह दस्तावेज़ पूरा नहीं हो रहा है क्योंकि यह होना चाहिए था। एक नई रिलीज के लिए हमेशा की तरह, स्रोत वितरण में MiscNEWS फ़ाइल में प्रत्येक छोटी सी चीज के बारे में विस्तृत जानकारी का धन होता है जिसे बदला गया था। सामान्य ठोकरें ब्लाकों यह खंड उन कुछ बदलावों को सूचीबद्ध करता है जो आपके लिए सबसे अधिक संभावनाएं हैं यदि आप 8,87,770 पायथन 2.5 के लिए इस्तेमाल करते हैं। प्रिंट एक फ़ंक्शन है प्रिंट स्टेटमेंट को प्रिंट () फ़ंक्शन के साथ बदल दिया गया है, पुरानी प्रिंट स्टेटमेंट (पीईपी 3105) के अधिकांश विशेष सिंटैक्स को बदलने के लिए कुंजीशब्द तर्क के साथ। उदाहरण: आप आइटम के बीच विभाजक को भी कस्टमाइज़ कर सकते हैं, उदा .: प्रिंट () फ़ंक्शन doesn8217t पुरानी प्रिंट स्टेटमेंट की 8220softspace8221 सुविधा का समर्थन करता है। उदाहरण के लिए, पायथन 2.x में, print quotAnquot, quotBquot quotAnBnquot लिखेंगे, लेकिन पायथन 3.0 में, प्रिंट (quotAnquot, quotBquot) लिखते हैं कि एएन ब्नक्ॉट प्रारंभ में, आप स्वयं को पुराने प्रिंट एक्स टाइप कर पाएंगे इंटरएक्टिव मोड में। इसके बजाय प्रिंट (x) टाइप करने के लिए अपनी उंगलियों को फिर से प्रशिक्षित करने का समय, जब 2to3 स्रोत-टू-सोर्स रूपांतरण उपकरण का उपयोग करते हैं, तो सभी प्रिंट स्टेटमेंट स्वचालित रूप से प्रिंट () फ़ंक्शन कॉल्स में परिवर्तित हो जाते हैं, इसलिए यह बड़ी परियोजनाओं के लिए अधिकतर गैर-मुद्दा है। दर्शकों और बदले में बदले जाने वाली सूची कुछ प्रसिद्ध एपीआई अब सूचियों को वापस नहीं लौटेगी: तन्त्र विधियों dict. keys () सूची के बजाय dict. items () और dict. values ​​() वापस 8220views8221। उदाहरण के लिए, यह अब काम नहीं करता है: k d. keys () k. sort ()। कश्मीर सॉर्ट करें (डी) के बजाय (यह पायथन 2.5 में भी काम करता है और वह उतना ही कुशल है)। इसके अलावा, dict. iterkeys () dict. iteritems () और dict. itervalues ​​() विधियां अब समर्थित नहीं हैं। मानचित्र () और फिल्टर () रिटर्न इटरेटर यदि आपको वास्तव में एक सूची की आवश्यकता है, तो एक त्वरित ठीक उदाहरण है सूची (नक्शा (।)) लेकिन एक बेहतर सुधार अक्सर एक सूची समझ का उपयोग करने के लिए अक्सर होता है (विशेषकर जब मूल कोड लैम्ब्डा का उपयोग करता है), या कोड को दोबारा लिखता है, इसलिए यह सभी को सूची की आवश्यकता नहीं है। विशेष रूप से मुश्किल है फ़ंक्शन के साइड इफेक्ट के लिए मानचित्र () लागू किया जाता है सही परिवर्तन लूप के लिए एक नियमित उपयोग करना है (एक सूची बनाते समय केवल बेकार हो जाएगा) रेंज () अब एक्सरेन्ज () को व्यवहार करने के लिए उपयोग की तरह व्यवहार करती है, सिवाय इसके कि यह मनमाना आकार के मूल्यों के साथ काम करता है उत्तरार्द्ध अब मौजूद नहीं है ज़िप () अब एक इटरेटर देता है तुलनात्मक क्रम की तुलना Python 3.0 ने तुलना करने के लिए नियमों को सरल किया है: क्रमिक तुलना ऑपरेटरों (लेफ्टिनेंट लेफ्टिगेट gt। Gt) एक टाइप ईर्रर अपवाद बढ़ाते हैं जब ऑपरेंड्स don8217t के पास अर्थपूर्ण प्राकृतिक क्रम है इस प्रकार, 1 एलटी जैसे भाव 0 जीपी कोई नहीं या लेन लेफ्टिन लेन अब वैध नहीं है, और उदा। कोई नहीं एलटी कोई भी गलत नहीं लौटने के बजाय TypeError उठाता है। एक परिणाम यह है कि एक विषम सूची को छांटने के बाद अब समझ में नहीं आता है 8211 सभी तत्व एक दूसरे के साथ तुलनीय होंगे। ध्यान दें कि यह और ऑपरेटरों पर लागू नहीं होता है: विभिन्न अतुलनीय प्रकार के ऑब्जेक्ट हमेशा एक-दूसरे के असमान की तुलना करते हैं। builtin. sorted () और list. sort () अब cmp तर्क को एक तुलना फ़ंक्शन प्रदान नहीं करते। इसके बजाय मुख्य तर्क का प्रयोग करें। N. B. कुंजी और रिवर्स तर्क अब 8220 कीवर्ड-केवल 8221 हैं। Cmp () फ़ंक्शन को चले गए के रूप में माना जाना चाहिए, और cmp () विशेष विधि अब समर्थित नहीं है। सॉर्टिंग के लिए एलटी () का उपयोग करें, eq () हैश के साथ () और अन्य समृद्ध तुलना की जरूरत है। (यदि आपको वास्तव में cmp () कार्यक्षमता की आवश्यकता होती है, तो आप अभिव्यक्ति (एक जीटी बी) - (एक लेफ्टिनेंट बी) का इस्तेमाल कर सकते हैं जैसे कि सीपीपी (ए, बी) के बराबर।) पीईपी 0237 अनिवार्य रूप से, लंबे समय तक int को पुनः नाम दिया गया था यही है, केवल इंटीग्रल प्रकार का एक इंटीग्रल प्रकार है, जिसका नाम आईएनआर है लेकिन यह ज्यादातर पुराने लंबे प्रकार की तरह व्यवहार करता है। पीईपी 0238 12 की तरह एक अभिव्यक्ति एक फ्लोट देता है काटने का व्यवहार करने के लिए 12 का उपयोग करें। (उत्तरार्द्ध वाक्यविन्यास साल के लिए अस्तित्व में है, कम से कम पायथन 2.2 के बाद से।) Sys. maxint निरंतर हटा दिया गया था, क्योंकि अब पूर्णांक के मूल्य की कोई सीमा नहीं है हालांकि, sys. maxsize को किसी भी व्यावहारिक सूची या स्ट्रिंग सूचकांक से बड़ा पूर्णांक के रूप में इस्तेमाल किया जा सकता है। यह कार्यान्वयन 8217 के 8220natural8221 पूर्णांक आकार के अनुरूप है और आमतौर पर समान मंच पर पिछले रिलीज में sys. maxint के समान ही है (समान बिल्ड विकल्प मानते हुए)। एक लंबे पूर्णांक के repr () doesn8217t में अनुगामी एल अब शामिल है, तो कोड है कि बिना शर्त स्ट्रिप्स कि चरित्र बजाय पिछले अंक काट होगा (इसके बजाय स्ट्र () का प्रयोग करें।) आक्टल लिटरल्स अब 0720 फार्म का नहीं हैं, बल्कि इसके बजाय 0o720 उपयोग करें। पाठ बनाम। इसके बजाय यूनिकोड बनाम डेटा। 8-बिट सब कुछ जो आपने सोचा था कि आप द्विआधारी डेटा के बारे में जानते थे और यूनिकोड बदल गया है। पायथन 3.0 यूनिकोड स्ट्रिंग्स और 8-बिट स्ट्रिंग्स के बजाय टेक्स्ट और (बाइनरी) डेटा की अवधारणाओं का उपयोग करता है। सभी पाठ युनिकोड है लेकिन एन्कोडेड यूनिकोड को बाइनरी डेटा के रूप में दर्शाया गया है पाठ रखने के लिए इस्तेमाल किया जाने वाला प्रकार str है डेटा को पकड़ने के लिए इस्तेमाल किया जाने वाला प्रकार बाइट है 2.x स्थिति के साथ सबसे बड़ा अंतर यह है कि पायथन 3.0 में पाठ और डेटा को मिश्रण करने का कोई भी प्रयास TypeError उठाता है। यद्यपि यदि आप पायथन 2.x में यूनिकोड और 8-बिट स्ट्रिंग्स को मिश्रण करने के लिए थे, तो यह 8-बिट स्ट्रिंग में केवल 7-बिट (एएससीआईआई) बाइट को शामिल करने पर काम करेगा, लेकिन आपको यूनिकोडडेकोड एरर मिलेगा अगर इसमें गैर - ASCII मान। इस मूल्य-विशिष्ट व्यवहार ने कई दुखद चेहरे का कारण बना दिया है दर्शन में इस परिवर्तन के परिणामस्वरूप, यूनिकोड, एन्कोडिंग या बाइनरी डेटा का उपयोग करने वाला सबसे ज्यादा कोड सभी को बदलना होगा। यह बदलाव बेहतर है, जैसा कि 2.x दुनिया में कई एन्कोडेड और असेंकड पाठ मिश्रण करने के लिए कई बग हैं। पायथन 2.x में तैयार होने के लिए, यूनिकोड का उपयोग सभी unencoded पाठ के लिए, और द्विआधारी या एन्कोडेड डेटा के लिए केवल स्ट्रिंग शुरू करें। तो 2to3 टूल आपके लिए अधिकांश काम करेगा। आप अब uquot का उपयोग नहीं कर सकते यूनिकोड पाठ के लिए प्रतिलेख हालांकि, आपको बक्ोट का उपयोग करना चाहिए। बाइनरी डेटा के लिए उद्धरण। जैसे कि स्ट्र और बाइट प्रकार मिश्रित नहीं किए जा सकते, आपको हमेशा उनके बीच स्पष्ट रूप से कन्वर्ट करना होगा। Str से बाइट्स पर जाने के लिए str. encode () का उपयोग करें। और bytes. decode () बाइट्स से str के लिए जाने के लिए आप बाइट्स (एन्कोडिंग।) और स्ट्र (बी, एन्कोडिंग।) का भी उपयोग कर सकते हैं। क्रमशः। Str की तरह बाइट्स प्रकार अपरिवर्तनीय है बफर द्विआधारी डेटा को धारण करने के लिए अलग-अलग अस्थिर प्रकार है, बायटैरेअरे। लगभग सभी एपीआई जो बाइट स्वीकार करते हैं, वे भी बाइटियर स्वीकार करते हैं। अस्थिर एपीआई संग्रह पर आधारित है। महत्वपूर्ण सफ़ेदता कच्चे स्ट्रिंग लीटरल्स में सभी बैकस्लैश शाब्दिक रूप से व्याख्या किए जाते हैं। इसका अर्थ है कि यू और यू को कच्चे तारों में पलायन विशेष रूप से नहीं किया जाता है। उदाहरण के लिए, ru20ac Python 3.0 में 6 अक्षर की एक स्ट्रिंग है, जबकि 2.6 में, uru20ac एकल 8220euro8221 वर्ण था। (बेशक, यह परिवर्तन केवल कच्चे स्ट्रिंग लिटरल्स को प्रभावित करता है, यूरो वर्ण पायथन 3.0 में यू 20ैक है।) अंतर्निहित आधारभूत सार प्रकार हटा दिया गया था। बजाय str का प्रयोग करें एक स्ट्रिंग और बाइट प्रकार don8217t में एक साझा बेस क्लास की गारंटी के लिए सामान्य में पर्याप्त कार्यक्षमता है। 2to3 टूल (नीचे देखें) स्ट्रॉ के साथ हर संभव बेस्टस्ट्रिंग को बदल देता है फ़ाइलों को पाठ फ़ाइलों के रूप में खोला गया (फिर भी खुले () के लिए डिफ़ॉल्ट मोड) हमेशा तारों (स्मृति में) और बाइट्स (डिस्क पर) के बीच मानचित्र के लिए एक एन्कोडिंग का उपयोग करते हैं। बाइनरी फ़ाइलें (मोड तर्क में ख के साथ खोला गया) हमेशा स्मृति में बाइट का उपयोग करें इसका अर्थ यह है कि यदि कोई ग़लत मोड या एन्कोडिंग के माध्यम से एक फ़ाइल खोल दी गई हो, तो आईओ संभवत: ग़लत डेटा को चुपचाप करने के बजाय जोर से असफल हो जायेगा। इसका भी मतलब है कि यूनिक्स उपयोगकर्ताओं को फाइल खोलते समय सही मोड (पाठ या बाइनरी) निर्दिष्ट करना होगा। एक मंच-आधारित डिफ़ॉल्ट एन्कोडिंग है, जो यूनिक्स प्लेटफार्मों पर LANG परिवेश चर (और कभी-कभी कुछ अन्य प्लेटफ़ॉर्म-विशिष्ट लोकेल-संबंधी वातावरण चर के साथ भी) सेट किया जा सकता है। कई मामलों में, लेकिन सभी नहीं, सिस्टम डिफ़ॉल्ट यूटीएफ -8 है जिसे आपको इस डिफ़ॉल्ट पर कभी नहीं गिना जाना चाहिए। शुद्ध एएससीआईआई पाठ से अधिक पढ़ने या लिखने के लिए कोई भी एप्लिकेशन शायद एन्कोडिंग को ओवरराइड करने का एक तरीका हो। अब कोडकोड मॉड्यूल में एन्कोडिंग-ज्ञात धाराओं का उपयोग करने की कोई ज़रूरत नहीं है। फ़ाइल नाम पास कर दिए गए हैं और एपीआई (यूनिकोड) स्ट्रिंग्स के रूप में लौट आए हैं। यह प्लेटफ़ॉर्म-विशिष्ट समस्याओं को पेश कर सकता है क्योंकि कुछ प्लेटफ़ॉर्म फ़ाइल नाम पर मनमाना बाइट स्ट्रिंग हैं। (दूसरी तरफ, विंडोज़ फाइल नामों पर यूनिकोड के रूप में जमा किया जाता है।) काम के आसपास के रूप में, ज्यादातर एपीआई (ओएस (ओएस मॉड्यूल) में ओपन () और कई फ़ंक्शंस) जो फाइलनामों को बाइट्स ऑब्जेक्ट्स के साथ-साथ तार को स्वीकार करते हैं, और कुछ एपीआई के पास बाइट्स रिटर्न वैल्यू के लिए पूछने का एक तरीका है। इस प्रकार, os. listdir () बाइट उदाहरणों की एक सूची देता है अगर तर्क एक बाइट उदाहरण है, और os. getcwdb () वर्तमान कार्य निर्देशिका को एक बाइट उदाहरण के रूप में देता है। ध्यान दें कि जब os. listdir () स्ट्रिंग्स की एक सूची लौटाता है, तो फ़ाइल नामों को ठीक से डीकोड नहीं किया जा सकता है, यूनिकोड एआरआर बढ़ाने के बजाय छोड़े गए हैं। कुछ सिस्टम एपीआई जैसे ओसेंइन और sys. argv भी समस्याएं पेश कर सकती है जब सिस्टम द्वारा उपलब्ध बाइट्स को डिफ़ॉल्ट एन्कोडिंग का उपयोग करने में व्याख्या नहीं होती है। लैंग वैरिएबल सेट करना और प्रोग्राम को फिर से बनाना संभवतः सबसे अच्छा तरीका है PEP 3138 स्ट्रिंग का repr () अब गैर-एएससीआईआई वर्णों से बच निकलता है। यह अभी भी यूनिकोड मानक में गैर-प्रिंट करने योग्य स्थिति के साथ नियंत्रण अक्षर और कोड बिंदुओं से बच जाता है, हालांकि PEP 3120 डिफ़ॉल्ट स्रोत एन्कोडिंग अब UTF-8 है PEP 3131 गैर-एएससीआईआई पत्र अब पहचानकर्ताओं में अनुमत हैं। (हालांकि, मानक पुस्तकालय एएससीआईआई को केवल टिप्पणियों में योगदानकर्ता नामों के अपवाद के साथ रहता है।) स्ट्रिंगआईओ और सीस्ट्रिंगियो मॉड्यूल चले गए हैं। इसके बजाय, io मॉड्यूल आयात करें और पाठ और डेटा के लिए क्रमशः io. StringIO या IO. BytesIO का उपयोग करें। यह भी देखें यूनिकोड HOWTO जो पायथन 3.0 के लिए अद्यतन किया गया था। सिंटेक्स परिवर्तनों का अवलोकन यह खंड पायथन 3.0 में हर वाक्यविन्यास परिवर्तन का संक्षिप्त विवरण देता है। नई सिंटैक्स PEP 3107 फंक्शन तर्क और रिटर्न मूल्य एनोटेशन। यह फ़ंक्शन 8217 के पैरामीटर और रिटर्न वैल्यू की व्याख्या करने का एक मानकीकृत तरीका प्रदान करता है। ऐसे एनोटेशन से कोई सिमेंटिक नहीं जुड़ा है, सिवाय इसके कि वे एनोटेशंस विशेषता का उपयोग करके रनटाइम पर आत्मविश्वास लगा सकते हैं। इसका उद्देश्य मेटैक्लास, सज्जाकार या चौखटे के माध्यम से प्रयोग को प्रोत्साहित करना है। PEP 3102 कीवर्ड-केवल तर्क। कॉलम में कीवर्ड वाक्यविन्यास का उपयोग करके पैरामीटर सूची में आरग्स के बाद निर्दिष्ट होने वाले नामांकित पैरामीटर निर्दिष्ट किए जाने चाहिए। आप पैरामीटर सूची में एक नंगे का उपयोग करने के लिए संकेत कर सकते हैं कि आप don8217t एक चर-लंबाई तर्क सूची स्वीकार करते हैं, लेकिन आपके पास केवल कीवर्ड-केवल तर्क है एक वर्ग की परिभाषा में आधार वर्गों की सूची के बाद कीवर्ड के तर्कों की अनुमति है यह मेटाक्लास निर्दिष्ट करने के लिए नए सम्मेलन (अगले भाग को देखें) द्वारा उपयोग किया जाता है, लेकिन इसका उपयोग अन्य उद्देश्यों के लिए भी किया जा सकता है, जब तक कि मेटाकल्सा इसका समर्थन करता है। PEP 3104 nonlocal बयान Nonlocal x का उपयोग करके आप अब एक बाहरी (लेकिन गैर-वैश्विक) दायरे में एक चर पर सीधे निर्दिष्ट कर सकते हैं। nonlocal एक नया आरक्षित शब्द है PEP 3132 विस्तारित इटेरेबल अनपैकिंग अब आप चीजों को लिख सकते हैं जैसे ए, बी, बाकी कम्फ्यूशन और यहां तक ​​कि आराम करो, सामान। बाकी ऑब्जेक्ट हमेशा एक (संभावित रूप से रिक्त) सूची है, दाएं हाथ की ओर किसी भी टिकाऊ हो सकता है उदाहरण: शब्दकोश की अभिव्यक्ति: शब्दा (सामग्री) के समान एक ही चीज़ है, लेकिन अधिक लचीली है (यह पीईपी 0274 पुष्टि है। -) लिटरल्स सेट करें, उदा। । ध्यान दें कि रिक्त सेट के लिए एक खाली शब्दकोश प्रयोग सेट () है अवधारणा सेट भी समर्थित हैं उदा। सेट (सामग्री) के रूप में एक ही बात का मतलब है, लेकिन अधिक लचीला है न्यू ऑक्टल लिटलल्स, उदा। 0o720 (पहले से 2.6 में) पुराने ऑक्टल लिटलल्स (0720) चले गए हैं नई बाइनरी लीटरल्स, उदा। 0b1010 (पहले से 2.6 में है), और एक नया समान निर्मित फ़ंक्शन, बिन () है। बाइट्स लिटलल्स को एक अग्रणी बी या बी के साथ पेश किया जाता है। और एक नया समान निर्मित फ़ंक्शन, बाइट्स () है रूप में और साथ में सिंटैक्स बदल दिया गया है अब शब्द आरक्षित हैं (2.6 के बाद से, वास्तव में।) सच है असत्य । और कोई भी आरक्षित शब्द नहीं हैं (2.6 आंशिक रूप से पहले से ही किसी पर प्रतिबंध लागू)। पीईपी 3115 न्यू मेटैक्लास सिंटेक्स के बजाय: अब आप का उपयोग करना चाहिए: मॉड्यूल-वैश्विक मेटाकल्ज़ चर अब समर्थित नहीं है। (यह ऑब्जेक्ट से हर वर्ग को प्राप्त किए बिना नए-शैली वाले कक्षाओं में डिफ़ॉल्ट करना आसान बनाना था।) सूची विन्यास अब वाक्यविन्यास रूप का समर्थन नहीं करते हैं। मद 1 में var के लिए आइटम 2 । उपयोग । इसके बदले में var (item1। item2।) के बजाय यह भी ध्यान रखें कि सूची की समझें अलग-अलग शब्दों में हैं: वे एक सूची () निर्माता के अंदर एक जनरेटर अभिव्यक्ति के लिए वाक्यात्मक चीनी के करीब हैं, और विशेष रूप से लूप नियंत्रण चर अब आसपास के क्षेत्र में लीक नहीं किए जा रहे हैं। एलीपिसिस (।) को किसी परमाणु अभिव्यक्ति के रूप में कहीं भी इस्तेमाल किया जा सकता है (पहले इसे केवल स्लाइस में ही अनुमति दी गई थी।) इसके अलावा, इसे अब के रूप में लिखा जाना चाहिए। । (पहले यह भी व्याकरण के एक मात्र दुर्घटना से। के रूप में लिखा जा सकता है।) हटाया गया सिंटेक्स पीईपी 3113 टपल पैरामीटर अनपैकिंग हटाया गया आप अब def foo (a, (b, c) लिख सकते हैं) । डेफ एफू (ए, बीसी): बी, सी बीसी के बजाय उपयोग करें हटाए गए बैकटीक्स (बजाय repr () का उपयोग करें)। हटाया गया एलटीजीटी (इसके बजाय उपयोग करें) हटाया गया कीवर्ड: exec () अब एक खोजशब्द नहीं है जो एक फ़ंक्शन के रूप में रहता है। (सौभाग्य से फ़ंक्शन सिंटैक्स को भी 2.x में स्वीकार किया गया था।) यह भी ध्यान रखें कि exec () अब exec (f) के बजाय स्ट्रीम तर्क को लेता है, आप exec (f. read ()) का उपयोग कर सकते हैं। पूर्णांक literals अब एक पीछे एल या एल का समर्थन नहीं करते स्ट्रिंग लीटरल्स अब एक प्रमुख यू या यू का समर्थन नहीं करते हैं। मॉड्यूल आयात वाक्यविन्यास से केवल मॉड्यूल स्तर पर अनुमति दी जाती है, फ़ंक्शन के अंदर नहीं। सापेक्ष आयात के लिए स्वीकार्य सिंटैक्स केवल से है मॉड्यूल आयात नाम सभी आयात फॉर्म प्रारंभ नहीं होते हैं। पूर्ण आयात के रूप में व्याख्या की जाती है (पीईपी 0328) क्लासिक कक्षाएं चले गए हैं पहले से मौजूद पायथन 2.6 में बदलाव वर्तमान में बहुत से उपयोगकर्ताओं को संभवतः पायथन 2.5 से पायथन 3.0 तक कूद कर लेते हैं, इसलिए यह खंड नई फीचर के रीडर को याद दिलाता है जो मूल रूप से पायथन 3.0 के लिए डिज़ाइन किया गया था, लेकिन यह पायथन 2.6 में बैक-पोर्ट किया गया था। पायथन 2.6 में क्या 8217 के न्यू में संबंधित वर्गों को अधिक विवरण के लिए परामर्श करना चाहिए। पीईपी 343: 8216 से 8217 बयान बयान के साथ अब एक मानक विशेषता है और अब भविष्य से आयात की आवश्यकता नहीं है। संदर्भ प्रलेख प्रबंधकों और प्रसंग लिब मॉड्यूल को भी देखें। पीईपी 366: एक मुख्य मॉड्यूल से स्पष्ट सापेक्ष आयात। यह - एम विकल्प की उपयोगिता को बढ़ाता है जब संदर्भित मॉड्यूल किसी पैकेज में रहता है। PEP 370: प्रति-उपयोगकर्ता साइट-संकुल निर्देशिका पीईपी 371: बहुप्रोसेसिंग पैकेज PEP 3101: उन्नत स्ट्रिंग फ़ॉर्मेटिंग नोट: 2.6 विवरण में 8-बिट और यूनिकोड स्ट्रिंग दोनों के लिए प्रारूप () विधि का उल्लेख किया गया है। 3.0 में, केवल str प्रकार (यूनिकोड समर्थन के साथ पाठ स्ट्रिंग) इस विधि का समर्थन करता है बाइट्स प्रकार नहीं। योजना को अंततः यह स्ट्रिंग फ़ॉर्मेटिंग के लिए केवल एपीआई बनाने और पायथन 3.1 में ऑपरेटर को पदावनत करने के लिए है। PEP 3105: एक समारोह के रूप में प्रिंट। यह अब एक मानक विशेषता है और भविष्य से आयात करने की आवश्यकता नहीं है। अधिक विवरण ऊपर दिए गए थे। PEP 3110: अपवाद-हैंडलिंग परिवर्तन सिवाय सिवाय वाक्यविन्यास अब मानक है और एक्स को छोड़कर var अब समर्थित नहीं है (बेशक, वैसे भाग के रूप में अभी भी वैकल्पिक है।) पीईपी 3112: बाइट लीटरल बक्ोट quot स्ट्रिंग शाब्दिक संकेतन (और इसके प्रकार जैसे बी। bquotquotquot। quotquotquot। और brquot। quot) अब टाइप बाइट्स का एक शाब्दिक उत्पादन करता है। पीईपी 3116: नई आईओ लाइब्रेरी आइओ मॉड्यूल अब फ़ाइल IO करने का मानक तरीका है, और sys. stdin का प्रारंभिक मान है। sys. stdout और sys. stderr अब io. extiobase के उदाहरण हैं। अंतर्निहित ओपन () फ़ंक्शन अब ओओ। ओपेन () के लिए एक उपनाम है और इसमें अतिरिक्त कीवर्ड आर्ग्यूमेंट एन्कोडिंग है। त्रुटियाँ नई लाइन और करीबी एफडी यह भी ध्यान रखें कि एक अवैध मोड तर्क अब ValueError उठाता है IOError नहीं एक पाठ फ़ाइल ऑब्जेक्ट के अंतर्गत बाइनरी फ़ाइल ऑब्जेक्ट को एफ. बफर के रूप में एक्सेस किया जा सकता है (लेकिन सावधान रहें कि एन्कोडिंग और डीकोडिंग ऑपरेशन को गति देने के लिए पाठ ऑब्जेक्ट स्वयं के बफ़र को बनाए रखता है)। पीईपी 3118: संशोधित बफर प्रोटोकॉल पुराने निर्मित बफर () अब वास्तव में नए निर्मित स्मृति मेमोरीव () चला गया है (अधिकतर) समान कार्यक्षमता प्रदान करता है PEP 3119: सार बेस कक्षाएं। संग्रह मॉड्यूल में परिभाषित एबीसी मॉड्यूल और एबीसी अब भाषा में कुछ हद तक प्रमुख भूमिका निभाता है, और संग्रह और संग्रह जैसे संग्रहित संग्रह प्रकार संग्रह के अनुरूप होते हैं। चुने हुए मैपिंग और संग्रह। बहुसंख्यक एबीसी क्रमशः। पीईपी 3127: इंटीगर लिटरल समर्थन और सिंटेक्स जैसा कि ऊपर उल्लेख किया गया है, नया अष्टक शाब्दिक अंकन केवल एक ही समर्थित है, और बाइनरी शाब्दिक जोड़े गए हैं। पीईपी 3129: क्लास डेकोरेटर PEP 3141: नंबर के लिए एक प्रकार पदानुक्रम नंबर मॉड्यूल एबीसी का एक और नया उपयोग है, जो पायथन 8217 के 8220 एनमेरिकर टॉवर 8221 को परिभाषित करता है। इसके अलावा नए अंशों के मॉड्यूल पर ध्यान दें जो संख्याओं को लागू करता है। लाइब्रेरी में परिवर्तन समय की कमी के कारण, यह दस्तावेज़ मानक पुस्तकालय में बहुत व्यापक परिवर्तनों को पूरी तरह से कवर नहीं करता है। पीईपी 3108 लाइब्रेरी में बड़े बदलाव के लिए संदर्भ है। यहां एक कैप्सूल की समीक्षा: 8217 में कई पुराने मॉड्यूल हटा दिए गए थे। कुछ लोग, जैसे गोफर लिब (अब उपयोग नहीं) और एमडी 5 (हस्लीब द्वारा प्रतिस्थापित), पीईपी 0004 द्वारा पहले ही हटा दिया गया था। अन्य Irix, BeOS और मैक ओएस 9 (पीईपी 0011 देखें) जैसे विभिन्न प्लेटफार्मों के समर्थन को हटाने के परिणामस्वरूप अन्य हटा दिए गए थे। उपयोग की कमी के कारण या कुछ बेहतर प्रतिस्थापन मौजूद होने के कारण कुछ मॉड्यूल को भी पायथन 3.0 में हटाने के लिए चुना गया था। संपूर्ण सूची के लिए पीईपी 3108 देखें बीएसडीडी 3 पैकेज को हटा दिया गया क्योंकि मुख्य मानक पुस्तकालय में इसकी उपस्थिति परीक्षण अस्थिरता और बर्कले डीबी 8217 रिलीज शेड्यूल के कारण मूल डेवलपर्स के लिए एक विशेष बोझ के रूप में साबित हुई है। हालांकि, पैकेज जिंदा है और अच्छी तरह से, बाहरी रूप से jcea. esprogramacionpybsddb. htm पर बनाए रखा है। कुछ मॉड्यूल का नाम बदल दिया गया क्योंकि उनका पुराना नाम PEP 0008 का उल्लंघन नहीं करता था। या अन्य अन्य कारणों के लिए। यहां 8217 की सूची: पायथन 2. में एक आम पैटर्न शुद्ध पायथन में कार्यान्वित एक मॉड्यूल का एक संस्करण है, उदाहरण के लिए सी एक्सटेंशन के रूप में लागू एक वैकल्पिक त्वरित संस्करण के साथ, अचार और cPickle। यह त्वरित संस्करण आयात करने और इन मॉड्यूल के प्रत्येक उपयोगकर्ता पर शुद्ध पायथन संस्करण पर वापस गिरने का बोझ रखता है। पायथन 3.0 में, त्वरित संस्करणों को शुद्ध पायथन संस्करणों के कार्यान्वयन विवरण माना जाता है। उपयोगकर्ताओं को हमेशा मानक संस्करण आयात करना चाहिए, जो त्वरित संस्करण आयात करने का प्रयास करता है और शुद्ध पायथन संस्करण में वापस आ जाता है। अचार cPickle जोड़ी इस उपचार प्राप्त किया। प्रोफ़ाइल मॉड्यूल 3.1 के लिए सूची में है। StringIO मॉड्यूल को io मॉड्यूल में एक वर्ग में बदल दिया गया है। कुछ संबंधित मॉड्यूल को संकुल में बांटा गया है, और आम तौर पर सबमिशन नामों को सरल किया गया है। परिणामस्वरूप नए संकुल हैं: डीबीएम (एएनडीबीएम डीबीएचटी डीबीएम डंबडीबीएम। जीडीबीएम। जेडीबी)। html (HTMLParser। htmlentitydefs) एचटीटीपी (सर्कलप्लिब बेसहेटीटीपीएसरवर। सीजीएचटीटीपीएसरवर। टंकलर (कछु को छोड़कर सभी टंकिनटर-संबंधित मॉड्यूल) कछुए के लक्ष्य दर्शकों doesn8217t वास्तव में tkinter के बारे में परवाह है यह भी ध्यान रखें कि पायथन 2.6 के रूप में, कछुए की कार्यक्षमता काफी बढ़ा दी गई है। urlib (urllib। urllib2। urlparse। robotparse)। xmlrpc (xmlrpclib. DocXMLRPCServer. SimpleXMLRPCServer)। मानक पुस्तकालय मॉड्यूल में कुछ अन्य बदलाव, जो कि पीईपी 3108 द्वारा कवर नहीं किया गया है। बिल्टिन सेट () फ़ंक्शन का उपयोग करें Sys मॉड्यूल की सफाई: हटाए गए sys. exitfunc () sys. excclear () sys. exctype sys. excvalue sys. exctraceback (नोट करें कि sys. lasttype आदि।) सरणी की सफाई। एररे प्रकार: पढ़ें () और लिखने () विधियों से उपयोग किए गए हैंफ़ाइल () और tofile () बजाय। साथ ही, सरणी के लिए सी टाइपकोड चला गया है 8211 या तो बाइट्स के लिए यू या यूनिकोड वर्णों के लिए यू। ऑपरेटर मॉड्यूल की सफाई: हटाए गए अनुक्रम शामिल () और संभवतः () थ्रेड मॉड्यूल की सफाई: acquirelock () और रिलीज़ेलॉक () का उपयोग अधिग्रहण () और रिलीज़ () के बजाय चला गया है। यादृच्छिक मॉड्यूल की सफाई: jumpahead () एपीआई हटाया नया मॉड्यूल चला गया है। कार्यों os. tmpnam () os. tempnam () और os. tmpfile () को tempfile मॉड्यूल के पक्ष में हटा दिया गया है। Tokenize मॉड्यूल बाइट्स के साथ काम करने के लिए बदल दिया गया है। मुख्य प्रविष्टि बिंदु अब टोकनइज़ कर रहा है। जनरेटोकेंस की बजाय string. letters और उसके दोस्तों (string. lowercase और string. uppercase) चले गए हैं। स्ट्रिंग का प्रयोग करें.सिसीलेटर आदि। इसके बजाय (हटाने का कारण यह है कि string. letters और दोस्तों के लोकेल विशिष्ट व्यवहार थे, जो कि इस तरह के आकर्षक-नामित वैश्विक 8220 कंसंटों 8221 के लिए एक बुरा विचार है।) बिल्टिन में निर्मित मॉड्यूल का निर्माण किया गया (अंडरस्कोर हटाने, 8216s8217 को जोड़ना) अधिकांश ग्लोबल नेमस्पेस में पाया गया बिल्टिन वैरिएबल अपरिवर्तित है। एक बिल्टिन को संशोधित करने के लिए, आपको बिल्टिंस का इस्तेमाल करना चाहिए। बिल्डिन पीईपी 3101 नहीं स्ट्रिंग फ़ॉर्मेटिंग के लिए एक नया तरीका अंतर्निर्मित स्ट्रिंग स्वरूपण संचालन के लिए एक नई प्रणाली स्ट्रिंग फ़ॉर्मेटिंग ऑपरेटर को बदल देती है। (हालांकि, ऑपरेटर अभी भी समर्थित है उसे पायथन 3.1 में पदावनत किया जाएगा और कुछ बाद के समय में भाषा से निकाल दिया जाएगा।) पूर्ण स्कूप के लिए पीईपी 3101 पढ़ें। अपवादों में परिवर्तन अपवाद को बढ़ाने और पकड़ने के लिए एपीआई को साफ कर दिया गया है और नए शक्तिशाली विशेषताएं शामिल हैं: पीईपी 0352। सभी अपवाद BaseException से प्राप्त (प्रत्यक्ष या अप्रत्यक्ष रूप से) होना चाहिए। यह अपवाद पदानुक्रम की जड़ है। यह एक सिफारिश के रूप में नया नहीं है, लेकिन बेस एक्सपैशन से आने की आवश्यकता नई है (अजगर 2.6 अभी भी क्लासिक कक्षाएं उठाई जाने की अनुमति दी गई है, और आप क्या पकड़ सकते हैं, इस पर कोई प्रतिबंध नहीं रखा गया।) परिणामस्वरूप, स्ट्रिंग अपवाद अंततः सचमुच और पूरी तरह से मृत हैं। लगभग सभी अपवाद वास्तव में एक्सपैशन बेस एक्सप्शन से प्राप्त होने चाहिए, केवल उन अपवादों के आधार क्लास के रूप में उपयोग किया जाना चाहिए जिन्हें केवल शीर्ष स्तर पर ही संभाला जाना चाहिए, जैसे SystemExit या KeyboardInterrupt अपवाद के अलावा सभी अपवादों को संभालने के लिए सुझाई गई मुहावरे का उपयोग करना है। मानक त्रुटि हटा दी गई थी (2.6 में पहले से ही) अपवाद अब अनुक्रम के रूप में व्यवहार नहीं करता है इसके बजाय आर्ग्स विशेषता का उपयोग करें PEP 310 9 अपवाद उठाना अब अपवाद उठाने के बजाय अब अपवाद (आर्ग्स) का उपयोग करें। आर्ग्स इसके अतिरिक्त, यदि आप ऐसा करने के लिए, इसके बजाय आप स्पष्ट रूप से एक ट्रैसबैक निर्दिष्ट नहीं कर सकते हैं, तो आप सीधे ट्रेसबैक विशेषता (नीचे देखें) को निर्दिष्ट कर सकते हैं। PEP 3110 अपवाद पकड़ने अब आप कुछException को छोड़कर कुछ ऐक्सैस्टेशन को छोड़कर चर का उपयोग कर सकते हैं। चर इसके अलावा, वेरिएबल को स्पष्ट रूप से हटा दिया जाता है जब ब्लॉक को छोड़ दिया जाता है PEP 3134 अपवाद चेनिंग दो मामलों हैं: अंतर्निहित चेनिंग और स्पष्ट चेनिंग अप्रभावित चेनिंग तब होता है जब एक अपवाद को छोड़कर या अंत में हेन्डलर ब्लॉक में उठाया जाता है। यह आम तौर पर हैंडलर ब्लॉक में एक बग के कारण होता है हम इसे एक द्वितीयक अपवाद कहते हैं। इस मामले में, मूल अपवाद (जिसे संभाला जा रहा था) को माध्यमिक अपवाद के संदर्भ विशेषता के रूप में सहेजा गया है। इस वाक्यविन्यास के साथ स्पष्ट चेनिंग लागू किया जाता है: (जहां प्राथमिक अपवाद कोई अपवाद है जो अपवाद वस्तु उत्पन्न करता है, संभवतः एक अपवाद जो पहले पकड़ा गया था)। इस मामले में, प्राथमिक अपवाद माध्यमिक अपवाद के कारण विशेषता पर संग्रहीत किया जाता है। ट्रेसबैक मुद्रित होता है जब एक अप्रयुक्त अपवाद तब होता है जब कारण और संदर्भ विशेषताओं की श्रृंखला चलता है और शीर्ष पर प्राथमिक अपवाद के साथ, श्रृंखला के प्रत्येक घटक के लिए एक अलग ट्रेसबैक प्रिंट करता है। (जावा उपयोगकर्ता इस व्यवहार को पहचान सकते हैं।) पीईपी 3134 अपवाद ऑब्जेक्ट्स अब अपने ट्रेसेबैक को ट्रेसबैक विशेषता के रूप में संग्रहीत करते हैं। इसका मतलब यह है कि अपवाद ऑब्जेक्ट में अब एक अपवाद से संबंधित सारी जानकारी शामिल है, और sys. excinfo () का उपयोग करने के लिए कम कारण हैं (हालांकि बाद हटाया नहीं गया है)। कुछ अपवाद संदेशों में सुधार हुआ है, जब Windows एक्सटेंशन मॉड्यूल लोड करने में विफल रहता है। उदाहरण के लिए, त्रुटि कोड 1 9 3 अब 1 वैध Win32 अनुप्रयोग नहीं है। स्ट्रिंग्स अब गैर-अंग्रेज़ी स्थानीय लोगों के साथ काम करती हैं। विविध अन्य परिवर्तन ऑपरेटर और विशेष तरीके अब के विपरीत देता है। जब तक रिटर्न नॉटिइम्प्लेड। भाषा से 8220 अनबाउंड विधियों 8221 की अवधारणा को हटा दिया गया है। जब एक क्लास विशेषता के रूप में एक विधि को संदर्भित करते हैं, तो अब आपको एक सादा फ़ंक्शन ऑब्जेक्ट मिलता है। होललिस () setlice () और delslice () मारे गए थे। वाक्यविन्यास ai: j अब a. getitem (टुकड़ा (i, j)) (या setitem () या delitem ()) का अनुवाद करते हैं। जब एक असाइनमेंट या हटाने के लक्ष्य के रूप में उपयोग किया जाता है)। PEP 3114 अगले मानक () विधि को अगले () नाम दिया गया है आइसीटी () और हेक्स () विशेष विधियों को हटा दिया गया 8211 ऑक्टो () और हेक्स () सूचकांक () का उपयोग अब एक पूर्णांक में तर्क परिवर्तित करने के लिए सदस्य और विधियों के लिए समर्थन हटाया गया FuncX नामित फ़ंक्शन एट्रीज को एक्स फॉर्म का उपयोग करने के लिए नाम दिया गया है, उपयोगकर्ता-परिभाषित विशेषताओं के लिए फ़ंक्शन विशेषता नामस्थान में इन नामों को मुक्त करने के लिए। बुद्धि के लिए, मितव्ययिता मज़ाकोड funcdefaults मज़ाकिया मज़ाकडॉक फ़नलग्लोबल्स funcname का नाम बदलकर बंद कर दिया गया था। कोड डिफ़ॉल्ट dict डॉक्टर ग्लोबल्स नाम क्रमशः। नोजेरोओ () अब बूल () है PEP 3135 नया सुपर () अब आप बिना बहस के सुपर () को आमंत्रित कर सकते हैं और (मानते हुए कि यह एक क्लास स्टेटमेंट के अंदर परिभाषित नियमित आवृत्ति विधि में है) सही वर्ग और उदाहरण स्वचालित रूप से चुना जाएगा। तर्कों के साथ, सुपर () का व्यवहार अपरिवर्तित है। PEP 3111 कच्चेइनपुट () को इनपुट () में बदल दिया गया था यही है, नया इनपुट () फ़ंक्शन sys. stdin से एक पंक्ति पढ़ता है और इसे पिछली नई लाइन के साथ छीन लिया जाता है यह EOFError उठाता है अगर इनपुट समय से पहले समाप्त हो जाता है इनपुट के पुराने व्यवहार को प्राप्त करने के लिए () eval (इनपुट ()) का उपयोग करें एक नया निर्माण अगले () एक वस्तु पर अगले () विधि कॉल करने के लिए जोड़ा गया था। इंटर्न () को स्थानांतरित किया गया (sys. intern) निकाला गया: लागू करें ()। लागू करने के बजाय (एफ, आर्ग्स) एफ (आर्ग्स) का उपयोग करें। कोलेबल () हटाया गया कॉल करने योग्य (एफ) के बजाय आप हैट्रर (एफ, कॉल) का उपयोग कर सकते हैं। ऑपरेटर. इसकलनीय () फ़ंक्शन भी चलाया जाता है। हटाया गया कॉरस () यह कार्य अब एक उद्देश्य का कार्य करता है, जो अब क्लासिक कक्षाएं चली गई हैं। निकाले गए execfile () Execfile (fn) के बजाय exec (खुला (fn).read ()) के बजाय निकाली गई फ़ाइल खुला () का उपयोग करें हटाया गया () को कम करें Functools. reduce () का उपयोग करें यदि आपको वास्तव में इसकी आवश्यकता है, तो 99% बार लूप के लिए एक स्पष्ट और अधिक पठनीय है। हटाया गया पुनः लोड () उपयोग करें import. reload () हटा दिया। dict. haskey () 8211 बजाय ऑपरेटर में उपयोग करें। निर्माण और सी API परिवर्तन समय की कमी के कारण, यहां सी API में परिवर्तन की एक बहुत ही अपूर्ण सूची है। मैक ओएस 9, बीओएस, आरआईएससीओएस, आईआरएसएक्स और ट्रू 64 सहित कई प्लेटफार्मों के लिए समर्थन हटा दिया गया था, लेकिन यह सीमित नहीं था। PEP 3118 नया बफर एपीआई PEP 3121 विस्तार मॉड्यूल प्रारंभिकरण समाप्ति PEP 3123 PyObjectHEAD को मानक सी के अनुरूप बनाना। प्रतिबंधित निष्पादन के लिए और नहीं सी API समर्थन। PyNumberCoerce PyNumberCoerceEx PyMemberGet और PyMemberSet सी एपीआई हटा दिए जाते हैं। नया सी एपीआई PyImportImportModuleNoBlock पीआईएमपोर्ट इंपोर्ट मॉड्यूल की तरह काम करता है लेकिन आयात लॉक पर 8217t ब्लॉक प्राप्त होता है (बजाय एक त्रुटि लौट रहा है)। बुलियन कनवर्ज़न C - स्तरीय स्लॉट और विधि का नाम बदला: nbnonzero अब nbbool है सी API से हटाए गए मीथेंडारग्स और बिना सीईएलएजीसी। निष्पादन 3.0 सामान्यीकरण का शुद्ध परिणाम यह है कि पायथन 3.0 Python 2.5 की तुलना में 10 धीमी गति के आसपास पीपोन बेंचमार्क चलाता है। सबसे अधिक संभावना सबसे बड़ी वजह यह है कि छोटे पूर्णांक के लिए विशेष-आवरण को हटाया जा रहा है। इसमें सुधार के लिए 8217 के कमरे हैं, लेकिन 3.0 के बाद पोर्टिंग टू पायथन 3.0 जारी किया जाएगा। मौजूदा पायथन 2.5 या 2.6 स्रोत कोड को पायथन 3.0 में पोर्टिंग करने के लिए, सबसे अच्छी रणनीति निम्न है: (पूर्वापेक्षा) उत्कृष्ट परीक्षण कवरेज पोर्ट पायथन 2.6 में। यह पायथन 2. एक्स से पायथन 2 तक औसत पोर्ट से अधिक काम नहीं होना चाहिए। (X1)। सुनिश्चित करें कि आपके सभी परीक्षण पास करें (अभी भी 2.6 का उपयोग कर रहा है) -3 कमांड लाइन स्विच चालू करें यह उन सुविधाओं के बारे में चेतावनियाँ सक्षम करता है जो कि 3.0 में हटाए जाएंगे (या बदलेंगे)। अपने परीक्षण सूट को फिर से चलाएं, और तय कोड के बारे में आपको चेतावनियां मिलें, जब तक कि कोई चेतावनी नहीं छोड़ी हो, और आपके सभी परीक्षण अभी भी पास हो जाते हैं अपने स्रोत कोड पेड़ पर 2to3 स्रोत-टू-सोर्स अनुवादक चलाएं। (इस उपकरण पर अधिक के लिए 2to3 - स्वचालित पायथन 2 से 3 कोड अनुवाद देखें।) Python 3.0 के अंतर्गत अनुवाद का परिणाम चलाएं। किसी भी शेष मुद्दों को मैन्युअल रूप से ठीक करें, समस्याओं को ठीक करने के लिए जब तक कि सभी परीक्षण फिर से न हो जाए। यह स्रोत कोड लिखने का प्रयास करने की अनुशंसा नहीं है जो दोनों Python 2.6 और 3.0 के अंतर्गत अपरिवर्तित चलाता है you8217d को एक बहुत ही कॉन्टोर्ड कोडिंग शैली का उपयोग करना है, उदा। प्रिंट स्टेटमेंट, मेटैक्लास, और बहुत कुछ से बचने यदि आप किसी पुस्तकालय को बनाए रखना चाहते हैं जिसमें पायथन 2.6 और पायथन 3.0 दोनों का समर्थन करने की आवश्यकता है, तो सबसे अच्छा तरीका 3 ऊपर स्रोत कोड के 2.6 संस्करण को संपादित करके और 2to3 अनुवादक को फिर से चलाने के बजाय 3 संस्करण को संशोधित करना है। सोर्स कोड। पायथन 3.0 में सी एक्सटेंशन को पोर्टिंग के लिए, कृपया पोर्टिंग एक्सटेंशन मॉड्यूल 3.0 से देखें .16.2। धाराओं के साथ काम करने के लिए io 8212 कोर उपकरण 16.2.1। अवलोकन io मॉड्यूल विभिन्न प्रकार के आईओ से निपटने के लिए पायथन 8217 की मुख्य सुविधाएं प्रदान करता है। आईओ के तीन मुख्य प्रकार हैं: पाठ IO बाइनरी आईओ और कच्चे आईओ ये सामान्य श्रेणी हैं, और उनमें से प्रत्येक के लिए विभिन्न बैकिंग स्टोर्स का उपयोग किया जा सकता है। इन श्रेणियों में से किसी एक से संबंधित कंक्रीट ऑब्जेक्ट को फ़ाइल ऑब्जेक्ट कहा जाता है। अन्य सामान्य शब्द स्ट्रीम और फ़ाइल-जैसी ऑब्जेक्ट हैं अपनी श्रेणी के स्वतंत्र रूप से, प्रत्येक कंक्रीट स्ट्रीम ऑब्जेक्ट में भी विभिन्न क्षमताओं होंगे: यह केवल-पढ़ने के लिए, केवल-लेखन, या पठन-लिखित हो सकता है। यह मनमाने ढंग से यादृच्छिक अभिगम (किसी भी स्थान के लिए पीछे या पीछे की ओर) की अनुमति दे सकता है, या केवल अनुक्रमिक पहुंच (उदाहरण के लिए एक सॉकेट या पाइप के मामले में)। सभी धाराएं उस प्रकार के डेटा के बारे में सावधान हैं, जो आप उन्हें देते हैं। उदाहरण के लिए द्विआधारी स्ट्रीम की लिखने () विधि में एक स्ट्रिंग ऑब्जेक्ट देने के लिए एक TypeError बढ़ाया जाएगा इसलिए एक पाठ स्ट्रीम के लिखने () विधि को बाइट्स ऑब्जेक्ट दे देंगे संस्करण 3.3 में बदलाः IOError बढ़ाने के लिए प्रयुक्त संचालन अब OSError बढ़ाते हैं। चूंकि IOError अब ओएसईआरआर के उपनाम है 16.2.1.1। आईओ टेक्स्ट IO टेक्स्ट को आरओआर ऑब्जेक्ट्स की अपेक्षा और पैदा करता है I This means that whenever the backing store is natively made of bytes (such as in the case of a file), encoding and decoding of data is made transparently as well as optional translation of platform-specific newline characters. The easiest way to create a text stream is with open(). optionally specifying an encoding: In-memory text streams are also available as StringIO objects: The text stream API is described in detail in the documentation of TextIOBase . 16.2.1.2. Binary IO Binary IO (also called buffered IO ) expects bytes-like objects and produces bytes objects. No encoding, decoding, or newline translation is performed. This category of streams can be used for all kinds of non-text data, and also when manual control over the handling of text data is desired. The easiest way to create a binary stream is with open() with b in the mode string: In-memory binary streams are also available as BytesIO objects: The binary stream API is described in detail in the docs of BufferedIOBase . Other library modules may provide additional ways to create text or binary streams. See socket. socket. makefile() for example. 16.2.1.3. Raw IO Raw IO (also called unbuffered IO ) is generally used as a low-level building-block for binary and text streams it is rarely useful to directly manipulate a raw stream from user code. Nevertheless, you can create a raw stream by opening a file in binary mode with buffering disabled: The raw stream API is described in detail in the docs of RawIOBase . 16.2.2. High-level Module Interface An int containing the default buffer size used by the module8217s buffered IO classes. open() uses the file8217s blksize (as obtained by os. stat() ) if possible. This is an alias for the builtin open() function. exception io. BlockingIOError This is a compatibility alias for the builtin BlockingIOError exception. exception io. UnsupportedOperation An exception inheriting OSError and ValueError that is raised when an unsupported operation is called on a stream. 16.2.2.1. In-memory streams It is also possible to use a str or bytes-like object as a file for both reading and writing. For strings StringIO can be used like a file opened in text mode. BytesIO can be used like a file opened in binary mode. Both provide full read-write capabilities with random access. 16.2.3. Class hierarchy The implementation of IO streams is organized as a hierarchy of classes. First abstract base classes (ABCs), which are used to specify the various categories of streams, then concrete classes providing the standard stream implementations. The abstract base classes also provide default implementations of some methods in order to help implementation of concrete stream classes. For example, BufferedIOBase provides unoptimized implementations of readinto() and readline() . At the top of the IO hierarchy is the abstract base class IOBase. It defines the basic interface to a stream. Note, however, that there is no separation between reading and writing to streams implementations are allowed to raise UnsupportedOperation if they do not support a given operation. The RawIOBase ABC extends IOBase. It deals with the reading and writing of bytes to a stream. FileIO subclasses RawIOBase to provide an interface to files in the machine8217s file system. The BufferedIOBase ABC deals with buffering on a raw byte stream ( RawIOBase ). Its subclasses, BufferedWriter. BufferedReader. and BufferedRWPair buffer streams that are readable, writable, and both readable and writable. BufferedRandom provides a buffered interface to random access streams. Another BufferedIOBase subclass, BytesIO. is a stream of in-memory bytes. The TextIOBase ABC, another subclass of IOBase. deals with streams whose bytes represent text, and handles encoding and decoding to and from strings. TextIOWrapper. which extends it, is a buffered text interface to a buffered raw stream ( BufferedIOBase ). Finally, StringIO is an in-memory stream for text. Argument names are not part of the specification, and only the arguments of open() are intended to be used as keyword arguments. The following table summarizes the ABCs provided by the io module: 16.2.3.1. IO Base Classes The abstract base class for all IO classes, acting on streams of bytes. There is no public constructor. This class provides empty abstract implementations for many methods that derived classes can override selectively the default implementations represent a file that cannot be read, written or seeked. Even though IOBase does not declare read(). readinto(). or write() because their signatures will vary, implementations and clients should consider those methods part of the interface. Also, implementations may raise a ValueError (or UnsupportedOperation ) when operations they do not support are called. The basic type used for binary data read from or written to a file is bytes. Other bytes-like objects are accepted as method arguments too. In some cases, such as readinto(). a writable object such as bytearray is required. Text IO classes work with str data. Note that calling any method (even inquiries) on a closed stream is undefined. Implementations may raise ValueError in this case. IOBase (and its subclasses) supports the iterator protocol, meaning that an IOBase object can be iterated over yielding the lines in a stream. Lines are defined slightly differently depending on whether the stream is a binary stream (yielding bytes), or a text stream (yielding character strings). See readline() below. IOBase is also a context manager and therefore supports the with statement. In this example, file is closed after the with statement8217s suite is finished8212even if an exception occurs: IOBase provides these data attributes and methods: Flush and close this stream. This method has no effect if the file is already closed. Once the file is closed, any operation on the file (e. g. reading or writing) will raise a ValueError . As a convenience, it is allowed to call this method more than once only the first call, however, will have an effect. True if the stream is closed. Return the underlying file descriptor (an integer) of the stream if it exists. An OSError is raised if the IO object does not use a file descriptor. Flush the write buffers of the stream if applicable. This does nothing for read-only and non-blocking streams. Return True if the stream is interactive (i. e. connected to a terminaltty device). Return True if the stream can be read from. If False. read() will raise OSError . Read and return one line from the stream. If size is specified, at most size bytes will be read. The line terminator is always bn for binary files for text files, the newline argument to open() can be used to select the line terminator(s) recognized. Read and return a list of lines from the stream. hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytescharacters) of all lines so far exceeds hint . Note that it8217s already possible to iterate on file objects using for line in file. without calling file. readlines() . Change the stream position to the given byte offset . offset is interpreted relative to the position indicated by whence . The default value for whence is SEEKSET. Values for whence are: SEEKSET or 0 8211 start of the stream (the default) offset should be zero or positive SEEKCUR or 1 8211 current stream position offset may be negative SEEKEND or 2 8211 end of the stream offset is usually negative Return the new absolute position. New in version 3.1: The SEEK constants. New in version 3.3: Some operating systems could support additional values, like os. SEEKHOLE or os. SEEKDATA. The valid values for a file could depend on it being open in text or binary mode. Return True if the stream supports random access. If False. seek(). tell() and truncate() will raise OSError . Return the current stream position. Resize the stream to the given size in bytes (or the current position if size is not specified). The current stream position isn8217t changed. This resizing can extend or reduce the current file size. In case of extension, the contents of the new file area depend on the platform (on most systems, additional bytes are zero-filled). The new file size is returned. Changed in version 3.5: Windows will now zero-fill files when extending. Return True if the stream supports writing. If False. write() and truncate() will raise OSError . Write a list of lines to the stream. Line separators are not added, so it is usual for each of the lines provided to have a line separator at the end. Prepare for object destruction. IOBase provides a default implementation of this method that calls the instance8217s close() method. Base class for raw binary IO. It inherits IOBase. There is no public constructor. Raw binary IO typically provides low-level access to an underlying OS device or API, and does not try to encapsulate it in high-level primitives (this is left to Buffered IO and Text IO, described later in this page). In addition to the attributes and methods from IOBase. RawIOBase provides the following methods: Read up to size bytes from the object and return them. As a convenience, if size is unspecified or -1, readall() is called. Otherwise, only one system call is ever made. Fewer than size bytes may be returned if the operating system call returns fewer than size bytes. If 0 bytes are returned, and size was not 0, this indicates end of file. If the object is in non-blocking mode and no bytes are available, None is returned. Read and return all the bytes from the stream until EOF, using multiple calls to the stream if necessary. Read bytes into a pre-allocated, writable bytes-like object b . and return the number of bytes read. If the object is in non-blocking mode and no bytes are available, None is returned. Write the given bytes-like object. बी। to the underlying raw stream, and return the number of bytes written. This can be less than the length of b in bytes, depending on specifics of the underlying raw stream, and especially if it is in non-blocking mode. None is returned if the raw stream is set not to block and no single byte could be readily written to it. The caller may release or mutate b after this method returns, so the implementation should only access b during the method call. class io. BufferedIOBase Base class for binary streams that support some kind of buffering. It inherits IOBase. There is no public constructor. The main difference with RawIOBase is that methods read(). readinto() and write() will try (respectively) to read as much input as requested or to consume all given output, at the expense of making perhaps more than one system call. In addition, those methods can raise BlockingIOError if the underlying raw stream is in non-blocking mode and cannot take or give enough data unlike their RawIOBase counterparts, they will never return None . Besides, the read() method does not have a default implementation that defers to readinto() . A typical BufferedIOBase implementation should not inherit from a RawIOBase implementation, but wrap one, like BufferedWriter and BufferedReader do. BufferedIOBase provides or overrides these methods and attribute in addition to those from IOBase : The underlying raw stream (a RawIOBase instance) that BufferedIOBase deals with. This is not part of the BufferedIOBase API and may not exist on some implementations. Separate the underlying raw stream from the buffer and return it. After the raw stream has been detached, the buffer is in an unusable state. Some buffers, like BytesIO. do not have the concept of a single raw stream to return from this method. They raise UnsupportedOperation . New in version 3.1. Read and return up to size bytes. If the argument is omitted, None. or negative, data is read and returned until EOF is reached. An empty bytes object is returned if the stream is already at EOF. If the argument is positive, and the underlying raw stream is not interactive, multiple raw reads may be issued to satisfy the byte count (unless EOF is reached first). But for interactive raw streams, at most one raw read will be issued, and a short result does not imply that EOF is imminent. A BlockingIOError is raised if the underlying raw stream is in non blocking-mode, and has no data available at the moment. Read and return up to size bytes, with at most one call to the underlying raw stream8217s read() (or readinto() ) method. This can be useful if you are implementing your own buffering on top of a BufferedIOBase object. Read bytes into a pre-allocated, writable bytes-like object b and return the number of bytes read. Like read(). multiple reads may be issued to the underlying raw stream, unless the latter is interactive. A BlockingIOError is raised if the underlying raw stream is in non blocking-mode, and has no data available at the moment. Read bytes into a pre-allocated, writable bytes-like object b . using at most one call to the underlying raw stream8217s read() (or readinto() ) method. Return the number of bytes read. A BlockingIOError is raised if the underlying raw stream is in non blocking-mode, and has no data available at the moment. New in version 3.5. Write the given bytes-like object. बी। and return the number of bytes written (always equal to the length of b in bytes, since if the write fails an OSError will be raised). Depending on the actual implementation, these bytes may be readily written to the underlying stream, or held in a buffer for performance and latency reasons. When in non-blocking mode, a BlockingIOError is raised if the data needed to be written to the raw stream but it couldn8217t accept all the data without blocking. The caller may release or mutate b after this method returns, so the implementation should only access b during the method call. 16.2.3.2. Raw File IO FileIO represents an OS-level file containing bytes data. It implements the RawIOBase interface (and therefore the IOBase interface, too). The name can be one of two things: a character string or bytes object representing the path to the file which will be opened. In this case closefd must be True (the default) otherwise an error will be raised. an integer representing the number of an existing OS-level file descriptor to which the resulting FileIO object will give access. When the FileIO object is closed this fd will be closed as well, unless closefd is set to False . The mode can be r. w. x or a for reading (default), writing, exclusive creation or appending. The file will be created if it doesn8217t exist when opened for writing or appending it will be truncated when opened for writing. FileExistsError will be raised if it already exists when opened for creating. Opening a file for creating implies writing, so this mode behaves in a similar way to w. Add a to the mode to allow simultaneous reading and writing. The read() (when called with a positive argument), readinto() and write() methods on this class will only make one system call. A custom opener can be used by passing a callable as opener . The underlying file descriptor for the file object is then obtained by calling opener with ( name . flags ). opener must return an open file descriptor (passing os. open as opener results in functionality similar to passing None ). See the open() built-in function for examples on using the opener parameter. Changed in version 3.3: The opener parameter was added. The x mode was added. Changed in version 3.4: The file is now non-inheritable. In addition to the attributes and methods from IOBase and RawIOBase. FileIO provides the following data attributes: The mode as given in the constructor. The file name. This is the file descriptor of the file when no name is given in the constructor. 16.2.3.3. Buffered Streams Buffered IO streams provide a higher-level interface to an IO device than raw IO does. A stream implementation using an in-memory bytes buffer. It inherits BufferedIOBase. The buffer is discarded when the close() method is called. The optional argument initialbytes is a bytes-like object that contains initial data. BytesIO provides or overrides these methods in addition to those from BufferedIOBase and IOBase : Return a readable and writable view over the contents of the buffer without copying them. Also, mutating the view will transparently update the contents of the buffer: As long as the view exists, the BytesIO object cannot be resized or closed. New in version 3.2. Return bytes containing the entire contents of the buffer. In BytesIO. this is the same as read() . In BytesIO. this is the same as readinto() . New in version 3.5. class io. BufferedReader ( raw . buffersizeDEFAULTBUFFERSIZE ) A buffer providing higher-level access to a readable, sequential RawIOBase object. It inherits BufferedIOBase. When reading data from this object, a larger amount of data may be requested from the underlying raw stream, and kept in an internal buffer. The buffered data can then be returned directly on subsequent reads. The constructor creates a BufferedReader for the given readable raw stream and buffersize . If buffersize is omitted, DEFAULTBUFFERSIZE is used. BufferedReader provides or overrides these methods in addition to those from BufferedIOBase and IOBase : Return bytes from the stream without advancing the position. At most one single read on the raw stream is done to satisfy the call. The number of bytes returned may be less or more than requested. Read and return size bytes, or if size is not given or negative, until EOF or if the read call would block in non-blocking mode. Read and return up to size bytes with only one call on the raw stream. If at least one byte is buffered, only buffered bytes are returned. Otherwise, one raw stream read call is made. class io. BufferedWriter ( raw . buffersizeDEFAULTBUFFERSIZE ) A buffer providing higher-level access to a writeable, sequential RawIOBase object. It inherits BufferedIOBase. When writing to this object, data is normally placed into an internal buffer. The buffer will be written out to the underlying RawIOBase object under various conditions, including: when the buffer gets too small for all pending data when flush() is called when a seek() is requested (for BufferedRandom objects) when the BufferedWriter object is closed or destroyed. The constructor creates a BufferedWriter for the given writeable raw stream. If the buffersize is not given, it defaults to DEFAULTBUFFERSIZE . BufferedWriter provides or overrides these methods in addition to those from BufferedIOBase and IOBase : Force bytes held in the buffer into the raw stream. A BlockingIOError should be raised if the raw stream blocks. Write the bytes-like object. बी। and return the number of bytes written. When in non-blocking mode, a BlockingIOError is raised if the buffer needs to be written out but the raw stream blocks. class io. BufferedRandom ( raw . buffersizeDEFAULTBUFFERSIZE ) A buffered interface to random access streams. It inherits BufferedReader and BufferedWriter. and further supports seek() and tell() functionality. The constructor creates a reader and writer for a seekable raw stream, given in the first argument. If the buffersize is omitted it defaults to DEFAULTBUFFERSIZE . class io. BufferedRWPair ( reader . writer . buffersizeDEFAULTBUFFERSIZE ) A buffered IO object combining two unidirectional RawIOBase objects 8211 one readable, the other writeable 8211 into a single bidirectional endpoint. It inherits BufferedIOBase . reader and writer are RawIOBase objects that are readable and writeable respectively. If the buffersize is omitted it defaults to DEFAULTBUFFERSIZE . BufferedRWPair does not attempt to synchronize accesses to its underlying raw streams. You should not pass it the same object as reader and writer use BufferedRandom instead. 16.2.3.4. Text IO Base class for text streams. This class provides a character and line based interface to stream IO. There is no readinto() method because Python8217s character strings are immutable. It inherits IOBase. There is no public constructor. TextIOBase provides or overrides these data attributes and methods in addition to those from IOBase : The name of the encoding used to decode the stream8217s bytes into strings, and to encode strings into bytes. The error setting of the decoder or encoder. A string, a tuple of strings, or None. indicating the newlines translated so far. Depending on the implementation and the initial constructor flags, this may not be available. The underlying binary buffer (a BufferedIOBase instance) that TextIOBase deals with. This is not part of the TextIOBase API and may not exist in some implementations. Separate the underlying binary buffer from the TextIOBase and return it. After the underlying buffer has been detached, the TextIOBase is in an unusable state. Some TextIOBase implementations, like StringIO. may not have the concept of an underlying buffer and calling this method will raise UnsupportedOperation . New in version 3.1. Read and return at most size characters from the stream as a single str. If size is negative or None. reads until EOF. Read until newline or EOF and return a single str. If the stream is already at EOF, an empty string is returned. If size is specified, at most size characters will be read. Change the stream position to the given offset . Behaviour depends on the whence parameter. The default value for whence is SEEKSET . SEEKSET or 0. seek from the start of the stream (the default) offset must either be a number returned by TextIOBase. tell(). or zero. Any other offset value produces undefined behaviour. SEEKCUR or 1. 8220seek8221 to the current position offset must be zero, which is a no-operation (all other values are unsupported). SEEKEND or 2. seek to the end of the stream offset must be zero (all other values are unsupported). Return the new absolute position as an opaque number. New in version 3.1: The SEEK constants. Return the current stream position as an opaque number. The number does not usually represent a number of bytes in the underlying binary storage. Write the string s to the stream and return the number of characters written. class io. TextIOWrapper ( buffer . encodingNone . errorsNone . newlineNone . linebufferingFalse . writethroughFalse ) A buffered text stream over a BufferedIOBase binary stream. It inherits TextIOBase . encoding gives the name of the encoding that the stream will be decoded or encoded with. It defaults to locale. getpreferredencoding(False) . errors is an optional string that specifies how encoding and decoding errors are to be handled. Pass strict to raise a ValueError exception if there is an encoding error (the default of None has the same effect), or pass ignore to ignore errors. (Note that ignoring encoding errors can lead to data loss.) replace causes a replacement marker (such as ) to be inserted where there is malformed data. backslashreplace causes malformed data to be replaced by a backslashed escape sequence. When writing, xmlcharrefreplace (replace with the appropriate XML character reference) or namereplace (replace with N escape sequences) can be used. Any other error handling name that has been registered with codecs. registererror() is also valid. newline controls how line endings are handled. It can be None. । n. r. and rn. It works as follows: When reading input from the stream, if newline is None. universal newlines mode is enabled. Lines in the input can end in n. r. or rn. and these are translated into n before being returned to the caller. If it is . universal newlines mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated. When writing output to the stream, if newline is None. any n characters written are translated to the system default line separator, os. linesep. If newline is or n. no translation takes place. If newline is any of the other legal values, any n characters written are translated to the given string. If linebuffering is True. flush() is implied when a call to write contains a newline character. If writethrough is True. calls to write() are guaranteed not to be buffered: any data written on the TextIOWrapper object is immediately handled to its underlying binary buffer . Changed in version 3.3: The writethrough argument has been added. Changed in version 3.3: The default encoding is now locale. getpreferredencoding(False) instead of locale. getpreferredencoding(). Don8217t change temporary the locale encoding using locale. setlocale(). use the current locale encoding instead of the user preferred encoding. TextIOWrapper provides one attribute in addition to those of TextIOBase and its parents: Whether line buffering is enabled. An in-memory stream for text IO. The text buffer is discarded when the close() method is called. The initial value of the buffer can be set by providing initialvalue . If newline translation is enabled, newlines will be encoded as if by write(). The stream is positioned at the start of the buffer. The newline argument works like that of TextIOWrapper. The default is to consider only n characters as ends of lines and to do no newline translation. If newline is set to None. newlines are written as n on all platforms, but universal newline decoding is still performed when reading. StringIO provides this method in addition to those from TextIOBase and its parents: Return a str containing the entire contents of the buffer. Newlines are decoded as if by read(). although the stream position is not changed. class io. IncrementalNewlineDecoder 16.2.4. Performance This section discusses the performance of the provided concrete IO implementations. 16.2.4.1. Binary IO By reading and writing only large chunks of data even when the user asks for a single byte, buffered IO hides any inefficiency in calling and executing the operating system8217s unbuffered IO routines. The gain depends on the OS and the kind of IO which is performed. For example, on some modern OSes such as Linux, unbuffered disk IO can be as fast as buffered IO. The bottom line, however, is that buffered IO offers predictable performance regardless of the platform and the backing device. Therefore, it is almost always preferable to use buffered IO rather than unbuffered IO for binary data. 16.2.4.2. Text IO Text IO over a binary storage (such as a file) is significantly slower than binary IO over the same storage, because it requires conversions between unicode and binary data using a character codec. This can become noticeable handling huge amounts of text data like large log files. Also, TextIOWrapper. tell() and TextIOWrapper. seek() are both quite slow due to the reconstruction algorithm used. StringIO. however, is a native in-memory unicode container and will exhibit similar speed to BytesIO . 16.2.4.3. Multi-threading FileIO objects are thread-safe to the extent that the operating system calls (such as read(2) under Unix) they wrap are thread-safe too. Binary buffered objects (instances of BufferedReader. BufferedWriter. BufferedRandom and BufferedRWPair ) protect their internal structures using a lock it is therefore safe to call them from multiple threads at once. TextIOWrapper objects are not thread-safe. 16.2.4.4. Reentrancy Binary buffered objects (instances of BufferedReader. BufferedWriter. BufferedRandom and BufferedRWPair ) are not reentrant. While reentrant calls will not happen in normal situations, they can arise from doing IO in a signal handler. If a thread tries to re-enter a buffered object which it is already accessing, a RuntimeError is raised. Note this doesn8217t prohibit a different thread from entering the buffered object. The above implicitly extends to text files, since the open() function will wrap a buffered object inside a TextIOWrapper. This includes standard streams and therefore affects the built-in function print() as well.

No comments:

Post a Comment