How to write variables to a temporary file in python
Question: I have been trying to write variables to a temporary text file but I get the
following error:

    
    
    Traceback (most recent call last):
      File "F:/A453/_Codes_/APP CONFIG/Temp.py", line 102, in <module>
        ORXQC-IIHL2-6AV55-FIJEV-2""")
      File "C:\Program Files (x86)\Python34\lib\tempfile.py", line 399, in     func_wrapper
        return func(*args, **kwargs)
    TypeError: 'str' does not support the buffer interface
    

My Script is the Following:

    
    
    import tempfile
    TEMPDIR=tempfile.TemporaryFile()
    TEMPDIR.write("""B5IB6-ELAZ1-RAPY9-V8X1I-3
    OKXVB-Q8B9G-IT9ZF-MI4EQ-2
    PLDZ6-769YT-YJSR4-682JT-7
    H67L5-9HO4C-4UDSR-BYA14-6
    Y73EC-S8OJG-O1APH-N41KM-3
    JCYVV-UXNIN-9RGSU-WQ9SD-1
    WL9AO-9BLI7-GXXGM-VESEU-2
    VDLHT-IXMUY-V4FPU-V3IFZ-1
    8CPVN-Z776Z-Y49J3-2C683-5
    ORXQC-IIHL2-6AV55-FIJEV-2""")
    Activation=input('Please Enter your Product Activation Key: ')
    if Activation in TEMPDIR:
        print('True')
    else:
        print('False')
    

Please help me overcome this error

Thanks


Answer: The default mode of `TemporaryFile` is `"w+b"`, e.g. binary. You have to
provide the mode explicitly for text:

    
    
    TEMPDIR = tempfile.TemporaryFile(mode="w+")
    

