I am using parameterized functions
in python. And I am passing some string value and access its value.
This is how my function definition looks like:
import constants
def print_error_table(self, header1, errormsg, icon):
# for header1
print(constants.GREEN)
print(constants.REPORT_HEADER_ERR)
print(constants.DATE_TIME)
print(constants.SPACE)
start = "| | "+constants.ICON_BOX
header1_count = len(header1)
available_space_for_first_part = 37 - (len(start) + header1_count)
s = ""
print(constants.REPORT_ROOF)
print(constants.REPORT_COLUMNS)
print(constants.REPORT_FLOOR)
print(constants.REPORT_MIDDLE)
print(start),
print(" "+constants.NC+header1+constants.GREEN),
for i in range(available_space_for_first_part):
s += " "
print(s),
print("|"),
# right part
end = " "
end2 = "| |"
s2 = ""
icon_count = len(icon)
available_space_for_second_part = 31 - (len(end) + icon_count)
print(end),
print(icon),
for i in range(available_space_for_second_part):
s2 += " "
print(s2),
print(end2)
print(constants.REPORT_SHORT_HORIZONTAL_LINE)
print(constants.REPORT_MIDDLE_NO_MIDDLE_SEPTUM)
# print(len(constants.SPACE)) # 84
# print first 40 characters
start = "| |"
print(start),
s3 = ""
for i in range(12):
print(" "),
print(constants.RED),
msg = "1.) " + errormsg,
print(""+msg), # this is where my error is getting
print(constants.GREEN),
# print(constants.RED+constants.ICON_CROSS+msg+constants.GREEN),
for i in range(12, 57 - len(msg)-1):
s3 += " "
print(s3),
print("| |"),
print("")
print(constants.REPORT_MIDDLE_NO_MIDDLE_SEPTUM)
print(constants.REPORT_MIDDLE)
print(constants.REPORT_FLOOR)
print(constants.REPORT_FOOTER)
And this is my other python file where I am calling this function from.
error_message = "\"etcd\" is impaired\n"
print_error_table(self, "ETCD", error_message, constants.ICON_CROSS)
And I get this error:
File "/home/jananath/Desktop/python-script/2/bitesizetrouble/report_error.py", line 57, in print_error_table print(""+msg), TypeError: cannot concatenate 'str' and 'tuple' objects
The problem is the value I am passing (i.e error_message
) is not passing as a string
it is some kind of an altered text for some reason.
I am telling this because, in above (first) command, where it says print(""+str(msg))
, instead of this, when I try print(msg),
it gives some weird output like this.
(`"etcd" is impaired\n',)
You can see two parenthesis
are there on each side. Where does it come from and why I cannot concatanate the string I am passing to the function with another string (i.e print(""+str(msg))
update: I am using , to stop print() printing a new line. This is the way I should do that in python 2.7.5
msg = "1.) " + errormsg,
, and see if that helps. – Kevin,
to stopprint()
printing a new line. This is the way I should do that inpython 2.7.5
– Jananath Banukapython 2.7.5
for reason. I can't change back to the newest version. – Jananath Banukaprint
but you have sprinkled it in a lot of places where it doesn't do that. It creates a tuple and now you are annoyed that you have a tuple. – tripleee