1

I'm kind of working on string operation, here is what i want to do
- i created a functions gettext(request) for getting text from *.txt files, this is the code

def gettext(request):
  if request.method == 'POST':
    form = UploadFileForm(request.POST, request.FILES)
    if form.is_valid():
        f = request.FILES['file']
        for chunk in f.chunks():
            text = chunk

        return render(request, 'ecs/index.html', {'text': text, 'form': form})      
    else:
        form = UploadFileForm()
return render_to_response('ecs/index.html', {'form': form})

and then i want to get the data that i stored on text variable to a functions, called preprocessing

def preprocessing(text):
    pp = Preprocess()

    wordTokenize = pp.tokenizing(text)

    return wordTokenize

how can i use the preprocessing(text) method to handle data from text variable on gettext method.
i tried some tricks, but still no progress.

1 Answer 1

1

import the preprocessing function from wherever you have it into the file that has gettext in it, and then do this:

def gettext(request):
  if request.method == 'POST':
    form = UploadFileForm(request.POST, request.FILES)
    if form.is_valid():
        f = request.FILES['file']
        for chunk in f.chunks():
            text = chunk
            text = preprocessing(text)
        return render(request, 'ecs/index.html', {'text': text, 'form': form})      
    else:
        form = UploadFileForm()
return render_to_response('ecs/index.html', {'form': form})
Sign up to request clarification or add additional context in comments.

1 Comment

still not working sir, when i run your code, the output was global name 'request' is not defined so i changed preprocess(text) to preprocess(request, text) and modify text = preprocessing(text) to preprocessing(request, text) and run well, thanks @IsaacRay

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.