School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,213 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,538 people online right now. Registration is fast and FREE... Join Now!




Python Script Error

 

Python Script Error, Works fine in interpreter.

Novast11

31 Aug, 2009 - 05:23 AM
Post #1

New D.I.C Head
*

Joined: 12 Jun, 2009
Posts: 20



Thanked: 1 times
My Contributions
I have this python program that accepts a date and checks if the input date is greater then 180 days from the current date. This program works fine when I call it from the interpreter.

I am using a third party program that uses python scripts. As I understand it passes arguments as dictionaries, so the only difference I am aware of is how I retrieve my arguments (arg.get('ret')). Can anyone see a problem with this code?

CODE

def diff(arg=""):
    """Accepts a date and return days between current date """
    if( arg == ""):
        return {'ret': "Input date String"}
    else:
        import datetime
        now = datetime.date.today()
        input = arg.get('ret').split("/")
        input = datetime.date(int(input[2]),int(input[0]),int(input[1]))
        change = datetime.timedelta(180)

        result = now - input
                    
        if(result  > change):
            return "false"
        else:
            return "true"


This is the error I am receiving when trying to test the script in my 3rd party program.

Arguments: {'ret': '9/27/2008'}
Error Line: 6
Traceback (innermost last):
File "./scripts/diff.py", line 6, in diff

The 3rd party program is written in Java btw.

Thanks!

This post has been edited by Novast11: 31 Aug, 2009 - 10:47 AM

User is offlineProfile CardPM
+Quote Post


Novast11

RE: Python Script Error

1 Sep, 2009 - 04:35 AM
Post #2

New D.I.C Head
*

Joined: 12 Jun, 2009
Posts: 20



Thanked: 1 times
My Contributions
Nothing? I am guessing there is nothing wrong with my code. It is probably how the Java Application is using the script, something to do with Jython perhaps.....

This post has been edited by Novast11: 1 Sep, 2009 - 05:50 AM
User is offlineProfile CardPM
+Quote Post

Novast11

RE: Python Script Error

1 Sep, 2009 - 06:22 AM
Post #3

New D.I.C Head
*

Joined: 12 Jun, 2009
Posts: 20



Thanked: 1 times
My Contributions
I Tried running the 3rd party program against my python script to see what happened. This is the erorr:

QUOTE

File "./scripts/diff.py", line 6, in diff
ImportError: no module named datetime
29211 ERROR engine.DataImport translateColumnValue.452 - Error with python script: Traceback (innermost last):
File "./scripts/diff.py", line 6, in diff
ImportError: no module named datetime


So why would datetime work when trying it in the interpreter. Does this datetime function not exist in Jython? What can I do to fix this?

This post has been edited by Novast11: 1 Sep, 2009 - 06:24 AM
User is offlineProfile CardPM
+Quote Post

Nykc

RE: Python Script Error

1 Sep, 2009 - 06:49 AM
Post #4

This script is cheap!
Group Icon

Joined: 14 Sep, 2007
Posts: 6,561



Thanked: 44 times
Dream Kudos: 375
My Contributions
I am not receiving any errors with that little snippet. Check your java syntax.
User is offlineProfile CardPM
+Quote Post

Novast11

RE: Python Script Error

1 Sep, 2009 - 07:00 AM
Post #5

New D.I.C Head
*

Joined: 12 Jun, 2009
Posts: 20



Thanked: 1 times
My Contributions
QUOTE(Nykc @ 1 Sep, 2009 - 06:49 AM) *

I am not receiving any errors with that little snippet. Check your java syntax.

I have no control over the vendor java software. All I have is the ability to create python scripts. My script works in the python interpreter. I believe datetime is not supported in the Jython version used by my software. I am going to investigate doing the function using the Date module.

Thanks

This post has been edited by Novast11: 1 Sep, 2009 - 07:01 AM
User is offlineProfile CardPM
+Quote Post

Nykc

RE: Python Script Error

1 Sep, 2009 - 11:30 AM
Post #6

This script is cheap!
Group Icon

Joined: 14 Sep, 2007
Posts: 6,561



Thanked: 44 times
Dream Kudos: 375
My Contributions
Sorry I couldn't be more help. Keep us posted of the solution if you encounter it, at least that way it can be referenced if it happens to someone else.
User is offlineProfile CardPM
+Quote Post

Novast11

RE: Python Script Error

2 Sep, 2009 - 04:50 AM
Post #7

New D.I.C Head
*

Joined: 12 Jun, 2009
Posts: 20



Thanked: 1 times
My Contributions
I am having trouble writing the same function but using the time module. Could someone tell me what I'm doing wrong or if it is possible to do using time. The dates inputed are in the format d/m/yyyy. I think my issue is in creating a time object with the inputed time.

CODE

def diff(arg=""):
    """Accepts a date and return days between current date """
    if( arg == ""):
        return {'ret': "Input date String"}
    else:
        import time
        now = time.gmtime()
        input = arg.split("/")
        input = time.strptime(input[0]+" "+input[1]+" "+input[2],"%m,%d,%YY")
        change = datetime.timedelta(180)

        result = now - input
        if(result  > change):
            return "false"
        else:
            return "true"

User is offlineProfile CardPM
+Quote Post

Novast11

RE: Python Script Error

3 Sep, 2009 - 10:10 AM
Post #8

New D.I.C Head
*

Joined: 12 Jun, 2009
Posts: 20



Thanked: 1 times
My Contributions
Can anyone help me compare the days between two times using the Time module and not DateTime???

CODE

def diff(arg=""):
    """Accepts a date and return days between current date """
    if( arg == ""):
        return {'ret': "Input date String"}
    else:
        import time
        now = time.gmtime()
        input = time.strptime(arg,"%m/%d/%Y")
       # change = datetime.timedelta(180)
        print input
        result = now - input
        #if(result  > change):
            #return "false"
        #else:
            #return "true"

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 09:55PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month