Interfacing python program to C++ program instance
Windows. Situation: Using a Python program called OpenRPG. I have a program that displays form data (a character sheet) in C++. I am able in the C++ program to build a string and copy it into the clipboard, then paste it into the input in the running Python program. I would like to somehow automate this, that is, have the python instance communicate with the C++ instance and vice versa. I'm still trying to think of a way to do this. There seems to be a number of options, but I'm not sure which one is best, or there is a better one. 1. Write a new C++ program/library with extern C that Python could call. This interface program would open up some shared memory that the C++ application would also open up, and python and C++ could communicate that way. Python writing requests to the memory, C++ responding with responses. 2. Have the C++ program interface directly into the python form, reading directly from controls. C++ could write to the input box with reponses. 3. Have Python write a small file with the request to the HD. Have the C++ program intermittedly check for the presense of this file. If it exists, it would open the file, read the request, write a response file, then delete the file Python wrote. 4. Find out if python can directly, somehow, open up shared memory and do the same as 1 without the need for the extern C interface program. 5. Something else I'm not thinking of but you know. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
2**2**2**2**2 wrong? Bug?
In Python 2.5 on intel, the statement 2**2**2**2**2 evaluates to >>> 2**2**2**2**2 20035299304068464649790723515602557504478254755697514192650169737108940595563114 53089506130880933348101038234342907263181822949382118812668869506364761547029165 04187191635158796634721944293092798208430910485599057015931895963952486337236720 30029169695921561087649488892540908059114570376752085002066715637023661263597471 44807111774815880914135742720967190151836282560618091458852699826141425030123391 10827360384376787644904320596037912449090570756031403507616256247603186379312648 47037437829549756137709816046144133086921181024859591523801953310302921628001605 68670105651646750568038741529463842244845292537361442533614373729088303794601274 72495841486491593064725201515569392262818069165079638106413227530726714399815850 88112926289011342377827055674210800700652839633221550778312142885516755540733451 07213112427399562982719769150054883905223804357045848197956393157853510018992000 02414196370681355984046403947219401606951769015611972698233789001764151719005113 34663068981402193834814354263873065395529696913880241581618595611006403621197961 01859534802787167200122604642492385111393400464351623867567078745259464670903886 5477434832178970127644555294090920219595857516229757615955239488529757995402 84719435299135437637059869289137571537400019863943324648900525431066296691652434 1917469138963247656028941519977547770313806478134230959619096065459130089017 58808473362595606544488850144733570605881709016210849971452956834406197969056546 98136311620535793697914032363284962330464210661362002201757878518574091620504897 11781820400187282939943446186224328009837323764931814789848119452713007440220765 68091037620399920349202390662626449190916798546151577883906039772075927937885224 12943010174580868622633692847258514030396155585643303854506886522131148136384083 84778263790459607186876728509763471271988890680478243230394718650525660978150729 86114143030581692792497140916105941718535227588750447759221830115878070197553572 22414000195481020056617735897814995323252085897534635470077866904064290167638081 61740550405117670093673202804549339027992491867306539931640720492238474815280619 16690093380573212081635070763435166986962502096902316285935007187419057916124153 68975148082619048479465717366010058924766554458408383347905441448176842553272073 15586349347605137419779525190365032198020108764738368682531025183377533908861426 18480037400808223810407646887847164755294532694766170042446106331123802113458869 45322001165640763270230742924260515828110703870183453245676356259514300320374327 40780879056283663406965030844225855967039271869461158513793386475699748568670079 82396060439347885086164926030494506174341236582835214480672667684180708375486221 14082365798029612000274413244384324023312574035450193524287764308802328508558860 89962774458164680857875115807014743763867976955049991643998284357290415378143438 84730348426190338884149403136613985425763557710533558020662218557706008255128889 33322264362819848386132395706761914096385338323743437588308592337222846442879962 45605476932428998432652677378373173288063210753211238680604674708428051166488709 0847702912081611049129832236624486855665140268464120969498259056551921618810 43412268389962830716548685255369148502995396755039549383718534059000961874894739 92880432496373165753803673586710175783994818471798498246948060532081996066183434 01247609663951977802144119975254670408060849934417825628509272652370989865153946 21930046073645079262129759176982938923670151709920915315678144397912484757062378 0469918293321306880570046591458387208088016887445835557926258465124763087148 56631352893416611749061752667149267217612833084527393646924458289257138887783905 6300482483799839692029154861459023734782226825216399574408017271441461795592 26175083889020074169926238300282286249284182671243405751424188569994272331606998 71298688277182061721445314257494401506613946316919762918150657974552623619122484 80638900336690743659892263495641146655030629659601997206362026035219177767406687 7746354937531889958786628212546979710206574723272137291814459421872003474508 94283091153518927111428710837615922238027660532782335166155514936937577846667014 57179719012271178127804502400263847587883393968179629506907988171216906869295382 48529830023476068454114178139110648560236549754227497231007615131870024053910510 91381784372179142252858743209852495787803468370333781842144401713868812424998441 86181292711985333153825673218704215306311977485352146709553346263366108646673322 92409879849256691109516143618601548909740241913509623043612196128165950518666022 03071561368473236466086890501426391390651506390819937885231836505989729912540447 94434251667742996598118492331515552728832740283526884424087528112832899806259126 7369954624734154500147231430612750390307397135252069338173843322950701049061 86753943313078479801565513038475815568523621801041965025559618193498631591323303 60964619059902361126811960234418433633345949276319461017
Re: 2**2**2**2**2 wrong? Bug?
"Paul Rubin" <http://[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "Jim Langston" <[EMAIL PROTECTED]> writes: >> In Python 2.5 on intel, the statement >> 2**2**2**2**2 >> evaluates to >> >>> 2**2**2**2**2 > > I get the same number from hugs--why do you think it might be wrong? 2**2 = 4 4**2 = 16 16**2 = 256 256**2 = 65536 65536**2 = 4294967296 In fact, if I put (2**2)**2**2**2 it comes up with the correct answer, 4294967296 -- http://mail.python.org/mailman/listinfo/python-list
Re: 2**2**2**2**2 wrong? Bug?
Gah! Python goes right to left? Dang, I haven't seen that since APL. <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >>> 2**2)**2)**2)**2) 65536 >>> 2**(2**(2**(2**2))) 200352993040684646497907235156025575044782547556975141926501697371089405955631145308950613088. The same as "2**2**2**2**2" -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jim Langston Sent: 2007Äê7ÔÂ10ÈÕ 12:47 To: python-list@python.org Subject: Re: 2**2**2**2**2 wrong? Bug? "Paul Rubin" <http://[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "Jim Langston" <[EMAIL PROTECTED]> writes: >> In Python 2.5 on intel, the statement >> 2**2**2**2**2 >> evaluates to >> >>> 2**2**2**2**2 > > I get the same number from hugs--why do you think it might be wrong? 2**2 = 4 4**2 = 16 16**2 = 256 256**2 = 65536 65536**2 = 4294967296 In fact, if I put (2**2)**2**2**2 it comes up with the correct answer, 4294967296 -- http://mail.python.org/mailman/listinfo/python-list
Re: Python version changes, sys.executable does not
"Jeffrey Froman" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hello All, > > I have two python versions installed, one in /usr/bin, and one in > /usr/local/bin. However, when invoking python without a full path, > I get the wrong executable with the right sys.executable string! > > [EMAIL PROTECTED] ~]# ls -l /usr/local/bin/python* > -rwxr-xr-x 2 root root 3783810 Jul 19 09:15 /usr/local/bin/python > -rwxr-xr-x 2 root root 3783810 Jul 19 09:15 /usr/local/bin/python2.5 > -rwxr-xr-x 1 root root1281 Jul 19 09:16 > /usr/local/bin/python2.5-config > lrwxrwxrwx 1 root root 16 Jul 19 09:16 > /usr/local/bin/python-config -> python2.5-config > > [EMAIL PROTECTED] ~]# ls -l /usr/bin/python* > -rwxr-xr-x 2 root root 5396 May 2 16:28 /usr/bin/python > lrwxrwxrwx 1 root root6 Jul 18 12:20 /usr/bin/python2 -> python > -rwxr-xr-x 2 root root 5396 May 2 16:28 /usr/bin/python2.3 > > [EMAIL PROTECTED] ~]# which python > /usr/local/bin/python > > [EMAIL PROTECTED] ~]# /usr/local/bin/python -c "import sys; print > sys.executable; > print sys.version; set()" > /usr/local/bin/python > 2.5 (r25:51908, Jul 19 2007, 09:13:48) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] > > [EMAIL PROTECTED] ~]# env python -c "import sys; print sys.executable; print > sys.version; set()" > /usr/local/bin/python > 2.5 (r25:51908, Jul 19 2007, 09:13:48) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] > > [EMAIL PROTECTED] ~]# python -c "import sys; print sys.executable; print > sys.version; set()" > /usr/local/bin/python > 2.3.4 (#1, May 2 2007, 19:26:00) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'set' is not defined > - > > > On a different machine, with same setup (as far as I can tell), I get the > expected > results: > - > [EMAIL PROTECTED] ~]# /usr/local/bin/python -c "import sys; print > sys.executable; > print sys.version; set()" > /usr/local/bin/python > 2.5 (r25:51908, Feb 8 2007, 16:29:18) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] > > [EMAIL PROTECTED] ~]# env python -c "import sys; print sys.executable; print > sys.version; set()" > /usr/local/bin/python > 2.5 (r25:51908, Feb 8 2007, 16:29:18) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] > > [EMAIL PROTECTED] ~]# python -c "import sys; print sys.executable; print > sys.version; set()" > /usr/local/bin/python > 2.5 (r25:51908, Feb 8 2007, 16:29:18) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] > - > > Can anyone tell me what might be causing the erroneous behavior in the > first example? I think it's because your python directory is in the path before your python2.5 directory. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python version changes, sys.executable does not
"Jeffrey Froman" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hello All, > > I have two python versions installed, one in /usr/bin, and one in > /usr/local/bin. However, when invoking python without a full path, > I get the wrong executable with the right sys.executable string! > > [EMAIL PROTECTED] ~]# ls -l /usr/local/bin/python* > -rwxr-xr-x 2 root root 3783810 Jul 19 09:15 /usr/local/bin/python > -rwxr-xr-x 2 root root 3783810 Jul 19 09:15 /usr/local/bin/python2.5 > -rwxr-xr-x 1 root root1281 Jul 19 09:16 > /usr/local/bin/python2.5-config > lrwxrwxrwx 1 root root 16 Jul 19 09:16 > /usr/local/bin/python-config -> python2.5-config > > [EMAIL PROTECTED] ~]# ls -l /usr/bin/python* > -rwxr-xr-x 2 root root 5396 May 2 16:28 /usr/bin/python > lrwxrwxrwx 1 root root6 Jul 18 12:20 /usr/bin/python2 -> python > -rwxr-xr-x 2 root root 5396 May 2 16:28 /usr/bin/python2.3 > > [EMAIL PROTECTED] ~]# which python > /usr/local/bin/python > > [EMAIL PROTECTED] ~]# /usr/local/bin/python -c "import sys; print > sys.executable; > print sys.version; set()" > /usr/local/bin/python > 2.5 (r25:51908, Jul 19 2007, 09:13:48) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] > > [EMAIL PROTECTED] ~]# env python -c "import sys; print sys.executable; print > sys.version; set()" > /usr/local/bin/python > 2.5 (r25:51908, Jul 19 2007, 09:13:48) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] > > [EMAIL PROTECTED] ~]# python -c "import sys; print sys.executable; print > sys.version; set()" > /usr/local/bin/python > 2.3.4 (#1, May 2 2007, 19:26:00) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] > Traceback (most recent call last): > File "", line 1, in ? > NameError: name 'set' is not defined > - > > > On a different machine, with same setup (as far as I can tell), I get the > expected > results: > - > [EMAIL PROTECTED] ~]# /usr/local/bin/python -c "import sys; print > sys.executable; > print sys.version; set()" > /usr/local/bin/python > 2.5 (r25:51908, Feb 8 2007, 16:29:18) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] > > [EMAIL PROTECTED] ~]# env python -c "import sys; print sys.executable; print > sys.version; set()" > /usr/local/bin/python > 2.5 (r25:51908, Feb 8 2007, 16:29:18) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] > > [EMAIL PROTECTED] ~]# python -c "import sys; print sys.executable; print > sys.version; set()" > /usr/local/bin/python > 2.5 (r25:51908, Feb 8 2007, 16:29:18) > [GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] > - > > Can anyone tell me what might be causing the erroneous behavior in the > first example? er, of course I meant python2.3 before python2.5 -- http://mail.python.org/mailman/listinfo/python-list
Re: Formatting Results so that They Can be Nicely Imported into a Spreadsheet.
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Aug 4, 6:35?pm, SMERSH009 <[EMAIL PROTECTED]> wrote: >> Hi All. >> Let's say I have some badly formatted text called doc: >> >> doc= >> """ >> friendid >> Female >> >> 23 years old >> >> Los Gatos >> >> United States >> friendid >> Male >> >> 24 years old >> >> San Francisco, California >> >> United States >> """ >> >> How would I get these results to be displayed in a format similar to: >> friendid;Female;23 years old;Los Gatos;United States >> friendid;Male; 24 years old;San Francisco, California;United States >> >> The latter is a lot easier to organize and can be quickly imported >> into Excel's column format. >> >> Thanks Much, >> Sam > > d = doc.split('\n') > > f = [i.split() for i in d if i] > > g = [' '.join(i) for i in f] > > rec = [] > temprec = [] > for i in g: >if i: >if i == 'friendid': >rec.append(temprec) >temprec = [i] >else: >temprec.append(i) > rec.append(temprec) > > output = [';'.join(i) for i in rec if i] > > for i in output: print i > > ##friendid;Female;23 years old;Los Gatos;United States > ##friendid;Male;24 years old;San Francisco, California;United States also, I would suggest you use CSV format. CSV stands for "Comma Seperated Variable" and Excel can load such a sheet directly. Instead of seperating using ; seperate using , Of course, this provides a problem when there is a , in a string. Resolution is to quote the string. Being such, you can just go ahead and quote all strings. So you would want the output to be: "friendid","Female","23 years old","Los Gatos","United States" "friendid","Male","24 years old","San Francisco, California","United States" Numbers should not be quoted if you wish to treat them as numeric and not text. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use C enum in Python CTypes?
"rozniy" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Aug 7, 2:11 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> On Tue, 07 Aug 2007 04:57:19 +, rozniy wrote: >> > typedef enum olss_tag >> >{ >> >OLSS_AD, >> >OLSS_DA, >> >OLSS_DIN, >> >OLSS_DOUT, >> >OLSS_SRL, >> >OLSS_CT >> >} >> > OLSS; >> >> > I managed to fudge the HDEV, UINT and PHDASS types as CTypes c_long(), >> > but I am not sure how translate a C enum into Python... >> >> > This site >> >http://python.net/crew/theller/ctypes/tutorial.html#bugs-todo-and-non... >> >> > says that enumeration types is not implemented, >> > "Enumeration types are not implemented. You can do it easily yourself, >> > using c_int as the base class." >> >> I would just define constants: >> >> (OLSS_AD, >> OLSS_DA, >> OLSS_DIN, >> OLSS_DOUT, >> OLSS_SRL, >> OLSS_CT) = map(ctypes.c_int, xrange(6)) >> >> Ciao, >> Marc 'BlackJack' Rintsch- Hide quoted text - >> >> - Show quoted text - > > > Wouldn't that assign integer values 0 to 5 to the things? I don't know > if it'll give me the correct results. Yes, that's how C's and C++'s enums work, unless an override is given (which I know you can do in C++ for sure). Otherwise, they are just numbers starting at 0. The size of the intergers (byte, 2 bytes, 4 bytes, etc..) is implemenation defined I believe, but an int normally works. -- http://mail.python.org/mailman/listinfo/python-list