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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:10:36+00:00 2026-05-22T17:10:36+00:00

Specifically I am converting a python script into a java helper method. Here is

  • 0

Specifically I am converting a python script into a java helper method. Here is a snippet (slightly modified for simplicity).

# hash of values
vals = {}
vals['a'] = 'a'
vals['b'] = 'b'
vals['1'] = 1

output = sys.stdout
file = open(filename).read()

print >>output, file % vals,

So in the file there are %(a), %(b), %(1) etc that I want substituted with the hash keys. I perused the API but couldn’t find anything. Did I miss it or does something like this not exist in the Java 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-22T17:10:37+00:00Added an answer on May 22, 2026 at 5:10 pm

    I doubt you’ll find a pure Java solution that’ll do exactly what you want out of the box.

    With this in mind, the best answer depends on the complexity and variety of Python formatting strings that appear in your file:

    • If they’re simple and not varied, the easiest way might be to code something up yourself.

    • If the opposite is true, one way to get the result you want with little work is by embedding Jython into your Java program. This will enable you to use Python’s string formatting operator (%) directly. What’s more, you’ll be able to give it a Java Map as if it were a Python dictionary (vals in your code).

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

Sidebar

Related Questions

I am converting a linux script from http://www.perlmonks.org/index.pl?node_id=217166 specifically this: #!/usr/bin/perl -w use strict;
I've run into a problem whilst converting some C code to PHP, specifically in
I have an application in C# that I am converting to Java, specifically the
Specifically I have a PHP command-line script that at a certain point requires input
I'd like to call Python's distutils' or setuptools' setup() function in a slightly unconventional
I am using python and specifically MySQLdb to fill a database, although a code
I am having hard time converting a BasicHttpBinding to custom binding. Specifically I need
I'm converting some functions into a DLL which relate to Windows 7 functionality. I
This is a follow up question from here specifically concerning its answer . From
Specifically this is regarding when using a client session cookie to identify a session

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.