('syntax %(name,name,name)', <open file '<stderr>', mode 'w' at 0x01CE60D0>)? [closed]

StackOverflow https://stackoverflow.com/questions/19421191

  •  01-07-2022
  •  | 
  •  

Question

Why when i run this line of code:

print ("syntax %(name,name,name)",sys.stderr)

I get the following error:

('syntax %(name,name,name)', <open file '<stderr>', mode 'w' at 0x01CE60D0>)
Was it helpful?

Solution

That's not an error.

When you do sys.stderr, you're printing the representation of it, which is <open file '<stderr>', mode 'w' at blah>. I'm not familiar with the sys module, so I'm not exactly sure what you should be doing. Here's a link to the documentation on it however.

OTHER TIPS

You seem to use Python 2.x. Here, print is a statement and you are printing a tuple to stdout.

You can achieve what you want with

print >> sys.stderr, "syntax %(name,name,name)"

but this string seems weird to me, especially the %(name,name,name) part. But as you don't tell us what you really want to print, that's all that can be done.

If you want to use print() as a function, be it in Python 3.x or after using from __future__ import print_function, you should obey the syntax of print():

print("syntax %(name,name,name)", file=sys.stderr)

Another issue seems to be the string you are printing:

"syntax %(name,name,name)"

resembles me of String formatting where you have omitted the parameters and use wrong syntax.

So, depending on what you want to do,

"syntax %(name)s%(name)s%(name)s" % some_dict_having_name_as_a_key

could be what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top