Python equivalent to Bash $()
Question: I search the Python equivalent for the following Bash code:

    
    
    VAR=$(echo $VAR)
    

Pseudo Python code could be:

    
    
    var = print var
    

Can you help? :-)

Regards

Edit:

I search a way to do this:

    
    
    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
    

In Bash i would do it like this:

print gi.country_code_by_addr($(dhIP)) # only pseudo code...

Hope it's more clear now.

Edit2:

Thank you all! Here's my solution which works. Thanks to Liquid_Fire for the
remark with the newline char and thanks to hop for his code!

    
    
    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()
    


Answer: You don't need a `print` in there, just use the name of the variable:

    
    
    for dhIP in open('dh-ips.txt', 'r'):
        gi = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)
        print gi.country_code_by_addr(dhIP)
    

Also note that iterating through a file object gives you lines with the
newline characters at the end. You may want to use something like
`dhIP.rstrip("\n")` to remove them before passing it on to
`country_code_by_addr`.

