我搜索了Python等值以下的Bash代碼:
VAR=$(echo $VAR)
僞Python代碼可能是:
var = print var
你能幫忙嗎? :-)
問候
編輯:
我搜索的方式來做到這一點:
for dhIP in open('dh-ips.txt', 'r'):
gi = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)
print gi.country_code_by_addr(print dhIP) # <-- this line is my problem
在bash我會做這樣的:
打印gi.country_code_by_addr ($(dhIP))#只有僞代碼...
希望現在更清楚。
編輯2:
謝謝大家!這是我的解決方案。感謝Liquid_Fire提供的換行符,並感謝跳轉代碼!
import GeoIP
fp = open('dh-ips.txt', 'r')
gi = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)
try:
for dhIP in fp:
print gi.country_code_by_addr(dhIP.rstrip("\n"))
finally:
fp.close()
你怎麼_actually_想幹什麼? – hop
你認爲bash代碼的作用是什麼?例如:'VAR =「 - e」'或'VAR =「a b」'(我不知道如何格式化多個空格)。你真的想做什麼? –
您是否嘗試將命令行程序的輸出分配給變量?或者可能獲取環境變量的值? –