Python documentation is not up to date :)

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

ThierryStiegler
Posts: 15
Joined: 24 Feb 2009, 12:49
Location: France
Contact:

Python documentation is not up to date :)

Post by ThierryStiegler »

Hi,

The example given in the documentation ( http://www.smartfoxserver.com/docs/inde ... python.htm ) about "importing module" and the destroy method does not work.

I get a NameError.

Because we do the import in the local scope of init() so we can't see the sys modules in the global scope and in the destroy scope... (erf there is too much scope :D )

So you have to add in init() "global sys" and idem in destroy() and all will work fine :)

Thierry
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Yes, that's correct.
Actually the import code should be done outside of the init() method.
I will make sure that the example is updated.

Thanks for noticing
Lapo
--
gotoAndPlay()
...addicted to flash games
icepick
Posts: 18
Joined: 03 Mar 2009, 17:43

Post by icepick »

Lapo wrote:Yes, that's correct.
Actually the import code should be done outside of the init() method.
I will make sure that the example is updated.

Thanks for noticing
I'm trying to manipulate my path in a python module. I do the following at the top of my python module, outside of the init() function:

Code: Select all

import os, sys 
sys.path.append(os.getcwd())
And it gives me the following traceback, for some reason:

Code: Select all

Traceback (innermost last):
  File "<string>", line 795, in ?
NameError: sys
I'm not really sure if this is a Jython-related problem or what. If I do this inside the init() function it seems to work ok. Any suggestions? I want to be able to import other python modules from the sfsExtensions directory, and have them available to all of my functions (in the global namespace).
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

That's strange, which SFS version do you use?
Maybe you have altered the classpath, but I can't be sure.
Lapo
--
gotoAndPlay()
...addicted to flash games
ThierryStiegler
Posts: 15
Joined: 24 Feb 2009, 12:49
Location: France
Contact:

Post by ThierryStiegler »

I get the same issue, I use the latest version 1.6.5.
icepick
Posts: 18
Joined: 03 Mar 2009, 17:43

Post by icepick »

ThierryStiegler wrote:I get the same issue, I use the latest version 1.6.5.
Glad it's not just me! Or maybe not, since this probably indicates that it's more difficult to fix. I am using 1.6.2, was going to upgrade to 1.6.5 but looks like that won't solve it.
icepick
Posts: 18
Joined: 03 Mar 2009, 17:43

Post by icepick »

Very weird... I added a comment at the top of the python module, and now it's working

So this works...

Code: Select all

  1 #foo
  2 import os, sys
  3 sys.path.append(os.getcwd())
...but this does not...

Code: Select all

  1 import os, sys
  2 sys.path.append(os.getcwd())
Hope that works for you as well, Thierry! Lapo, any idea why it behaves this way?
ThierryStiegler
Posts: 15
Joined: 24 Feb 2009, 12:49
Location: France
Contact:

Post by ThierryStiegler »

hmmm normaly you have to set at the first line the right script interpreter #!/bin/bash

Myabe this an old spec of Python 2.2, don't forget that SFS use Jython 2.2 so...

I will try tomorow at office :)

Thnaks for sharing :)

Thierry.
icepick
Posts: 18
Joined: 03 Mar 2009, 17:43

Post by icepick »

I wouldn't think a shebang line or comment would be necessary, but my Python experience only goes back to 2.3, so maybe it is a 2.2 or Jython restriction. Either way, it's working for me now with just a comment there.
ThierryStiegler wrote:hmmm normaly you have to set at the first line the right script interpreter #!/bin/bash

Myabe this an old spec of Python 2.2, don't forget that SFS use Jython 2.2 so...

I will try tomorow at office :)

Thnaks for sharing :)

Thierry.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Hi there,
I think there's a small bug in the interpreter when it joins the server python library behind the scenes. A comment as the first line prevents the problem.
We'll fix it in the next release.
Lapo
--
gotoAndPlay()
...addicted to flash games
ThierryStiegler
Posts: 15
Joined: 24 Feb 2009, 12:49
Location: France
Contact:

Post by ThierryStiegler »

I continue here :)

I convert the Server Scheduler example in python. But I got a really little problem with a call of Scheduler.destroy().

It need one argument.

Here my fix :


scheduler.destroy( object() )

So it works :)
Gnoll
Posts: 128
Joined: 10 Mar 2009, 10:14

Post by Gnoll »

Try passing null,

Good luck,
Gnoll
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Code: Select all

scheduler.destroy(None)
Lapo
--
gotoAndPlay()
...addicted to flash games
ThierryStiegler
Posts: 15
Joined: 24 Feb 2009, 12:49
Location: France
Contact:

Post by ThierryStiegler »

:)

Why passing None ? Maybe this should be an optionnal arg ? no ?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

No, the init() and destroy() come from a parent interface which allows a parameter to be passed. In this case (the Scheduler) the parameter is not needed, so None (null) is the best thing.

(This is Java, so you have to pass an object when it's required :( )
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply