शुरू करेंमुफ़्त में शुरू करें

Python में एक वेरिएबल पढ़ना

आपने समझा है कि अपने Dags में Variables का उपयोग करने से अलग-अलग environments में कॉन्फ़िगरेशन पर थोड़ा नियंत्रण मिल सकता है, जिनमें आपके development और test Airflow servers भी शामिल हैं. ताकि आपको हर सर्वर के लिए अपना Dag कोड अपडेट न करना पड़े, आप सर्वर पर अलग-अलग फाइलों के लोकेशन को रखने के लिए Output_Path नाम का एक variable लागू करने का फ़ैसला करते हैं.

dag और task ऑब्जेक्ट्स, साथ ही datetime, आपके लिए इम्पोर्ट कर दिए गए हैं.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Python में Apache Airflow परिचय

पाठ्यक्रम देखें

अभ्यास निर्देश

  • Variables के साथ काम करने के लिए ज़रूरी लाइब्रेरी इम्पोर्ट करें.
  • Airflow से Output_Path वेरिएबल पढ़ें.
  • अगर Output_Path परिभाषित नहीं है, तो /home का fallback मान दें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Import the proper library to read Variables
from airflow.____ import ____

@dag(dag_id='process_sales', start_date=datetime(2026, 4, 15))
def process_sales():
    @task()
    def parse_file():
        # Get the output file location, otherwise default to "/home"
        output_path = ____.____("Output_Path", ____="/home")      
        # Logging only currently - processing to be added later
        print(f"File parsed and saved to {output_path}/sales_report.pdf")
    
    parse_file()
process_sales()
कोड संपादित करें और चलाएँ