0

I am taking data from .csv file and user to create a string template,Now I want to save this template as a text file.I have assigned the whole template into a single variable as

Temp=A, t.substitute(values))

but I am getting error.

def Mail_Temp():

    NSTT=input("Enter Case Number Number :")
    ActDate=input("Enter Activity Schedule date and time:")
    ProD=input("Enter Problem Description")

    A=  """
    ----------------------------------------------------------------------------------------
                    Basic Details Required for Logging Complaints
    ----------------------------------------------------------------------------------------
                        END CLIENT --Internate Network
    ```````````````````````````````````````````````````````````````````````````````````````` """
    values={'Dev':HostN, 'Add': Add,'Con':Contact,'Mail':Mail_ID,'SN':SN,'Ven':Ven,'NSTT':NSTT,'ActDate':ActDate,'ProD':ProD}

    #values = {'var': 'HOSTNMAE'}

    t = string.Template("""
    DEVICE HOSTNAME    : $Dev
    CONTACT Person Name: $Con
    EMAIL              : $Mail
    NSTT               : $NSTT
    Device SN          : $SN
    Vendor             : $Ven
    ADDRESS            : $Add
    Problem Description: $ProD
    Note               : Engineer must carry laptop ,console cable & data card
    Activity Schedule  : $ActDate
    """)

    print(A, t.substitute(values))


    Temp = (A, t.substitute(values))
    f= open("Text.txt","w+")
    f.write(Temp)
    f.close()


HostN, Add, Ven, SN, Contact, Mail_ID = get_Data()
Mail_Temp()

Error::

File "C:\Users\xxxx\Desktop\xxxx\xxxxx\final data read and select.py", line 59, in Mail_Temp
    f.write(Temp)
TypeError: write() argument must be str, not tuple

How I can import this template to Text file ...

1
  • The issue has been resolved by doing this, I have combined A and t and printed. Commented Jan 21, 2019 at 9:44

1 Answer 1

2

To me the question is not very clear. But from the code it is clear that your program is asking for some input and then giving output in a special template format. So here, what I think you really need is a way to "export" the template in text format. And not import, like the question says. To export the template you can simply write it out in a text file, and then reuse it however you like, wherever you like.

To export/write in a text file all you need is this example from Quora.

def out_fun():
    return "Hello World"
output = out_fun()
file = open("sample.txt","w")
file.write(output)
file.close()
Sign up to request clarification or add additional context in comments.

1 Comment

It is interrupting to taking input user creating a loop of input variables .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.