2017-10-24 4 views
0

私はPythonで新しくなっています。私はそのパスといくつかのコマンドでPythonでファイル名のリストを作成する必要があります。私はcmdで実行する必要があります。コンパイラを開き、ファイルをコンパイルするためのいくつかの設定を行います。 私の問題は、私がコマンドを実行するときにcmdでコマンドを使って複数のファイルを入力すると、同じリストをPythonで実行すると、ピンマップファイルが見つからないということです。次の行はcmdで書いてあり、うまくいきます。 (APCとで始まる ' - ' CMDのコマンドです) APCのG:\組織\ TE \パテル\ ASCII_Open_Program \ SRC \ ATP \機能\ clk_Watchdog.atp G:\組織\ TE \パテル\ ASCII_Open_Program \ SRC \ ATP \機能性\ CP_UV_Threshold.atp -opcode_mode単一 - ピンマップ_ワークブックG:¥Organization¥TE¥Patel¥ASCII_Open_Program¥src¥xls¥PinMap_BE.txt -commentspythonでファイルリストをコンパイルする方法

私はPythonで同じことをやっていると思います。私のコードは

def APC_Compiler(): 
    list = ["apc "] 
    #list.append('apc ') 
    for root,dirs,files in os.walk(atp_folder_path + '\\SCAN'): 
     for file in files: 
      if file.endswith(".atp"):     
       list.append(os.path.join(root, file)) 

    list.append(' -opcode_mode single ') 
    list.append(' -pinmap_workbook ') 
    list.append(' G:\\Organisation\\TE\\Patel\\ASCII_Open_Program\\src\\xls\\PinMap_BE.txt') 
    list.append(' -comments ')    
    print (list) 
    subprocess.call(list) 

誰でも私が間違っていることを教えてください。 コマンドを使ってファイルのリストを作成して実行する方法はありますか?ここ

+0

私は文法に集中しなかったことを申し訳なく思っています。次回は心に留めておきます。しかし、今私は答えを得た。文字列を開くには、コマンドですべてのリストを実行する必要があります。これは私が '' .join(list)コマンドを使って行ったものです –

答えて

0

が私の解決策ですが、私がしなければならないすべては、1つの文字列の中のすべてのリストを変換し、それを実行することができます一つの命令を追加することです。私は私の問題を解決するために追加した指示に近くコメントしました。

def apc_compiler(): 
     """ Compiles all the *.atp files into *.pat file """ 

    list = ['apc '] 
    for root, dirs, files in os.walk(atp_folder_path): 
     for file in files: 
      if file.endswith('.atp'): 
       list.append(os.path.join(root, file) + ' ') 

    list.append(' -opcode_mode single ') 
    list.append(' -pinmap_workbook ') 
    list.append(pinmap_folder_path) 
    list.append(' -comments ') 
    list = ''.join(list) # instruction to convert list in to single string 

    subprocess.call(list) 
関連する問題