| 久し振りの "python" する 
"jw" の "line" を読み込むプログラムです。 
"python38" のソースコード、長文注意 
 
#................................................. 
# jw_line.py : line(jwc_temp.txt)のみ読込 
#         by chika 
#................................................. 
 
m_line=[]; # [ sx, sy, ex, ey, lg, ly, lc, lt ] 
 
def setLine(str): 
  tkn=str.split(" ") 
  sx=float(tkn[1]); sy=float(tkn[2]) 
  ex=float(tkn[3]); ey=float(tkn[4]) 
  line=[sx, sy, ex, ey ]; m_line.append(line); 
# 
 
def readData(fname): 
  fin=open(fname, "r") 
  for str in fin: 
    ts0=str[0]; ts1=str[:2]; ts2=str[:3]; ts3=str[:4]; 
    if ts0 == " ": setLine(str); 
# 
 
def gettkData(col): 
  str="" 
  for Li in m_line: 
    ts="%.1f, %.1f, %.1f, %.1f, fill = 'red')\n" % (Li[0], Li[1], Li[2], Li[3]) 
    str=str + "c0.create_line(" + ts 
  return str 
# 
 
# ...main......................................... 
 
readData("jwc_temp.txt"); 
print("lineの数",len(m_line)); 
for n in m_line: 
  print(n) 
#...end........................................... 
 
以下、結果出力->errline.txt 
lineの数 5 
[2500.0, -2000.0, 7500.0, -2000.0] 
[2500.0, -3000.0, 7500.0, -3000.0] 
[2500.0, -4000.0, 7500.0, -4000.0] 
[2500.0, -5000.0, 7500.0, -5000.0] 
[2500.0, -6000.0, 7500.0, -6000.0] 
 
リストで座標データを記憶させているのがミソ 
ついでに "tkinter" まで足を 
伸ばしたのでその "img" を投稿します。 |  
  |