Eliminate "extra" variable

Dave Angel davea at davea.name
Mon Dec 16 03:58:24 CET 2013


On Sun, 15 Dec 2013 18:43:53 -0800, Igor Korot <ikorot01 at gmail.com> 
wrote:
> On Sun, Dec 15, 2013 at 4:58 PM, MRAB <python at mrabarnett.plus.com> 
wrote:




> > When writing paths on Windows, it's a good idea to use raw string
> > literals or slashes instead of backslashes:
> >
> >     conn = sqlite3.connect(r'c:\Documents and
> > Settings\Igor.FORDANWORK\Desktop\mydb.db', detect_types =
> > sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
> >
> > or:
> >
> >     conn = sqlite3.connect('c:/Documents and
> > Settings/Igor.FORDANWORK/Desktop/mydb.db', detect_types =
> > sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)

> So, how do I convert my string to one of those?
> I realized I can just do replace '/' to '\', but is there a better 
alternative?

The "conversion" is done with a text editor.  The string literals you 
had were just wrong. By the time they have been turned into strings 
it's too late to algorithmically recover your intended string values.

-- 
DaveA




More information about the Python-list mailing list