[Baypiggies] translating shell environment variables
max at theslimmers.net
Tue Sep 2 18:13:14 CEST 2008
Shiqi Yang wrote:
> Hi, My python code is reading some xml files that have several shell
> style environment variables like "$_" or "$$".
> for example:
> <var name='tmp_log_file'>/tmp/$$.log</var>
> I need to extract them and translate them into real value when I read the file.
> Now I can only think of two ways of doing this,
> 1 is to have a big dictionary in my python code which have all the
> mappings from shell to python os module(or others as well)
> another way is to get shell involved and have it pre-process the file,
> but I'm afraid that way some of the values may not be well translated
> since the context switch (like the pids, etc).
> Are there any python module that could help this kind of task?
> or anyone has done similar work can share your experience?
> Any help will be highly appreciated.
you can use os.path.expandvars() on the cdata
More information about the Baypiggies