Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6636455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:11:17+00:00 2026-05-25T23:11:17+00:00

I search the Python equivalent for the following Bash code: VAR=$(echo $VAR) Pseudo Python

  • 0

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()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:11:17+00:00Added an answer on May 25, 2026 at 11:11 pm

    Just use dhIP as it is. There is no need to do anything special with it:

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

    NB: There are some other issues with your code.

    Without being familiar with the library you use, it seems to me that you unnecessarily instantiate GeoIP in every iteration of the loop. Also, you should not throw away the file handle, so you can close the file afterwards.

    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)
    finally:
        fp.close()
    

    Or, even better, in 2.5 and above you can use a context manager:

    with open('dh-ips.txt', 'r') as fp:
        gi = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)
        for dhIP in fp:
            print gi.country_code_by_addr(dhIP)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following Python code: 30 url = http://www.google.com/search?hl=en&safe=off&q=Monkey 31 url_object = urllib.request.urlopen(url); 32
How can I make such a conditional search in Bash like in Google python
Consider the following Python code: >>> re.search(r'.*(99)', 'aa99bb').groups() ('99',) >>> re.search(r'.*(99)?', 'aa99bb').groups() (None,) I
I have this regex code in python : if re.search(r\{\\fad|fade\(\d{1,4},\d{1,4}\)\}, text): print(re.search(r\{\\fad|fade\((\d{1,4}),(\d{1,4})\)\}, text).groups()) text
I can use map to implement the case insensitive list search with Python. a
I want python to parse string user:12345 location:ny search Then I can use: if
A search for python and xml returns a variety of libraries for combining the
I'm looking for a regex to search my python program to find all lines
I would like my python script to search through a directory in SVN, locate
What is the difference between the search() and match() functions in the Python re

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.