Pyodbc and minimock with doctest

2008-10-31 Thread dj
Hello,

I have just started working with minimock in doctest.
I want to create a mock pyodbc object which returns a string value
when the method execute is called.

Here is my doctest:

>>> from minimock import Mock
>>> import pyodbc

>>> def database_response()
...   ServerName = 'test_server'
...   DbName = 'test_database'
...   User = 'test_user'
...   Pass ='test_pass'
...   connstring ='DRIVER{SQL Server};SERVER=%s;DATABASE=%s;UID=
%s;PWD=%s;' % (ServerName,
...  DbName, User, Pass)
...   cnx = pyodbc.connect(connstring)
...   cur = cnx.cursor()
...   name = cur.execute("select user_id from user")
...   print 'name:%s' % name

>>>pyodbc = Mock('pyodbc')
>>>pyodbc.connect.mock_returns = Mock('pyodbc')
>>>pyodbc.cursor.mock_returns = Mock('pyodbc')
>>>pyodbc.execute = Mock('pyodbc.execute', returns=True)
>>>pyodbc.execute.returns = 'Return this string.'
>>>pyodbc.execute.mock_returns = Mock('pyodbc.execute')

>>>database_response() #doctest: +ELLIPSIS
...


Here is the output from doctest:
*
File ".\pyodbc_test.txt", line 35, in pyodbc_test.txt
Failed example:
database_response()  #doctest: +ELLIPSIS
Expected nothing
Got:

Called pyodbc.connect({DRIVER{SQLServer};
SERVER=test_server;DATABASE=test_database;UID=test_user;PWD=test_pass;')
Called pyodbc.cursor()
Called pyodbc.execute('select user_id from users')
name: None
***
The last line of the output, name : Name, should read, name: Return
this string.
Clearly I am not assigning the string correctly, but I can't figure
out what I am
doing wrong. Any ideas ?
--
http://mail.python.org/mailman/listinfo/python-list


create a log level for python logging module

2009-03-30 Thread dj
I am trying to create a log level called userinfo for the python
logging. I read the source code and tried to register the level to the
logging namespace with the following source:

 from logging import Logger

 # create the custom log level
  class userinfo(Logger):
   def userinfo(self, msg,
*args, **kwargs):
  if
self.isEnabledFor(WARNING):
 
self._log(WARNING, msg, args, **kwargs)

  # Register log level in the
logging.Logger namespace
  Logger.userinfo = userinfo


Has I am sure you guessed, it did not work. If you know how this is
done or know what I am doing work or can provide a link to example
code (because I have not been able to locate any), I would greatly
appreciate it.
My sincere and heartfelt thanks in advance.


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


Re: create a log level for python logging module

2009-03-31 Thread dj
On Mar 30, 4:18 pm, Vinay Sajip  wrote:
> On Mar 30, 4:13 pm, dj  wrote:
>
>
>
> > I am trying to create a log level called userinfo for the pythonlogging. I 
> > read the source code and tried to register the level to theloggingnamespace 
> > with the following source:
>
> >              fromloggingimport Logger
>
> >                          # create the custom log level
> >                                   class userinfo(Logger):
> >                                                def userinfo(self, msg,
> > *args, **kwargs):
> >                                                           if
> > self.isEnabledFor(WARNING):
>
> > self._log(WARNING, msg, args, **kwargs)
>
> >                               # Register log level in thelogging.Logger 
> > namespace
> >                               Logger.userinfo = userinfo
>
> > Has I am sure you guessed, it did not work. If you know how this is
> > done or know what I am doing work or can provide a link to example
> > code (because I have not been able to locate any), I would greatly
> > appreciate it.
> > My sincere and heartfelt thanks in advance.
>
> See the example script at
>
> http://dpaste.com/hold/21323/
>
> which contains, amongst other things, an illustration of how to use
> custom logging levels in an application.
>
> Regards,
>
> Vinay Sajip

I got the code setup, however, I still get an error for my custom log
level.

### Python code
###


import sys, logging

# log levels
CRITICAL = 50
ERROR = 40
WARNING = 30
USERINFO =25 # my custom log level
INFO = 20
DEBUG  = 10

# define the range
LEVEL_RANGE = range(DEBUG, CRITICAL +1)

# level names

log_levels = {

CRITICAL : 'critical',
ERROR : 'error',
WARNING : 'warning',
USERINFO : 'userinfo',
INFO : 'info',
DEBUG : 'debug',

}

# associate names with our levels.
for lvl in log_levels.keys():
logging.addLevelName(lvl, log_levels[lvl])



# setup a log instance
logger = logging.getLogger('myLog')
logger.setLevel(CRITICAL)
hdlr = logging.StreamHandler()
hdlr.setLevel(CRITICAL)
logger.addHandler(hdlr)

# give it a try
print 'write logs'
logger.critical('this a critical log message')
logger.userinfo('this is a userinfo log message')   #call custom log
level

# Output from my interpreter
##

Python 2.6 (r26:66721, Oct  2 2008, 11:35:03) [MSC v.1500 32 bit
(Intel)]
Type "help", "copyright", "credits" or "license" for more information.
>>>
Evaluating log_level_test.py
write logs
this a critical log message
AttributeError: Logger instance has no attribute 'userinfo'
>>>

I would love to know what I am doing wrong. Thanks again for your
help, it is really appreciated.



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


custom handler does not write to log file

2009-03-31 Thread dj
It seems that you can create custom handlers and add them to the
logging.handlers namespace(http://mail.python.org/pipermail/python-
list/2008-May/493826.html.)
But for reasons beyond my understanding my log file (test.log) is not
written to.

  my handler class
###
import logging.handlers


# create my handler class
class MyHandler(logging.handlers.RotatingFileHandler):
def __init__(self, filename):
logging.handlers.RotatingFileHandler.__init__(self, filename,
 
maxBytes=10485760, backupCount=5)


# Register handler in the "logging.handlers" namespace
logging.handlers.MyHandler = MyHandler

  test app.py
##
import logging
import logging.handlers

from myhandler import MyHandler

# log file path
LOG_FILE_PATH='H:/python_experiments/logging/test.log'  # log file
path
#log file formatter
myformatter = logging.Formatter('%(asctime)s %(levelname)s %(filename)
s %(lineno)d %(message)s')

# setup a log instance for myHandler
logger2 = logging.getLogger('myLog2')
logger2.setLevel(logging.CRITICAL)
hdlr2 = logging.handlers.MyHandler(LOG_FILE_PATH)
hdlr2.setFormatter(myformatter)
hdlr2.setLevel(logging.CRITICAL)
logger2.addHandler(hdlr2)

# give it a try
print 'using myHandler'
logger2.debug('this is a test of myHandler')
print 'after logger using myHandler'

Thanks in advance for your help.
--
http://mail.python.org/mailman/listinfo/python-list


Re: custom handler does not write to log file

2009-03-31 Thread dj
On Mar 31, 1:13 pm, dj  wrote:
> It seems that you can create custom handlers and add them to the
> logging.handlers namespace(http://mail.python.org/pipermail/python-
> list/2008-May/493826.html.)
> But for reasons beyond my understanding my log file (test.log) is not
> written to.
>
>   my handler class
> ###
> import logging.handlers
>
> # create my handler class
> class MyHandler(logging.handlers.RotatingFileHandler):
>     def __init__(self, filename):
>         logging.handlers.RotatingFileHandler.__init__(self, filename,
>
> maxBytes=10485760, backupCount=5)
>
> # Register handler in the "logging.handlers" namespace
> logging.handlers.MyHandler = MyHandler
>
>   test app.py
> ##
> import logging
> import logging.handlers
>
> from myhandler import MyHandler
>
> # log file path
> LOG_FILE_PATH='H:/python_experiments/logging/test.log'  # log file
> path
> #log file formatter
> myformatter = logging.Formatter('%(asctime)s %(levelname)s %(filename)
> s %(lineno)d %(message)s')
>
> # setup a log instance for myHandler
> logger2 = logging.getLogger('myLog2')
> logger2.setLevel(logging.CRITICAL)
> hdlr2 = logging.handlers.MyHandler(LOG_FILE_PATH)
> hdlr2.setFormatter(myformatter)
> hdlr2.setLevel(logging.CRITICAL)
> logger2.addHandler(hdlr2)
>
> # give it a try
> print 'using myHandler'
> logger2.debug('this is a test of myHandler')
> print 'after logger using myHandler'
>
> Thanks in advance for your help.

Kindly ingnore this message, turns out the problem was  a
misunderstanding of the severity for the logging levels.
My bad. Thanks anyway :-).
--
http://mail.python.org/mailman/listinfo/python-list


Re: create a log level for python logging module

2009-03-31 Thread dj
On Mar 31, 12:58 pm, MRAB  wrote:
> dj wrote:
> > On Mar 30, 4:18 pm, Vinay Sajip  wrote:
> >> On Mar 30, 4:13 pm, dj  wrote:
>
> >>> I am trying to create a log level called userinfo for the pythonlogging. 
> >>> I read the source code and tried to register the level to 
> >>> theloggingnamespace with the following source:
> >>>              fromloggingimport Logger
> >>>                          # create the custom log level
> >>>                                   class userinfo(Logger):
> >>>                                                def userinfo(self, msg,
> >>> *args, **kwargs):
> >>>                                                           if
> >>> self.isEnabledFor(WARNING):
> >>> self._log(WARNING, msg, args, **kwargs)
> >>>                               # Register log level in thelogging.Logger 
> >>> namespace
> >>>                               Logger.userinfo = userinfo
> >>> Has I am sure you guessed, it did not work. If you know how this is
> >>> done or know what I am doing work or can provide a link to example
> >>> code (because I have not been able to locate any), I would greatly
> >>> appreciate it.
> >>> My sincere and heartfelt thanks in advance.
> >> See the example script at
>
> >>http://dpaste.com/hold/21323/
>
> >> which contains, amongst other things, an illustration of how to use
> >> custom logging levels in an application.
>
> >> Regards,
>
> >> Vinay Sajip
>
> > I got the code setup, however, I still get an error for my custom log
> > level.
>
> > ### Python code
> > ###
>
> > import sys, logging
>
> > # log levels
> > CRITICAL = 50
> > ERROR = 40
> > WARNING = 30
> > USERINFO =25 # my custom log level
> > INFO = 20
> > DEBUG  = 10
>
> > # define the range
> > LEVEL_RANGE = range(DEBUG, CRITICAL +1)
>
> > # level names
>
> > log_levels = {
>
> >     CRITICAL : 'critical',
> >     ERROR : 'error',
> >     WARNING : 'warning',
> >     USERINFO : 'userinfo',
> >     INFO : 'info',
> >     DEBUG : 'debug',
>
> >     }
>
> > # associate names with our levels.
> > for lvl in log_levels.keys():
> >     logging.addLevelName(lvl, log_levels[lvl])
>
> > # setup a log instance
> > logger = logging.getLogger('myLog')
> > logger.setLevel(CRITICAL)
> > hdlr = logging.StreamHandler()
> > hdlr.setLevel(CRITICAL)
> > logger.addHandler(hdlr)
>
> > # give it a try
> > print 'write logs'
> > logger.critical('this a critical log message')
> > logger.userinfo('this is a userinfo log message')   #call custom log
> > level
>
> > # Output from my interpreter
> > ##
>
> > Python 2.6 (r26:66721, Oct  2 2008, 11:35:03) [MSC v.1500 32 bit
> > (Intel)]
> > Type "help", "copyright", "credits" or "license" for more information.
> > Evaluating log_level_test.py
> > write logs
> > this a critical log message
> > AttributeError: Logger instance has no attribute 'userinfo'
>
> > I would love to know what I am doing wrong. Thanks again for your
> > help, it is really appreciated.
>
> I think that custom levels don't get their own method; you have to use:
>
>      logger.log(USERINFO, 'this is a userinfo log message')
>
> although you could add it yourself with, say:
>
>      setattr(logger, 'userinfo', lambda *args: logger.log(USERINFO, *args))

If it's not asking to much, could you show me how these would be
used ?
I tried on my own, but I keep getting errors.
--
http://mail.python.org/mailman/listinfo/python-list


Re: create a log level for python logging module

2009-03-31 Thread dj
On Mar 31, 4:01 pm, MRAB  wrote:
> dj wrote:
> > On Mar 31, 12:58 pm, MRAB  wrote:
> >> dj wrote:
> >>> On Mar 30, 4:18 pm, Vinay Sajip  wrote:
> >>>> On Mar 30, 4:13 pm, dj  wrote:
> >>>>> I am trying to create a log level called userinfo for the 
> >>>>> pythonlogging. I read the source code and tried to register the level 
> >>>>> to theloggingnamespace with the following source:
> >>>>>              fromloggingimport Logger
> >>>>>                          # create the custom log level
> >>>>>                                   class userinfo(Logger):
> >>>>>                                                def userinfo(self, msg,
> >>>>> *args, **kwargs):
> >>>>>                                                           if
> >>>>> self.isEnabledFor(WARNING):
> >>>>> self._log(WARNING, msg, args, **kwargs)
> >>>>>                               # Register log level in thelogging.Logger 
> >>>>> namespace
> >>>>>                               Logger.userinfo = userinfo
> >>>>> Has I am sure you guessed, it did not work. If you know how this is
> >>>>> done or know what I am doing work or can provide a link to example
> >>>>> code (because I have not been able to locate any), I would greatly
> >>>>> appreciate it.
> >>>>> My sincere and heartfelt thanks in advance.
> >>>> See the example script at
> >>>>http://dpaste.com/hold/21323/
> >>>> which contains, amongst other things, an illustration of how to use
> >>>> custom logging levels in an application.
> >>>> Regards,
> >>>> Vinay Sajip
> >>> I got the code setup, however, I still get an error for my custom log
> >>> level.
> >>> ### Python code
> >>> ###
> >>> import sys, logging
> >>> # log levels
> >>> CRITICAL = 50
> >>> ERROR = 40
> >>> WARNING = 30
> >>> USERINFO =25 # my custom log level
> >>> INFO = 20
> >>> DEBUG  = 10
> >>> # define the range
> >>> LEVEL_RANGE = range(DEBUG, CRITICAL +1)
> >>> # level names
> >>> log_levels = {
> >>>     CRITICAL : 'critical',
> >>>     ERROR : 'error',
> >>>     WARNING : 'warning',
> >>>     USERINFO : 'userinfo',
> >>>     INFO : 'info',
> >>>     DEBUG : 'debug',
> >>>     }
> >>> # associate names with our levels.
> >>> for lvl in log_levels.keys():
> >>>     logging.addLevelName(lvl, log_levels[lvl])
> >>> # setup a log instance
> >>> logger = logging.getLogger('myLog')
> >>> logger.setLevel(CRITICAL)
> >>> hdlr = logging.StreamHandler()
> >>> hdlr.setLevel(CRITICAL)
> >>> logger.addHandler(hdlr)
> >>> # give it a try
> >>> print 'write logs'
> >>> logger.critical('this a critical log message')
> >>> logger.userinfo('this is a userinfo log message')   #call custom log
> >>> level
> >>> # Output from my interpreter
> >>> ##
> >>> Python 2.6 (r26:66721, Oct  2 2008, 11:35:03) [MSC v.1500 32 bit
> >>> (Intel)]
> >>> Type "help", "copyright", "credits" or "license" for more information.
> >>> Evaluating log_level_test.py
> >>> write logs
> >>> this a critical log message
> >>> AttributeError: Logger instance has no attribute 'userinfo'
> >>> I would love to know what I am doing wrong. Thanks again for your
> >>> help, it is really appreciated.
> >> I think that custom levels don't get their own method; you have to use:
>
> >>      logger.log(USERINFO, 'this is a userinfo log message')
>
> >> although you could add it yourself with, say:
>
> >>      setattr(logger, 'userinfo', lambda *args: logger.log(USERINFO, *args))
>
> > If it's not asking to much, could you show me how these would be
> > used ?
> > I tried on my own, but I keep getting errors.
>
> Have you read:
>
>      http://www.python.org/doc/current/library/logging.html

Problem solved. Thanks for the link to the updated docs :-).
--
http://mail.python.org/mailman/listinfo/python-list


ValueError: I/O operation on closed file

2009-04-10 Thread dj
I have a handler which I use with a set of log levels for the python
logging module.

--- myhandler.py

import logging.handlers

# create my handler class
class MyHandler(logging.handlers.RotatingFileHandler):
def __init__(self, fn):
logging.handlers.RotatingFileHandler.__init__(self, fn,
 
maxBytes=10485760, backupCount=5)

# Register handler in the "logging.handlers" namespace
logging.handlers.MyHandler = MyHandler


Using it, repeatedly generates this error:

Traceback (most recent call last):
  File "C:\python26\lib\logging\handlers.py", line 74, in emit
if self.shouldRollover(record):
  File "C:\python26\lib\logging\handlers.py", line 146, in
shouldRollover
self.stream.seek(0, 2)  #due to non-posix-compliant Windows
feature
ValueError: I/O operation on closed file


I am completely stumped  has to what could be the issue.
Any help would be greatly appreciated.
--
http://mail.python.org/mailman/listinfo/python-list


Re: ValueError: I/O operation on closed file

2009-04-13 Thread dj
On Apr 11, 12:30 am, Dennis Lee Bieber  wrote:
> On Fri, 10 Apr 2009 13:25:25 -0700 (PDT), dj 
> declaimed the following in gmane.comp.python.general:
>
>
>
> > I have a handler which I use with a set of log levels for the python
> > logging module.
>
> > --- myhandler.py
> > 
> > import logging.handlers
>
> > # create my handler class
> > class MyHandler(logging.handlers.RotatingFileHandler):
> >     def __init__(self, fn):
> >         logging.handlers.RotatingFileHandler.__init__(self, fn,
>
> > maxBytes=10485760, backupCount=5)
>
> > # Register handler in the "logging.handlers" namespace
> > logging.handlers.MyHandler = MyHandler
>
>         Don't you need to pass an INSTANCE of the handler? Or SOMEWHERE
> create an instance for use. Note that the filename is one of the
> arguments needed to initialize this, and since we see no code with a
> root file name ... ???
>
>         No addHandler() anywhere?
>
> > 
>
> > Using it, repeatedly generates this error:
>
> > Traceback (most recent call last):
> >   File "C:\python26\lib\logging\handlers.py", line 74, in emit
> >     if self.shouldRollover(record):
> >   File "C:\python26\lib\logging\handlers.py", line 146, in
> > shouldRollover
> >     self.stream.seek(0, 2)  #due to non-posix-compliant Windows
> > feature
> > ValueError: I/O operation on closed file
>
>         That's a rather short traceback -- where are the calls to the logger
> that would trigger the emit() call? Where do you specify that this
> handler is suppose to be used
> --
>         Wulfraed        Dennis Lee Bieber               KD6MOG
>         [email protected]             [email protected]
>                 HTTP://wlfraed.home.netcom.com/
>         (Bestiaria Support Staff:               [email protected])
>                 HTTP://www.bestiaria.com/

Hello again,

I thought I included the specifics of my custom logger, but I did not
do that.
Please allow me to present this issue again with the complete
details.

--- myhandler.py ---
import logging.handlers

# create my handler class
class MyHandler(logging.handlers.RotatingFileHandler):
def __init__(self, fn):
logging.handlers.RotatingFileHandler.__init__(self, fn,

maxBytes=10485760, backupCount=5)

# Register handler in the "logging.handlers" namespace
logging.handlers.MyHandler = MyHandler

--- myLogs.py -
import logging
import logging.handlers
from myhandler import MyHandler  #custom handler
import os

# EXCLUDED THE DETAILS FOR THE CUSTOMIZED LOGGER


#log file formatter
format = logging.Formatter("%(asctime)s %(levelname)s %(filename)s %
(lineno)d %(message)s")

# setup the logger instance
log = logging.getLogger("app_log")
# set the log level
log.setLevel(logging.DEBUG)
# add a method for the custom log level to the logger
setattr(log, 'userinfo', lambda *args: log.log(USERINFO, *args))

# create the handler for app.log
app_handler = logging.handlers.MyHandler(APP_LOG_FILENAME)#using
myhandler
# set handler level
app_handler.setLevel(logging.DEBUG)
# add the formatter to the handler
app_handler.setFormatter(format)


# create the handler for notice.log
notice_handler =  logging.handlers.MyHandler(NOTICE_LOG_FILENAME)  #
using my handler
# set handler level
notice_handler.setLevel(logging.ERROR)
# add the formatter to the handler
notice_handler.setFormatter(format)


# setup the logger for user.log
userLog = logging.getLogger("user_log")
# set the level
userLog.setLevel(logging.INFO)
# add a method for the custom log level to the logger
setattr(userLog, 'userinfo', lambda *args: userLog.log(USERINFO,
*args))

# create the  handler for user.log
user_handler =  logging.handlers.MyHandler(USER_LOG_FILENAME)  # using
myhandler
# handler level
user_handler.setLevel(logging.INFO)
# add the formatter to the handler
user_handler.setFormatter(format)

# add the handlers to log
log.addHandler(app_handler)
log.addHandler(notice_handler)

# add the handler to userLog
userLog.addHandler(user_handler)

- app.py ---

import logging
import myLogs


myLogs.log.debug('this is debug message')



###

I hope this provides much better clarification.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using the indent method

2008-05-14 Thread dj
Hello All,

I am using elementtree to write an XML document and I am having a hard
time adding the correct indentation.
I have tried using the indent method, but I can not figure out how to
use it. Any suggestions.
--
http://mail.python.org/mailman/listinfo/python-list


Using file objects with elementtree

2008-05-14 Thread dj
Hello,

Rather then holding my XML document in memory before writing it to
disk, I want to create a file object that elementtree will write each
element to has it is created. Does any one know how to do that ?

Here is my code so, far:

fd = open("page.xml", "w")
tree.write( fd, encoding="iso-8859-1")

I know there's something I am doing wrong, but I just do not know
what.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using os.walk to return files in subdirectories

2008-05-22 Thread dj
Hello All,

I am attempting to us os.walk to populate two lists with values from a
directory. The first list contains all the files in the directory and
subdirectories.
The second list contains only the files in the subdirectories.

Here is the code:

import os

# list of matching files
allfiles = [] #store all files found
subfiles = []  # subdir

for root,dir,files in os.walk("H:/python_experiments", f1):
 # this list has the files in all directories and subdirectories
 filelist = [ os.path.join(root,fi) for fi in files if
fi.endswith(".py") or fi.endswith(".txt") ]
 for f in filelist:
 allfiles.append(f)

 # split the root
 s= root.split(('\\') or ('\/'))
 print 's ',
 print s

 # assign the last value to end to come to values in dir
 end= s[-1]
 print 'end ',
 print end
 print '\n'

 # this list contains only the files in subdirectories
 for d in dir:
if end == d:
 print 'subdir % s' % (end)
 sublist = [ os.path.join(root, fi) for fi in files if
fi.endswith(".py") or fi.endswith(".txt")]
 for f in sublist:
 subfiles.append(f)

for i in subfiles:
print 'subfile', i


for i in allfiles:
print "file ", i

The allfiles list is populated, but the subfiles list is not. Any
Suggetions ?
--
http://mail.python.org/mailman/listinfo/python-list


Has a file been opened by another program ?

2008-05-30 Thread dj
Hello All,

First, Is there a python library, method or module that will tell you
if a file has been opened by another program (i.e: Word, PowerPoint,
IE etc.), the methods I have found in the standard library will only
work with the python open method.

Second, I want to take the time to thank each and everyone of you for
your help. If you have not already guessed, I am a python novice ( I
know your surprised), and I am learning a lot and have discovered alot
about python from your answers. So, I just want to say... THANK
YOU !
--
http://mail.python.org/mailman/listinfo/python-list


Re: time module methods give an am or pm value ?

2008-06-07 Thread dj
Hello again,

Does anyone know which method in the time module will generate and am
or pm ?
If none of the method will do this for me. Can I produce the value on
my own ?
Any suggestions ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: time module methods give an am or pm value ?

2008-06-09 Thread dj
On Jun 7, 9:24 am, "Mark Tolonen" <[EMAIL PROTECTED]> wrote:
> "dj" <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
>
> > Hello again,
>
> > Does anyone know which method in the time module will generate and am
> > or pm ?
> > If none of the method will do this for me. Can I produce the value on
> > my own ?
> > Any suggestions ?
> >>> from time import *
> >>> strftime('%I:%M:%S %p',localtime(time()))
> '07:23:24 AM'
> >>> strftime('%I:%M:%S %p',gmtime(time()))
>
> '02:23:39 PM'
>
> -Mark

Hello Mark,

Thank you very much. I finally found this function in the
documentation.
--
http://mail.python.org/mailman/listinfo/python-list


Re: time module methods give an am or pm value ?

2008-06-09 Thread dj
On Jun 7, 9:40 am, Scott David Daniels <[EMAIL PROTECTED]> wrote:
> dj wrote:
> > Hello again,
>
> > Does anyone know which method in the time module will generate and am
> > or pm ?
> > If none of the method will do this for me. Can I produce the value on
> > my own ?
> > Any suggestions ?
>
> Read up about strftime (a function, not a method).
>
> Generally, if you know you'll be using something for more than a few
> uses, it is worth reading the entire documentation for that module.
> People put a fair amount of effort into documentation, and they do it
> to reduce the number of questions they have to answer one user at a
> time.  Reading the results of that effort before asking shows courtesy.
> Few people mind explaining unclear documentation when the confusing part
> is identified (and they know the answer).  Similarly, asking (5000?, a
> million?) to each spend a second so you can save an hour is bad economics.
>
> --Scott David Daniels
> [EMAIL PROTECTED]

Hello Scott,

Thank you very much. I did find this function after shortly after I
posted this question.
I appreciated your help :-). And you are right, I do need to be a
better job of checking
the documentation, before I post. Thank you again for your help.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for Fredrik Lundh; documentation and code examples for elementtree

2008-05-07 Thread dj
Hello All,

I am trying to get in touch with Mr. Lundh. I am looking for exmaple
code regarding the use of elementtree. I have read through most of the
examples on http://effbot.org and I am hoping he can suggest some
others. Additionally, I am hoping he can give me an example use of the
comment method. I have tried a couple times, but I can not figure it
out. Thank you so very much.

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


Re: The Semicolon Wars as a software industry and human condition

2006-08-17 Thread DJ Stunks
Xah Lee wrote:
> Of interest:
>
> · The Semicolon Wars, by Brian Hayes. 2006.
>  http://www.americanscientist.org/template/AssetDetail/assetid/51982
>
> in conjunction to this article, i recommend:
>
> · Software Needs Philosophers, by Steve Yegge, 2006
> http://xahlee.org/Periodic_dosage_dir/_p/software_phil.html
>
> · What Languages to Hate, Xah Lee, 2002
> http://xahlee.org/UnixResource_dir/writ/language_to_hate.html

speak of the devil...

-jp

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


Gmail Error using smtplib

2007-07-20 Thread DJ Fadereu
Hello, can anyone help me with this? What am I doing wrong here?

(I've changed private info to /xx)
 I'm getting an authentication error while using a standard script
Gmail:
--SCRIPT-
import smtplib
from email.MIMEText import MIMEText

msg = MIMEText('Hello, this is fadereu...')
>From = '[EMAIL PROTECTED]'

msg['Subject'] = 'Hello'
msg ['From'] = '[EMAIL PROTECTED]'
msg['To'] = '[EMAIL PROTECTED]'

s = smtplib.SMTP('alt1.gmail-smtp-in.l.google.com')
s.set_debuglevel(1)
s.login('[EMAIL PROTECTED]','x')
s.sendmail(msg['From'], msg['To'], msg.as_string())
s.close()
ERROR--
Traceback (most recent call last):
  File "C:\Documents and Settings\Acer User\Desktop\Code\S60 scripts
\Fadereu's Codez\gmail.py", line 13, in 
s.login('[EMAIL PROTECTED]','x'')
  File "C:\Python25\lib\smtplib.py", line 554, in login
raise SMTPException("SMTP AUTH extension not supported by
server.")
SMTPException: SMTP AUTH extension not supported by server.

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


Help with PySMS

2007-05-27 Thread DJ Fadereu
Hello -

Background:

I'm not a coder, but I got a degree in Chem Engg about 7 years ago. I
have done some
coding in my life, and I'm only beginning to pick up Python. So assume
that I'm very stupid
when and if you are kind enough to help me out.

Problem:

I need an SMS server running on my WinXP PC, as soon as possible. I'm
currently using a Nokia 6300 phone which has the S60 platform. I
downloaded the PySMS by Dave Berkeley from
http://www.wordhord.co.uk/pysms.html and started testing it, but I
haven't been able to get it working. Maybe I don't know how to do some
configurations before using it, I dunno. I'm pretty lost.

Do I need to tweak Nokia.ini? What ports am I supposed to use? Can
anybody tell me a step-by-step way of setting up and getting this
thing running?

I don't have enough to pay for this information, or I would gladly
shell out some cash. But I can bet that I'll be able to help you out
with something or the other in the future, if not money. And I am
willing to negotiate a portion of royalties if I make any money off
this project. My project is very simple - I will use incoming SMS to
generate a visualisation and automatic responder. This system will be
part of a multiplayer game that lots of people can play using SMS.

cheers,
DJ Fadereu
http://www.algomantra.com

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


Re: ten small Python programs

2007-05-27 Thread DJ Fadereu

>
> You could try this wiki page:
>
> http://rosettacode.org/wiki/Main_Page
>
> It has a fair amount of Python examples as well as many more other
> languages (doing the same algorithm).
>
> Hope this helps.
>
> Adonis


THIS IS GREAT :) Thanx!

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


Re: Help with PySMS

2007-05-27 Thread DJ Fadereu
On May 28, 1:53 am, Petr Jakes <[EMAIL PROTECTED]> wrote:
> Maybe you can try python binding for gammu, which works great for me.
> HTH
> Petr Jakes
>
> http://cihar.com/gammu/python/

I'm going to try and setup Gammu today. I'm using a DKU-2
cable connection. The Gammu guide says that:"Before you will try
connect to Gammu, you have to install gnapplet application in phone
first. Later steps depends on connection type. For example for
Bluetooth use "bluerfgnapbus" connection and model "gnap" and device
addresss as "port". You can read notes described below for infrared
and Bluetooth too. Cables connections (DKE-2, DKU-2, etc.) are not
supported by gnapplet now."

Now I'm having some trouble catching Bluetooth on my laptop, I don't
know why - maybe the radio died. So now it's unclear whether this
gnapplet thingie stillneeds to be on my Nokia 6300 even if I'm going
through the cable route.

Any hints?





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


Re: Any "consumer review generators" available?

2007-04-02 Thread DJ Stunks
On Mar 30, 1:46 am, nullified <[EMAIL PROTECTED]> wrote:
> On 29 Mar 2007 20:34:26 -0700, "Evil Otto" <[EMAIL PROTECTED]> wrote:
>
> >On Mar 29, 2:19 pm, [EMAIL PROTECTED] wrote:
> >> I am looking for a fake consumer review generator that could generate 
> >> realistic looking reviews for any products, kind of like on amazon.com but 
> >> generated by Artificial Intelligence. Is there a package available in your 
> >> favorite programing language... thx alan
>
> >I really, really hope that you're looking to generate test data or
> >filler text.
>
> >If you're not, then DIAF.
>
> Die In A Fire? Drop In A Fryer? Doug Is A Fucker? Drown In A Fart?

You knew Doug too?  I could tell he was a fucker right from the moment
I met him.

-jp

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


Re: list vs tuple for a dict key- why aren't both hashable?

2009-11-08 Thread Dj Gilcrease
On Sun, Nov 8, 2009 at 11:15 AM, Wells  wrote:
> I'm not quite understanding why a tuple is hashable but a list is not.
> Any pointers? Thanks!

tuple is hashable because it is immutable whereas a list is mutable.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding element by tag in xml

2010-02-20 Thread Dj Gilcrease
On Sat, Feb 20, 2010 at 9:27 AM, sWrath swrath  wrote:
> from xml.dom.minidom import parse
> from xml.etree.ElementTree import*
>
> file1="book.xml"
> tmptree=ElementTree()
> tmptree.parse(file1)
> items=root.getiterator()
>
>
> dom = parse(file1)
>
>
> #Find tag names
> for node in items :
>    if node.tag == 'author': #Get tag
>        print dom.getElementsByTagName ('book') #Error 1

You are mixing two different types of xml parsers, either user minidom

for node in dom.getElementsByTagName('author'):
print node.getElementsByTagName('book')

or use etree

for el in items:
if el.tag == 'author':
print el.find('book')

There are a few differences you need to note, the getElementsByTagName
always returns a list even if there is only 1 element and find only
returns the first element found no matter what. If you want to print
all books associated with an author you would need to do something
like

for author in tmptree.getiterator('author'):
for book in author.getiterator('book'):
print book
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] Mercurial migration: help needed

2009-08-18 Thread Dj Gilcrease
On Tue, Aug 18, 2009 at 2:12 AM, "Martin v. Löwis" wrote:
> The second item is line conversion hooks. Dj Gilcrease has posted a
> solution which he considers a hack himself. Mark Hammond has also
> volunteered, but it seems some volunteer needs to be "in charge",
> keeping track of a proposed solution until everybody agrees that it
> is a good solution. It may be that two solutions are necessary: a
> short-term one, that operates as a hook and has limitations, and
> a long-term one, that improves the hook system of Mercurial to
> implement the proper functionality (which then might get shipped
> with Mercurial in a cross-platform manner).


My solution is a hack because the hooks in Mercurial need to be
modified to support it properly, I would be happy to help work on this
as it is a situation I run into all the time in my own projects. I can
never seem to get all the developers to enable the hooks, and one of
them always commits with improper line endings =P
-- 
http://mail.python.org/mailman/listinfo/python-list


Application Packages

2009-09-15 Thread Dj Gilcrease
Say I have an application that lives in /usr/local/myapp it comes with
some default plugins that live in /usr/local/myapp/plugins and I allow
users to have plugins that would live in ~/myapp/plugins

Is there a way to map ~/myapp to a user package so I could do "from
user.plugins import *" or better yet map it to myapp.user?


Dj Gilcrease
OpenRPG Developer
~~http://www.openrpg.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Application Packages

2009-09-15 Thread Dj Gilcrease
when looking up namespace-packages I found pkgutil which lets me add a
myapp.user package with the following in its __init__.py and nothing
else

import os, os.path

from pkgutil import extend_path
homedir = os.environ.get('HOME') or os.environ.get('USERPROFILE')
__path__ = extend_path([os.path.abspath(homedir + os.sep + 'myapp')], __name__)



now I can do "from myapp.user.plugins import *" and it works
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Are min() and max() thread-safe?

2009-09-16 Thread Dj Gilcrease
I dont see anything wrong with it and it works for me on a sequence of 5000
-- 
http://mail.python.org/mailman/listinfo/python-list