[Tutor] VERY newbie question
Sean 'Shaleh' Perry
shaleh@valinux.com
Fri, 21 Jul 2000 12:30:37 -0700 (PDT)
On 21-Jul-2000 Jacob Williams wrote:
> Why won't this work, and/or how can I get this to work?
>
> import sys
> name = raw_input("Enter name of the dir: ")
> sys.path.append("C:\ + name")
>
> thanks for your support, and patience with such a newbie question,
>
geisha [~] $ python
Python 1.5.2 (#0, Apr 3 2000, 14:46:48) [GCC 2.95.2 20000313 (Debian
GNU/Linux)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> a = "Hello"
>>> b = "World"
>>> string = a + ", " + b
>>> print string
Hello, World
>>> import sys
>>> name = raw_input("Enter name of the dir: ")
Enter name of the dir: foo
>>> print name
foo
>>> print "C:\ + name"
C:\ + name
>>> print "C:\" + name
File "<stdin>", line 1
print "C:\" + name
^
SyntaxError: invalid token
>>> print "C:\\" + name
C:\foo
As you typed it, it should print "C:\ + name". Also watch out for '\' it
escapes the character in front of it. It is a good idea to always use \\ or
function(r"c:\path"), the r means do not escape things in side the string.