[Tutor] VERY newbie question

Daniel Yoo dyoo@hkn.EECS.Berkeley.EDU
Fri, 21 Jul 2000 14:02:51 -0700 (PDT)


On Fri, 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")

There are 2 small bugs.  The most important one is the quoting of
'name'; you probably meant to do

  "C:\" + name

instead.

The other one is obscure to new users; the backslash character, '\', is
special in Python strings.  It indicates a control ("escape") sequence.  
Some of these are useful; for example, "\n" means "skip to a new
line".  Try this out, and you'll understand:

  print "Hello, this is\non another\nline.\t\tThis is tabbed a bit."

There are a few escape sequences.  The example above uses '\n'
(newline) and '\t' (tab).  To tell Python not to see the backslash as an
escape, you can trap it using "raw" string notation:

  r"C:\"

Put an 'r' in front of your string quotes, and it should be ok.

If you have any other questions, feel free to ask.  Good luck to you!