[Zope] Basic Python Question

Marius Gedminas mgedmin at b4net.lt
Wed May 19 16:56:03 EDT 2004


On Wed, May 19, 2004 at 08:18:37AM -0500, Laura McCord wrote:
> I am writing a .htaccess file like below:
> 
> basedir = "12345678"
> username = "joe"
> dirpwd = "./htpasswd"
> dirpath = "/var/www/html/test/" + basedir + "/.htpasswd"
> filename=open(dirpath, 'w')
> filename.write("AuthType Basic")
> filename.write("AuthName Password Required")
> filename.write("AuthUserFile" + dirpwd)

You're missing a space here --^

> filename.write("Require user " + username)
> 
> My question is how do I make each of my statements on a separate line.

As Matt has already replied, you can add a "\n" at the end of each
string.  Or you can use the print statement, as it adds newlines
automatically:

  ...
  f = open(dirpath, 'w')
  print >> f, 'AuthType Basic'
  print >> f, 'AuthName "Password Required"'
  print >> f, 'AuthUserFile ' + dirpwd
  print >> f, 'Require user ' + username

> Once the file is created it should look like this when the .htaccess is
> opened:
> 
> AuthType Basic
> AuthName "Password Required"
> AuthUserFile /var/www/html/test/12345678/.htpasswd
> Require user joe
> 
> Plus, filename.write("AuthName Password Required") how do I make
> Password Required have quotes around it when written to the file?

'AuthName "Password Required"'

Or "AuthName \"Password Required\"" (but it looks clumsier).

HTH,
Marius Gedminas
-- 
C is for Cookies.  Perl is even better for Cookies.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope/attachments/20040519/e02525bc/attachment.bin


More information about the Zope mailing list