Python Script Error

Works fine in interpreter.

Page 1 of 1

7 Replies - 1920 Views - Last Post: 03 September 2009 - 11:10 AM Rate Topic: -----

#1 Novast11  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 30
  • Joined: 12-June 09

Python Script Error

Posted 31 August 2009 - 06:23 AM

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?

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 August 2009 - 11:47 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Python Script Error

#2 Novast11  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 30
  • Joined: 12-June 09

Re: Python Script Error

Posted 01 September 2009 - 05:35 AM

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: 01 September 2009 - 06:50 AM

Was This Post Helpful? 0
  • +
  • -

#3 Novast11  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 30
  • Joined: 12-June 09

Re: Python Script Error

Posted 01 September 2009 - 07:22 AM

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: 01 September 2009 - 07:24 AM

Was This Post Helpful? 0
  • +
  • -

#4 Nykc  Icon User is offline

  • Gentleman of Leisure
  • member icon

Reputation: 726
  • View blog
  • Posts: 8,638
  • Joined: 14-September 07

Re: Python Script Error

Posted 01 September 2009 - 07:49 AM

I am not receiving any errors with that little snippet. Check your java syntax.
Was This Post Helpful? 0
  • +
  • -

#5 Novast11  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 30
  • Joined: 12-June 09

Re: Python Script Error

Posted 01 September 2009 - 08:00 AM

View PostNykc, on 1 Sep, 2009 - 06:49 AM, said:

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: 01 September 2009 - 08:01 AM

Was This Post Helpful? 0
  • +
  • -

#6 Nykc  Icon User is offline

  • Gentleman of Leisure
  • member icon

Reputation: 726
  • View blog
  • Posts: 8,638
  • Joined: 14-September 07

Re: Python Script Error

Posted 01 September 2009 - 12:30 PM

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.
Was This Post Helpful? 0
  • +
  • -

#7 Novast11  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 30
  • Joined: 12-June 09

Re: Python Script Error

Posted 02 September 2009 - 05:50 AM

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.

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"


Was This Post Helpful? 0
  • +
  • -

#8 Novast11  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 30
  • Joined: 12-June 09

Re: Python Script Error

Posted 03 September 2009 - 11:10 AM

Can anyone help me compare the days between two times using the Time module and not DateTime???

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"


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1