2017-01-31 11 views
2

私は、ターミナルを通過するpythonスクリプトを書いています。私は、VIMでPythonファイルを開いてコードを書いています。私は現在、(VIMエディタで開きます)Vimのファイルに私を取得する次のコードを使用しています:Pythonスクリプトのvimエディタでコードを書く

#!/usr/bin/env python 



import ctypes 
import os 


def is_hidden(filepath): 
    name = os.path.basename(os.path.abspath(filepath)) 
    return (name) or (has_hidden_attribute(filepath)) 

def has_hidden_attribute(filepath): 
    try: 
     attrs = ctypes.windll.kernel32.GetFileAttributesW(unicode(filepath)) 
     assert attrs != -1 
     result = bool(attrs & 2) 
    except (AttributeError, AssertionError): 
     result = False 
    return result 

def main(): 
    print("found:",is_hidden('~/.jupyter')) 

    #write cd ~/.jupyter in bash terminal 
    os.system('~/.jupyter') #change to be ~/name 
    os.system('vim file') 




if __name__ == "__main__": main() 

os.systemを使用して(「vimのファイルは、」)のvimでファイルを開き、ときに私が実行されますスクリプト、空のファイルが表示されています。私は、この空のファイルをpythonスクリプトで書き、保存して終了します。

どうすればいいですか?

+0

のvimを介してこれをやりたいと思っためのあなたの理由は何であると、ファイルへの
書くのか?なぜファイルを直接書き込まないのですか? – FamousJameous

+0

これが私ができることならば、私は本当に興味があります。 vimにアクセスしてvimに書き込みます。 :) – Emily

+0

私はそれを尊重することができます。残念ながら、私はあなたを助ける方法を知らない、申し訳ありません。 – FamousJameous

答えて

0

まず、コマンドラインから試してみてください。それが動作するときは、Pythonでコードを貼り付けます。

vi file <<END 
iThis line started with i for the insert mode. 
You will need an Escape to leave the insert mode. 
Difficult to write here, it will be something like ctrl-v ESC. 
It will look like ^] 
:wq 
END 
関連する問題