Re: [Tutor] Need help with registry access
ALAN GAULD wrote: The _winreg module is part of the standard library and provides functions for accessing the Windows registry. There's some (incomplete) help here, but as Alan said, you need to learn Python to some extent before trying to do this. http://timgolden.me.uk/python-on-windows/programming-areas/registry.html TJG ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help with registry access
Always use ReplyAll to include the mailing list. The _winreg module is part of the standard library and provides functions for accessing the Windows registry. But you need to learn enough about Python to be able to use modules and functions. You will also need to know enough about Windows internals to manage the keyboard. I suggest you start with a beginners python tutorial. If you have never programmed before then look at the non programmers list (or just try mine), if you have programmed in another language try the official tutorial http://wiki.python.org/moin/BeginnersGuide/NonProgrammers http://docs.python.org/tutorial/ Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ - Original Message > From: Christopher Barkley > To: Alan Gauld > Sent: Friday, 8 May, 2009 5:09:25 AM > Subject: Re: [Tutor] Need help with registry access > > no idea what any of that means. Total newb. Examples would help. > - Original Message - From: "Alan Gauld" > To: > Sent: Thursday, May 07, 2009 5:20 PM > Subject: Re: [Tutor] Need help with registry access > > > > > > "Christopher Barkley" wrote > >> My friend and I are techies, he's on my LAN. I want to disable his > >> keyboard > through the registry (or some other fun way) while he's in the middle of > playing > starcraft by running a script through the LAN. > > > > Look at the winreg module for accessing the registry. > > > > How you do it over the LAN and how you disable the keyboard I'll leave as > > an > exercise for your investigation! > > > > One other option is to look into using WSH via the pythonwin or ctypes API. > > > > -- Alan Gauld > > Author of the Learn to Program web site > > http://www.alan-g.me.uk/ > > > > ___ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Pythonic way to normalize vertical whitespace
Note: Following cross-posted to python-list where it got queued due to suspicious subject line. I'm looking for suggestions on technique (not necessarily code) about the most pythonic way to normalize vertical whitespace in blocks of text so that there is never more than 1 blank line between paragraphs. Our source text has newlines normalized to single newlines (\n vs. combinations of \r and \n), but there may be leading and trailing whitespace around each newline. Approaches: 1. split text to list of lines that get stripped then: a. walk this list building a new list of lines that track and ignore extra blank lines -OR- b. re-join lines and replace '\n\n\n' wth' \n\n' until no more '\n\n\n' matches exist 2. use regular expressions to match and replace whitespace pattern of 3 or more adjacent \n's with surrounding whitespace 3. a 3rd party text processing library designed for efficiently cleaning up text Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] glob paramiko
Hey All. All I need to do in this script is scp or sftp a bunch of files to a remote server. This script will run from a cron job eventually. For whatever reason, paramiko can't cope with a list. --- AttributeErrorTraceback (most recent call last) /Users/msh/ in () AttributeError: 'NoneType' object has no attribute 'put' In [18]: type localpath ---> type(localpath) Out[18]: In [19]: for each in localpath -- script begins import paramiko import glob import os paramiko.util.log_to_file('/tmp/paramiko.log') host = "sftp.okcomputer.yo" port = 22 transport = paramiko.Transport((host, port)) password = "T0pS3kr1t!" username = "schizznits" transport.connect(username = username, password = password) sftp = paramiko.SFTPClient.from_transport(transport) os.chdir("/home/fatcat/") filepath = '/' localpath = glob.glob("*.tab") sftp.put(localpath, filepath) sftp.close() transport.close() --- script ends -- -- I fear you speak upon the rack, Where men enforced do speak anything. - William Shakespeare ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] glob paramiko
On Fri, May 8, 2009 at 1:04 PM, Matt Herzog wrote: > Hey All. > > All I need to do in this script is scp or sftp a bunch of files to a remote > server. This script will run from a cron job eventually. > > For whatever reason, paramiko can't cope with a list. > > --- > AttributeError Traceback (most recent call last) > > /Users/msh/ in () > > AttributeError: 'NoneType' object has no attribute 'put' It would be helpful to see the full stack trace. > sftp = paramiko.SFTPClient.from_transport(transport) > > os.chdir("/home/fatcat/") > filepath = '/' > localpath = glob.glob("*.tab") > sftp.put(localpath, filepath) It looks like sftp is None. That is why it has no attribute "put". Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] glob paramiko
On Fri, May 08, 2009 at 02:30:22PM -0400, Kent Johnson wrote: > On Fri, May 8, 2009 at 1:04 PM, Matt Herzog wrote: > > Hey All. > > > > All I need to do in this script is scp or sftp a bunch of files to a remote > > server. This script will run from a cron job eventually. > > > > For whatever reason, paramiko can't cope with a list. > > > > --- > > AttributeError ? ? ? ? ? ? ? ? ? ? ? ? ? ?Traceback (most recent call last) > > > > /Users/msh/ in () > > > > AttributeError: 'NoneType' object has no attribute 'put' > > It would be helpful to see the full stack trace. Here it is, unless I can give you something more verbose. Not sure how to produce "full stack trace." Do you mean this: http://docs.python.org/library/traceback.html ? (15)[datas...@iggy ~/AIG]$ ./parameek0.py Traceback (most recent call last): File "./parameek0.py", line 24, in ? sftp.put(localpath, filepath) File "build/bdist.linux-x86_64/egg/paramiko/sftp_client.py", line 547, in put TypeError: coercing to Unicode: need string or buffer, list found > > > sftp = paramiko.SFTPClient.from_transport(transport) > > > > os.chdir("/home/fatcat/") > > filepath = '/' > > localpath = glob.glob("*.tab") > > sftp.put(localpath, filepath) > > It looks like sftp is None. That is why it has no attribute "put". Yeah, it shows up as a type list. I haven't been doing any python thinking in a couple months. The script works without the glob syntax on a single file defined as: localpath = '/home/foo/bar.txt' Thanks for helping. > > Kent -- I fear you speak upon the rack, Where men enforced do speak anything. - William Shakespeare ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] glob paramiko
On Fri, May 8, 2009 at 2:56 PM, Matt Herzog wrote: > On Fri, May 08, 2009 at 02:30:22PM -0400, Kent Johnson wrote: >> On Fri, May 8, 2009 at 1:04 PM, Matt Herzog wrote: >> > Hey All. >> > >> > All I need to do in this script is scp or sftp a bunch of files to a >> > remote server. This script will run from a cron job eventually. >> > >> > For whatever reason, paramiko can't cope with a list. >> > >> > --- >> > AttributeError ? ? ? ? ? ? ? ? ? ? ? ? ? ?Traceback (most recent call last) >> > >> > /Users/msh/ in () >> > >> > AttributeError: 'NoneType' object has no attribute 'put' >> >> It would be helpful to see the full stack trace. > > Here it is, unless I can give you something more verbose. Not sure how to > produce "full stack trace." > Do you mean this: http://docs.python.org/library/traceback.html ? > > (15)[datas...@iggy ~/AIG]$ ./parameek0.py > Traceback (most recent call last): > File "./parameek0.py", line 24, in ? > sftp.put(localpath, filepath) > File "build/bdist.linux-x86_64/egg/paramiko/sftp_client.py", line 547, > in put > TypeError: coercing to Unicode: need string or buffer, list found That's what I was asking for. Note that this is completely different from the first error you posted! It is telling you the problem, it just doesn't support a list as the first argument. And in fact there is nothing in the docs to indicate that it should work with a list. Just put the put() call in a loop and do each file separately. > >> >> > sftp = paramiko.SFTPClient.from_transport(transport) >> > >> > os.chdir("/home/fatcat/") >> > filepath = '/' >> > localpath = glob.glob("*.tab") >> > sftp.put(localpath, filepath) >> >> It looks like sftp is None. That is why it has no attribute "put". > > Yeah, it shows up as a type list. I haven't been doing any python thinking in > a couple months. No, localpath is a list. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Pythonic way to normalize vertical whitespace
pyt...@bdurham.com wrote: Note: Following cross-posted to python-list where it got queued due to suspicious subject line. I'm looking for suggestions on technique (not necessarily code) about the most pythonic way to normalize vertical whitespace in blocks of text so that there is never more than 1 blank line between paragraphs. Our source text has newlines normalized to single newlines (\n vs. combinations of \r and \n), but there may be leading and trailing whitespace around each newline. I can't follow that! Please provide a before and after example. Approaches: 1. split text to list of lines that get stripped then: a. walk this list building a new list of lines that track and ignore extra blank lines -OR- b. re-join lines and replace '\n\n\n' wth' \n\n' until no more '\n\n\n' matches exist 2. use regular expressions to match and replace whitespace pattern of 3 or more adjacent \n's with surrounding whitespace 3. a 3rd party text processing library designed for efficiently cleaning up text Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Bob Gailer Chapel Hill NC 919-636-4239 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Optparse question: if only certain values are acceptable
I'm tryng to use optparse for the first time. The toy summary is that I want to have the following command format: prognam -f FORMAT Where FORMAT, if specified, must be one of "X", "Y", or "Z". In otherwords, if the user enters: progname -f X It runs, producing its output in format X. Similar if "Y" or "Z" is specified instead of "X". But if the user specifies progname -f A I want it to spit up because A is not a recognized format. I don't see anything in the docs that directly addresses this. Is this something that I should use the callback parameter for? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Optparse question: if only certain values are acceptable
2009/5/9 Terry Carroll : > In otherwords, if the user enters: > > progname -f X > > It runs, producing its output in format X. Similar if "Y" or "Z" is > specified instead of "X". > > But if the user specifies > > progname -f A > > I want it to spit up because A is not a recognized format. Is the below what you are looking for? >>> import optparse >>> parser = optparse.OptionParser() >>> parser.add_option('-f', '--format', type='choice', action='store', >>> choices=('x','y','z'), dest='format') >>> args = ['-f', 'd'] #Wrong format d >>> options, restargs = parser.parse_args(args) Usage: [options] : error: option -f: invalid choice: 'd' (choose from 'x', 'y', 'z') Traceback (most recent call last): File "", line 1, in parser.parse_args(args) File "C:\Python26\lib\optparse.py", line 1382, in parse_args self.error(str(err)) File "C:\Python26\lib\optparse.py", line 1564, in error self.exit(2, "%s: error: %s\n" % (self.get_prog_name(), msg)) File "C:\Python26\lib\optparse.py", line 1554, in exit sys.exit(status) SystemExit: 2 >>> args = ['-f', 'x'] #Correct format x >>> options, restargs = parser.parse_args(args) >>> options.format 'x' Greets Sander ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Optparse question: if only certain values are acceptable
On Sat, 9 May 2009, Sander Sweers wrote: > Is the below what you are looking for? It's exactly what I was looking for. Thanks very much. Now I'm going to have to re-read the docs and see why I couldn't pick that up from them. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] glob paramiko
On Fri, May 8, 2009 at 3:50 PM, Matt Herzog wrote: > localpath = glob.glob("*.tab") > > for blob in localpath: > sftp.put(blob, filepath) > sftp.close() > transport.close() > > This fails. I have forgotten most of what I knew, I guess. How does it fail? Again, the full traceback and error message are very helpful. Kent PS Please use Reply All to reply to the list. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Pythonic way to normalize vertical whitespace
On Fri, May 8, 2009 at 1:03 PM, wrote: > Note: Following cross-posted to python-list where it got queued due to > suspicious subject line. > > I'm looking for suggestions on technique (not necessarily code) about the > most pythonic way to normalize vertical whitespace in blocks of text so that > there is never more than 1 blank line between paragraphs. Our source text > has newlines normalized to single newlines (\n vs. combinations of \r and > \n), but there may be leading and trailing whitespace around each newline. > > Approaches: > > 1. split text to list of lines that get stripped then: > > a. walk this list building a new list of lines that track and ignore extra > blank lines > > -OR- > > b. re-join lines and replace '\n\n\n' wth' \n\n' until no more '\n\n\n' > matches exist > > 2. use regular expressions to match and replace whitespace pattern of 3 or > more adjacent \n's with surrounding whitespace > > 3. a 3rd party text processing library designed for efficiently cleaning up > text 1 sounds simple enough. That is the first thing I thought of. 2 should also be easy if you have any regex-fu and might turn out to be faster if you have a lot of text. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor