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

  • SEARCH
  • Home
  • 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 933139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:46:56+00:00 2026-05-15T20:46:56+00:00

In Ruby, instead of repeating the "require" (the "import" in Python) word lots of

  • 0

In Ruby, instead of repeating the "require" (the "import" in Python) word lots of times, I do

%w{lib1 lib2 lib3 lib4 lib5}.each { |x| require x }

So it iterates over the set of "libs" and "require" (import) each one of them. Now I’m writing a Python script and I would like to do something like that. Is there a way to, or do I need to write "import" for all of them.

The straight-forward "traduction" would be something like the following code. Anyway, since Python does not import libs named as strings, it does not work.

requirements = [lib1, lib2, lib3, lib4, lib5]
for lib in requirements:
    import lib
  • 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-15T20:46:56+00:00Added an answer on May 15, 2026 at 8:46 pm

    For known module, just separate them by commas:

    import lib1, lib2, lib3, lib4, lib5
    

    If you really need to programmatically import based on dynamic variables, a literal translation of your ruby would be:

    modnames = "lib1 lib2 lib3 lib4 lib5".split()
    for lib in modnames:
        globals()[lib] = __import__(lib)
    

    Though there’s no need for this in your example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using Ruby on Rails 2.3.2, since I already created Scaffold for Story, so instead
In a Ruby on Rails form, I'm trying to use a button instead of
Ruby code is: a = [] h = {} 2.times.each do |i| %w(a b
Why would I choose Ruby on Rails instead of PHP or ASP.NET when starting
In Ruby practice is to send id instead of object in workers. Isn't that
I''m curious about why ruby returns an Enumerator instead of an Array for something
Possible Duplicate: Why does Ruby on Rails use 0.0.0.0:3000 instead of localhost:3000? I am
Is it at all possible to write irssi scripts in Ruby instead of Perl?
Is there a way to point Ruby FFI to a header file instead of
A long time ago I saw this trick in Ruby. Instead of doing (for

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.