What is use and purpose of read_text in python











up vote
-5
down vote

favorite












this is the code



import pydoc
def read_float(prompt):
while True:
try:
number_text = read_text(prompt)
result = float(number_text)
break
except ValueError:
print('Enter a number')
return result
read_float(1)


I am trying to use read_text function in python in this imageread_text program



but the in terminal i am getting a error of read_text is not defined










share|improve this question









New contributor




Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 4




    read_text() isn't defined anywhere in the standard library, but you'll probably find it wherever you found the code you pasted.
    – jedwards
    Nov 17 at 5:37










  • Also please post the code instead of the image.
    – Abdul Niyas P M
    Nov 17 at 5:38










  • Thanks jedwards..i got it i have to define another function read_text in the current file..
    – Ahmed Sheikh
    Nov 17 at 5:45















up vote
-5
down vote

favorite












this is the code



import pydoc
def read_float(prompt):
while True:
try:
number_text = read_text(prompt)
result = float(number_text)
break
except ValueError:
print('Enter a number')
return result
read_float(1)


I am trying to use read_text function in python in this imageread_text program



but the in terminal i am getting a error of read_text is not defined










share|improve this question









New contributor




Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 4




    read_text() isn't defined anywhere in the standard library, but you'll probably find it wherever you found the code you pasted.
    – jedwards
    Nov 17 at 5:37










  • Also please post the code instead of the image.
    – Abdul Niyas P M
    Nov 17 at 5:38










  • Thanks jedwards..i got it i have to define another function read_text in the current file..
    – Ahmed Sheikh
    Nov 17 at 5:45













up vote
-5
down vote

favorite









up vote
-5
down vote

favorite











this is the code



import pydoc
def read_float(prompt):
while True:
try:
number_text = read_text(prompt)
result = float(number_text)
break
except ValueError:
print('Enter a number')
return result
read_float(1)


I am trying to use read_text function in python in this imageread_text program



but the in terminal i am getting a error of read_text is not defined










share|improve this question









New contributor




Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











this is the code



import pydoc
def read_float(prompt):
while True:
try:
number_text = read_text(prompt)
result = float(number_text)
break
except ValueError:
print('Enter a number')
return result
read_float(1)


I am trying to use read_text function in python in this imageread_text program



but the in terminal i am getting a error of read_text is not defined







python python-3.x






share|improve this question









New contributor




Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 17 at 6:31









Vaibhav Vishal

933418




933418






New contributor




Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 17 at 5:36









Ahmed Sheikh

12




12




New contributor




Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Ahmed Sheikh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 4




    read_text() isn't defined anywhere in the standard library, but you'll probably find it wherever you found the code you pasted.
    – jedwards
    Nov 17 at 5:37










  • Also please post the code instead of the image.
    – Abdul Niyas P M
    Nov 17 at 5:38










  • Thanks jedwards..i got it i have to define another function read_text in the current file..
    – Ahmed Sheikh
    Nov 17 at 5:45














  • 4




    read_text() isn't defined anywhere in the standard library, but you'll probably find it wherever you found the code you pasted.
    – jedwards
    Nov 17 at 5:37










  • Also please post the code instead of the image.
    – Abdul Niyas P M
    Nov 17 at 5:38










  • Thanks jedwards..i got it i have to define another function read_text in the current file..
    – Ahmed Sheikh
    Nov 17 at 5:45








4




4




read_text() isn't defined anywhere in the standard library, but you'll probably find it wherever you found the code you pasted.
– jedwards
Nov 17 at 5:37




read_text() isn't defined anywhere in the standard library, but you'll probably find it wherever you found the code you pasted.
– jedwards
Nov 17 at 5:37












Also please post the code instead of the image.
– Abdul Niyas P M
Nov 17 at 5:38




Also please post the code instead of the image.
– Abdul Niyas P M
Nov 17 at 5:38












Thanks jedwards..i got it i have to define another function read_text in the current file..
– Ahmed Sheikh
Nov 17 at 5:45




Thanks jedwards..i got it i have to define another function read_text in the current file..
– Ahmed Sheikh
Nov 17 at 5:45












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










What you're looking at is not valid python code, unless read_text() is defined somewhere out of view. The function read_text() does not exist in standard python; rather, the built-in function input() serves that purpose instead. A proper implementation of that image you've provided is:



def read_float(prompt):                  # prompt is a string, e.g. "Enter a float"
while True: # this is to continue trying if not-a-float is entered
try:
number_text = input(prompt) # this prompts the user for input, and returns a string
result = float(number_text) # this tries to convert the string to a float
break # exit this loop to return the float
except ValueError: # this is thrown by the previous line if number_text isn't able to be converted to a float
print('Enter a Number') # ask the user to try again
return result


The result of running this function in my python console:



>>> read_float("Enter a float, please: ")
Enter a float, please: float
Enter a Number
Enter a float, please: 7.5
7.5





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });






    Ahmed Sheikh is a new contributor. Be nice, and check out our Code of Conduct.










     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348557%2fwhat-is-use-and-purpose-of-read-text-in-python%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    What you're looking at is not valid python code, unless read_text() is defined somewhere out of view. The function read_text() does not exist in standard python; rather, the built-in function input() serves that purpose instead. A proper implementation of that image you've provided is:



    def read_float(prompt):                  # prompt is a string, e.g. "Enter a float"
    while True: # this is to continue trying if not-a-float is entered
    try:
    number_text = input(prompt) # this prompts the user for input, and returns a string
    result = float(number_text) # this tries to convert the string to a float
    break # exit this loop to return the float
    except ValueError: # this is thrown by the previous line if number_text isn't able to be converted to a float
    print('Enter a Number') # ask the user to try again
    return result


    The result of running this function in my python console:



    >>> read_float("Enter a float, please: ")
    Enter a float, please: float
    Enter a Number
    Enter a float, please: 7.5
    7.5





    share|improve this answer

























      up vote
      1
      down vote



      accepted










      What you're looking at is not valid python code, unless read_text() is defined somewhere out of view. The function read_text() does not exist in standard python; rather, the built-in function input() serves that purpose instead. A proper implementation of that image you've provided is:



      def read_float(prompt):                  # prompt is a string, e.g. "Enter a float"
      while True: # this is to continue trying if not-a-float is entered
      try:
      number_text = input(prompt) # this prompts the user for input, and returns a string
      result = float(number_text) # this tries to convert the string to a float
      break # exit this loop to return the float
      except ValueError: # this is thrown by the previous line if number_text isn't able to be converted to a float
      print('Enter a Number') # ask the user to try again
      return result


      The result of running this function in my python console:



      >>> read_float("Enter a float, please: ")
      Enter a float, please: float
      Enter a Number
      Enter a float, please: 7.5
      7.5





      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        What you're looking at is not valid python code, unless read_text() is defined somewhere out of view. The function read_text() does not exist in standard python; rather, the built-in function input() serves that purpose instead. A proper implementation of that image you've provided is:



        def read_float(prompt):                  # prompt is a string, e.g. "Enter a float"
        while True: # this is to continue trying if not-a-float is entered
        try:
        number_text = input(prompt) # this prompts the user for input, and returns a string
        result = float(number_text) # this tries to convert the string to a float
        break # exit this loop to return the float
        except ValueError: # this is thrown by the previous line if number_text isn't able to be converted to a float
        print('Enter a Number') # ask the user to try again
        return result


        The result of running this function in my python console:



        >>> read_float("Enter a float, please: ")
        Enter a float, please: float
        Enter a Number
        Enter a float, please: 7.5
        7.5





        share|improve this answer












        What you're looking at is not valid python code, unless read_text() is defined somewhere out of view. The function read_text() does not exist in standard python; rather, the built-in function input() serves that purpose instead. A proper implementation of that image you've provided is:



        def read_float(prompt):                  # prompt is a string, e.g. "Enter a float"
        while True: # this is to continue trying if not-a-float is entered
        try:
        number_text = input(prompt) # this prompts the user for input, and returns a string
        result = float(number_text) # this tries to convert the string to a float
        break # exit this loop to return the float
        except ValueError: # this is thrown by the previous line if number_text isn't able to be converted to a float
        print('Enter a Number') # ask the user to try again
        return result


        The result of running this function in my python console:



        >>> read_float("Enter a float, please: ")
        Enter a float, please: float
        Enter a Number
        Enter a float, please: 7.5
        7.5






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 17 at 6:00









        Green Cloak Guy

        2,178720




        2,178720






















            Ahmed Sheikh is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            Ahmed Sheikh is a new contributor. Be nice, and check out our Code of Conduct.













            Ahmed Sheikh is a new contributor. Be nice, and check out our Code of Conduct.












            Ahmed Sheikh is a new contributor. Be nice, and check out our Code of Conduct.















             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348557%2fwhat-is-use-and-purpose-of-read-text-in-python%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown