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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:16:12+00:00 2026-06-09T21:16:12+00:00

I am using Iron Python as an added ‘for free’ tool to test the

  • 0

I am using Iron Python as an added ‘for free’ tool to test the an API that wrapps comms to some custom hardware so the non-development team can play with the hardware via python.

However I can’t work out how to get .NET void func(params object[] args) to map to Python def (*args).

Here is some code to explain.

I have a type that allows injecting a logging callback to format and deal with messages is follows the signature of Console.WriteLine and Debug.WriteLine.

public class Engine
{
    Action<string, object[]> _logger;
    public void Run()
    {
        Log("Hello '{0}'", "world");
    }
    public void SetLog(Action<string, object[]> logger)
    {
        _logger = logger;
    }
    void Log(string msg, params object[] args)
    {
        _logger(msg, args);
    }
}

in my IronPython code

import clr
from System import *
from System.IO import Path
clr.AddReferenceToFileAndPath(Path.GetFullPath(r"MyAssembly.dll"))
from MyNamespace import *

def logger(msg, *args):
    print( String.Format(msg, args))
    print( String.Format(msg, list(args)))
    print( String.Format(msg, [args]))
    a=[]
    for i in args:
        a.append(i)
    print( String.Format(msg, a) )

e = Engine()
e.SetLog(logger)
e.Run()

output

Hello '('world',)'
Hello 'IronPython.Runtime.List'
Hello 'IronPython.Runtime.List'
Hello 'IronPython.Runtime.List'

I would like

Hello 'world'
  • 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-09T21:16:14+00:00Added an answer on June 9, 2026 at 9:16 pm

    Because String.Format handles your iron python objects (tuple for your first output case, lists for the last three) as single objects and is not aware that you would like the python collection to be used as params object[] you are getting the unexpected output. The single python object/tuple is implicitly created when def logger is invoked.

    Depending on your actual use-case/style you can solve this in different ways.

    The most python-y way would be expanding the arguments at their call site like Jeff explains in his answer:

    def logger(msg, *args):
        print( String.Format(msg, *args) )
    

    If you call logger only as from CLR as implementation of Action<string, object[]> you could just have args be a single (not variable) argument of type object[] like

    def logger(msg, args):
        print( String.Format(msg, args) )
    

    If you would like to call logger from python with variable arguments as well (and you don’t mind the back and forth conversion) you could do

    def logger(msg, *args):
        print( String.Format(msg, Array[object](args)) )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some ETL scripts in Iron Python and have found that I could
I have some IronPython code that is creating a Mutex using the following constructor:
Is it okay to start using Iron Ruby and Iron Python in production systems?
I have an IronPython script that looks for current running processes using WMI. The
I've got Visual Studio 2010. To develop a web app in Iron Python (i.e.
I have a python .pyd that is a mixed mode C++ DLL. The DLL
I'm writing an windforms application using .NET (actually IronPython, but that's not relevant), and
To embed some IronPython Code into C# I want to use the ScriptEngine using
I am getting started with developing an Excel-DNA addin using IronPython with some C#
I am using IronPython to create a shell for a plugin API to Autodesk

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.