[Tutor] Embedding Python
I am attempting to embed Python in a C++ app and have a question before I get too far into it. Is is possible to to dynamically create an extension module? eg, I want a module name spam and I have a stuct that contains all my method names, and a pointer to the proper c++ function to call ### Suto Code ### typedef struct _COMMAND { CHAR Name[64]; fCommand Function; struct _COMMAND* pLast; struct _COMMAND* pNext; } COMMAND, *PCOMMAND; ### End Sudo Code ### What I would like to do is something like ### Sudo Code ### class MyClass { MyClass(PCOMMAND pCommand ) {pComd = pCommand;} static PyObject* spam_Func(PyObject *self, PyObject *args) { PCHAR sLine = NULL; if (!PyArg_ParseTuple(args, "z", &sLine)) return NULL; pCmd->Function(sLine); Py_RETURN_NONE; } static PCOMMAND pCmd; }; static PyMethodDef Methods[] = {0} PCOMMAND pCommand = pCommands; while(pCommand) { MyClass* cmd = new MyClass(pCommand); Methods[pCommand->Name, cmd->spam_Func, METH_VARARGS, ""]; pCommand = pCommand->pNext; } Methods[NULL, NULL, 0, NULL]; PyMODINIT_FUNC initspam(void) { (void) Py_InitModule("spam", Methods); } ### End Sudo Code ### Now I know my Sudo code wont work or I wouldnt be asking, but is it possible to do something like that. The reason I ask is there are about 150 commands, plus plugins can add and remove commands when they get loaded or unloaded so I will need to add / remove their commands from the spam module as well. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] stumped again adding bytes
Hey there, and thanks for all your help here, i started getting some values that look like what they are supposed to. Funny, i have been with python for over a year, and just downloaded a hex cheatsheet. thanks again for all of the help, gents. shawn On 2/23/07, Alan Gauld <[EMAIL PROTECTED]> wrote: > > "shawn bright" <[EMAIL PROTECTED]> wrote > > > if i use i bitmask of 240 it will mask the most significant 4 bits > > When using bitmasks its much easier to think in hex (or octal). > there are exactly 2 hex digits per byte so you only need to think > about each group of 4 bits and its hex bit pattern. It saves a > heap of mental calculations! > > Alan G. > > ___ > 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] geeks like us and the rest of THEM
OK, my project is to come up with a wiki which is easy to install and use in a windows laptop, to wikify the notebook into a hypernotebook. ok, it must be EASY to install. And LEGAL. MiniWiki is in python. I can do it in a self extracting installer as there is a nice free pone out there someplace- links please? BUT PYTHON IS ANOTHER MATTER. It needs to have python on the notebook, which is not the case. It aldso needs a small server in the notebook, and I have one in python and another in C++, which alas is not freeware. The hurdle is it must be a legal and simple and almost droolproof solution from soup to nuts. the beta solution is working in this laptop NOW. Now how do I turn this into a turnkey solution for THEM? We are geeks. But the end result is intended for pointy haired bosses, soccer moms with Avon dealerships, and other regular humans. And as awlays, we must avoid the dread lawyer vampires. -- Salute! -Kirk Bailey Think +-+ | BOX | +-+ knihT Fnord. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] DICOM Header
Bill Sconce wrote: > On Thu, 22 Feb 2007 13:51:35 -0700 > "Andrew Liimatta" <[EMAIL PROTECTED]> wrote: > >> I have a directory that is filled with DICOM files that I obtained >> by using the Offis DICOM tool kit. > > Ah. The light dawns. I should offer to communicate with you off-list, > and report back here after we've solved the problem. I have DICOM files > here, and it sounds like an interesting and useful thing to be able to > do (inspect DICOM files with Python). Googling 'python dicom' yields a few hits that might be helpful. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] index swap?
Switanek, Nick wrote: > Kent, > > Thank you for the good suggestions. As you suspected, the data were not > what I thought they were, which is a comforting thought since that's > more evidence that I can trust python but can't always trust myself (no > surprise there). I have multiple years of entries for each observation > and the order of the columns was interchanged midway through. I didn't > see this at first because the rows are grouped by year, not by > observation, so looking at the first twenty rows didn't reveal any > problem. > > Is there a speed advantage to using nested list comps, or stringing > together multiple string method calls (e.g. str.rstrip().split('\t')), > as you advise? Or is the main benefit cleaner code? Is there a limit to > the number of nestings, apart from the potential for confusion in my > head? There is probably a speed advantage to the list comps but for me the big advantage is ease of use. It takes a little while to get used to the syntax and the idea but I find it much more natural because (to me) it clearly expresses an idea. I will think, "I need a list of all the lines in the file, split by tabs." The list comp [ line.split('\t') for line in open('file.txt') ] expresses this naturally and concisely without introducing anything extra. The explicit for loop introduces a lot of mechanism that doesn't really have anything to do with the actual concept, it is just the way we are used to implementing the concept. The list comp avoids the explicit plumbing. Nested list comps push the readability a bit, in this case it is pretty simple. You can go to extremes to shoehorn something into a list comp but I don't see any point to that other than for fun and showing off and perhaps a useful optimization. All IMO of course. Kent PS Please reply on-list ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] dictionaries and memory handling
Arild B. Næss wrote: > Hi, > > I'm working on a python script for a task in statistical language > processing. Briefly put it all boils down to counting different > things in very large text files, doing simple computations on these > counts and storing the results. I have been using python's dictionary > type as my basic data structure of storing the counts. This has been > a nice and simple solution, but turns out to be a bad idea in the > long run, since the dictionaries become _very_ large, and create > MemoryErrors when I try to run my script on texts of a certain size. > > It seems that an SQL database would probably be the way to go, but I > am a bit concerned about speed issues (even though running time is > not all that crucial here). In any case it would probably take me a > while to get a database up and running and I need to hand in some > preliminary results pretty soon, so for now I think I'll postpone the > SQL and try to tweak my current script to be able to run it on > slightly longer texts than it can handle now. > > So, enough beating around the bush, my questions are: > > - Will the dictionaries take up less memory if I use numbers rather > than words as keys (i.e. will {3:45, 6:77, 9:33} consume less memory > than {"eloquent":45, "helpless":77, "samaritan":33} )? And if so: > Slightly less, or substantially less memory? I'm going to guess here. I think the number will take up 4 bytes plus the overhead of an object and the string will take about the number of bytes in the string plus the same overhead. But I am guessing and there are optimizations in the Python interpreter for both strings and ints that may affect this. > > - What are common methods to monitor the memory usage of a script? > Can I add a snippet to the code that prints out how many MBs of > memory a certain dictionary takes up at that particular time? See various discussions on comp.lang.python: http://tinyurl.com/ysrocc Kent > > regards, > Arild Næss > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] geeks like us and the rest of THEM
Kirk Bailey wrote: > OK, my project is to come up with a wiki which is easy to install and > use in a windows laptop, to wikify the notebook into a hypernotebook. > > ok, it must be EASY to install. And LEGAL. > > MiniWiki is in python. I can do it in a self extracting installer as > there is a nice free pone out there someplace- links please? BUT PYTHON > IS ANOTHER MATTER. It needs to have python on the notebook, which is not > the case. It aldso needs a small server in the notebook, and I have one > in python and another in C++, which alas is not freeware. You can use py2exe to create an executable that includes Python. You can create a single file executable or a directory that can be packaged up with InnoSetup or another installer maker. Python has a simple built-in web server - see SimpleHTTPServer and CGIHTTPServer modules. Beyond that there are many freely distributed web servers available, CherryPy, Karrigell and Snakelets are all pretty small. Kent > > The hurdle is it must be a legal and simple and almost droolproof > solution from soup to nuts. > > the beta solution is working in this laptop NOW. Now how do I turn this > into a turnkey solution for THEM? > > We are geeks. But the end result is intended for pointy haired bosses, > soccer moms with Avon dealerships, and other regular humans. And as > awlays, we must avoid the dread lawyer vampires. > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] geeks like us and the rest of THEM
Kent Johnson wrote: > Kirk Bailey wrote: >> OK, my project is to come up with a wiki which is easy to install and >> use in a windows laptop, to wikify the notebook into a hypernotebook. >> >> ok, it must be EASY to install. And LEGAL. >> >> MiniWiki is in python. I can do it in a self extracting installer as >> there is a nice free pone out there someplace- links please? BUT >> PYTHON IS ANOTHER MATTER. It needs to have python on the notebook, >> which is not the case. It aldso needs a small server in the notebook, >> and I have one in python and another in C++, which alas is not freeware. > > You can use py2exe to create an executable that includes Python. You can > create a single file executable or a directory that can be packaged up > with InnoSetup or another installer maker. That's part of it. a good installer is another, and I am loo]king at a couple. A solid and drool-proof server is the remaining leg of the tripod. So far, none of the servers I have seen are satisfactory on all scores- simplicity to install, reliability, economy of cost, (free or unlimited license to me for a modest fee) and ease to configure if the use\r so wishes. the closest I have yet seen SMALL HTTP SERVER. And it is very good. http://smallsrv.com/ The wiki code is considerably improved and is working 99.5% right, and is almost finished. I need to kick it hard with Doc Martins on to insure it is completely righteous before putting it to bed and worrying exclusively about the server and installer issues. This has to be baby carriage reliable and simple for the business road warrior who has not a geekified bone in their body. > > Python has a simple built-in web server - see SimpleHTTPServer and > CGIHTTPServer modules. Beyond that there are many freely distributed web > servers available, CherryPy, Karrigell and Snakelets are all pretty small. > > Kent >> >> The hurdle is it must be a legal and simple and almost droolproof >> solution from soup to nuts. >> >> the beta solution is working in this laptop NOW. Now how do I turn >> this into a turnkey solution for THEM? >> >> We are geeks. But the end result is intended for pointy haired bosses, >> soccer moms with Avon dealerships, and other regular humans. And as >> awlays, we must avoid the dread lawyer vampires. >> >> > > > -- Salute! -Kirk Bailey Think +-+ | BOX | +-+ knihT Fnord. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor