dzz: Dizzy の春 (Default)
[personal profile] dzz
Наваял на даче со скуки питоновский модуль для преобразования "европейской" записи японского (слева направо, сверху вниз) в традиционную (сверху вниз, справа налево) и обратно.

Получилось простенько, но занятно, работает в консоли.
Спасибо юникоду за любезно предоставленные monospace-символы ;)

Date: 2008-09-13 09:27 am (UTC)
From: [identity profile] dzz.livejournal.com

#!/usr/bin/python
# -*- coding: utf-8 -*-

# Sample for japanese printout 

in_lines=u"""ドミトリ
ポバロ
は
プログラマ
2008年08月05日"""

# Convert european order to traditional one

# Todo: convert ASCII to unicode-monospace-ASCII (0x3000, 0xFF** etc)

def e2jap_print(in_array):

  liness=in_array.split()
  
  t=[]
  jap=[]
  
  for i in liness: t.append(len(i))
  
  xl=len(liness)
  yl=max(t)
  
  for i in range(yl):
    jap.append([])
    for j in range(xl):
      jap[i].append([])
      try:
        jap[i][j]=liness[xl-j-1][i]
      except Exception, message:
        jap[i][j]=u" "

  for i in range(len(jap)):
    jap[i]="".join(jap[i])
  
  return jap

import sys

print in_lines
print "-"*80
for i in e2jap_print(in_lines):
  print i

sys.exit(0)

# -[ The End ]-
Edited Date: 2008-09-13 09:33 am (UTC)

Date: 2008-09-13 09:42 am (UTC)
From: [identity profile] dzz.livejournal.com

Было:

ドミトリ
ポバロ

プログラマ
2008年08月05日

--------------------------------------------------------------------------------
Стало:

2プはポド
0ロ バミ
0グ ロト
8ラ  リ
年マ   
0    
8    
月    
0    
5    
日   

Edited Date: 2008-09-14 09:10 am (UTC)

April 2026

S M T W T F S
   1 2 34
56 7 891011
1213141516 1718
19202122232425
2627282930  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Apr. 21st, 2026 04:28 pm
Powered by Dreamwidth Studios