Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 8th, 2004, 05:44 PM
bquad20 bquad20 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 13 bquad20 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Jython Help

I am getting an error: SyntaxError: invalid syntax
when I try to run this code with Jython. I can run the function in another .py file (no Jython) and it works great.
I am running it from a command prompt: jython myFile.py

I am still pretty new to Python/Jython and I am not sure why this happening, maybe a conflict of Java and Python APIs.

Any ideas?

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())    


Thanks!

Reply With Quote
  #2  
Old October 9th, 2004, 08:18 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 11 m 13 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Well, theres nothing that really jumps out as an error at first glance. It might be helpful if you could post the full error message (including the line number).

I can't really test this with Jython right now since I don't have it set up, but, if we can't figure it out I'll install it and give it a go.

Oh, you might want to choose either import time or from time import *, since there's not much point in importing the time module and then importing the strftime() function after - and then not using it . Also, you don't need to declare minutesList as global. So, after a few changes you'll end up with something like:

Code:
from time import localtime, strftime

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

minutesList = [stringTime for stringTime in todaysMinutes()]   

print minutesList


Note: I used a list comprehension here simply out of preferance, but you can still use list() if need's be in it's place.

I hope this helps ,

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old October 11th, 2004, 12:12 PM
bquad20 bquad20 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 13 bquad20 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for taking the time to review my problem. After some research and talking with a few people, it turns out the "yield"
is not valid in Jython 2.1, so you get this error:

Code:
Traceback (innermost last):
  (no code object) at line 0
  File "a.py", line 8
                    yield strftime("%a %b %d %H:%M", time)
                          ^
SyntaxError: invalid syntax


Can anyone else think of a simple way to get all the minutes of the day in list that doesnt use yield? I will need to make this work with Jython, but even something basic in Python would be great.

Thanks!

Reply With Quote
  #4  
Old October 11th, 2004, 03:57 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 11 m 13 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Ah, I'd totaly forgetten that Jython was that far behind Python right now. Anyway, this should do what you want:

Code:
from time import localtime, strftime

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

minutesList = todaysMinutes()  

print minutesList


Enjoy ,

Mark.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Jython Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT