Re: [Tutor] REport Card Question
Robert Sjöblom robert.sjob...@gmail.com wrote On a related note, do all functions implicitly contain return None in them? All functions return a value because thats the definition of what a function does. (Some languages have a construct known as a procedure which is a function with no return value, but Python does not support procedures.) Trying out this function (correctly) would get None added, such as: Enter grade:76 B, Try Harder None That depends on how you use the function. Functions should ideally have a single clearly defined purpose. In this case the purpose is to determine the grade based on a score. The caller of the function is then responsible for deciding what to do with the resulting grade - including ignoring (or correcting) a None result. Is there a way to avoid return None without explicitly having the function return something? Nope, because that's how functions work. Even an empty string will return a new line. What the function returns doesn't have to be what the program displays. Separating the application logic from presentation is an important design principle in any program. In this case the code should return the value to the caller rather than directly printing it. Then the code that calls the function can decide what to do with the result - to print or not to print... As a secondary benefit this also makes the function more reusable, since we may not always want to print the result but rather store it in a database or display it in a GUI. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Package loading
On 11/30/2010 12:58 AM, Karim wrote: On 11/29/2010 09:15 PM, Karim wrote: Hello every one, I created a package with the following structure: * ops/ o __init__.py o tcl/ + __init__.py + pythontcl.py *python -c import sys; print sys.path; import ops.tcl.pythontcl* ['', '/usr/local/lib/python2.6/dist-packages/pyparsing-1.5.5-py2.6.egg', '*/home/karim/build/UML2PDK/lib/python*', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/usr/lib/pymodules/python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.6/gtk-2.0', '/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode', '/usr/local/lib/python2.6/dist-packages'] /*home/karim/build/UML2PDK/lib/python/ops/tcl/pythontcl.py:109: RuntimeWarning: Parent module 'pythontcl' not found while handling absolute import import unittest /home/karim/build/UML2PDK/lib/python/ops/tcl/pythontcl.py:110: RuntimeWarning: Parent module 'pythontcl' not found while handling absolute import import sys* At the lines I import standard modules sys and unittest I get these non-sense warning (my consideration) though I added the top package root, namely, */home/karim/build/UML2PDK/lib/python. The programesecute correctly but I alaways get this nerving warning. *Any idea will be welcome!* :-) *Regards Karim* * I believed I know why: Traceback (most recent call last): File string, line 1, in module File /home/karim/build/UML2PDK/lib/python/ops/tcl/pythontcl.py, line 119, in module print sys.modules[__package__] KeyError: 'pythontcl' It is due to method determine parent in class ModuleImporter. I don't know why sys.modules has the key 'ops.tcl.pythontcl' and this class search for the key module 'pythontcl'. Big mess between relative path or whatever. Any idea to fix that? Karim Ok fixed. I must not set the special variable __name__. I set it for pydoc docstrings. Now the __name__ is automatically set to 'ops.tcl.pythontcl' and __package__ is set correctly to 'ops.tcl'. Kind Regards Karim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A regular expression problem
Sorry, something went wrong and my message got sent before I could finish it. I'll try again. On Tue, Nov 30, 2010 at 2:19 PM, Josep M. Fontana josep.m.font...@gmail.com wrote: On Sun, Nov 28, 2010 at 6:03 PM, Evert Rol evert@gmail.com wrote: snip intro snip - with open('output_tokens.txt', 'a') as out_tokens: with open('text.txt', 'r') as in_tokens: t = RegexpTokenizer('[^a-zA-Z\s0-9]+\w+\S') output = t.tokenize(in_tokens.read()) for item in output: out_tokens.write( %s % (item)) I don't know for sure, but I would hazard a guess that you didn't specify unicode for the regular expression: character classes like \w and \s are dependent on your LOCALE settings. A flag like re.UNICODE could help, but I don't know if Regexptokenizer accepts that. OK, this must be the problem. The text is in ISO-8859-1 not in Unicode. I tried to fix the problem by doing the following: - import codecs [...] with codecs.open('output_tokens.txt', 'a', encoding='iso-8859-1') as out_tokens: with codecs.open('text.txt', 'r', encoding='iso-8859-1') as in_tokens: t = RegexpTokenizer('[^a-zA-Z\s0-9]+\w+\S') output = t.tokenize(in_tokens.read()) for item in output: out_tokens.write( %s % (item)) --- Specifying that the encoding is 'iso-8859-1' didn't do anything, though. The output I get is still the same. It would also appear that you could get a long way with the builtin re.split function, and supply the flag inside that function; no need then or Regexptokenizer. Your tokenizer just appears to split on the tokens you specify. Yes. This is in fact what Regexptokenizer seems to do. Here's what the little description of the class says: A tokenizer that splits a string into substrings using a regular expression. The regular expression can be specified to match either tokens or separators between tokens. Unlike C{re.findall()} and C{re.split()}, C{RegexpTokenizer} does not treat regular expressions that contain grouping parenthases specially. source: http://code.google.com/p/nltk/source/browse/trunk/nltk/nltk/tokenize/regexp.py?r=8539 Since I'm using the NLTK package and this module seemed to do what I needed, I thought I might as well use it. I thought (and I still do) the problem I was didn't have to do with the correct use of this module but in the way I constructed the regular expression. I wouldn't have asked the question here if I thought that the problem had to do with this module. If I understand correctly how the re.split works, though, I don't think I would obtain the results I want, though. re.split would allow me to get a list of the strings that occur around the pattern I specify as the first argument in the function, right? But what I want is to match all the words that contain some non alpha-numeric character in them and exclude the rest of the words. Since these words are surrounded by spaces or by line returns or a combination thereof, just as the other normal words, I can't think of any pattern that I can use in re.split() that would discriminate between the two types of strings. So I don't know how I would do what I want with re.split. Josep M. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A regular expression problem
On Sun, Nov 28, 2010 at 6:14 PM, Steven D'Aprano st...@pearwood.info wrote: snip Have you considered just using the isalnum() method? '¿de'.isalnum() False Mmm. No, I didn't consider it because I didn't even know such a method existed. This can turn out to be very handy but I don't think it would help me at this stage because the texts I'm working with contain also a lot of non alpha-numeric characters that occur in isolation. So I would get a lot of noise. The first thing to do is to isolate the cause of the problem. In your code below, you do four different things. In no particular order: 1 open and read an input file; 2 open and write an output file; 3 create a mysterious RegexpTokenizer object, whatever that is; 4 tokenize the input. We can't run your code because: 1 we don't have access to your input file; 2 most of us don't have the NLTK package; 3 we don't know what RegexTokenizer does; 4 we don't know what tokenizing does. As I said in my answer to Evert, I assumed the problem I was having had to do exclusively with the regular expression pattern I was using. The code for RegexTokenizer seems to be pretty simple (http://code.google.com/p/nltk/source/browse/trunk/nltk/nltk/tokenize/regexp.py?r=8539) and all it does is: Tokenizers that divide strings into substrings using regular expressions that can match either tokens or separators between tokens. snip you should write: r'[^a-zA-Z\s0-9]+\w+\S' Now you can understand why I didn't use r' ' The methods in the module already use this internally and I just need to insert the regular expression as the argument. Your regex says to match: - one or more characters that aren't letters a...z (in either case), space or any digit (note that this is *not* the same as characters that aren't alphanum); - followed by one or more alphanum character; - followed by exactly one character that is not whitespace. I'm guessing the not whitespace is troublesome -- it will match characters like ¿ because it isn't whitespace. This was my first attempt to match strings like: 'patre--' or 'patre' The not whitespace was intended to match the occurrence of non-alphanumeric characters appearing after regular characters. I realize I should have added '*' after '\S' since I also want to match words that do not have a non alpha-numeric symbol at the end (i.e 'patre' as opposed to 'patre--' I'd try this: # untested \b.*?\W.*?\b which should match any word with a non-alphanumeric character in it: - \b ... \b matches the start and end of the word; - .*? matches zero or more characters (as few as possible); - \W matches a single non-alphanumeric character. So putting it all together, that should match a word with at least one non-alphanumeric character in it. But since '.' matches any character except for a newline, this would also yield strings where all the characters are non-alphanumeric. I should have said this in my initial message but the texts I'm working with contain lots of these strings with sequences of non-alphanumeric characters (i.e. '%+' or '//'). I'm trying to match only strings that are a mixture of both non-alphanumeric characters and [a-zA-Z]. [...] If you notice, there are some words that have an accented character that get treated in a strange way: all the characters that don't have a tilde get deleted and the accented character behaves as if it were a non alpha-numeric symbol. Your regex matches if the first character isn't a space, a digit, or a a-zA-Z. Accented characters aren't a-z or A-Z, and therefore will match. I guess this is because the character encoding was not specified but accented characters in the languages I'm dealing with should be treated as a-z or A-Z, shouldn't they? I mean, how do you deal with languages that are not English with regular expressions? I would assume that as long as you set the right encoding, Python will be able to determine which subset of specific sequences of bytes count as a-z or A-Z. Josep M. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Pyserial and invalid handle
Hello John On 29 November 2010 21:44, John Smith jocj...@verizon.net wrote: Hi, Walter - Thanks for all the research. This was my second attempt at installing the 2.4 version. I did it thus: E:\Python27\pyserial-2.4..\python setup.py install standart distutils running install running build running build_py creating build creating build\lib creating build\lib\serial copying serial\serialcli.py - build\lib\serial copying serial\serialjava.py - build\lib\serial copying serial\serialposix.py - build\lib\serial copying serial\serialutil.py - build\lib\serial copying serial\serialwin32.py - build\lib\serial copying serial\sermsdos.py - build\lib\serial copying serial\__init__.py - build\lib\serial running install_lib running install_egg_info Removing E:\Python27\Lib\site-packages\pyserial-2.4-py2.7.egg-info Writing E:\Python27\Lib\site-packages\pyserial-2.4-py2.7.egg-info E:\Python27\pyserial-2.4 But, when I tried it in Python, I got the same as before: import serial ser = serial.Serial(0, timeout = 1) ser Serialid=0x225c240, open=True(port='COM1', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False, dsrdtr=False) ser.read() Traceback (most recent call last): File pyshell#3, line 1, in module ser.read() File E:\Python27\lib\site-packages\serial\serialwin32.py, line 236, in read raise SerialException(ReadFile failed (%s) % ctypes.WinError()) SerialException: ReadFile failed ([Error 6] The handle is invalid.) I've checked and I think it was a mistake to suggest installing pyserial 2.4 on top of 2.5 without first removing 2.5 explicitly. It appears that doing so actually still retains the previous version of serialwin32.py in use, based on the fact that I've manually had a look at serialwin32.py from both pyserial2.4 and pyserial2.5 and that fact that line 236 in pyserial2.5 is where the error is raised, and pySerial2.4 by contrast has if err: #will be ERROR_IO_PENDING: on line 236. Consequently this implies that you're still using pyserial2.5 above. (Aside: I originally tested my suggestion for installing pyserial2.4 and tested it by importing the module (e.g. import serial) and then did a help(serial) which gave me the impression of it having done the right thing and using pyserial2.4, but apparently that's not definitve, or I made a mistake somewhere along the line and got the wrong end of the stick.) So. My apologies, but I think that suggestion has added to the confusion. In any case, to fix it let's delete all instances of pySerial and then install it again, as follows: 1.) Open up your Python site-packages folder in Windows Explorer, e.g. open up: E:\Python27\lib\site-packages 2.) Delete any folder named serial that you may see. 3.) Delete any *file* name pyserial*.* that you may see, probably you'll see pyserial-2.4-py2.7.egg, there may also be an info file. 4.) Open up a Python shell and confirm that you can't import pyserial anymore (e.g. import serial fails with e.g. ImportError: No module named serial. If it still imports then you still have some vestiges of the existing pyserial installation left over. 5.) After confirming the previous versions are gone, please try reinstalling it again from scratch. (E.g. extract source to some suitable place and run python setup.py install from there, which copies the required files into site-packages etc.) 6.) After installing, confirm import serial works again, then try your test again. Apologies again for adding to the confusion, and hopefully we're getting closer. :-( Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Pyserial and invalid handle
On 11/30/2010 10:37 AM, Walter Prins wrote: Hello John (snip) In any case, to fix it let's delete all instances of pySerial and then install it again, as follows: 1.) Open up your Python site-packages folder in Windows Explorer, e.g. open up: E:\Python27\lib\site-packages 2.) Delete any folder named serial that you may see. 3.) Delete any *file* name pyserial*.* that you may see, probably you'll see pyserial-2.4-py2.7.egg, there may also be an info file. 4.) Open up a Python shell and confirm that you can't import pyserial anymore (e.g. import serial fails with e.g. ImportError: No module named serial. If it still imports then you still have some vestiges of the existing pyserial installation left over. 5.) After confirming the previous versions are gone, please try reinstalling it again from scratch. (E.g. extract source to some suitable place and run python setup.py install from there, which copies the required files into site-packages etc.) 6.) After installing, confirm import serial works again, then try your test again. Apologies again for adding to the confusion, and hopefully we're getting closer. :-( Walter Hi, Walter - I did the above and then got this: import serial Traceback (most recent call last): File pyshell#0, line 1, in module import serial File E:\Python27\lib\site-packages\serial\__init__.py, line 18, in module from serialwin32 import * File E:\Python27\lib\site-packages\serial\serialwin32.py, line 9, in module import win32file # The base COM port and file IO functions. ImportError: No module named win32file I guess that file was included in 2.5 but not in 2.4? Thanks, John ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to handle exceptions raised inside a function?
Please take a look at 2 functions I just wrote to calculate the harmonic and geometric means of lists of positive numbers: http://tutoree7.pastebin.com/VhUnZcma. Both Hlist and Glist must contain only positive numbers, so I really need to test for this inside each function. But is there a good way to do this? What should the functions return should a non-positive number be detected? Is there a conventional Pythonic way to do this? Thanks, Dick Moores ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to handle exceptions raised inside a function?
On Tue, Nov 30, 2010 at 3:00 PM, Richard D. Moores rdmoo...@gmail.com wrote: Both Hlist and Glist must contain only positive numbers, so I really need to test for this inside each function. But is there a good way to do this? What should the functions return should a non-positive number be detected? Is there a conventional Pythonic way to do this? If the value passed to the function is illegal, you should raise a ValueError exception. Something like this in your harmonic_mean function, maybe: if not all(x 0 for x in Hlist): raise ValueError(All items in Hlist must be positive numbers.) -- Jerry ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to handle exceptions raised inside a function?
Richard D. Moores wrote: Please take a look at 2 functions I just wrote to calculate the harmonic and geometric means of lists of positive numbers: http://tutoree7.pastebin.com/VhUnZcma. Both Hlist and Glist must contain only positive numbers, so I really need to test for this inside each function. But is there a good way to do this? What should the functions return should a non-positive number be detected? Is there a conventional Pythonic way to do this? There are two basic approaches to handling errors in Python: (1) Don't do any error checking at all. If the input is bad, an exception will (hopefully!) be raised. Provided you know that bad input *will* lead to an exception, and not just plausible-looking but incorrect result, this is often the simplest way. (2) If you don't trust that a sensible exception will be raised, then do your own error checking, and raise an exception. For numeric work, another approach is to return a floating point NAN (Not A Number). Unfortunately Python doesn't give any standard way to specify *which* NAN is returned, but you can return float(nan) to return one of them. A fourth approach, rare in Python, is to return some sort of magic value to indicate an exceptional case. Just about the only example of this I can think of is string.find(), which returns -1 to indicate not found. A fifth approach, common in some other languages, is to return some arbitrary value, and set an error flag. The caller then has to write code like this: result = function(arguments) if not last_result_error: # no error occurred print result is, result If you do this, I will *personally* track you down and beat you to death with a rather large fish. *wink* For what it's worth, I have a module of statistics functions (shameless plug: http://pypi.python.org/pypi/stats and http://code.google.com/p/pycalcstats -- feedback and bug reports welcome) that includes the harmonic and geometric mean. My harmonic mean looks like this: def harmonic_mean(data): try: m = mean(1.0/x for x in data) except ZeroDivisionError: return 0.0 if m == 0.0: return math.copysign(float('inf'), m) return 1/m Notice that if the data includes one or more zeroes, the harmonic mean itself will be zero: limit as x-0 of 1/x - infinity, and 1/infinity - 0. If the sum of reciprocals itself cancels to zero, I return the infinity with the appropriate sign. The only exceptions that could occur are: * mean will raise ValueError if the data is empty; * if an argument is non-numeric, TypeError will occur when I take the reciprocal of it. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to handle exceptions raised inside a function?
This is very interesting to me - the below excerpt is something I was trying to do for one of my programs and gave up on it: A fifth approach, common in some other languages, is to return some arbitrary value, and set an error flag. The caller then has to write code like this: result = function(arguments) if not last_result_error: # no error occurred print result is, result If you do this, I will *personally* track you down and beat you to death with a rather large fish. *wink* I think I was trying to do something like thius at the end of a function I wrote- return 2 or return my_special_integer_mvar and then do something or other depending on this value once it passes back to calling function or main(). I think I used similar code as you have above. It didn't go well and also there seemed to be a problem related to where I was returning this value _to_ (where I actually placed this snippet of code like you wrote above) - a function or module I wrote or main(). So, could you expand on this for me? I would have to dig around to find the actual program I was working on. Thanks, Patty - Original Message - From: Steven D'Aprano st...@pearwood.info To: tutor@python.org Sent: Tuesday, November 30, 2010 1:23 PM Subject: Re: [Tutor] How to handle exceptions raised inside a function? Richard D. Moores wrote: Please take a look at 2 functions I just wrote to calculate the harmonic and geometric means of lists of positive numbers: http://tutoree7.pastebin.com/VhUnZcma. Both Hlist and Glist must contain only positive numbers, so I really need to test for this inside each function. But is there a good way to do this? What should the functions return should a non-positive number be detected? Is there a conventional Pythonic way to do this? There are two basic approaches to handling errors in Python: (1) Don't do any error checking at all. If the input is bad, an exception will (hopefully!) be raised. Provided you know that bad input *will* lead to an exception, and not just plausible-looking but incorrect result, this is often the simplest way. (2) If you don't trust that a sensible exception will be raised, then do your own error checking, and raise an exception. For numeric work, another approach is to return a floating point NAN (Not A Number). Unfortunately Python doesn't give any standard way to specify *which* NAN is returned, but you can return float(nan) to return one of them. A fourth approach, rare in Python, is to return some sort of magic value to indicate an exceptional case. Just about the only example of this I can think of is string.find(), which returns -1 to indicate not found. A fifth approach, common in some other languages, is to return some arbitrary value, and set an error flag. The caller then has to write code like this: result = function(arguments) if not last_result_error: # no error occurred print result is, result If you do this, I will *personally* track you down and beat you to death with a rather large fish. *wink* For what it's worth, I have a module of statistics functions (shameless plug: http://pypi.python.org/pypi/stats and http://code.google.com/p/pycalcstats -- feedback and bug reports welcome) that includes the harmonic and geometric mean. My harmonic mean looks like this: def harmonic_mean(data): try: m = mean(1.0/x for x in data) except ZeroDivisionError: return 0.0 if m == 0.0: return math.copysign(float('inf'), m) return 1/m Notice that if the data includes one or more zeroes, the harmonic mean itself will be zero: limit as x-0 of 1/x - infinity, and 1/infinity - 0. If the sum of reciprocals itself cancels to zero, I return the infinity with the appropriate sign. The only exceptions that could occur are: * mean will raise ValueError if the data is empty; * if an argument is non-numeric, TypeError will occur when I take the reciprocal of it. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Pyserial and invalid handle
Hello John, On 30 November 2010 16:57, John Smith jocj...@verizon.net wrote: Hi, Walter - I did the above and then got this: import serial Traceback (most recent call last): File pyshell#0, line 1, in module import serial File E:\Python27\lib\site-packages\serial\__init__.py, line 18, in module from serialwin32 import * File E:\Python27\lib\site-packages\serial\serialwin32.py, line 9, in module import win32file # The base COM port and file IO functions. ImportError: No module named win32file I guess that file was included in 2.5 but not in 2.4? Apparently so. Well, win32file is part of the PyWin32 package, which are a set of modules that wrap many Windows API's. I'm not sure why it was't/isn't required for PySerial 2.5 or whether as you say perhaps this module is included in PySerial2.5 and isn't in 2.4. But whatever the case may be, suffice it to say I've reproduced your issue on my Win7 64bit box, and then resolved it by installing the PyWin32 modules. It's probably a good idea to install this package anyway -- if you're working on Windows the PyWin32 modules are very useful - they basically wrap and makes available a shedload of Windows specific API's to Python. (Many people working with Python on Windows almost automatically would install this, it's also why i didn't run into this issue in the first place as I already had PyWin32 installed prior to testing my suggestion. Sorry.) Anyway. To download and install PyWin32, go here: http://ur.ly/vLwv Presumably you want the AMD64 (64 bit) Py2.7 version. Install it then try your test again. Fingers crossed. ;) Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Pyserial and invalid handle
On 11/30/2010 6:23 PM, Walter Prins wrote: Hello John, (snip) Apparently so. Well, win32file is part of the PyWin32 package, which are a set of modules that wrap many Windows API's. I'm not sure why it was't/isn't required for PySerial 2.5 or whether as you say perhaps this module is included in PySerial2.5 and isn't in 2.4. But whatever the case may be, suffice it to say I've reproduced your issue on my Win7 64bit box, and then resolved it by installing the PyWin32 modules. It's probably a good idea to install this package anyway -- if you're working on Windows the PyWin32 modules are very useful - they basically wrap and makes available a shedload of Windows specific API's to Python. (Many people working with Python on Windows almost automatically would install this, it's also why i didn't run into this issue in the first place as I already had PyWin32 installed prior to testing my suggestion. Sorry.) Anyway. To download and install PyWin32, go here: http://ur.ly/vLwv Presumably you want the AMD64 (64 bit) Py2.7 version. Install it then try your test again. Fingers crossed. ;) Walter Hi, Walter - I got pywin32-214.win32-py2.7.exe because I have the Intel i7 (I'm guessing that the AMD versions are for the AMD processor). However, all of the exe offerings have the same Python not found in registry problem that started this whole thing. So, since the only source module available is pywin32-214.zip, I got it and installed it. It does not work, maybe because I'm using Python 2.7 and the zip is for 3.2. I really appreciate all the time you have put into my problems, Walter. Thank you. Cheers, John ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Pyserial and invalid handle
On 01/12/10 01:00, John Smith wrote: Hi, Walter - I got pywin32-214.win32-py2.7.exe because I have the Intel i7 (I'm guessing that the AMD versions are for the AMD processor). However, all of the exe offerings have the same Python not found in registry problem that started this whole thing. So, since the only source module available is pywin32-214.zip, I got it and installed it. It does not work, maybe because I'm using Python 2.7 and the zip is for 3.2. I really appreciate all the time you have put into my problems, Walter. Thank you. Cheers, John Actually, AMD 64 is now the standard x86-64. It was originally designed by AMD because intel were making their Itanium thing but that didn't go so well. Anyway if you're running 64 bit windows that's probably why the 32-bit python install is having a problem. Download the version Walter suggested and you should be good to go. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Pyserial and invalid handle
On 11/30/2010 7:27 PM, Adam Bark wrote: On 01/12/10 01:00, John Smith wrote: Hi, Walter - I got pywin32-214.win32-py2.7.exe because I have the Intel i7 (I'm guessing that the AMD versions are for the AMD processor). However, all of the exe offerings have the same Python not found in registry problem that started this whole thing. So, since the only source module available is pywin32-214.zip, I got it and installed it. It does not work, maybe because I'm using Python 2.7 and the zip is for 3.2. I really appreciate all the time you have put into my problems, Walter. Thank you. Cheers, John Actually, AMD 64 is now the standard x86-64. It was originally designed by AMD because intel were making their Itanium thing but that didn't go so well. Anyway if you're running 64 bit windows that's probably why the 32-bit python install is having a problem. Download the version Walter suggested and you should be good to go. Yes! I have gone no farther than to say ser.read() knowing that nothing is attached to the port and expected a delay of 5 seconds. It now does that, so I have a clue that it is working. I had no idea that the AMD thing was now standard. Thanks for that. I also found that the file Walter recommended did install from the exe while the non-AMD file did not due to the registry thing. Wow! All I can say is thanks to everybody for the help. Now I need to start trying to get a modem to talk to me. By the way, the whole purpose of doing this is to communicate with some test instruments via GPIB/HPIB to automate some testing that is time consuming. The last time I did this (using a BASIC program), it took about 45 minutes (not due to BASIC, but due to instrument response time). I was able to start the test, go to lunch, then analyze the data when I returned. Thanks again for the help. Cheers, John ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Web Harvesting AJAX/Javascript
Hello Roy On 29 November 2010 19:42, Roy Hinkelman royh...@gmail.com wrote: Researching this has led me to PAMIE and Selenium. PAMIE is giving me problems with permissions, and the discussion group appears to be fading away. I have not tried Selenium yet. Both open a browser instance, and PAMIE is quite slow, and I expect Selenium to be quite slow as well. How are you navigating around these Javascript based pages? Is there a library or plugin that I am missing? I'm no expert in this area, however I have done some research in this direction in the past, also to deal with sites that use Javascript (obviously Python is very adept at interacting with sites that are plain HTML by itself, e.g. there's lxml, BeautifulSoup friends etc) and I remain interested in this. Anyway so then, here's my $0.02 for what it's worth. Firstly, Selenium may be an option, I briefly played with it quite some time ago, I don't know PAMIE. However, I suspect what you might rather want to look at is perhaps something like the PyWebkitGTK (or PyWebkitQT) which leverages the webkit browser engine. (This kind of assumes you're on Linux... are you?) Some hopefully relevant links: http://webkit.org/ http://code.google.com/p/pywebkitgtk/ http://www.gnu.org/software/pythonwebkit/ http://www.pygtk.org/pygtkmozembed/ http://directfb.org/ Best wishes, Walter ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor