Hi!
I don't have much experience with python, so I hope you could help me.
I have to do a program that delete all the punctuations of a input txt document, but i can't figure out how to input the name(of the xy.txt) in the function.

Function

import string
def punc(s):
    txt = open( ' s ', 'r').read() #s should be replaced with the name.txt

    for punct in string.punctuation:
        txt2 = txt.replace(punct,"")
    return txt2

Program where you are supposed to enter the name of the txt document, you have to clean of punctuations

import function

s=raw_input("Enter the name of the text document: ")
a=function.punc(s)

print a

I would be very grateful if somebody could help me.

You are close:

import string

def punc(s):
    txt = open(s, 'r').read()
    print(txt)  # for test only
    for punct in string.punctuation:
        if punct in txt:
            # update txt
            txt = txt.replace(punct, "")
    return txt

# test your potential function.py module
if __name__ == '__main__':
    # pick a text file you have in the working folder
    fname = "name.txt"
    new_text = punc(fname)
    # show the result return from the function punc()
    print(new_text)
    
"""my test display -->
Frank, Miller: III
Dr. August Jarr
Mrs. Lola Meyer-Lipstick


Frank Miller III
Dr August Jarr
Mrs Lola MeyerLipstick
"""

Thank you so much, it works!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.