How to edit offline vmx file using python

Dave Angel davea at davea.name
Thu Feb 28 01:38:34 EST 2013


On 02/28/2013 12:29 AM, sasikiran2k7 at gmail.com wrote:
> Hi,
>
> I am new to python, how can we edit a .vmx file offline or just simply a file containing the data in the below format.
>
> My file sample.vmx contains data
>
> pciBridge7.virtualDev = "pcieRootPort"
> pciBridge7.functions = "8"
> vmci0.present = "TRUE"
> hpet0.present = "TRUE"
> nvram = "testvmdk.nvram"
> virtualHW.productCompatibility = "hosted"
> powerType.powerOff = "soft"
> powerType.powerOn = "hard"
>
>
> I need to update those values and the updated file should contains the data
>
> pciBridge7.virtualDev = "pcieRootPort"
> pciBridge7.functions = "8"
> vmci0.present = "TRUE"
> hpet0.present = "TRUE"
> nvram = "testing.nvram"
> virtualHW.productCompatibility = "hosted"
> powerType.poweroff='hard"
> powerType.poweron="sof't"
>
>

Since the file is tiny, start by reading it all into memory, into a 
list.  Then replace last two line's 16th character with a lowercase "O" 
  And replace the last line's string following the equals sign with the 
string "\"sof't\"

There are also some spacing differences, but they're harder to describe, 
and I suspect they were accidental.

-- 
DaveA



More information about the Python-list mailing list