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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:02:59+00:00 2026-06-09T01:02:59+00:00

Python is calling a C++ function (wrapped using swig). C++: std::wstring getFilePathMultiByte(); I can

  • 0

Python is calling a C++ function (wrapped using swig).

C++:

  std::wstring getFilePathMultiByte();

I can call this function in python. Question is how do I use this returned wstring? want to append filename to this path which gives error as shown in output below.

Python:

  path = getFilePathMultiByte()
  print path, type(path)
  file = path + "/Information.log"

Output:

_2012ad3900000000_p_std__wstring, type 'SwigPyObject'
TypeError: unsupported operand type(s) for +: 'SwigPyObject' and 'str'

How do I create a std::wstring in python? That may allow concatenation for me.

Thanks.

  • 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-09T01:03:00+00:00Added an answer on June 9, 2026 at 1:03 am

    The following example worked as intended with SWIG 2.0 on my machine:

    %module test
    
    %include "std_wstring.i"
    
    %inline %{
      std::wstring foo() {
        return L"hi";
      }
    %}
    

    Which I then tested with:

    Python 2.7.3rc2 (default, Apr 22 2012, 22:30:17)
    [GCC 4.6.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import test
    >>> path = test.foo()
    >>> print path, type(path)
    hi <type 'unicode'>
    >>> file = path + "/Information.log"
    >>> print file
    hi/Information.log
    >>>
    

    I’m not exactly sure what you’ve done wrong here – my guess would be you haven’t got %include "std_wstring.i", but it’s hard to say for certain given what you’ve shown.

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

Sidebar

Related Questions

I'm having trouble with encodings when calling the Quickbase API using Python. I call
Referring to this Python List Comprehension Vs. Map question, can someone explain why List
I'm a Python beginner and have just started using packages. When you're calling a
I'm calling a web API exposed by TheyWorkForYou (TWFI). http://www.theyworkforyou.com/api/ I'm using the Python
I am trying to determine the owning class of a calling function in python.
From the c-api, I would like to call a python function by name. I
I'm profiling in Python using cProfile . I found a function that takes a
My python code is calling a C function in a native library (also written
I refactored some code, and now I get this error when calling a function.
In python, I can do something like this: List=[3, 4] def Add(x, y): return

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.