Control Printer Queue On Windows 2000/XP

2005-06-30 Thread binarystar
Hi folks,

I am writing a script to print a few thousand pdf documents and I need
to have some control over the number of jobs that are sent to the
printer queue at time ... something along the lines of

if number_jobs > MAX_JOBS:
time.sleep(10)
else:
#Print More Files


I have been investigating the win32print utility
http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/pywin32/win32print.html

... but can not see how to get print queue information eg the number of
jobs pending .. atleast my attempts are failing

any ideas??

thx in advance 

**

-- 
http://mail.python.org/mailman/listinfo/python-list


Introspection Class/Instance Name

2006-04-25 Thread *binarystar*
Hello there,

what method would you use to return the name of the class and/or 
instance introspectively eg.

class Bollocks:

def __init__( self ):

print self.__method_that_returns_class_name__()
print self.__method_that_returns_instance_name__()


instance_of_bollocks= Bollocks()

# Which outputs

'Bollocks'
'instance_of_bollocks'



I have been scouring the 2.4 docs ... I am sure it is frustratingly simple

thx in advance

**
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can i set up a mysql db connection as a class ?

2006-04-27 Thread *binarystar*
that's definitely the way to go ..

-create a database_object
-initialise at start up
-then pass the database object to other classes as needed ...

If you want to get really fancy have a look at some ORM's ... I think 
there is a Python one called SQLObject?

[EMAIL PROTECTED] wrote:
> hey there,
> i have a huge app that connects to MySQL. There are three threads that
> are continually connecting and disconnecting to the db. The problem is,
> if there is an error, it faults out sometimes without closing the
> connection. i connect like this.
> db = MySQLdb.connect(host="localhost", user="MyUser",
> passwd="MyPassword", db="Stuff")
> cursor=db.cursor()
> 
> then i use the cursor.execute("SELECT yadda yadda
> 
> my question is, is there a way i can set up a global connection so that
> when the program loads, it connects once, then stays connected ? maybe
> i could assign instances of the cursor ?
> 
> please someone let me know if you have any good ideas
> 
> sk
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can i set up a mysql db connection as a class ?

2006-04-27 Thread *binarystar*
your on the right track ... create something like this ( hope the formatting 
doesn't go to hay wire )
 
class DB_Connector(object):

 """ Humble Database Connection Class """
 
 def __init__(self, host="localhost", user="MyUser",passwd="MyPassword", 
**other_db_arguments):

self.host   =   host
self.user   =   user
self.passwd =   passwd

# Unpack Other Database Arguments Here


self.CreateConnection()

 def CreateConnection( self ):

self.cursor = MySQLdb.connect(self.host, self.user, self.passwd)

 def DestroyConnection( self ):

self.cursor.close()

 def Execute( self, sql_statement ):

self.cursor.Execute( sql_statement )

return self.cursor.FetchAll()

Then when you run your program create an instance of the object

db_connection   = DB_Connector( 'localhost', 'administrator', 'betelgeuse99', 
auto_commit=1, other_keyword_arg="yes" )

now when you pass the db_connection instance to other classes, a copy will be 
made automagically

thread_1_instance   = ThreadingClass( db_connection )
thread_2_instance   = ThreadingClass( db_connection )
thread_3_instance   = ThreadingClass( db_connection )

should work .. 

I hope this is useful

[EMAIL PROTECTED] wrote:
> This is great !
> 
> ok, i dont really have a lot of time to get into the ORMS (before your
> post, this is the first i have heard of it) and my stuff is due on
> Monday. he he.
> 
> but, if i am able to make a global db connection, and multiple cursors
> pointing to the same connection object, how do i pull that off without
> making new db connections?
> 
> something like
> class db(self):
> def __init__(self):
>   db = MySQLdb.connect(host="localhost", user="MyUser",
>  passwd="MyPassword",
> db="Stuff")
> def cursor(self):
>   cursor = db.cursor()
>   return cursor
> 
> 
> then have in my threads that need to connect
> 
> cursor = db.cursor()
> cursor2 = db.cursor()
> 
> and so on ? i may be way outta whack here. i am still new at classes,
> methods, and modules.
> i do have Essential Reference on the way from Amazon though ! :)
> 
> thanks again
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can i set up a mysql db connection as a class ?

2006-04-27 Thread *binarystar*
Oops .. slight edit


now when you pass the db_connection instance to other classes, a reference will 
be passed automagically 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: append function problem?

2006-04-27 Thread *binarystar*
# Try This
seed = [2, 3, 4, 5]
next = [7]
seed1 = seed + next



[EMAIL PROTECTED] wrote:
> hello, recently i tried to use list.append() function in seemingly
> logical ways, however, i cannot get it to work, here is the test code:
> 
 seed = [2, 3, 4, 5]
 next = 7
 seed1 = seed.append(next)
 seed1
 print(str(seed1))
> None
 def test(lst):
> ...   print(str(lst))
> ...
 test(seed.append(next))
> None
> 
> I'm using Activestate python (latest) on win xp sp2..
> 
> I'm not sure why seed1 and the function doesn't recognize the list..
> 
> If anyone can point out where i'm going wrong would be much
> appreciated!
> Thanks in advance!
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can i set up a mysql db connection as a class ?

2006-04-27 Thread *binarystar*
I suppose that is possible because you are calling the one instance of a cursor 
object ... maybe you have to create a copy of the cursor object, rather than 
passing a reference to the one object? or set up the db_connection objects 
inside each of the threads? .. 


Winfried Tilanus wrote:
> On 04/28/2006 07:54 AM, *binarystar* wrote:
> 
> Just wondering: is there any risk of two threads accessing the Execute
> function at the same time and getting something like this on the same
> cursor object:
> 
> thread_1: self.cursor.Execute( sql_statement )
> thread_2: self.cursor.Execute( sql_statement )
> thread_1: return self.cursor.FetchAll()
> thread_2: return self.cursor.FetchAll()
> 
> In that case the queries would seriously be messed up. My intuition says
> this would need some locking or a 'cursor-pool'.
> 
> best wishes,
> 
> Winfried
> 
> 
>> your on the right track ... create something like this ( hope the
>> formatting doesn't go to hay wire )
>>
>> class DB_Connector(object):
>>
>> """ Humble Database Connection Class """
>> def __init__(self, host="localhost",
>> user="MyUser",passwd="MyPassword", **other_db_arguments):
>>   self.host   =   host
>>self.user   =   user
>>self.passwd =   passwd
>>   # Unpack Other Database Arguments Here
>>  self.CreateConnection()
>>def CreateConnection( self ):
>>   self.cursor = MySQLdb.connect(self.host, self.user,
>> self.passwd)
>>def DestroyConnection( self ):
>>   self.cursor.close()
>>def Execute( self, sql_statement ):
>>   self.cursor.Execute( sql_statement )
>>   return self.cursor.FetchAll()
>>Then when you run your program create an instance of the object
>>
>> db_connection = DB_Connector( 'localhost', 'administrator',
>> 'betelgeuse99', auto_commit=1, other_keyword_arg="yes" )
>>
>> now when you pass the db_connection instance to other classes, a copy
>> will be made automagically
>>
>> thread_1_instance= ThreadingClass( db_connection )
>> thread_2_instance= ThreadingClass( db_connection )
>> thread_3_instance= ThreadingClass( db_connection )
>>
>> should work ..
>> I hope this is useful
-- 
http://mail.python.org/mailman/listinfo/python-list