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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:22:42+00:00 2026-06-03T11:22:42+00:00

how can i iterate on a Jython PyList and cast or convert my contained

  • 0

how can i iterate on a Jython PyList and cast or convert my contained object to java.lang.String ?

in this old tutorial, it is done by using __ tojava __ like :

(EmployeeType)employeeObj.__tojava__(EmployeeType.class);

i suppsoe this may be something like :

 PyList pywords = pythonFactoryCreatedObject.pythonMethodReturningPyList()

 int count = pywords.__len__();
 for (int idx = 0 ; idx < count ; idx++) {
     PyObject obj = pywords.__getitem__(idx);

    //here i do not know how to have a kind of 'String word = pywords[idx]' statement

    //System.out.println(word);
 }

is it also possible to have :

  • a conversion from PyList to java Array or List ? so that the construct ‘for (String word : mylist) { }’ can be used ?

  • i will have the same trouble with simple python dictionary mapping to an adequate java object, what will be the best mapping ?

Is there a tutorial doc on the java part usage of Jython ? i’m quite ok with python, but new to Java and Jython, and i found only documentation on the Java usage from Jython while i need to embed a Python module inside a Java framework…

best

  • 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-03T11:22:43+00:00Added an answer on June 3, 2026 at 11:22 am

    PyList actually implements java.util.List<Object>, so you can use that directly from Java side.
    If you fill with strings, its elements will be PyString (or maybe PyUnicode).
    So:

    List pywords = pythonFactoryCreatedObject.pythonMethodReturningPyList();
    for (Object o : pyList){
      String string = ((PyString) o).getString();
      //whatever you want to do with it 
    }
    

    or

    List pywords = pythonFactoryCreatedObject.pythonMethodReturningPyList()
    for (Object o : pyList){
      String string = ((PyObject) o).__toJava__(String.class);
      //whatever you want to do with it 
    }
    

    whichever you find clearer.

    Edit:
    here’s the standard doc on embedding Jython into Java. The better way to use Jython from Java would be to implement Java interfaces from Jython and manipulate the interfaces from Java, but it seems you’re working with an existing Python codebase, so that wouldn’t work without some changes.

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

Sidebar

Related Questions

I know that I can iterate over an object's properties like this: for (property
How can iterate through an NSString object in Objective c whiling maintaining an index
I'm trying to make a PHP (5) object that can iterate through its properties,
How I can iterate a vector in a JSP page? I have done it:
Why doesn't this return a map I can iterate over? function createSObjectMap() { //this
How can I go about populating a simple Java object with data from any
I'm trying to understand why I can iterate along the string. What I see
In Java I can iterate collection and remove some objects from it using Iterator.remove()
I'm trying to find out how I can iterate over the final results of
How can i iterate over the (public or private) properties of a php class?

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.