[Tutor] Question on option parser

2006-05-16 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Everyone, I have a program that I'd would like to enhance flexibility in calling. Is there a way to leverage optionparser so it can accept input from both command line and a configuration file? Current code block is: # # Parse command li

Re: [Tutor] Question on option parser

2006-05-16 Thread Andrew Robert
to") (options, args) = parser.parse_args() print options.qmanager If so, the code generates the following deletion error. Traceback (most recent call last): File "C:\Documents and Settings\Andrew Robert\My Documents\receiver.py", line 326, in ? (options, args) =

[Tutor] Solution found for option parser

2006-05-16 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi everyone, Just to be complete, I figured I would share the solution to use option parser for both command line and configuration file option passing. I hope it may be of use to someone in the future. parser = OptionParser() if len(sys.argv) ==

[Tutor] File encoding strategy question

2006-05-20 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi everyone, I am in the process of creating a file transmit/receiver program using MQSeries. The way it works is through creation of an XML message. Elements within the XML message contain things such as file name, size, and the file contents. The

[Tutor] Problem with a class

2006-05-22 Thread Andrew Robert
scripts\receiver.py", line 238, in ? test = TriggerMessage.decode(data) TypeError: unbound method decode() must be called by TriggerMessage instance as first argument (got str instance instead) Does this make any sense? The variable data passed to the class is valid and is used elsewhere correctly. - -- Than

Re: [Tutor] problem with class - get message that self is not defined

2006-05-22 Thread Andrew Robert
self.envdata, self.userdata, self.qmgr \ = struct.unpack(format,self.data) - -- Thank you, Andrew Robert Systems Architect Information Technologies MFS Investment Management Phone: 617-954-5882 E-mail: [EMAIL PROTECTED] Linux User Number: #201204 -BEGIN PGP SIGNATURE- Version:

[Tutor] Question on regular expressions

2006-05-24 Thread Andrew Robert
or similar module? I've begun reading about using re expressions at http://www.amk.ca/python/howto/regex/ but I am still hazy on implementation. Any help you can provide would be greatly appreciated. - -- Thank you, Andrew Robert Systems Architect Information Technologies MFS Investment Manag

[Tutor] Hex conversion strangeness

2006-05-24 Thread Andrew Robert
statement but I am not sure why. int(a,16) 33 If the 0X21 is the actual hex value, then why convert to integer? Is this the ASCII table reference to the hex value? - -- Thank you, Andrew Robert Systems Architect Information Technologies MFS Investment Management Phone: 617-954-5882 E-mai

Re: [Tutor] Question on regular expressions

2006-05-24 Thread Andrew Robert
me ; at least in this special case (Python lacks something like the > -l switch). > > With bash it's a bit easier. (maybe there's also a way with cmd.com to > write multiple lines)? > > $ python -c "import re,sys > for line in sys.stdin: print re.sub(r'([^\w\s]

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Andrew Robert
>> >> Not familiar with lamda :). > > You ae absolutely right. > It creates an un-named(or anonymous function). :-) > >> The un-named function does in-place transformation of the character to >> the established hex value. > > Its actually the call

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Andrew Robert
stdout.write() instead of print: > for line i open(r'e:\pycode\sigh.txt','rb'): > line = re.sub(r'([^\w\s])', lambda s: '%%%2X' % ord(s.group()), line) > sys.stdout.write(line) > > Kent > - -- Thank you, Andrew Robert Systems Arc

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Andrew Robert
any chance, do you see where the syntax issue is? Kent Johnson wrote: > Andrew Robert wrote: > Use int(s, 16) to convert a base 16 string to an integer, and chr() to > convert the int to a string. So something like this: > lambda s: chr(int(s.group(), 16))) > > Kent > >

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Andrew Robert
a format string. > > The syntax error is caused by mismatched parentheses. > > Kent > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > - -- Thank you, Andrew Robert Systems Architect Infor

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Andrew Robert
But I'd also recommend writing a helper function here. Just because you > can do this in one line doesn't mean you have to. *grin* It might be > useful to change the lambda back to a helper function. > - -- Thank you, Andrew Robert Systems Architect Information Techn

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Andrew Robert
. The hex to char pass does not appear to work at all. No error is generated. It just appears to be ignored. Kent Johnson wrote: > Andrew Robert wrote: > > You have an argument in the wrong place. Stop trying to do everything in > one line! Put the lambda in a def'd

Re: [Tutor] Question on regular expressions

2006-05-25 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Everyone, Thanks for all of your patience on this. I finally got it to work. Here is the completed test code showing what is going on. Not cleaned up yet but it works for proof-of-concept purposes. #!/usr/bin/python import re,base64 # Eva

Re: [Tutor] How to import a module which was not in the current working directory?

2006-05-26 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Linda, You can append your path to include the location of the module. An example of this would be: sys.path.append(r'\\share\somedirectory') linda.s wrote: > Hi, > How to import a module which was not in the current working directory? > Thanks

[Tutor] Python related mags

2006-06-12 Thread Andrew Robert
appears to be defunct. - -- Thank you, Andrew Robert Systems Architect Information Technologies MFS Investment Management Phone: 617-954-5882 E-mail: [EMAIL PROTECTED] Linux User Number: #201204 -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (MingW32) Comment: GnuPT 2.7.2

[Tutor] Odd traceback - invalid token when extracting contents of XML data element

2006-06-12 Thread Andrew Robert
it plays nice with existing perl code already in place. Not my choice, but what can you do. Any help you can provide on this would be greatly appreciated. -- Thank you, Andrew Robert #!c:\python24\python # Program: sender.py # Authors: Andrew Robert and Dariusz Suchojad # # Function: T

Re: [Tutor] Python related mags

2006-06-12 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Now that is a real pity. Wish I were talented enough to do it myself. Mike Hansen wrote: > On Jun 12, 2006, at 5:53 AM, Andrew Robert wrote: > >> -BEGIN PGP SIGNED MESSAGE- >> Hash: SHA1 >> >> Hi everyone,

[Tutor] If then else question

2006-06-14 Thread Andrew Robert
f accomplishing the same thing? - -- Thank you, Andrew Robert -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (MingW32) Comment: GnuPT 2.7.2 iD8DBQFEkFgfDvn/4H0LjDwRAophAKCZbJaMWBr2G8dLjHO3VtOA98/+1gCbBsys 4B/Q6g9m+3DW+PzcnCpki6k= =t0E4 -END PGP SIGNATURE-

Re: [Tutor] If then else question

2006-06-14 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Excellent.. much better than testing each value independently. Thank you. Mike Hansen wrote: > > >> -Original Message- >> From: [EMAIL PROTECTED] >> [mailto:[EMAIL PROTECTED] On Behalf Of Andrew Robert >>

Re: [Tutor] Universal error handler

2006-06-20 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 You may also want to try a error handling like this. It is platform clean and uses the system standard logging routines. import os, logging, logging.handlers def eventlogger(level,message): """ Sent trapped events to NT application

[Tutor] Question regarding commit/backout of a message using the pymqi module

2006-06-22 Thread Andrew Robert
if csums.checksum_compare(sys.argv[0],sum,check,file_name) == True: queue.commit() sys.exit(0) else: queue.backout() mqevlog.event("error","CheckSums of r

Re: [Tutor] How can I add my folder to pythonpath?

2006-06-23 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 What you need to do is append your existing path. for example: import sys sys.path.append(r'd:\python_modules') You can then import any modules that reside in that path as if they where part of the standard library. Andy -BEGIN PGP SIGNATURE--

Re: [Tutor] How to check a files size

2006-06-28 Thread Andrew Robert
Perhaps this? stat = os.stat(self.file_name) file_size = stat[6] Thank you, Andrew Robert ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Python module and HP OpenView

2006-07-12 Thread Andrew Robert
there were anything specifically created. Any insight you might have on this would be greatly appreciated. - -- Thank you, Andrew Robert Systems Architect Information Technologies MFS Investment Management Phone: 617-954-5882 E-mail: [EMAIL PROTECTED] Linux User Number: #201204 -BEGIN PGP

[Tutor] Using python to create and save a Ms Word file

2006-07-20 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Everyone, I have a text file being broadcast on a web site and I would like to download it and save it as an MS Word file. The download from web is relatively painless. #!C:\Python24\Python import sys from urllib import urlopen if len(sys

Re: [Tutor] Using python to create and save a Ms Word file

2006-07-21 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Thanks for your help on this. Here is the completed code in case anyone is interested. #! C:\Python24\python # # program: mswword.py # Author: Andrew Robert # # Ver Date ProgrammerModification # 1.0 07/20/06 AAR

[Tutor] Using python to create and save a Ms Word file

2006-07-21 Thread Andrew Robert
ormat document from it. The program is not platform dependent but it does require installation of the PyRTF module. I hope someone finds this useful/interesting. #!C:\Python24\python # # program: rtfmaker.py # Author: Andrew Robert # # Function: Take a supplied file and dump its contents to an RTF

Re: [Tutor] [whitelist] Re: regular expressions question

2006-08-22 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Nimrodx, In case you haven't found a solution yet, I developed a program to encode/decode stuff similar to this. You may want to take a look at it at http://home.townisp.com/~arobert/python/file_encoder.py nimrodx wrote: > Hi Alan, > > I fou

Re: [Tutor] omnicomplete vim python

2006-08-29 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Mike Hansen wrote: > > >> -Original Message- >> From: [EMAIL PROTECTED] >> [mailto:[EMAIL PROTECTED] On Behalf Of Alan Gauld >> Sent: Tuesday, August 29, 2006 1:26 AM >> To: anil maran >> Cc: tutor@python.org >> Subject: Re: [Tutor] omnic

Re: [Tutor] Simple SQL server access...

2006-09-06 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Chris Hengge wrote: > I've been doing some searching for ways to access existing SQL server > databases, but I'm finding so many different ways to do it, is there one > that anyone recommends for a "new to python" programmer? I've used VB > and C# for

Re: [Tutor] Simple SQL server access...

2006-09-06 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Chris Hengge wrote: > I've been doing some searching for ways to access existing SQL server > databases, but I'm finding so many different ways to do it, is there one > that anyone recommends for a "new to python" programmer? I've used VB > and C# for

Re: [Tutor] Help with parsing

2006-09-18 Thread Andrew Robert
Bryan Leber wrote: > > Hello, I am trying to create a script that reads from the command line > and puts the sysargv into a list. I have this part done. I have added > code for testing and one of those testing procedures is to print the > list out in a text file. Not all field are required and may

[Tutor] Python code to split and reassemble files

2006-10-01 Thread Andrew Robert
to smaller chunks would improve efficiency. - -- Thank you, Andrew Robert Senior MQ Engineer Information Technologies MFS Investment Management Phone: 617-954-5882 E-mail: [EMAIL PROTECTED] Linux User Number: #201204 -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (MingW32) Comment: GnuPT

Re: [Tutor] Python code to split and reassemble files

2006-10-01 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Never mind.. :) found it at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/224800 However, if someone has something better, I would be very interested. Andrew Robert wrote: > Hi guys, > > Awhile back, I believe I saw a cookbo

Re: [Tutor] sending mails from python

2006-10-21 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 How about something like this? Create a function and then call it with the required optins of server url, sender address, destination address, subject, and message text? def send(serverURL=None, sender='', to='', subject='', text=''): """ F

[Tutor] pysvn samples

2006-12-15 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi guys, I am looking to experiment with pysvn and was wondering if anyone knew of a location for code samples/snippets using it? I'm reviewing the pysvn programmers guide and tutorial but some live examples would be great. If anyone can point me at

[Tutor] Testing the status of NFS mounts

2007-01-04 Thread Andrew Robert
attempt a write on the share and clean up after itself but I am hoping for a more elegant solution. Any insight anyone can provide on this would be greatly appreciated. -- Thank you, Andrew Robert Senior MQ Engineer Information Technologies Massachussetts Financial Services Phone: 617-954-5882

[Tutor] Question on joining out of order dictionary elements

2007-01-10 Thread Andrew Robert
his kind of operation or is this it? The key/value pairs in these examples are contrived for purposes of this discussion but the end goal is to piece together server and directory path information for use with pysvn. I have a Perl programmer who is learning Python and he is griping that this kind

Re: [Tutor] Question on joining out of order dictionary elements

2007-01-11 Thread Andrew Robert
ligent. > > > > Are there a more efficient/compact ways of doing this kind of > > operation or is this it? > > > > Maybe you like: > print "\\".join([config[val] for val in ["val2","val1","val3"]]) > > -- > Andre Engels,