importing another .py file from same folder?

Please post any questions about developing your plugin here. Please use the search function before posting!
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

importing another .py file from same folder?

Postby Tuck » Sun Aug 19, 2012 5:33 pm

I'm getting a error for doing this, i have no idea why.. works perfectly fine in idle, they are in same directory and everything, i tried adding __init__.py since it needed that in a sub directory to import scripts from it but that did not help either

I'm lost at this point because i never had this problem before >_>
-Tuck
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Aug 19, 2012 5:34 pm

What exactly are you trying to do? A lot more info would help us understand your specific issue. And, you do not need __init__.py files for Python3.3.

Satoon
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sun Aug 19, 2012 5:36 pm

i know but i though the source python was running a older version.

My main addon needs to import another .py file in same directory (the addon directory) top of the line in my addon i have, "import sql" in the same directory as addon i have sql.py witch is the file im trying to import however i just get a error.. on load with "no module named etc.."
-Tuck
User avatar
Monday
Administrator
Posts: 98
Joined: Thu Jul 12, 2012 4:15 am

Postby Monday » Sun Aug 19, 2012 5:45 pm

Make sure sql.py will run on python 3.3
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sun Aug 19, 2012 5:47 pm

Monday i've tested this in idle 900 times i've run it multiple times i can even run it now this error ONLY comes when i load it true Source python >_>
-Tuck
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Sun Aug 19, 2012 5:48 pm

The addon's namespace is not one that can, by default, be imported directly from. You need to use:[python]from <addon> import sql[/python]Satoon
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sun Aug 19, 2012 5:51 pm

Ight now it works :)

Thanks satoon
-Tuck
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sun Aug 19, 2012 6:17 pm

I've got a debug message (print) in my sql.py and for some reason this importing does not work correctly on first load however on the 2nd reload it works? im guessing this is a bug..

I did not change my script at all bellow i just typed sp_load and sp_unload

Image

and for some reason my sql.py doesnt work as intended most of the time, as it actually does in idle >_>
-Tuck
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sun Aug 19, 2012 8:54 pm

I'm getting pretty frustrated over this -.- i created and tested my script in idle and it worked just fine in this it's rather really weird >_>

If i have this line where should my data.db suppose to be >_>, i cannot find it anywhere >_> idle would put it next to the .py files as im intending to do>_>

Syntax: Select all

conn = sqlite3.connect('data.db')


My sql.py looks like this, bellow. The idea is it runs in a seperate thread side by side with main thread and do sql stuff, and it works perfectly fine in idle however i cant figure out why the heck it fucks up on source python -.-

Syntax: Select all

import threading
import queue
import sqlite3

_exec = [queue.Queue(), queue.Queue()]
_close = False
_commit = False


class _thread(threading.Thread):
def run(self):
global _exec
global _close
global _commit
conn = sqlite3.connect('data.db')
c = conn.cursor()
#INSERT IF TABLE DOES NOT EXISTS ETC..
conn.commit()
while True:
if _exec[0].qsize() > 0:
wildcard, sql_statement, func, args = _exec[0].get()
if wildcard:
obj = c.execute(*sql_statement)
else:
obj = c.execute(sql_statement)
if not (func is None):
func(obj, *args)
_exec[0].task_done()
elif _exec[1].qsize() > 0:
wildcard, sql_statement, func, args = _exec[1].get()
if wildcard:
obj = c.execute(*sql_statement)
else:
obj = c.execute(sql_statement)
if not (func is None):
func(obj, *args)
_exec[1].task_done()
if _close and (_exec[0].qsize() == 0 and
_exec[1].qsize() == 0):
conn.commit()
conn.close()
print('## SQL ## - Thread closed.')
break
elif not _close and (_exec[0].qsize() == 0 and
_exec[1].qsize() == 0):
if _commit:
print('## SQL ## - Thread committing.')
conn.commit()
print('## SQL ## - Thread committed.')
_commit = False

_t = _thread()
_t.start()
print('## SQL ## - 1.')


def execution(priority, wildcard, sql_statement, func, *args):
global _exec
_exec[(priority - 1)].put((wildcard, sql_statement, func, args))


def close():
global _close
_close = True


def commit():
global _commit
_commit = True
-Tuck
your-name-here
Developer
Posts: 168
Joined: Sat Jul 07, 2012 1:58 am

Postby your-name-here » Sun Aug 19, 2012 9:04 pm

This might have something to do with the fact that I just realized sqlite3.dll isn't being loaded by Source.Python. This will be fixed in an update soon. I am actually updating the Python distribution from 3.3 alpha2 to 3.3 beta 2.

Also of note, we had very strange issues with hibernation and threading / timings. I would suggest you force sv_hibernate_when_empty to 0 and test.
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Sun Aug 19, 2012 9:08 pm

Ight that will explain it all ! thanks :) , and thanks for the headsup about hibernate
-Tuck
Tuck
Global Moderator
Posts: 205
Joined: Sat Jul 14, 2012 9:35 pm
Location: Copenhagen

Postby Tuck » Mon Aug 20, 2012 1:32 pm

how do i force the cvar?
-Tuck
User avatar
Monday
Administrator
Posts: 98
Joined: Thu Jul 12, 2012 4:15 am

Postby Monday » Mon Aug 20, 2012 1:46 pm

just use ServerVar.Set() works just like force in it's current form :)

Return to “Plugin Development Support”

Who is online

Users browsing this forum: Bing [Bot] and 23 guests