Re: [Pythonmac-SIG] inputing multi-digit numbers
Paul Berkowitz wrote: >[Excel's scripting interface is] definitely not very "English-like", which >AppleScript is meant to be, The 'English-like' aspect is superficial and somewhat by-the-by; the defining characteristic of the Apple Event Object Model is that it's query-driven. Excel and Word expose conventional OO-style interfaces; everything is done via accessors and iteration and invoking methods on objects one at a time. It's the sort of lower-level API a true AEOM would abstract over, but MS - presumably for reasons of economy - just bridge it directly. >But the model is definitely more accommodating to VBA, and to >Python, for that matter, than to normal AppleScript, Python has no technical issues with the AEOM. One problem that does occur is that most Python users aren't familiar with the AEOM, so they look at some appscript code and because it uses OO-like syntax they assume it will behave according to OO rules too, which it doesn't. For the latest release I've added a couple chapters to the manual that explain all this stuff in some detail, so hopefully there'll be less of this confusion in future. >since it was designed >for a language where you can specify the arguments of a method explicitly by >naming both the arguments (keys) and values rather than just have them all >run on like AppleScript does it. Don't really follow you here, unless you mean that Excel doesn't use whitespace in its keywords. (AS-style keywords are a non-issue for Python, etc. anyway, since it's easy to transform them automatically to C-style identifiers.) > > I cede to your knowledge about the specifics of this, as I do very >> little with Excel from AS, and am still using v. X. I stand corrected in >> particular on driving it from Python via appscript. > >It would certainly be "interesting" - but can be done. Sure - errors and omissions excepted. I've done some minor tests and shaken out a couple 'issues' so far, as Excel is one of those odd corner cases that's good for flushing out subtle incompatibilities with AppleScript. It's been a bit of a PITA determining where appscript's tolerance of other parties' rank stupidity should begin and end. AppleScript's merry acceptance of all kinds of weird slop masks a whole bunch of application sins, and Apple don't set down sufficiently rigorous specifications for application and AE bridge developers to avoid creating/being caught out by them. I try to resolve these as I find them/they're reported, but you never know for sure; application developers can be awfully creative. So if you do run into any problems, let me know of them. Currently there are a couple caveats I'm aware of: 1. Excel defines 'Get' and 'Set' commands in its dictionary, but these do not work correctly. Use 'get' and 'set' instead (appscript defines these as standard since so many applications don't). 2. htmldoc re-formats direct parameters of type 'reference'; this omits some description info that might be of use and fails to indicate when a direct parameter is optional (there are bugs filed on this, but I've yet to figure out the best solution) If someone (Paul, maybe?) wants to send me some non-trivial AppleScripts and test data that will work on Excel X (I don't have 2004), I'll be happy to port them to Python and see how they fare. has -- http://freespace.virgin.net/hamish.sanderson/ ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] inputing multi-digit numbers
On 11/10/05 12:06 PM, "Kevin Walzer" <[EMAIL PROTECTED]> wrote: > Paul Berkowitz wrote: > >> It mirrors the VBA model, definitely, and its AppleScript syntax is thus a >> little, shall we say "obscure", > > > This is what I referring to. From Matt Neuburg's book, p. 331: > "instead of working out an AppleScript scriptability implementation from > scratch, they've simply taken the existing internal scripting > implementation (Visual Basic for Applications) and exposed its entire > object model, lock, stock, and barrel, to AppleScript...if you don't > know how to drive Excel with Visual Basic it's really hard to figure out > how to drive it with AppleScript." Well, that was before they published the AppleScript Reference, which makes it quite a bit easier. It's definitely not very "English-like", which AppleScript is meant to be, but that shouldn't be a hindrance to Python scripters. Using appscript with its dot language will actually put it back to something more like the VBA from which it was "derived". Matt doesn't have that quite right either: both VBA and AppleScript actually hook in, separately, to the underlying OLE Automation model: AppleScript does not "go through" VBA. But the model is definitely more accommodating to VBA, and to Python, for that matter, than to normal AppleScript, since it was designed for a language where you can specify the arguments of a method explicitly by naming both the arguments (keys) and values rather than just have them all run on like AppleScript does it. > > I cede to your knowledge about the specifics of this, as I do very > little with Excel from AS, and am still using v. X. I stand corrected in > particular on driving it from Python via appscript. It would certainly be "interesting" - but can be done. -- Paul Berkowitz ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] inputing multi-digit numbers
Paul Berkowitz wrote: > It mirrors the VBA model, definitely, and its AppleScript syntax is thus a > little, shall we say "obscure", This is what I referring to. From Matt Neuburg's book, p. 331: "instead of working out an AppleScript scriptability implementation from scratch, they've simply taken the existing internal scripting implementation (Visual Basic for Applications) and exposed its entire object model, lock, stock, and barrel, to AppleScript...if you don't know how to drive Excel with Visual Basic it's really hard to figure out how to drive it with AppleScript." I cede to your knowledge about the specifics of this, as I do very little with Excel from AS, and am still using v. X. I stand corrected in particular on driving it from Python via appscript. -- Cheers, Kevin Walzer, PhD WordTech Software - "Tame the Terminal" http://www.wordtech-software.com sw at wordtech-software.com ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] inputing multi-digit numbers
On Nov 10, 2005, at 11:29 AM, Dethe Elza wrote: >> Excel on Mac is AppleScriptable through a weird path: Excel exposes >> the VBA object model to AppleScript. So, it's not AppleScriptable >> in the standard sense and I am not sure how you would access it >> from Python. > > Thanks for the info, Kevin. It sounds like downloading OpenOffice > and using PyUNO would be fun in comparison. You can do it, it's just an awkward API.. but anyway, using a Java library to do it is much nicer, faster, cheaper, and more portable (anywhere with a JRE installed). Conveniently, the jar is also a CLI app that can just convert to CSV and XML without even having to look at any Java code, so it's really quite ideal. I haven't had any issues with it, and unlike the Perl equivalent (Spreadsheet::Excel or something), it deals with Unicode correctly. -bob ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] inputing multi-digit numbers
On 11/10/05 11:25 AM, "Kevin Walzer" <[EMAIL PROTECTED]> wrote: > Excel on Mac is AppleScriptable through a weird path: Excel exposes the > VBA object model to AppleScript. So, it's not AppleScriptable in the > standard sense and I am not sure how you would access it from Python. > Actually, that's completely false - you must have been thinking of PowerPoint X and (effectively) Word X and earlier, which have 'do Visual Basic' commands in AppleScript. (Word always had a limited pure AppleScript dictionary too, but it was far too buggy and didn't work properly - until Word 2004, which works just fine.) Although Excel does also have VBA, it has always had a first-rate AppleScript object model, even in earlier versions (X and earlier), which always worked well. In the most recent recent version, Office 2004, its AppleScript dictionary was completely rewritten along with Word's and PowerPoint's - and its native AppleScript is now even better, and complete. It mirrors the VBA model, definitely, and its AppleScript syntax is thus a little, shall we say "obscure", but it's pure AppleScript. Aside from its voluminous AppleScript dictionary, there's also an AppleScript Reference Guide you can get from MacTopia - the Microsoft Mac website (http://www.microsoft.com/mac/) /Resources/Developer/AppleScript. You can access it (and earlier versions too) via has's appscript from Python. -- Paul Berkowitz ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] inputing multi-digit numbers
> Excel on Mac is AppleScriptable through a weird path: Excel exposes > the VBA object model to AppleScript. So, it's not AppleScriptable > in the standard sense and I am not sure how you would access it > from Python. Thanks for the info, Kevin. It sounds like downloading OpenOffice and using PyUNO would be fun in comparison. --Dethe ...if there's not much you can do with HTML, it does have the advantage of being easy to learn. -- Paul Graham ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] inputing multi-digit numbers
Dethe Elza wrote: > On 10-Nov-05, at 10:18 AM, Bob Ippolito wrote: >> I use this to convert excel to xml, and parse that from Python. >> http://www.andykhan.com/jexcelapi/ >> >> -bob > > Oops. Obviously I failed to note which list this question was posed > on, I assumed it was edu-sig for some reason. Sorry, didn't mean to > give you Windows tips on a Mac list, just forgot that Mac folks use > Excel too. > > I don't actually have Office on any of my Macs. Does anyone know if > it is AppleScript-able? Can you drive Excel directly from Python on > OS X like you can on Windows? > > --Dethe > > Windows has detected the mouse has moved. Please restart your system > for changes to take effect. > > > ___ > Pythonmac-SIG maillist - Pythonmac-SIG@python.org > http://mail.python.org/mailman/listinfo/pythonmac-sig > > Excel on Mac is AppleScriptable through a weird path: Excel exposes the VBA object model to AppleScript. So, it's not AppleScriptable in the standard sense and I am not sure how you would access it from Python. -- Cheers, Kevin Walzer, PhD WordTech Software - "Tame the Terminal" http://www.wordtech-software.com sw at wordtech-software.com ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] inputing multi-digit numbers
On 10-Nov-05, at 10:18 AM, Bob Ippolito wrote: > I use this to convert excel to xml, and parse that from Python. > http://www.andykhan.com/jexcelapi/ > > -bob Oops. Obviously I failed to note which list this question was posed on, I assumed it was edu-sig for some reason. Sorry, didn't mean to give you Windows tips on a Mac list, just forgot that Mac folks use Excel too. I don't actually have Office on any of my Macs. Does anyone know if it is AppleScript-able? Can you drive Excel directly from Python on OS X like you can on Windows? --Dethe Windows has detected the mouse has moved. Please restart your system for changes to take effect. ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] inputing multi-digit numbers
On Nov 10, 2005, at 10:05 AM, Dethe Elza wrote: > > On 10-Nov-05, at 5:01 AM, <[EMAIL PROTECTED]> > <[EMAIL PROTECTED]> wrote: > >> >> -Original Message- >> From: [EMAIL PROTECTED] [mailto:pythonmac-sig- >> [EMAIL PROTECTED] On Behalf Of Kirk Durston >> Sent: Thursday, November 10, 2005 2:00 AM >> To: pythonmac-sig@python.org >> Subject: [Pythonmac-SIG] inputing multi-digit numbers >> >> I’m having a hard time figuring out how to input a list of numbers, >> each one of which can be 1, 2, or 3 digits in length. First, I >> select a column in an Excel file, and copy and past it into a Word >> file. I then save it as a text file. > > Wouldn't it be simpler to use Excel to export as CSV and use python's > csv module to read them in? > > http://python.org/doc/current/lib/module-csv.html > > I don't understand why Word is involved in getting numbers from Excel > to Python. I use this to convert excel to xml, and parse that from Python. http://www.andykhan.com/jexcelapi/ -bob ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] inputing multi-digit numbers
On 10-Nov-05, at 5:01 AM, <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> wrote: > > -Original Message- > From: [EMAIL PROTECTED] [mailto:pythonmac-sig- > [EMAIL PROTECTED] On Behalf Of Kirk Durston > Sent: Thursday, November 10, 2005 2:00 AM > To: pythonmac-sig@python.org > Subject: [Pythonmac-SIG] inputing multi-digit numbers > > I’m having a hard time figuring out how to input a list of numbers, > each one of which can be 1, 2, or 3 digits in length. First, I > select a column in an Excel file, and copy and past it into a Word > file. I then save it as a text file. Wouldn't it be simpler to use Excel to export as CSV and use python's csv module to read them in? http://python.org/doc/current/lib/module-csv.html I don't understand why Word is involved in getting numbers from Excel to Python. Another alternative would be to use the excellent pywin32 tools to extract Excel data directly from within Python, using Excel's COM interface. http://sourceforge.net/projects/pywin32/ Excel has other interfaces it exposes besides COM. Here is a recipe from the Python Cookbook to extract tabular data from an Excel file using pywin32 and the ADODB interface. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440661 I hope this is helpful. --Dethe "the city carries such a cargo of pathos and longing that daily life there vaccinates us against revelation" -- Pain Not Bread, The Rise and Fall of Human Breath ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] inputing multi-digit numbers
>> Question: how do I get rid of the \n attached to each member in my >> list? > > Choose: > > map(int(map(string.strip, yourlist)) (Python 2.2) > > [ int(x.strip()) for x in yourlist ] (Python 2.3) > > ( int(x.strip()) for x in yourlist ) (Python 2.4) > You don't need strip(), int() ignores white space. So the generator- expression version could be (others could be shortened similarly): (int(x) for x in yourlist) --Dethe A miracle, even if it's a lousy miracle, is still a miracle. --Teller ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] trouble with NSXMLDocument
On Nov 10, 2005, at 2:15 AM, Jack Nutting wrote:Hi gang,I wanted to play around with NSXMLDocument a bit, and figured PyObjC would be a good way to do it. Unfortunately, I get strange errors.>>> doc, error = Foundation.NSXMLDocument.alloc ().initWithContentsOfURL_options_error_(u"asdfkjsda.svg", 0)2005-11-10 11:03:20.618 python[1018] *** -[OC_PythonUnicode absoluteURL]: selector not recognized [self = 0x370db0]Traceback (most recent call last): File "", line 1, in ?ValueError: NSInvalidArgumentException - *** -[OC_PythonUnicode absoluteURL]: selector not recognized [self = 0x370db0]Note that the "asdfkjsda.svg" file is in the same directory where I started python. I tried using a file URL instead, but both " file://asdfkjsda.svg" and "file:///Users/jnutting/Documents/svg/shapes/asdfkjsda.svg" give me the same result, as does wrapping the string in unicode(string, 'utf-8') instead of just prepending it with 'u'. It's telling you that strings are not URLs. You need to use a NSURL instance as the first parameter.-bob___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] inputing multi-digit numbers
Hi - > > Thank you. That gives me something closer to a list, but the output is now: > > ['939\n', '936\n', '937\n', '885\n', '886\n', '887\n', '171\n', '19\n', ...] You could do: inf = open(fileName) numbers = inf.read().splitlines() splitlines() is smarter than readlines() - Craig ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] inputing multi-digit numbers
> Thank you. That gives me something closer to a list, but the output is now: > ['939\n', '936\n', '937\n', '885\n', '886\n', '887\n', '171\n', '19\n', ...] > Question: how do I get rid of the \n attached to each member in my list? Choose: map(int(map(string.strip, yourlist)) (Python 2.2) [ int(x.strip()) for x in yourlist ] (Python 2.3) ( int(x.strip()) for x in yourlist ) (Python 2.4) Best regards, Henning Hraban Ramm Südkurier Medienhaus / MediaPro Support/Admin/Development Dept. ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] inputing multi-digit numbers
Title: Re: [Pythonmac-SIG] inputing multi-digit numbers On 11/10/05 8:01 AM, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: I’m having a hard time figuring out how to input a list of numbers, each one of which can be 1, 2, or 3 digits in length. First, I select a column in an Excel file, and copy and past it into a Word file. I then save it as a text file. I then open a new window in Python and copy and paste the column of numbers from the text file into the window and save it as ‘Function ID’ In my main program, I type input=open('Function ID', 'r') x=input.readlines() input.close() print x Try open (or file) with mode 'rU' (universal newline support), apparently the \r is not recognized as \n Best regards, Henning Hraban Ramm Südkurier Medienhaus / MediaPro Support/Admin/Development Dept. Thank you. That gives me something closer to a list, but the output is now: ['939\n', '936\n', '937\n', '885\n', '886\n', '887\n', '171\n', '19\n', ...] Question: how do I get rid of the \n attached to each member in my list? I still need to do a lot of work with the contents of the list. I could run each member of the list through a loop and slice off the \n, but I imagine there is a more efficient way to do the job. Is there? Thank you for your help. Kirk ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
[Pythonmac-SIG] inputing multi-digit numbers
Title: inputing multi-digit numbers I’m having a hard time figuring out how to input a list of numbers, each one of which can be 1, 2, or 3 digits in length. First, I select a column in an Excel file, and copy and past it into a Word file. I then save it as a text file. I then open a new window in Python and copy and paste the column of numbers from the text file into the window and save it as ‘Function ID’ In my main program, I type input=open('Function ID', 'r') x=input.readlines() input.close() print x What I get, when x is printed out, looks like this: ['939\r936\r937\r885\r886\r887\r171\r19\r169\r149\r36\r37\r38\r1\r51\r81\r102\r827\r919\r14\r85\r20\r895\r88\r89\r167\r163\r111\r168\r128\r66\r880\r884\r71\r131\r67\r419\r415\r68\r103\r82\r2\r39\r40\r41\r132\r107\r123\r150\r155\r897\r901\r911\r949\r21\r15\r9\r883\r129\r69\r70\r130\r124\r112\r142\r164\r159\r881\r882\r72\r22\r23\r24\r3\r108\r133\r388\r113\r160\r165\r393\r156\r144\r161\r25\r4\r134\r905\r907\r26\r114\r95\r96\r162\r174\r27\r125\r389\r888\r145\r16\r100\r126\r28\r891\r5\r115\r143\r75\r29\r73\r74\r76\r98\r83\r104\r30\r42\r43\r44\r151\r172\r109\r135\r6\r940\r892\r912\r903\r898\r17\r10\r390\r136\r116\r45\r46\r47\r899\r173\r146\r117\r31\r77\r894\r893\r900\r902\r913\r7\r941\r938\r910\r11\r78\r105\r84\r32\r48\r49\r50\r118\r110\r127\r101\r137\r152\r79\r80\r908\r906\r33\r138\r909\r890\r153\r154\r157\r170\r106\r416\r914\r921\r8\r12\r13\r18\r34\r99\r139\r147\r392\r'] What I want is [‘939’, ‘936’, ... ,’392’] What am I doing wrong? Kirk ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] inputing multi-digit numbers
Title: Nachricht -Original Message-From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kirk DurstonSent: Thursday, November 10, 2005 2:00 AMTo: pythonmac-sig@python.orgSubject: [Pythonmac-SIG] inputing multi-digit numbers Im having a hard time figuring out how to input a list of numbers, each one of which can be 1, 2, or 3 digits in length. First, I select a column in an Excel file, and copy and past it into a Word file. I then save it as a text file. I then open a new window in Python and copy and paste the column of numbers from the text file into the window and save it as Function IDIn my main program, I typeinput=open('Function ID', 'r')x=input.readlines()input.close()print x Try open (or file) with mode 'rU' (universal newline support), apparently the \r is not recognized as \n Best regards,Henning Hraban RammSüdkurier Medienhaus / MediaProSupport/Admin/Development Dept. ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
[Pythonmac-SIG] trouble with NSXMLDocument
Hi gang,I wanted to play around with NSXMLDocument a bit, and figured PyObjC would be a good way to do it. Unfortunately, I get strange errors.>>> doc, error = Foundation.NSXMLDocument.alloc ().initWithContentsOfURL_options_error_(u"asdfkjsda.svg", 0)2005-11-10 11:03:20.618 python[1018] *** -[OC_PythonUnicode absoluteURL]: selector not recognized [self = 0x370db0]Traceback (most recent call last): File "", line 1, in ?ValueError: NSInvalidArgumentException - *** -[OC_PythonUnicode absoluteURL]: selector not recognized [self = 0x370db0]Note that the "asdfkjsda.svg" file is in the same directory where I started python. I tried using a file URL instead, but both " file://asdfkjsda.svg" and "file:///Users/jnutting/Documents/svg/shapes/asdfkjsda.svg" give me the same result, as does wrapping the string in unicode(string, 'utf-8') instead of just prepending it with 'u'. Running framework python 2.4.1, mac os 10.4.3, PyObjC 1.3.7 (from the installer package for 2.4.1/10.3; is it odd that there's not a 1.3.7 for 2.4.1/10.4, or should the one I've got work OK?)-- // jack // http://www.nuthole.com ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig