Jython

I am using this function to get all the minutes of the day:

[code]
import time
from time import strftime

global minutesList
minutesList = []

def todaysMinutes():
year, month, day = time.localtime()[0:3]
for hour in xrange(0, 24):
for minute in xrange(0, 60):
t = (year, month, day, hour, minute, 0, 0, 0, 0)
yield time.strftime("%a %b %d %H:%M", t)

minutesList = list(todaysMinutes())
[/code]

It works great in python, but when I try to use it with Jython
from a command prompt (python & jython in class path): jython myFile.py
I get an error: SyntaxError: invalid syntax

Any ideas why this is happening?

Comments

  • : I am using this function to get all the minutes of the day:
    :
    : [code]
    : import time
    : from time import strftime
    :
    : global minutesList
    : minutesList = []
    :
    : def todaysMinutes():
    : year, month, day = time.localtime()[0:3]
    : for hour in xrange(0, 24):
    : for minute in xrange(0, 60):
    : t = (year, month, day, hour, minute, 0, 0, 0, 0)
    : yield time.strftime("%a %b %d %H:%M", t)
    :
    : minutesList = list(todaysMinutes())
    : [/code]
    :
    : It works great in python, but when I try to use it with Jython
    : from a command prompt (python & jython in class path): jython myFile.py
    : I get an error: SyntaxError: invalid syntax
    :
    : Any ideas why this is happening?

    Does it tell you which line has the syntax error?


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • After some research and talking with a few people, it turns out the "yield" is not valid in Jython 2.1. This leads me to another issue that is popping up using Jython:

    [code]
    tolerance = 0

    for minute in minutesList:
    mt = (time.localtime()[0],) + time.strptime(minute, '%a %b %d %H:%M')[1:]

    for job in parsedJobsFile:
    # split at / to pickup the path to script >> (' ' and $...how?)
    parts = job.split('/', 1)
    t = parts[0].strip()
    jt = (time.localtime()[0],) + time.strptime(t, '%a %b %d %H:%M')[1:]

    m = time.mktime(mt)
    j = time.mktime(jt)

    if m >= j - (tolerance * 60) and m <= j + (tolerance * 60):
    for x in parsedJobsFile:
    if x not in jobsDB:
    shouldHaveRan.append(x)

    for x in parsedJobsFile and jobsDB:
    didRun.append(x)

    if len(shouldHaveRan) == 0:
    shouldHaveRan.append("nothing was scheduled to run")

    if len(didRun) == 0:
    didRun.append("nothing ran")
    [/code]

    I get this error:
    [code]
    Traceback (innermost last):
    File "watchdog.py", line 19, in ?
    File "watchdog.py", line 214, in crontabParse << my class name
    File "watchdog.py", line 158, in testIt << my function name
    NameError: time
    [/code]

    I "think" this is the same issue. If so, I am looking for a way to modify the code above to work in Jython. The user Infidel helped me come up with a function to compare 2 lists and find differences. The code takes place in a for loop, for each minute of the day and checks to see if a script is eligible to run @ that time of day and
    day of week.

    Any ideas?
  • : After some research and talking with a few people, it turns out the "yield" is not valid in Jython 2.1. This leads me to another issue that is popping up using Jython:
    :
    : [code]
    : tolerance = 0
    :
    : for minute in minutesList:
    : mt = (time.localtime()[0],) + time.strptime(minute, '%a %b %d %H:%M')[1:]
    :
    : for job in parsedJobsFile:
    : # split at / to pickup the path to script >> (' ' and $...how?)
    : parts = job.split('/', 1)
    : t = parts[0].strip()
    : jt = (time.localtime()[0],) + time.strptime(t, '%a %b %d %H:%M')[1:]
    :
    : m = time.mktime(mt)
    : j = time.mktime(jt)
    :
    : if m >= j - (tolerance * 60) and m <= j + (tolerance * 60):
    : for x in parsedJobsFile:
    : if x not in jobsDB:
    : shouldHaveRan.append(x)
    :
    : for x in parsedJobsFile and jobsDB:
    : didRun.append(x)
    :
    : if len(shouldHaveRan) == 0:
    : shouldHaveRan.append("nothing was scheduled to run")
    :
    : if len(didRun) == 0:
    : didRun.append("nothing ran")
    : [/code]
    :
    : I get this error:
    : [code]
    : Traceback (innermost last):
    : File "watchdog.py", line 19, in ?
    : File "watchdog.py", line 214, in crontabParse << my class name
    : File "watchdog.py", line 158, in testIt << my function name
    : NameError: time
    : [/code]
    :
    : I "think" this is the same issue. If so, I am looking for a way to modify the code above to work in Jython. The user Infidel helped me come up with a function to compare 2 lists and find differences. The code takes place in a for loop, for each minute of the day and checks to see if a script is eligible to run @ that time of day and
    : day of week.
    :
    : Any ideas?

    Are you certain your code has used "import time"?


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • : : After some research and talking with a few people, it turns out the "yield" is not valid in Jython 2.1. This leads me to another issue that is popping up using Jython:
    : :
    : : [code]
    : : tolerance = 0
    : :
    : : for minute in minutesList:
    : : mt = (time.localtime()[0],) + time.strptime(minute, '%a %b %d %H:%M')[1:]
    : :
    : : for job in parsedJobsFile:
    : : # split at / to pickup the path to script >> (' ' and $...how?)
    : : parts = job.split('/', 1)
    : : t = parts[0].strip()
    : : jt = (time.localtime()[0],) + time.strptime(t, '%a %b %d %H:%M')[1:]
    : :
    : : m = time.mktime(mt)
    : : j = time.mktime(jt)
    : :
    : : if m >= j - (tolerance * 60) and m <= j + (tolerance * 60):
    : : for x in parsedJobsFile:
    : : if x not in jobsDB:
    : : shouldHaveRan.append(x)
    : :
    : : for x in parsedJobsFile and jobsDB:
    : : didRun.append(x)
    : :
    : : if len(shouldHaveRan) == 0:
    : : shouldHaveRan.append("nothing was scheduled to run")
    : :
    : : if len(didRun) == 0:
    : : didRun.append("nothing ran")
    : : [/code]
    : :
    : : I get this error:
    : : [code]
    : : Traceback (innermost last):
    : : File "watchdog.py", line 19, in ?
    : : File "watchdog.py", line 214, in crontabParse << my class name
    : : File "watchdog.py", line 158, in testIt << my function name
    : : NameError: time
    : : [/code]
    : :
    : : I "think" this is the same issue. If so, I am looking for a way to modify the code above to work in Jython. The user Infidel helped me come up with a function to compare 2 lists and find differences. The code takes place in a for loop, for each minute of the day and checks to see if a script is eligible to run @ that time of day and
    : : day of week.
    : :
    : : Any ideas?
    :
    : Are you certain your code has used "import time"?

    You were right, the import statement was commented out, thanks.
    If I run the script now I get this:

    [code]
    error @ testIt() > class 'org.python.modules.time' has no attribute 'strptime'
    [/code]

    I know this module works: strftime ...but the other one does not in the
    code above. Any ideas or am I doing something wrong?

    Thanks for all your help on this!
  • : : Are you certain your code has used "import time"?
    :
    : You were right, the import statement was commented out, thanks.
    : If I run the script now I get this:
    :
    : [code]
    : error @ testIt() > class 'org.python.modules.time' has no attribute 'strptime'
    : [/code]
    :
    : I know this module works: strftime ...but the other one does not in the
    : code above. Any ideas or am I doing something wrong?
    :
    : Thanks for all your help on this!

    Here's all I know about these two functions:

    [code]
    >>> import time
    >>> help(time.strftime)
    Help on built-in function strftime:

    strftime(...)
    strftime(format[, tuple]) -> string

    Convert a time tuple to a string according to a format specification.
    See the library reference manual for formatting codes. When the time tuple
    is not present, current time as returned by localtime() is used.

    >>> help(time.strptime)
    Help on built-in function strptime:

    strptime(...)
    strptime(string, format) -> struct_time

    Parse a string to a time tuple according to a format specification.
    See the library reference manual for formatting codes (same as strftime()).

    >>> [/code]

    The error you're getting makes it look like the time module doesn't even have the strptime function. Maybe that's a limitation of Jython. I've never used Jython but I'm surprised it would be missing such a function from the stdlib. I'll see if I can find anything else.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • : : : Are you certain your code has used "import time"?
    : :
    : : You were right, the import statement was commented out, thanks.
    : : If I run the script now I get this:
    : :
    : : [code]
    : : error @ testIt() > class 'org.python.modules.time' has no attribute 'strptime'
    : : [/code]
    : :
    : : I know this module works: strftime ...but the other one does not in the
    : : code above. Any ideas or am I doing something wrong?
    : :
    : : Thanks for all your help on this!
    :
    : Here's all I know about these two functions:
    :
    : [code]
    : >>> import time
    : >>> help(time.strftime)
    : Help on built-in function strftime:
    :
    : strftime(...)
    : strftime(format[, tuple]) -> string
    :
    : Convert a time tuple to a string according to a format specification.
    : See the library reference manual for formatting codes. When the time tuple
    : is not present, current time as returned by localtime() is used.
    :
    : >>> help(time.strptime)
    : Help on built-in function strptime:
    :
    : strptime(...)
    : strptime(string, format) -> struct_time
    :
    : Parse a string to a time tuple according to a format specification.
    : See the library reference manual for formatting codes (same as strftime()).
    :
    : >>> [/code]
    :
    : The error you're getting makes it look like the time module doesn't even have the strptime function. Maybe that's a limitation of Jython. I've never used Jython but I'm surprised it would be missing such a function from the stdlib. I'll see if I can find anything else.
    :

    After doing some debugging, Jython doesnt support that module. I believe Jython is a little bit behind the most current version of Python unfortunately.

    So, I am going to have to find a way to re-write this:

    [code]
    tolerance = 0

    for minute in minutesList:
    mt = (time.localtime()[0],) + time.strptime(minute, '%a %b %d %H:%M')[1:]

    for job in parsedJobsFile:
    # split at / to pickup the path to script >> (' ' and $)
    parts = job.split('/', 1)
    t = parts[0].strip()
    jt = (time.localtime()[0],) + time.strptime(t, '%a %b %d %H:%M')[1:]

    m = time.mktime(mt)
    j = time.mktime(jt)

    if m >= j - (tolerance * 60) and m <= j + (tolerance * 60):
    for x in parsedJobsFile:
    if x not in jobsDB:
    shouldHaveRan.append(x)

    for x in parsedJobsFile and jobsDB:
    didRun.append(x)

    if len(shouldHaveRan) == 0:
    shouldHaveRan.append("nothing was scheduled to run")

    if len(didRun) == 0:
    didRun.append("nothing ran")
    [/code]

    Basically the strptime is the only thing that looks to be making this error out. I would prefer to stick with Python if possible...
  • can anyone help me hack? i need to learn the language i got a book but i dont understand it!
  • [b][red]This message was edited by Moderator at 2004-10-18 8:35:30[/red][/b][hr]
    : can anyone help me hack? i need to learn the language i got a book but i dont understand it!

    If you can't understand python, especially with the help of a book, then you have no business being a "hacker", if you even know what the word means.

    Now if you have specific questions then I'll be happy to try to answer them.

    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]



  • : Basically the strptime is the only thing that looks to be making this error out. I would prefer to stick with Python if possible...

    Well, you could always write your own "strptime" function or look around for someone else who has.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • : [b][red]This message was edited by Moderator at 2004-10-18 8:35:30[/red][/b][hr]
    : : can anyone help me hack? i need to learn the language i got a book but i dont understand it!
    :
    : If you can't understand python, especially with the help of a book, then you have no business being a "hacker", if you even know what the word means.
    :
    : Now if you have specific questions then I'll be happy to try to answer them.
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    : [code]
    : $ select * from users where clue > 0
    : no rows returned
    : [/code]
    :
    :
    :
    :
    Heh I personally love the fact people think Hackers are the ones that break code apart to "screw things up" or to "cheat/steal". However hackers are actually a coder that hacks together code for others. Where as crackers are the ones people are talking about when they generally say hacker. As for helping you hack, what do you mean by what you want help with. The general definition or the real definition.
  • hey frnds..HACKERS ARE DEVELOPERS..(Hackers created Internet..etc.) CRACKERS ARE PEOPLE WHO BREAK IN TO COMPUTERS..STEALING THINGS...specially they call them self Hackers..but actually they are not..muahahaha..
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories