How Do You Eliminate the “Namespace”, Quotes and Brackets from the Variable You Are Printing with Python?

Problem scenario
You are trying to print a variable, but it prints out like this:


How do you print out just "foobar" with no quotes?


The key word here is "string".  The "string" text in this is the attribute you will want.

Your program may have something like this:

args = parser.parse.args()     # Assuming this is the variable assignment of "foobar"
print (args)     

1.  Eliminate the "print(args)" line.

2.  Insert these lines into your code:

var1 = args.string  # this retrieves the string attribute per the "string" that was printed out
newvar = var1[0]    # This retrieves the content of the item without the quotes and brackets.
print (newvar) 

Leave a comment

Your email address will not be published. Required fields are marked *