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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:05:50+00:00 2026-05-13T21:05:50+00:00

The snippet below is generating weird output: for s in servers: vo = ss.getServerVO(s)

  • 0

The snippet below is generating “weird” output:

for s in servers:
    vo = ss.getServerVO(s)
    values = []
    for f in voFields:
        attribValue = getattr(vo, f)
        values.append(attribValue)
    customValues = ss.getCustomFields(s)
    for f in customFields:
        values.append(customValues[f])
    # Convert all values to string before writing
    values = map(str, values)
    csvFile.writerow( values )

For some – not all – items in the customFields dictionary, I get the following output:

<bound method ServerVO.getCreatedDate of <pytwist.com.opsware.server.ServerVO instance at 0x3da8680>>

What do I need to do to get the bound method to execute / put its results into my values dictionary?

(Specific context is in writing a PyTwist script against the HP Server Automation API)

  • 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-13T21:05:50+00:00Added an answer on May 13, 2026 at 9:05 pm

    You could try calling the bound method if it is one:

    for f, v in customFields.iteritems():
      try:
        v = v()
      except TypeError:
        pass
      values.append(v)
    

    The problem, of course, is with the design choice (by HP or whoever) to mix “accessors” with other kinds of values — accessors are not a good Pythonic choice and should be replaced with properties (where this “call” gets automated for you where needed). This suggestion is about a possible way to work around that bad design choice.

    Just trying to call, and checking for the TypeError that can result if the value is not callable (or not callable without arguments) is better than using callable or checking for a __call__ special method, because those checks would never tell you if “calling without argument” is OK. So, as usual in Python, “it’s better to ask forgiveness by permission”: try the operation, catch possible errors (“ask forgiveness”) — rather than try to check if the operation is permissible before attempting it (“ask permission”).

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

Sidebar

Related Questions

No related questions found

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.