Re: Making a shorter shebang

2006-10-14 Thread veracon
Thanks, at least now I know I wasn't doing something wrong.

Marc 'BlackJack' Rintsch wrote:
> In <[EMAIL PROTECTED]>, veracon wrote:
>
> > Actually, it appears to still be using the default binary
> > (/usr/bin/python). Can I be sure it's actually reading the .profile
> > file? I'm executing through regular CGI in Apache.
>
> The `~/.profile` is executed when *you* log into your account.  CGI
> scripts are executed by the web server which usually has its own user and
> group,  `wwwrun` or something like that, and does not read the `.profile`
> in your home directory.
> 
> Ciao,
>   Marc 'BlackJack' Rintsch

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Making a shorter shebang

2006-10-14 Thread veracon
Actually, it appears to still be using the default binary
(/usr/bin/python). Can I be sure it's actually reading the .profile
file? I'm executing through regular CGI in Apache.

veracon wrote:
> Thanks a lot!
>
> Jerry wrote:
> > /usr/bin/env just searches your PATH variable to find it, but it does
> > so in order.  So, if you want it to find your python instead of a
> > system provided one, just alter your PATH variable and put
> > /home/my_username/python2.5 in front of everything else.
> >
> > example in .profile:
> >
> > PATH=/home//python2.5:$PATH
> > export PATH
> >
> > --
> > Jerry
> >
> > On Oct 14, 10:37 am, "veracon" <[EMAIL PROTECTED]> wrote:
> > > Long story short, in order to use Python 2.5, I've compiled it in my
> > > own account on my hosting. It works fantastic as
> > > /home/my_username/python2.5, but the shebang is a bit long. Is there a
> > > way to shorten it (environment variables?) or, even better, make
> > > /usr/bin/env python point to it?
> > > 
> > > Thanks in advance!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Making a shorter shebang

2006-10-14 Thread veracon
Thanks a lot!

Jerry wrote:
> /usr/bin/env just searches your PATH variable to find it, but it does
> so in order.  So, if you want it to find your python instead of a
> system provided one, just alter your PATH variable and put
> /home/my_username/python2.5 in front of everything else.
>
> example in .profile:
>
> PATH=/home//python2.5:$PATH
> export PATH
>
> --
> Jerry
>
> On Oct 14, 10:37 am, "veracon" <[EMAIL PROTECTED]> wrote:
> > Long story short, in order to use Python 2.5, I've compiled it in my
> > own account on my hosting. It works fantastic as
> > /home/my_username/python2.5, but the shebang is a bit long. Is there a
> > way to shorten it (environment variables?) or, even better, make
> > /usr/bin/env python point to it?
> > 
> > Thanks in advance!

-- 
http://mail.python.org/mailman/listinfo/python-list


Making a shorter shebang

2006-10-14 Thread veracon
Long story short, in order to use Python 2.5, I've compiled it in my
own account on my hosting. It works fantastic as
/home/my_username/python2.5, but the shebang is a bit long. Is there a
way to shorten it (environment variables?) or, even better, make
/usr/bin/env python point to it?

Thanks in advance!

-- 
http://mail.python.org/mailman/listinfo/python-list


Hierarchy - how?

2006-04-30 Thread veracon
I'd like to know how to make the following string:
food
 fruit
  red
   cherry
  yellow
   banana
 meat
  pork
foo
 bar
  baz
 qux

Result in a dictionary like this:
{'food': {'fruit': {'red': 'cherry', 'yellow': 'banana'}, 'meat':
'pork'}, 'foo': {'bar': 'baz', 'qux': {}}}

Or something like that (if you understand). What would be the best way
of doing so? I'm thinking re.finditer might be appropriate, but I'm not
sure. I'd prefer not looping TOO much, since it's actually made using a
loop or two.

Actually, if anyone has a better idea of how to do the entire thing,
that'd be even better:
def hierarchy(data, parent='', level=0, out=''):
for item in which_parent(data, parent):
out += ' ' * level + item + '\n'
out = hierarchy(data, item, level + 1, out)

return out

def which_parent(data, parent):
return filter(None, [item[1] == parent and item[0] or None for item
in data])

data = (('food', ''),
('fruit', 'food'),
('red', 'fruit'),
('yellow', 'fruit'),
('cherry', 'red'),
('banana', 'yellow'),
('meat', 'food'),
('pork', 'meat'),
('foo', ''),
('bar', 'foo'),
('baz', 'bar'),
('qux', 'foo'))

print hierarchy(data)

-- Keep in mind that I don't want a string, I want a dictionary (but I
can't figure out how to do it).

-- 
http://mail.python.org/mailman/listinfo/python-list


Parsing XML/XSLT

2006-04-23 Thread veracon
Hello,

I'm looking to use XML and XSLT for templates in a system I'm writing,
however I'm not really sure which parser is the "best". Basically,
which library has the most features, and which is the most supported?

A guide I saw mentioned importing xml.xslt, however it appears the xml
module/package contains pretty much nothing - xml.xslt outputs an
exception, No module named xslt.

Help?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: re.sub problem

2006-03-31 Thread veracon
Thanks a lot! Compiling with re.DOTALL did fix my problem for the most
part; there still are a few problems with my code, but I think I can
fix those myself.

Again, thanks!

> Okay I just woke up and haven't had enough coffee so if I'm off here
> please forgive me.  Are you saying that if there is an emptly line then
> it borks?  If so just use re.S ( re.DOTALL ) and that should take care
> of it.  It will treat the ( . ) special.  Otherwise it ignores new
> lines.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: re.sub problem

2006-03-31 Thread veracon
Actually, it happens in general when there is more than one linebreak
between the open and close statements; not only when there are empty
lines.

-- 
http://mail.python.org/mailman/listinfo/python-list


re.sub problem

2006-03-31 Thread veracon
I'm trying to make a (tiny) template system (Cheetah and like have far
more than what I need), but I've run into a problem. To simplify
everything, I've decided to make for loops matching the indentation
level of the open and close statements; it appears to work fine, but
apparently it chokes once there are empty lines inside the string being
replaced in.

It's a bit hard to explain, so I'll just show an example:
stm = re.compile('\n(\s+)\{\{for (.+?) in
(.+?)\}\}\n?(.+?)\n\\1\{\{end for\}\}', re.M)
data = re.sub(stm, self.handle_for, data)

I do have a self.handle_for, and I can see that it's not called if I
give it the following string:
[... (not beginning of actual string) ]
  {{for baz in bar}}
  foo:{baz}
b

  {{end for}}

There, nothing is matched; if there wasn't an empty line, it would
match something.

What am I doing wrong?

-- 
http://mail.python.org/mailman/listinfo/python-list


Find directory name of file?

2006-01-29 Thread veracon
I'm pretty new at Python, so I have no idea how to do this: How do I
find the name of the directory that contains the application currently
being executed (e.g. if the file is /home/user/file.py, I want to get
the /home/user part)?

Thanks!

-- 
http://mail.python.org/mailman/listinfo/python-list