5 Replies - 1386 Views - Last Post: 03 October 2014 - 07:27 AM Rate Topic: -----

#1 rcbandit   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 18-March 11

Rewrite Python code in Java

Posted 03 October 2014 - 07:00 AM

I need help for rewriting Python code into Java. Unfortunately I know how to write Java programs but I don't have any experience with Python.

from collections import namedtuple


_nt_cpu_temp = namedtuple('cputemp', 'name temp max critical')

def get_cpu_temp(fahrenheit=False):
    """Return temperatures expressed in Celsius for each physical CPU
    installed on the system as a list of namedtuples as in:

    >>> get_cpu_temp()
    [cputemp(name='atk0110', temp=32.0, max=60.0, critical=95.0)]
    """
    # http://www.mjmwired.net/kernel/Documentation/hwmon/sysfs-interface
    cat = lambda file: open(file, 'r').read().strip()
    base = '/sys/class/hwmon/'
    ls = sorted(os.listdir(base))
    assert ls, "%r is empty" % base
    ret = []
    for hwmon in ls:
        hwmon = os.path.join(base, hwmon)
        label = cat(os.path.join(hwmon, 'temp1_label'))
        assert 'cpu temp' in label.lower(), label
        name = cat(os.path.join(hwmon, 'name'))
        temp = int(cat(os.path.join(hwmon, 'temp1_input'))) / 1000
        max_ = int(cat(os.path.join(hwmon, 'temp1_max'))) / 1000
        crit = int(cat(os.path.join(hwmon, 'temp1_crit'))) / 1000
        digits = (temp, max_, crit)
        if fahrenheit:
            digits = [(x * 1.8) + 32 for x in digits]
        ret.append(_nt_cpu_temp(name, *digits))
    return ret


Is there is someone whiling to help for my home project?

Is This A Good Question/Topic? 0
  • +

Replies To: Rewrite Python code in Java

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15561
  • View blog
  • Posts: 62,304
  • Joined: 12-June 08

Re: Rewrite Python code in Java

Posted 03 October 2014 - 07:15 AM

What have you tried, or are you just asking for folks to do the conversion for you?
Was This Post Helpful? 0
  • +
  • -

#3 rcbandit   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 18-March 11

Re: Rewrite Python code in Java

Posted 03 October 2014 - 07:18 AM

I tried just to read the file with value. But it's worthless.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15561
  • View blog
  • Posts: 62,304
  • Joined: 12-June 08

Re: Rewrite Python code in Java

Posted 03 October 2014 - 07:19 AM

Really? You haven't created a project? Made a few variables? Translated that for loop?
Was This Post Helpful? 0
  • +
  • -

#5 rcbandit   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 18-March 11

Re: Rewrite Python code in Java

Posted 03 October 2014 - 07:22 AM

I mean I created Java project and I read the value with Java.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15561
  • View blog
  • Posts: 62,304
  • Joined: 12-June 08

Re: Rewrite Python code in Java

Posted 03 October 2014 - 07:27 AM

Okay.... and then what happened? What was supposed to happen? Did you get an error? If so copy/paste the text here.

Look, being coy and not forthcoming with what is going on is *not* an effective strategy to help people to help you, right? Be verbose. Explain what is going on. Folks are not there looking over your shoulder.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1