Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error: Nested method ?
#1
Hi people.

In the method of a class I receive parameters for data processing. As a solution I had to nest methods to be able to sequence the code, but I encounter the following error (TypeError: expected string or bytes-like object), the error presented when I nested the method, below follows the detailed code:

# Native Module, Import : re, regex
import re, json

# Name Class: CrositeScript
class CrositeScript:

    def m_purl (o_output, v_url, v_inp):

        # Regex Condition - exist if check
        if re.search (
           r "my-regex",
           v_url, re.IGNORECASE
        ):
            # Variable: get response status for client browser:
            status = "200 OK"
            # Variable: obtain http header for client browser
            headers = [("Content-type", "application/json; charset=utf-8")]
            # Function: Sending variable to the client browser:
            o_output (status, headers)
            # Output:
            return "msg ..."

        else:
            # ...
            def m_pinp (o_output, v_url, v_inp):
            
               # Regex Condition - exist if check
               if re.search (
                  r "my-regex",
                  v_inp, re.IGNORECASE
               ):
                  # Variable: get response status for client browser:
                  status = "200 OK"
                  # Variable: obtain http header for client browser
                  headers = [("Content-type", "application/json; charset=utf-8")]
                  # Function: Sending variable to the client browser:
                  o_output (status, headers)
                  # Output:
                  return "msg ..."
               
               else:
                  v_keo = v_inp.getvalue("v_query")
                  # Convert to dictionary
                  o_data = dict()
                  # Pre-structure for the json format
                  o_data ["term"] = "The search term -" + v_keo
                  # Output in json format
                  v_json = json.dumps(o_data)

                  # Variable: get response status for client browser:
                  status = "200 OK"
                  # Variable: obtain http header for client browser
                  headers = [("Content-type", "application/json; charset = utf-8")]
                  # Function: Sending variable to the client browser:
                  o_output (status, headers)
                  # Method Return Instruction:
                  return v_json

        return m_pinp (o_output, v_url, v_inp)
Reply


Messages In This Thread
Error: Nested method ? - by JohnnyCoffee - May-03-2020, 12:23 AM
RE: Error: Nested method ? - by bowlofred - May-03-2020, 02:34 AM
RE: Error: Nested method ? - by JohnnyCoffee - May-03-2020, 09:52 AM
RE: Error: Nested method ? - by pyzyx3qwerty - May-03-2020, 10:03 AM
RE: Error: Nested method ? - by deanhystad - May-03-2020, 01:55 PM
RE: Error: Nested method ? - by JohnnyCoffee - May-03-2020, 02:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Read nested data from JSON - Getting an error marlonbown 5 1,367 Nov-23-2022, 03:51 PM
Last Post: snippsat
  Error on nested loop : Invalid syntax dvazquezgu 3 3,236 Nov-25-2020, 10:04 AM
Last Post: palladium
  Type error when reading in different data types on an __init__ method Dylanmull 3 2,797 May-09-2019, 02:05 PM
Last Post: buran
  Index error using pop in nested loop PerksPlus 3 3,397 Mar-28-2019, 03:11 PM
Last Post: ichabod801
  Getting error when called through instance method aankrose 2 2,576 Mar-02-2019, 07:19 PM
Last Post: aankrose

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020