簡體   English   中英

使用-c選項時如何自動告訴python導入模塊?

[英]How to tell python import modules automatically when use the -c option?

我寫這個命令來測試一個正則表達式非常經常:

$ python -c 'import re; print(re.sub("e", "E", "hello"))'
hEllo

問題是,當我導入乘法模塊時,命令變得越來越長。
如果我可以配置python import re; import XXX; import YYY; import re; import XXX; import YYY; 自動地
該命令變得更短:

$ python -c 'print(re.sub("e", "E", "hello"))'

我認為,與配置Python相比,編寫一個單獨的腳本並傳遞正則表達式進行測試要容易得多,並且更加方便:

test.py 're.sub("e", "E", "hello"))'

然后test.py將導入所有需要的模塊(未測試):

import re
import XXX
import YYY
import sys

exec sys.argv[1]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM