Reputation: 169
How do you keep an input string from printing if you have not told it to print. This:
class o():
row = int(input("Select number > "))
will print out 'Select number even if i have not told it to print.
and this:
class o():
def select(self,row):
row = int(input("Select number > "))
pracObj = o()
o.select(self,row)
will give me an error.
and if I place the input outside the class it still prints.
Upvotes: 0
Views: 53
Reputation: 3964
You're on the right track. Try this:
class o():
def select(self):
row = int(input('Number > '))
return row
pracObj = o()
row = pracObj.select()
print(row)
You create an instance of the class with
pracObj = o()
Now, pracObj is the instance, and you can access its methods as you please:
row = pracObj.select()
will return
the value of the input
to the variable row
.
Upvotes: 0
Reputation: 117981
The input
function will print whatever you have in quotes. To have it "not print anything" you just need to call it without any text.
row = int(input())
To get your behavior of sometimes printing, you can split it up like this
if wantToPrint: # where wantToPrint is some bool
print("Select number >")
row = int(input())
Upvotes: 1