Attachment 'add.py'

Download

   1 # -*- coding: utf-8 -*-
   2 
   3 d = {
   4     'name': u'יוניקוד'
   5 }
   6 
   7 class U:
   8     def __str__(self):
   9         print '%s.__str__ called' % self.__class__.__name__
  10         return 'string'
  11     def __unicode__(self):
  12         print '%s.__unicode__ called' % self.__class__.__name__
  13         return u'יוניקוד'
  14 
  15 string = 'String'
  16 unicode_string = u'יוניקוד'
  17 expected = u'Stringיוניקוד'
  18 
  19         
  20 print 'add unicode literal to string'       
  21 assert string + u'יוניקוד' == expected
  22 
  23 print 'add unicode from dict to string'       
  24 assert string + d['name'] == expected
  25 
  26 print 'add unicode from variable to string'       
  27 assert string + unicode_string == expected
  28 
  29 print 'add object unicode value to string'
  30 obj = U()    
  31 assert string + unicode(obj) == expected

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2004-10-06 22:16:20, 0.8 KB) [[attachment:add.py]]
  • [get | view] (2004-10-06 22:16:30, 1.1 KB) [[attachment:modulo.py]]
  • [get | view] (2004-10-06 20:06:10, 1.3 KB) [[attachment:uni.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.