php equivalents?

Duncan Booth duncan at NOSPAMrcp.co.uk
Thu Apr 24 18:21:49 CEST 2003


"Daniel Dittmar" <daniel.dittmar at sap.com> wrote in 
news:b890vo$rpj$1 at news1.wdf.sap-ag.de:

>>> var_export($var)
>>
>> This function converts a variable to a text string of valid code
>> which can be reevaluated at any time. Python has pickle/cPickle, and
>> also has modules that can dump/load to XML, however, none of these
>> create actual code, but instead create a formatted data string.
> 
> repr () is the equivalent function, at least for the builtin types.

repr() won't give the desired effect if there are multiple references to 
the same object involved. e.g.

>>> aList = [1, 2, 3]
>>> aDict = {'x': aList, 'y': aList }
>>> aDict
{'y': [1, 2, 3], 'x': [1, 2, 3]}

Evaluating the repr of aDict won't give you an equivalent structure, and if 
you do:

>>> aList[1] = aDict
>>> aDict
{'y': [1, {...}, 3], 'x': [1, {...}, 3]}

then you no longer have something you can eval at all.

(Mind you, I have no idea whether PHP's var_export handles the equivalent 
of these cases either.)

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list