[Tutor] Hello, and a newbie question

Andy McKenzie amckenzie4 at gmail.com
Wed Apr 17 01:46:06 CEST 2013


On Tue, Apr 16, 2013 at 7:39 PM, Alan Gauld <alan.gauld at btinternet.com>wrote:

> On 16/04/13 22:20, Andy McKenzie wrote:
>
>  For instance:  output of running print_r on a very short dictionary from
>> PHP:
>>
>> Array
>> (
>>      [key3] => thing3
>>      [key2] => thing2
>>      [key1] => thing1
>> )
>>
>> And running pprint on the same dict in Python:
>>
>> {'key1': 'thing1', 'key2': 'thing2', 'key3': 'thing3'}
>>
>>
>> I finally decided that a good project would be building a quick function
>> that recreates the print_r function, and I got that working.  New
>> function output, in Python:
>>
>> (
>>      [key3] => thing3
>>      [key2] => thing2
>>      [key1] => thing1
>> )
>>
>
>
> You should probably use {} instead of () as the delimiter to indicate that
> the thing is a dictionary and not a tuple. but otherwise that's a good
> starter project.
>
>
Good idea.  I went with () because I was just trying to duplicate the
output in PHP.  Now that I've got that, I can start thinking about
improvements.  Varying the punctuation to match the type would probably be
a good idea.

Thanks,
  Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130416/fe0b3d2d/attachment.html>


More information about the Tutor mailing list