Reputation: 331
I have these two lines of code:
outfile="C:\Temp\gens.csv"
print("SaveData(" + outfile + ",CSV,GEN,[BusNum, ID, MW, MVAR, VoltSet], [])")
The output is
SaveData(C:\Temp\gens.csv,CSV,GEN,[BusNum, ID, MW, MVAR, VoltSet], [])
But would like to see output like this...double quotes around the path.
SaveData("C:\Temp\gens.csv",CSV,GEN,[BusNum, ID, MW, MVAR, VoltSet], [])
Upvotes: 1
Views: 930
Reputation: 16740
You must format your string so the double quotes are actually printed. Here, you have several solutions.
"these too \" will be printed"
'these double quotes " will be printed'
"""You can print "s or 's here without having to escape either"""
'''And this "works" 'as' well'''
The main advantage of triple quotes is that you rarely want to display triple quotes, so you won't ever have to bother with escaping.
Using simple quotes for your string can be bothersome, because '
happens to be an apostrophe too, which is pretty common in English.
In most situation, double quotes "
are the best choice, since it's simple, doesn't require escaping simple quotes, and escaping a double quote is really easy ("\""
).
If you happen to have a lot of textual data, I would recommend the use of triple quotes.
But anyway, in the end, all the ways to declare strings are equivalent.
Upvotes: 0
Reputation: 3859
print('SaveData("' + outfile + '",CSV,GEN,[BusNum, ID, MW, MVAR, VoltSet], [])'
Upvotes: 2