Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Total Noob question

Status
Not open for further replies.

simian336

Programmer
Sep 16, 2009
723
US
Hey,

I am new to python. I am trying to write a line out to a file.

f.write('findstr "directory\billing\"' + var)

I guess the \b is being interpreted as a dot when it writes to file. Is there way to write the literal line to the file?

Thanks

Simi
 
Hi

Simi said:
I guess the \b is being interpreted as a dot when it writes to file.
[tt]\b[/tt] is a backspace character. Not only in Python, in almost any language with C-like syntax.

Simi said:
Is there way to write the literal line to the file?
Either use the raw string notation :
Python:
f[teal].[/teal][COLOR=darkgoldenrod]write[/color][teal]([/teal][highlight]r[/highlight][green][i]'findstr "directory\billing\"'[/i][/green] [teal]+[/teal] var[teal])[/teal]
( Python | Lexical analysis | Literals | String literals )

Or just escape the backslashes ( \ ) :
Python:
f[teal].[/teal][COLOR=darkgoldenrod]write[/color][teal]([/teal][green][i]'findstr "directory[highlight]\[/highlight]\billing[highlight]\[/highlight]\"'[/i][/green] [teal]+[/teal] var[teal])[/teal]


Feherke.
[link feherke.github.com/][/url]
 
Hey,

Thanks... I also found that it is almost impossible to write a backslash at the end of a string. So you have to add it as a seperate string and doubled.

f.write(r'findstr "\directory\billing' + '\\' + var)

Thanks

Simi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top