read-only attributes

2006-02-09 Thread john peter
while reading the lib manual, i came across mentions of read-only attributes.  for example, a method has a read-only attribute (called _im_self ?) for binding  a class instance to the method. is such a facility available to custom application  code? if so, what do i have to do if i want my application code to have read-only  attributes?  
		  
What are the most popular cars? Find out at Yahoo! Autos 
-- 
http://mail.python.org/mailman/listinfo/python-list

two generators working in tandem

2006-02-10 Thread john peter
I'd like to write two generators: one is a min to max sequence number generator that  rolls over to min again once the max is reached. the other is a generator that cycles  through N (say, 12) labels. currently, i'm using these generators in nested loops like  this:     seq_numbers = genSeqNum(min,max)  for label in genLabel():     for some_date in genDate(init):    for i in xrange(0, LIMIT):   print label, some_date, i, seq_numbers.next()     The problem I'm trying to solve is this:  when the seq_numbers generator rolls over, the label generator must be advanced  to the next one "in tandem". does anyone has any suggestion? thanks for any hepl!
		 Yahoo! Mail 
Use Photomail to share photos without annoying attachments.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: read-only attributes

2006-02-10 Thread john peter
Thank you for the suggestion!bruno at modulix <[EMAIL PROTECTED]> wrote:  limodou wrote:> On 2/10/06, john peter  wrote:(snip)>> what do i have to do if i want my application code to have>>read-only>> attributes?>>> I think you may consider property() built-in function:> > property( [fget[, fset[, fdel[, doc)> > Return a property attribute for new-style classes (classes that derive> from object).> fget is a functions/function/callable/> for getting an attribute value, likewise fset is a> function for setting, and fdel a function for del'ing, an attribute.> Typical use is to define a managed attribute x:> > > class C(object):&g!
 t;
 def __init__(self): self.__x = None> def getx(self): return self.__x> def setx(self, value): self.__x = value> def delx(self): del self.__x> x = property(getx, setx, delx, "I'm the 'x' property.")Note that you don't need to define all three accessors. For a'read-only' attribute, just define the getter:class ReadOnly(object):   def __init__(self, x):  self._x = x   x = property(fget=lambda self: self._x)-- bruno desthuillierspython -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) forp in '[EMAIL PROTECTED]'.split('@')])"-- http://mail.python.org/mailman/listinfo/python-list
		 Yahoo! Mail 
Use Photomail to share photos without annoying attachments.-- 
http://mail.python.org/mailman/listinfo/python-list

how to use RotatingFileHandler

2006-02-13 Thread john peter
Hi!     I have the following logging.conf :  [loggers]keys=root     [handlers]keys=roth     [formatters]keys=simpleFormatter     [logger_root]level=INFOhandlers=roth     [handler_roth]class=RotatingFileHandlerlevel=INFOformatter=simpleFormatterargs=('adssim.log','w', 200, 4)     [formatter_simpleFormatter]format=%(asctime)s - %(message)sdatefmt=     and sampleLogging.py script:import logging  import logging.config  logging.config.fileConfig("logging.conf")  logger = logging.getLogger("root")  for i in xrange(0, 5000):  logger.debug("debug message %s" % i)  logger.info("info message %s" % i)  logger.warn("warn!
  message
 %s" % i)  logger.error("error message %s" % i)  logger.critical("critical message %s" % i)     for some reason, i keep getting the following error message:  C:\adssim1>python sampleLogging.pyTraceback (most recent call last):  File "C:\Python24\lib\logging\config.py", line 157, in fileConfig    log.addHandler(handlers[hand])KeyError: 'roth'No handlers could be found for logger "root"     when i did a help(logging) on the logging module, i don't see RotatingFileHandler.  Could somebody please help? Thanks!
		  
What are the most popular cars? Find out at Yahoo! Autos 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: FOLLOW-UP how to use RotatingFileHandler

2006-02-13 Thread john peter
the fix was to specify handler.RotatingFileHandler     does RotatingFileHandler work with Windows XP? john peter <[EMAIL PROTECTED]> wrote:Hi!     I have the following logging.conf :  [loggers]keys=root     [handlers]keys=roth     [formatters]keys=simpleFormatter     [logger_root]level=INFOhandlers=roth     [handler_roth]class=RotatingFileHandlerlevel=INFOformatter=simpleFormatterargs=('adssim.log','w', 200, 4)     [formatter_simpleFormatter]format=%(asctime)s - %(message)sdatefmt=     and sampleLogging.py script:import
 logging  import logging.config  logging.config.fileConfig("logging.conf")  logger = logging.getLogger("root")  for i in xrange(0, 5000):  logger.debug("debug message %s" % i)  logger.info("info message %s" % i)  logger.warn("warn! message %s" % i)  logger.error("error message %s" % i)  logger.critical("critical message %s" % i)     for some reason, i keep getting the following error message:  C:\adssim1>python sampleLogging.pyTraceback (most recent call last):  File "C:\Python24\lib\logging\config.py", line 157, in fileConfig    log.addHandler(handlers[hand])KeyError: 'roth'No handlers could be found for logger "root"     when i did a help(logging) on the logging module, i don't see RotatingFileHandler.  Could somebody please help? Thanks!  !
  
   What are the most popular cars? Find out at Yahoo! Autos -- http://mail.python.org/mailman/listinfo/python-list  
		 Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews, & more on new and used cars.-- 
http://mail.python.org/mailman/listinfo/python-list

file existence checking

2006-02-15 Thread john peter
does anyone have a suggestion on simplest way to check for the existence of a file  within the same directory where a python script was started without really opening it?  i've seen some people use this as a mechanism for informing an application of  an external event, signalling it for example to disable some functionalities,  or perhaps a thread. Is such an approach a good one? Are there other "simple" approaches that  might be better (if so, why is it/are they better?)__Do You Yahoo!?Tired of spam?  Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- 
http://mail.python.org/mailman/listinfo/python-list

logging problem on Windows XP

2006-02-15 Thread john peter
i'm using python's logging facilities in all of my application modules.  my logging.conf file is:  [loggers]keys=root  [handlers]keys=roth  [formatters]keys=simpleFormatter  [logger_root]level=DEBUGhandlers=roth  [handler_roth]class=handlers.RotatingFileHandlerlevel=DEBUGformatter=simpleFormatterargs=('adssim.log','w', 200, 4)  [formatter_simpleFormatter]format=%(asctime)s - %(message)sdatefmt=%Y-%m-%d %H:%M:%S     i'm "creating" a logger in my adslogging module in the following way:  import loggingimport logging.config  logging.config.fileConfig("logging.conf")logger = logging.getLogger("root")     all my app modules import the adslogging module, and refer to the logger  as adslogging.logger and perform stuff like
 adslogging.logger.debug(msg1)  or adslogging.logger.info(msgN)     although i'm not explicitly closing the logfile and i don't think the logfile size has  maxed out (i see one logfile under my app directory with size 31K), i'm getting the following error messages in windows xp. what might i be doing wrong?        C:\adssim1>python adstest.py 19.52.160.171 139 W04Traceback (most recent call last):  File "C:\Python24\lib\logging\handlers.py", line 71, in emit    if self.shouldRollover(record):  File "C:\Python24\lib\logging\handlers.py", line 143, in shouldRollover    self.stream.seek(0, 2)  #due to non-posix-compliant Windows featureValueError: I/O operation on closed fileTraceback (most recent call last):  File "C:\Python24\lib\logging\handlers.py", line 71, in emit    if
 self.shouldRollover(record):  File "C:\Python24\lib\logging\handlers.py", line 143, in shouldRollover    self.stream.seek(0, 2)  #due to non-posix-compliant Windows featureValueError: I/O operation on closed fileTraceback (most recent call last):  File "C:\Python24\lib\logging\handlers.py", line 71, in emit    if self.shouldRollover(record):  File "C:\Python24\lib\logging\handlers.py", line 143, in shouldRollover    self.stream.seek(0, 2)  #due to non-posix-compliant Windows featureValueError: I/O operation on closed fileTraceback (most recent call last):  File "C:\Python24\lib\logging\handlers.py", line 71, in emit    if self.shouldRollover(record):  File "C:\Python24\lib\logging\handlers.py", line 143, in shouldRollover    self.stream.seek(0, 2)  #due to non-posix-compliant Windows featureValueError:!
  I/O
 operation on closed fileTraceback (most recent call last):  File "C:\Python24\lib\logging\handlers.py", line 71, in emit    if self.shouldRollover(record):  File "C:\Python24\lib\logging\handlers.py", line 143, in shouldRollover    self.stream.seek(0, 2)  #due to non-posix-compliant Windows featureValueError: I/O operation on closed file            
		  
What are the most popular cars? Find out at Yahoo! Autos 
-- 
http://mail.python.org/mailman/listinfo/python-list

Queue.Queue()

2006-02-16 Thread john peter
 what happens behind the scenes when i create a Queue.Queue() without specifying  a maxsize?  does a block of space gets allocated initially then  dynamically "expanded" as needed?  if so, what is the default size  of the initial space? is it  always better to specify a big enough maxsize initially for efficiency purposes, or  does it matter much? Thanks in advance for any help/detail  __Do You Yahoo!?Tired of spam?  Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- 
http://mail.python.org/mailman/listinfo/python-list

Queue.Queue()

2006-02-17 Thread john peter
 what happens behind the scene when i create a Queue.Queue() without specifyinga maxsize?  does a block of space gets allocated initially then  dynamically "expanded" as needed?  if so, what is the default size of  the initial space? is italways better to specify a big enough maxsize initially for efficiency purposes, ordoes it matter much? Thanks in advance for any help/detail
		  
What are the most popular cars? Find out at Yahoo! Autos 
-- 
http://mail.python.org/mailman/listinfo/python-list

commenting out blocks of code

2006-02-17 Thread john peter
 in java, i can  prevent a block of code from executing  by bracketing the block with comment indicators, as shown  below:  /*    statement1 will not execute;    statement2 will not execute;  */    statement3 will executeis there a similar mechanism in python, other than prefixing  the '#' character to the start of each statement i do  not  want to execute (which gets old very quickly if one needs to  comment and uncomment several statements a couple of  times while "playing around with code" say during initial design)?  
		 Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews, & more on new and used cars.-- 
http://mail.python.org/mailman/listinfo/python-list

interpreting the fractional portion of time.clock() vs time.time() measurements

2006-02-21 Thread john peter
   let's say i'm taking timing measurements in Windows XP     t1 = time.clock()  ...  t2 = time.clock()     t3 = t2 - t1 = say, 0.018what is the unit of measurement for t3? is it correct to say that t3 = 18 milliseconds? microseconds?   what if the timing function used for t1 and t2 was time.time()? is it still correct to  say that t3 = 18 milliseconds? i kinda know that in Windows, time.clock() has  higher resolution than time.time().  all i need is millisecond resolution. which  of these functions would be easier to translate into millisecond units of measurement?  __Do You Yahoo!?Tired of spam?  Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- 
http://mail.python.org/mailman/listinfo/python-list

interpreting the fractional portion of time.clock() vs time.time(0 measurements

2006-02-22 Thread john peter
let's say i'm taking timing measurements in Windows XP     t1 = time.clock()  ...  t2 = time.clock()     t3 = t2 - t1 = say, 0.018  what is the unit of measurement for t3? is it correct to say that t3 = 18 milliseconds?  microsends?     what if the timing function used for t1 and t2 was time.time()? is it still correct to say  that t3 = 18 milliseconds? i kinda know that in Windows, time.clock() has higher  resolution than time.time(), and all i need is millisecond resolution. which of these  functions would be easier to translate into millisecond units of measurement?
		 Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews, & more on new and used cars.-- 
http://mail.python.org/mailman/listinfo/python-list

event/job scheduling

2006-02-22 Thread john peter
i'd like to do the following kind of event/job scheduling:  run some task(s) (python code) everyday at (say) 8am for (say) a week.i need to do this for both windows xp and suse linux machines. although i know  that i can use cron or its equivalent in windows to kick off the python interpreter,  i was kinda hoping python has a builtin mechanism i can use for both OSes.can python's scheduler class do the job? if so, can someone share some code  snippets (it's not clear to me from reading the docs if python's scheduler class  can do the job).if python's scheduler class cannot do the job, can someone recommend a  third-party software/library that can do the job?  thanks for any  help!__Do You Yahoo!?Tired of spam?  Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- 
http://mail.python.org/mailman/listinfo/python-list

ANSWERED: event/job scheduling

2006-02-22 Thread john peter
about further investigation, i figured the basic answer out. gosh, i love python! :-)import sched, timedef print_time():     print "From print_time", time.time()if __name__ == '__main__':   s = sched.scheduler(time.time, time.sleep)     fmt = '%Y-%m-%d-%H:%M'     print time.time()     s.enterabs(time.mktime(time.strptime('2006-02-22-21:15', fmt)), 1, print_time, ())     s.enterabs(time.mktime(time.strptime('2006-02-22-21:17', fmt)), 1, print_time, ())     s.enterabs(time.mktime(time.strptime('2006-02-22-21:19', fmt)), 1, print_time, ())     s.run()     print time.time()john peter <[EMAIL PROTECTED]> wrote:  i'd like to do the
 following kind of event/job scheduling:  run some task(s) (python code) everyday at (say) 8am for (say) a week.i need to do this for both windows xp and suse linux machines. although i know  that i can use cron or its equivalent in windows to kick off the python interpreter,  i was kinda hoping python has a builtin mechanism i can use for both OSes.can python's scheduler class do the job? if so, can someone share some code  snippets (it's not clear to me from reading the docs if python's scheduler class  can do the job).if python's scheduler class cannot do the job, can someone recommend a  third-party software/library that can do the job?  thanks for any  help!__Do You Yahoo!?Tired of spam?  Yahoo! Mail has the best spam protection around http://mail.yahoo.com --
 http://mail.python.org/mailman/listinfo/python-list
		  
What are the most popular cars? Find out at Yahoo! Autos 
-- 
http://mail.python.org/mailman/listinfo/python-list

is Queue.Queue() serializable with cPickle?

2006-03-01 Thread john peter
i have the following custom extenstion of Queue.Queue() to save and load  queue contents but I think there's a problem with it.  Does anybody know qhether Queue.Queue() is pickle-able? if so,  can I get sample code? If not, can anybody recommend a pickle-able  Queue from another library that I might be able to use?  Thank you for any help!     Here's my "PersistentQueue" extension:     import cPickleimport Queueimport osfrom os.path import *  class PersistentQueue(Queue.Queue):   def __init__(self, maxsize=0):  #print "init"  Queue.Queue.__init__(self,maxsize)     def saveState(self, file):  fullFilePath = join(os.getcwd(),'savedStates', file)!
 ; 
 #print fullFilePath  f = open(fullFilePath, 'w')  l = []  while not self.empty(): l.append(self.get())  cPickle.dump(l, f)  f.close()     def loadState(self, file):  fullFilePath = join(os.getcwd(),'savedStates', file)  #print fullFilePath  f = open(fullFilePath)  l = cPickle.load(f)  f.close()  for i in l: self.put(i)  if __name__ == '__main__':   q = PersistentQueue(20)   q.loadState("q1.sav")   print q.get()    
 q.put("four")   q.saveState("q1.sav")
	
		 Yahoo! Mail 
Use Photomail to share photos without annoying attachments.-- 
http://mail.python.org/mailman/listinfo/python-list