Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Python to java

  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Python to java

    Can someone help me in converting a python program to java program?

    I know jab but not familiar with python.....please do help me....

    import time
    print "spam?"
    import csv
    import win32com.client
    import pythoncom
    import os
    import sys
    from time import localtime, strftime
    print strftime("%Y-%m-%d %H:%M:%S", localtime())

    #Obtaining necessary input from user
    print 'How many characters are in the file name? (Including .csv)'
    length = None
    while not length:
    try:
    length = int(raw_input())
    except:
    print 'Invalid number, please enter an integer.'

    print 'How many columns do the files have?'
    colm = None
    while not colm:
    try:
    colm = int(raw_input())
    except:
    print 'Invalid number, please enter an integer.'

    print 'What column contains the latitude?'
    lats = None
    while not lats:
    try:
    lats = int(raw_input())
    except:
    print 'Invalid number, please enter an integer.'

    print 'What column contains the longitude?'
    lons = None
    while not lons:
    try:
    lons = int(raw_input())
    except:
    print 'Invalid number, please enter an integer.'

    #Functions Code section
    def textmealert(text):
    # This texting routine sends an e-mnail
    import smtplib
    fromaddr = 'wsu.research.error@gmail.com' #Do not change this!
    toaddrs = 'dfsimkins@aol.com' #Can change this to whatever email/text address desired
    msg = text
    # Credentials (if needed)
    username = 'wsu.research.error@gmail.com'
    password = 'researcherror'
    # The actual mail send
    server = smtplib.SMTP('smtp.gmail.com:587')
    server.starttls()
    server.login(username,password)
    server.sendmail(fromaddr, toaddrs, msg)
    server.quit()
    return
    def isrunning(exe):
    p = os.popen(r'tasklist /FI "IMAGENAME eq "'+ exe + ' /FO "LIST" 2>&1' , 'r' )
    PID = p.read().split('\n')[2].split(":")[1].lstrip(" ")
    p.close()
    return PID
    # End Functions Code
    textmealert('Computer 222: Program has started.')
    Knightswhosayni = win32com.client.Dispatch("GoogleEarth.ApplicationGE")
    time.sleep(5)
    flightname = ['0']
    myfile = open('index.txt')
    P = 0
    guido = 0.0
    for rows in myfile:
    flightname.append(rows)
    J=1
    L = ['0']
    P = P+1
    print strftime("%Y-%m-%d %H:%M:%S", localtime())
    with open(flightname[P][0:length],'rb') as f:
    print flightname[P][0:length]
    reader = csv.reader(f)
    for row in reader:
    L.append(row)
    L[J].append(0)
    L[J].append(0)
    J=J+1
    I = 8
    Zee = 1
    for row in L:
    I = I+8
    Zee = Zee+1
    if Zee>=1000:
    PID = isrunning('googleearth.exe')
    if PID != "None" :
    os.system(r'taskkill /F /PID ' + PID)
    time.sleep(5)
    Knightswhosayni = win32com.client.Dispatch("GoogleEarth.ApplicationGE")
    time.sleep(5)
    Zee = 0
    print "1"
    if I>=J:break
    x = L[I][lats-1]
    y = L[I][lons-1]
    z = 100
    tilt = 0
    azimuth = 360
    speed = 6
    bob = 0
    altMode = 2
    limit = 0
    while True:
    limit=limit+1
    try:
    Brian = Knightswhosayni.SetCameraParams( x, y, z, altMode, bob, tilt, azimuth, speed)
    DeadParrot=0
    SamShakusky=time.time()
    quitval=0
    while DeadParrot<100:
    DeadParrot = Knightswhosayni.StreamingProgressPercentage
    SuzyBishop=time.time()
    MoonriseKingdom=SuzyBishop-SamShakusky
    if MoonriseKingdom>10:
    quitval=quitval+1
    if quitval==3:
    sys.exit()
    print 'program has stalled!!!!'
    textmealert('Computer 222, Program has stalled, trying to restart.')
    PID = isrunning('googleearth.exe')
    if PID != "None" :
    os.system(r'taskkill /F /PID ' + PID)
    time.sleep(5)
    Knightswhosayni = win32com.client.Dispatch("GoogleEarth.ApplicationGE")
    time.sleep(5)
    SamShakusky=time.time()
    time.sleep(0.005)
    Ministryofsillywalks = Knightswhosayni.GetPointOnTerrainFromScreenCoords(0,0)
    saraghina = Ministryofsillywalks.Altitude
    break
    except:
    print "Google not responding, raise attempt:",limit
    textmealert('Computer 222, GE not responding, attempting a restart')
    Knightswhosayni = win32com.client.Dispatch("GoogleEarth.ApplicationGE")
    time.sleep(5)
    if limit>=3:
    time.sleep(5)
    sys.exit()
    try:
    L[I][colm] = saraghina*3.2808399
    if I>15:
    federico = saraghina*3.2808399
    fellini = guido*3.2808399
    eighthalf = (federico-fellini)/8
    L[I-1][colm] = federico-eighthalf
    L[I-2][colm] = federico-eighthalf*2
    L[I-3][colm] = federico-eighthalf*3
    L[I-4][colm] = federico-eighthalf*4
    L[I-5][colm] = federico-eighthalf*5
    L[I-6][colm] = federico-eighthalf*6
    L[I-7][colm] = federico-eighthalf*7
    guido = saraghina
    except:
    badfile='Computer 222, Bad file encountered:'+flightname[P][0:29]
    textmealert(badfile)
    print "BAD FILE ABOVE, BAD FILE ABOVE, BAD FILE ABOVE, BAD FILE ABOVE, BAD FILE ABOVE"
    break
    K = 1
    newfile = "new"+flightname[P][0:length]
    spamWriter = csv.writer(open(newfile, 'wb'), delimiter = ',', quoting = csv.QUOTE_MINIMAL)
    Z=0
    for spam in L:
    Z=Z+1
    if Z>=J:break
    spamWriter.writerow(L[Z][0colm+1)])
    print "spam, spam and eggs."
    print strftime("%Y-%m-%d %H:%M:%S", localtime())
    textmealert('Computer 222, The program has finished.')

  • #2
    Regular Coder
    Join Date
    May 2012
    Location
    USA
    Posts
    101
    Thanks
    0
    Thanked 7 Times in 7 Posts

  • #3
    New Coder
    Join Date
    Aug 2014
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Python and Java programs both compile to machine-independent byte code, which can then be run on virtual machines (PVM and JVM, respectively) on host computers. Both languages support objects and classes, but Python, like C++, also allows the programmer to define free functions as well. Type checking in Java is done at compile time and in Python at run time. Python code can also be tried out interactively within an interpreter, whereas Java programs must flow through an edit/compile/execute cycle.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •