It's not a secret anymore!
The moose likes Jython/Python and the fly likes Converting Python to Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "Converting Python to Java" Watch "Converting Python to Java" New topic

Converting Python to Java

J Hicks

Joined: Aug 23, 2012
Posts: 1
Hey guys, I had hoped to find a great place to get information on converting Python to Java, either using Jython or some other program.

I dont know Java. I wrote this script in python and I'm wanting to be able to make it work for Android/iOS. There doesnt seem to be an easy way to do this without distributing the python file directly (using sl4a). I use these imports:

import sys
import csv
import re
import json
import time
import string
import random
import urllib
import urllib2

Does anyone have advice on where to start etc? This is essentially a farming robot that automates farming in a game we play online. If anyone wants to see the code or can translate to Java easily please let me know. I have started the Java translation but fear I'm getting in way over my head with Java. Thanks guys take care.
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

Welcome to the JavaRanch.

J Hicks wrote: I wrote this script in python and I'm wanting to be able to make it work for Android/iOS.

Android and iOS are very different ecosystems. Programming in iOS is usually done with Objective-C. Android programmers use a customized version of Java. If you want to target both OS's, you'll either have to write two versions of your app or use a cross-platform development tool like Appcelerator.
As for translating a Python program to Java, they use very different programming paradigms so there will not be a 1:1 match for functionality (especially given your mobile requirement, which adds another API in the mix). I honestly don't think you can hope to translate the app without getting knowledgeable about Java and Android.

[How To Ask Questions On JavaRanch]
chris webster

Joined: Mar 01, 2009
Posts: 2290

It is possible to run Python on Android, via the Scripting Layer for Android (SL4A). Not sure which libraries etc are supported, but you could have a look at getting your Python app to run with SL4A e.g. using the Android emulator.

Of course, this doesn't help you at all with iOS.

Edit: Duh - just saw that you'd already looked at SL4A!

No more Blub for me, thank you, Vicar.
I agree. Here's the link:
subject: Converting Python to Java
It's not a secret anymore!