|
This is OT but I know that there are some PYTHON users on this list and
I am finally getting back to starting with python after a long delay.
1) Is there a PYTHON list someplace? 2) Where would I find the documentation for Python error numbers? 3) My python that starts with this import re, textwrap # read the combined file and split into individual papers alltext = file("C:\Users\Art\Desktop\fed\feder16v2.txt").readlines() papers= re.split(r'FEDERALIST No\.'," ".join(alltext)) print len(papers) outfile = file("C:\Users\Art\desktop\fed\federalistCounts.txt", "w") words = """A ABANDON ABANDONED . . . ZEALAND ZEALOUS """ gets this error message: >>> Traceback (most recent call last): File "C:\Users\Art\Desktop\fed\countFedWords.py", line 5, in <module> alltext = file("C:\Users\Art\Desktop\fed\feder16v2.txt").readlines() IOError: [Errno 22] invalid mode ('r') or filename: 'C:\\Users\\Art\\Desktop\x0ced\x0ceder16v2.txt' >>> the filespec python does not seem to like is not what is in the code. Also the file does exist. 4) The list of words is now hard coded in the python code. How would I replace words = """A ABANDON ABANDONED . . . ZEALAND ZEALOUS """ with a command to read the list from another file? Art Kendall Social Research Consultants ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Art Kendall
Social Research Consultants |
|
Jon Peck SPSS, an IBM Company [hidden email] 312-651-3435
This is OT but I know that there are some PYTHON users on this list and I am finally getting back to starting with python after a long delay. 1) Is there a PYTHON list someplace? There is a version active Python language list at http://groups.google.com/group/comp.lang.python/topics but they won't know much about SPSS in particular. Besides this list, you can post to the forums at Developer Central 2) Where would I find the documentation for Python error numbers? >>>The Python language and standard library generally don't use error numbers. Some SPSS messages do, but there is no additional documentation for these. 3) My python that starts with this import re, textwrap # read the combined file and split into individual papers alltext = file("C:\Users\Art\Desktop\fed\feder16v2.txt").readlines() papers= re.split(r'FEDERALIST No\.'," ".join(alltext)) print len(papers) outfile = file("C:\Users\Art\desktop\fed\federalistCounts.txt", "w") words = """A ABANDON ABANDONED . . . ZEALAND ZEALOUS """ gets this error message: >>> Traceback (most recent call last): File "C:\Users\Art\Desktop\fed\countFedWords.py", line 5, in <module> alltext = file("C:\Users\Art\Desktop\fed\feder16v2.txt").readlines() IOError: [Errno 22] invalid mode ('r') or filename: 'C:\\Users\\Art\\Desktop\x0ced\x0ceder16v2.txt' >>> the filespec python does not seem to like is not what is in the code. Also the file does exist. >>>In Python strings, escape sequence such as \f are interpreted as special characters - in this case a form feed. To avoid this, - use forward slashes (even for paths), or - precede the whole string with r for raw, e.g., r"\feder16", or - double the slash, e.g., "desktop\\fed 4) The list of words is now hard coded in the python code. How would I replace words = """A ABANDON ABANDONED . . . ZEALAND ZEALOUS """ with a command to read the list from another file? >>>One way f = open(filespec) mylist = f.readlines() mylist = [item.rstrip("\n") for item in mylist] This time you do want the \n to be interpreted as a newline character. Dep Art Kendall Social Research Consultants ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD |
|
|
In reply to this post by Art Kendall
|
|
In reply to this post by Jon K Peck
Thank you. That worked.
Art On 5/3/2010 7:10 PM, Jon K Peck wrote: ===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Art Kendall
Social Research Consultants |
| Free forum by Nabble | Edit this page |
