Python缂栫▼瀹炵幇瀵笴odeSys涓璖T浠g爜鐨勮嚜鍔ㄦ帓鐗(浜)-CODESYS璧勬簮涓嬭浇鍖-閰峰痉缃 - CoDeSys杞欢鏁欑▼涓嬭浇,CoDeSys宸ユ帶璧勮闂ㄦ埛
HSC6490-cn涓浗鍒堕狅紝涓浗鑺瘇
鏌ョ湅: 1608|鍥炲: 1

Python缂栫▼瀹炵幇瀵笴odeSys涓璖T浠g爜鐨勮嚜鍔ㄦ帓鐗(浜)

[澶嶅埗閾炬帴]
  • TA鐨勬瘡鏃ュ績鎯
    鎿︽睏
    2019-8-13 14:13
  • 绛惧埌澶╂暟: 32 澶

    [LV.5]甯镐綇灞呮皯I

    鍙戣〃浜 2020-8-7 16:41:24 | 鏄剧ず鍏ㄩ儴妤煎眰 |闃呰妯″紡
    鐢变簬鍒氬Python锛屽寰堝鐭ヨ瘑閮借繕鏄竴鐭ュ崐瑙o紝娆㈣繋鍚勪綅澶т緺缁欏嚭瀹濊吹鎰忚銆

    涓婄瘒闅忕瑪涓殑浠g爜鍩虹涓婏紝鍙堝仛浜嗕竴浜涗慨鏀癸紝瀹屽杽浜嗕竴浜涘姛鑳姐
    锛1锛夎兘澶熺缉杩汭F..ELSIF..ELSE..END_IF璇彞
    锛2锛夎兘澶熺缉杩沇HILE....END_WHILE璇彞
    锛3锛夎兘澶熺缉杩汧OR...END_FOR璇彞
    锛4锛夎兘澶熺畝鍗曠殑缂╄繘CASE...END_CASE璇彞锛岀敱浜庢病鏈夊緢濂界殑鍔炴硶鍒ゆ柇CASE椤癸紝灏辨殏鏃跺CASE涔嬪悗鐨勪唬鐮佽繘琛屼簡4涓瓧绗︾殑缂╄繘锛屼互涓婁笁鏉¢兘鏄缉杩2涓瓧绗︺
    锛5锛夊杈撳叆杈撳嚭鐨勬枃浠跺悕杩涜浜嗗垽鏂傛祴璇曟柟娉曟槸鎶婃簮鏂囦欢鍜岀敓鎴愮殑鏂囦欢閮芥斁鍦ㄤ簡Python鏂囦欢鐨勫悓涓鐩綍涓嬨

    涓婁唬鐮侊紙姣忚浠g爜鍐欑殑澶暱浜嗭紝濂藉儚闇瑕佹粴鍔ㄦ潯....   锛

    [Python] 绾枃鏈煡鐪 澶嶅埗浠g爜
     #FormatCodeSysST.py
    #coding:gb2312
    import string
    getFile = raw_input("璇疯緭鍏ヨ杞崲鐨勬枃浠跺悕绉(鍖呮嫭鍚庣紑鍚):")
    try:
    file_in= open(getFile,'r')
    Get_Flag = True
    except IOError:
    print "鈽呮枃浠惰鍙栧け璐モ槄"
    raw_input("鎸夊洖杞﹂敭杩斿洖...")
    Get_Flag = False
    
    if Get_Flag:
    outputFile = raw_input("璇疯緭鍏ヨ浆鎹㈠悗淇濆瓨鐨勬枃浠跺悕绉(鍖呮嫭鍚庣紑鍚):")
    try:
    file_out = open(outputFile,'w')
    Out_Flag = True
    except:
    print "鈽呮枃浠朵繚瀛樺け璐モ槄"
    raw_input("鎸夊洖杞﹂敭杩斿洖...")
    Out_Flag = False
    
    if Out_Flag:
    print "姝e湪澶勭悊涓紝璇风◢鍊...."
    text1 = file_in.readline()
    lst1 = []
    #-----------------------------------------------------------------------------
    #鍒犻櫎琛岄鍜岃鏈殑绌烘牸
    while (text1 != ''):
    lst1.append(string.strip(text1))
    text1 = file_in.readline()
    indent = 0
    #-----------------------------------------------------------------------------
    #鍒ゆ柇姣忎竴琛岀殑寮澶村瓧绗︿覆锛屽苟鏍规嵁涓嶅悓鐨勫瓧绗︿覆杩涜涓嶅悓鐨勭缉杩
    for i in lst1:
    if (i[:3] == 'IF ') or (i[:3] == 'IF(') or (i[:len(i)]=='IF'): #if寮澶寸殑琛
    i = ' '*indent + i
    indent += 2
    elif (i[:5] == 'ELSE ')or (i[:len(i)] == 'ELSE') or (i[:5] == 'ELSE(') : #else寮澶寸殑琛
    indent -= 2
    i = ' '*indent + i
    indent += 2
    elif (i[:len(i)] == 'ELSIF')or (i[:6] == 'ELSIF ') or (i[:6] == 'ELSIF('): #elsif 寮澶寸殑琛
    indent -= 2
    i = ' '*indent + i
    indent += 2 
    elif (i[:7] =='END_IF ') or (i[:len(i)] =='END_IF') or (i[:7] =='END_IF('): #end_if寮澶寸殑琛
    indent -= 2
    i = ' '*indent + i
    elif i[:6] == 'WHILE ' or i[:len(i)] == 'WHILE': #while寮澶寸殑琛
    i = ' '*indent + i
    indent += 2
    elif (i[:len(i)] == 'END_WHILE') or i[:10] == 'END_WHILE(' or i[:10] == 'END_WHILE ' :#end_while寮澶寸殑琛
    indent -= 2
    i = ' '*indent + i
    elif i[:4] == 'FOR ': #for寮澶寸殑琛
    i = ' '*indent + i
    indent += 2
    elif (i[:len(i)] == 'END_FOR') or (i[:8] == 'END_FOR(')or (i[:8] == 'END_FOR '): #end_for寮澶寸殑琛
    indent -= 2
    i = ' '*indent + i 
    elif (i[:5]=='CASE '): #CASE寮澶寸殑琛
    i = ' '*indent + i
    indent += 4
    elif (i[:len(i)]=='END_CASE') or (i[:9]=='END_CASE(') or (i[:9]=='END_CASE '):#END_CASE寮澶寸殑琛
    indent -= 4 
    i = ' '*indent + i
    else:
    i = ' '*indent + i
    file_out.write(i + '\n')
    print '杞崲瀹屾垚锛'
    file_in.close()
    file_out.close()
    raw_input("鎸夊洖杞﹂敭杩斿洖...")

    +10
    涓嶈禐涓涓紵
    鎵撹祻榧撳姳涓涓嬶紒
    鍥炲

    浣跨敤閬撳叿 涓炬姤

  • TA鐨勬瘡鏃ュ績鎯
    寮蹇
    2021-12-17 13:51
  • 绛惧埌澶╂暟: 1 澶

    [LV.1]鍒濇潵涔嶅埌

    鍙戣〃浜 2021-12-17 11:55:59 | 鏄剧ず鍏ㄩ儴妤煎眰
    濂藉儚涓嶈兘鐢ㄥ憿
    +10
    涓嶈禐涓涓紵
    鎵撹祻榧撳姳涓涓嬶紒
    鎮ㄩ渶瑕佺櫥褰曞悗鎵嶅彲浠ュ洖甯 鐧诲綍 | 绔嬪嵆娉ㄥ唽 鏂版氮寰崥鐧婚檰

    鏈増绉垎瑙勫垯

    椤堕儴qrcode搴曢儴
    鍏虫敞閰峰痉缃戣闃呭彿锛岃幏鍙栨洿澶氳祫璁紒

    QQ|灏忛粦灞|鎵嬫満鐗|Archiver|閰峰痉璁哄潧 ( 鑻廔CP澶16065247鍙-1 )|缃戠珯鍦板浘

    GMT+8, 2024-11-23 22:32 , Processed in 0.207697 second(s), 61 queries .

    閰峰痉缃

    © 2001-2013 Hicodesys. 鎶鏈敮鎸 by 閰峰痉缃

    蹇熷洖澶 杩斿洖椤堕儴 杩斿洖鍒楄〃