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 8252107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:27:33+00:00 2026-06-08T00:27:33+00:00

I am trying to use both argparse and logging modules in python. I have

  • 0

I am trying to use both argparse and logging modules in python. I have a program that I run that has a lot of possible options and I’ve successfully implemented the argparse module to handle this task.

I’d like to keep a record of the values each option has when the program is run and send it to a log file. I tried the following couple of things, and I included the associated error I encounter as a comment beneath it.

parser = argparse.ArgumentParser()
parser.add_argument('input', action="store", default='fort.13', type=str)

args = parser.parse_args()

# First try:
logging.info("Input args: " + args)
# TypeError: cannot concatenate 'str' and 'Namespace' objects

# Second try:
for x in args:
  logging.info(x)
# TypeError: 'Namespace' object is not iterable

What is the proper way to do this?

  • 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-06-08T00:27:35+00:00Added an answer on June 8, 2026 at 12:27 am

    You can use vars to get the attributes of your parsed arguments:

    for arg, value in sorted(vars(args).items()):
        logging.info("Argument %s: %r", arg, value)
    

    This is detailed in the docs.

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

Sidebar

Related Questions

I'm trying to use jQuery to find the number of divs that are both
I'm trying to make use of both :only and :include options in to_xml call
I am trying to use the ExpandableListActivity in my program but I have already
I'm trying to use construction injection using both Jersey-injected @Context parameters and Guice-injected parameters.
I'm trying to use mezzanine's overextends tag to both override and extends the existing
I'm trying to use an open-source project. Both the latest official (from a *.tar.gz
I am trying use gem tire to search in my application. I have tables
I was trying use a set of filter functions to run the appropriate routine,
I am trying to use both mysqli_real_escape_string and trim together before making a MySQL
I have a program which embeds both python2 and python3 interpreters. The libpython shared

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.