Re: add elements to indexed list locations
Thanks for the answers. Enumerating in reverse is indeed quite a smart idea. The fact is though, I overly simplified the task in the super-hero example. In the real case, the dictionary keys are not necessarily the indices for inserts; that is to say, the inserts do not necessarily take place in some sorted order. I think I was thinking more of a linked-list idea, where you do not store the indices as integers to some random access array but rather as pointers into list's nodes. Then the subsequent inserts would not hurt previously stored pointers. For those who know a bit C++/STL here is a sketch of the idea: name_list heros; heros.push_back("clark"); // ... add the rest indexed_name_list surnames; surnames.push_back( make_pair( find( heros.begin(), heros.end(), "clark"), "kent") ) ); // the find function returns an iterator to appropriate location // ... add the rest for_each(surnames.begin(), surnames.end(), insert_surnames) // insert_surnames is a callback that receives a single indexed surname // at a time and does the job, without affecting outer iterators. I was wondering how to make indices as *robust* in Python... Any ideas? PS: following is the compilable code-let of the task in C++ // #include #include #include #include #include #include using namespace std; typedef string name; typedef pair::iterator, string> indexed_name; void insert_name( list* into, indexed_name in ) { into->insert(in.first, in.second); } int main() { using namespace std; // Define super-heros (fathers ignored) list heros; heros.push_back("super"); heros.push_back("clark"); heros.push_back("spider"); heros.push_back("peter"); heros.push_back("bat"); heros.push_back("bruce"); // Assign father names to proper son list surnames; surnames.push_back( // ++ is to have surname inserted _after_ the name make_pair(++find(heros.begin(),heros.end(),"clark"), string("kent")) ); surnames.push_back( make_pair(++find(heros.begin(),heros.end(),"peter"), string("parker")) ); surnames.push_back( make_pair(++find(heros.begin(),heros.end(),"bruce"), string("wayne")) ); // Insert surnames succeeding appropriate heros for_each(surnames.begin(), surnames.end(), bind1st(ptr_fun(insert_name), &heros) ); // Salute the heros copy(heros.begin(),heros.end(),ostream_iterator(cout," ")); cout << endl; return 0; } // = -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem on win xp and run time error
Chris Lambacher wrote: > On Fri, Jun 16, 2006 at 06:11:53PM +, Michele Petrazzo wrote: >> Hi list, just found in this moment that my applications stop to >> work with win xp and receive this error: >> >> """ This application has requested the Runtime to terminate it in >> an unusual way. Please contact the application's support team for >> more information. """ >> >> (Note that the same application [python source code + py2exe] with >> python 2.3.x work well!) > Don't use the single file executatble option with py2exe and the > problem will go away. > I'm not using that option! (that has also problems on win9x with python+wx) I'm not using any of the "bundle_files" options, but only: zipfile = "lib/libraries.zip" > -Chris Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Legitimate use of the "is" comparison operator?
I just recently realized that the comparison operator "is" actually works for comparing numeric values. Now, I know that its intended use is for testing object identity, but I have used it for a few other things, such as type checking, and I was just wondering whether or not it is considered bad practice in the Python Community to use it for numerics as well. Example: a = range(5) b = range(5) if len(a) is len(b): print "They're the same size!" else: print "They're not the same size!" -- http://mail.python.org/mailman/listinfo/python-list
Re: Legitimate use of the "is" comparison operator?
On 17 Jun 2006 00:49:51 -0700, Mike Duffy <[EMAIL PROTECTED]> wrote: >I just recently realized that the comparison operator "is" actually >works for comparing numeric values. Now, I know that its intended use >is for testing object identity, but I have used it for a few other >things, such as type checking, and I was just wondering whether or not >it is considered bad practice in the Python Community to use it for >numerics as well. > >Example: > >a = range(5) >b = range(5) > >if len(a) is len(b): >print "They're the same size!" >else: >print "They're not the same size!" > No, this is wrong. >>> a = range(100) >>> b = range(100) >>> len(a) is len(b) False Use "is" to determine if two variables refer to exactly the same object, never to determine if two objects are equal. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem on win xp and run time error
Fredrik Lundh wrote: >> I see that the page says: """ This problem may occur when you use >> the /GR and the /MD compiler switches """ > > hint 1: the use of "may" in that sentence is intentional. This is the only, real, answer/solution that I found on internet, so I thought that was the problem. This also convince me because the page said that this happen only on win xp sp2, that is the platform where the problem happens! All work on win2k! > > hint 2: python 2.4 wasn't built with Visual C++ 6.0 (but python 2.3 > was) > But, I have problems only on with 2.4! With 2.3, and the *same* code, all work! > hint 3: on Windows, this message is displayed when the "abort" > function is called (including when an assert fails): > > http://msdn2.microsoft.com/en-us/library/k089yyh0.aspx > > the python interpreter will call abort() when it stumbles upon a > fatal error (Py_FatalError), or when an internal assertion fails. > when this happens, the program will print a "Fatal Python error" > message to both stderr and the debug console before it calls abort. Normally py2exe catch that messages and show them when the program are closed, but in this case, I don't see any message :( Is it possible that some, but I don't know what, can be modified from py2.3 to py2.4 and now my program wont work? Is there some tried that I can do for try to solve my issue? > > > Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Legitimate use of the "is" comparison operator?
Mike Duffy wrote: > I just recently realized that the comparison operator "is" actually > works for comparing numeric values. except that it doesn't work. > Now, I know that its intended use is for testing object identity, but > I have used it for a few other things, such as type checking, and I > was just wondering whether or not it is considered bad practice in > the Python Community to use it for numerics as well. writing broken code is never a good practice. >>> a = range(1) >>> if len(a) is len(a): ... print "same size" ... else: ... print "not the same size" ... not the same size (the reason that it appears to work for small integers is that the interpreter is caching the objects for some commonly used values, including small integers and one-character strings. but that's an interpreter implementation detail, not something you can rely on). -- http://mail.python.org/mailman/listinfo/python-list
Re: Legitimate use of the "is" comparison operator?
Jean-Paul Calderone wrote: > On 17 Jun 2006 00:49:51 -0700, Mike Duffy <[EMAIL PROTECTED]> wrote: > >> I just recently realized that the comparison operator "is" actually >> works for comparing numeric values. Now, I know that its intended use >> is for testing object identity, but I have used it for a few other >> things, such as type checking, and I was just wondering whether or not >> it is considered bad practice in the Python Community to use it for >> numerics as well. >> >> Example: >> >> a = range(5) >> b = range(5) >> >> if len(a) is len(b): >>print "They're the same size!" >> else: >>print "They're not the same size!" >> >> > > No, this is wrong. > An even simpler demo of why this DEAD WRONG: Consider: >>> 100 is (99+1) False This is asking if two different ways of computing the value (of 100) are stored internally as one object with that value or two separate objects each with that value. But, lest you think you understand that, consider also: >>> 2 is (1+1) True >>> 100 is 100 True This is highly implementation dependent. The current (C) implementation of Python has a cache for small integers, so the attempt to compare values with "is" works for some small integers, and fails for some large integers, but curiously, not all instances of comparing large integers. Gary Herron > a = range(100) b = range(100) len(a) is len(b) > False > > Use "is" to determine if two variables refer to exactly the same > object, never to determine if two objects are equal. > > Jean-Paul > -- http://mail.python.org/mailman/listinfo/python-list
Re: msvcr71.dll necessary? - Re: Which compiler will Python 2.5 / Windows (Intel) be built with?
Martin v. Löwis wrote: > robert wrote: > > codecs are in python24.dll, mscvr71, mfc71 and all are not. > However, they are not in core - the operating system demand-pages code, > loading into core memory only what is being used. So if you don't use > the codecs, they are not loaded into core. > > While mscvr71 is likely loaded into core (even though it is not in > python24.dll), mfc71.dll does not play a role at all in Python 2.4. > Python is written entire in C, not in C++. yes, yet as a consequence win32xx is forced to be linked against MFC71.dll (no other functional reason): another MegaByte which I'd need to package most times - while mfc42 from VC6 is pre-installed on each Windows. > >>* Is there a fundamental reason that the C-RTL of VC6 (which is >>pre-installed on on all Windows today) is not sufficient for current >>Python and extensions? instable? > > > The compiler that is used (VS 2003) won't ship it, and links with > msvcr71.dll. That's why that library version is used. hmm, yet msvcrt4 is obviously preinstalled on each Windows - and its in Windows Update Process. Its tagged: "4.20 - OS use only. DO NOT DISTRIBUTE") Think, in principle its possible to compile against that with VS2003/2005... ? ( think msvcrt4 is not delivered extra even in the python2.3 installer ) >>In case not: As the short living VS 2003 compiler is now more rare than >>the good old VC6, wouldn't it be better to switch back to VC6 for Py2.5 >>or at least to VC6 libs (which are maybe "free" of dev-license as they >>sit on each Windows). > > Better in what respect? Predictability of software development? > Certainly not: the development will be more predictable if a decision > that was once taken is implemented as promised. 2.4 and 2.5 compiled stuff is anyway not interchangeable - thus at alpha-stage a (down) step to a common system lib would probably have no countable negative effects at all. > Making more users happy? Certainly not, either. Some users request that > VS2005 is being used, not that VC6 is being used. Other users request > that Python 2.5 continues to be built with VS 2003. You can't please > everybody. Yet if the C runtime lib (distribution) problem is solved, the question of the compiler becomes irrelevant. Everybody could use his compiler without worry - a soft recommendation could be in the Python2.5 doc's to link extensions also against the same common basic ctrl in order to keep the numer of libs small. >>Maybe a suitable policy: the default crtl for Python should better be >>the default library of the OS and not that of a random compiler which is >>currently hip? > > That would make a good policy if the OS had a system C library. Windows > doesn't. Windows NT does have a CRT, namely crtdll.dll - but you weren't > suggesting to use that one, were you? msvcrt4 is probably a reliable system C lib and still used by most apps. Think it doesn't lack Pythons needs. there is also a "msvcrt.dll" - also updated by the Windows system. maybe its on each Windows ? On XP it has version 7. What is this? >>* can't the Mingw/gcc be used together with Windows default crt/mfc libs >>for Python2.5 ? - Python getting away the from this MS studio (lib) >>harassment? > > Sure, you can use gcc/mingw to build extensions for Python 2.4 and > Python 2.5. yes, the lib is 90% the object of concern. > >>* how many (serious) python users require to build distributable >>installers (which have carry the python-rtls and non-default crtl's)? > > > Apparently not many. I repeatedly asked for contribution of a That would be very intersting for me - number about where (project type, LOC, #-of-users) and how (system, distribution, ..) python is used. Is there already something. Maybe a research/poll in this NG would be feasible. > specification how pythonxy.dll should be modularized, and never > received one. Maybe most a most simple cutoff criteria with "costs" does it magically. Basic proposal: cost = (C1 * module-size - C2 * frequency-of-module-usage) I'd suggest: cutoff cost = 0 C1 = 1/200kB C2 = 1/80% Example CJK codecs: cost = 500k/200k - 30%/80% = 2.13 => too expensive by far Example zlib: cost = 70k/200k - 95%/80% = -0.84 => go in -robert -- http://mail.python.org/mailman/listinfo/python-list
Re: add elements to indexed list locations
levent wrote: > Thanks for the answers. Enumerating in reverse is indeed quite a smart > idea. > > The fact is though, I overly simplified the task in the super-hero > example. In the real case, the dictionary keys are not necessarily the > indices for inserts; that is to say, the inserts do not necessarily > take place in some sorted order. > > I think I was thinking more of a linked-list idea, where you do not > store the indices as integers to some random access array but rather as > pointers into list's nodes. Then the subsequent inserts would not hurt > previously stored pointers. For those who know a bit C++/STL here is a > sketch of the idea: > > name_list heros; > heros.push_back("clark"); > // ... add the rest > indexed_name_list surnames; > surnames.push_back( >make_pair( find( heros.begin(), heros.end(), "clark"), "kent") ) >); // the find function returns an iterator to appropriate location > // ... add the rest > > for_each(surnames.begin(), surnames.end(), insert_surnames) > // insert_surnames is a callback that receives a single indexed surname > // at a time and does the job, without affecting outer iterators. > > > I was wondering how to make indices as *robust* in Python... Any ideas? Python's list is technically a vector. You can therefore either search for the insertion point in a timely fashion: heros = ["super", "clark", "spider", "peter", "bat", "bruce"] names = [("clark", "kent"), ("peter", "parker"), ("bruce", "wayne")] for first, last in names: heros.insert(heros.index(first)+1, last) print heros or you have to snatch a real (linked) list from somewhere. Here's an ad-hoc implementation: class Node(object): def __init__(self, value, next=None): self.value = value self.right = next def __str__(self): return "List(%s)" % ", ".join(repr(n.value) for n in self) def __iter__(self): item = self while item: yield item item = item.right def find(self, value): for item in self: if item.value == value: return item raise ValueError("%r not found" % (value,)) def insert_after(self, value): self.right = Node(value, self.right) @staticmethod def from_list(items): items = iter(items) try: first = items.next() except StopIteration: raise ValueError("empty lists not supported") cur = head = Node(first) for value in items: node = Node(value) cur.right = node cur = node return head if __name__ == "__main__": heros = ["super", "clark", "spider", "peter", "bat", "bruce"] heros = Node.from_list(heros) names = [("clark", "kent"), ("peter", "parker"), ("bruce", "wayne")] surnames = [(heros.find(f), s) for f, s in names] print heros for node, value in surnames: node.insert_after(value) print heros Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Legitimate use of the "is" comparison operator?
Fredrik Lundh wrote: > > except that it doesn't work. > > writing broken code is never a good practice. > With all due respect, for some reason it seems to work on my machine. Because I certainly agree with you about writing broken code. Python 2.4.2 (#1, Jan 17 2006, 16:52:02) [GCC 4.0.0 20041026 (Apple Computer, Inc. build 4061)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> a = range(5) >>> b = range(5) >>> >>> if len(a) is len(b): ... print "They're the same size!" ... else: ... print "They're not the same size!" ... They're the same size! >>> > > (the reason that it appears to work for small integers is that the > interpreter is caching the objects for some commonly used values, > including small integers and one-character strings. but that's an > interpreter implementation detail, not something you can rely on). > That's very interesting. Thank you for explaining :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: python texts?
On 2006-06-17, nate <[EMAIL PROTECTED]> wrote: > reading Learning Python 2nd edition by O'Reilly. I am enjoying it at the I'd get the Python Cookbook, next. Dave Cook -- http://mail.python.org/mailman/listinfo/python-list
Re: Legitimate use of the "is" comparison operator?
Mike Duffy wrote: >> writing broken code is never a good practice. >> > With all due respect, for some reason it seems to work on my machine. if you always work with 5-item sequences, you don't need the test at all. -- http://mail.python.org/mailman/listinfo/python-list
[OT] Python Argentina T-shirt to exchange
Hi guys, sorry for this _very_ off-topic message. I'll be in Paris, France next week and I thought someone there might be interested to exchange this http://www.python.com.ar/moin/Remeras T-shirt (size M) with me? I'd really like to take home a py-french (or wherever) one instead. Thanks and sorry again if this has been an inappropriate place to make the request. Pablo -- http://mail.python.org/mailman/listinfo/python-list
Re: add elements to indexed list locations
In <[EMAIL PROTECTED]>, levent wrote: > I think I was thinking more of a linked-list idea, where you do not > store the indices as integers to some random access array but rather as > pointers into list's nodes. Then the subsequent inserts would not hurt > previously stored pointers. For those who know a bit C++/STL here is a > sketch of the idea: > > name_list heros; > heros.push_back("clark"); > // ... add the rest > indexed_name_list surnames; > surnames.push_back( >make_pair( find( heros.begin(), heros.end(), "clark"), "kent") ) >); // the find function returns an iterator to appropriate location > // ... add the rest > > for_each(surnames.begin(), surnames.end(), insert_surnames) > // insert_surnames is a callback that receives a single indexed surname > // at a time and does the job, without affecting outer iterators. > > > I was wondering how to make indices as *robust* in Python... Any ideas? What about putting all information for each super hero into an object or at least a list? And those objects/lists can then be stored into a dictionary with the first name of the heroes as key. Something like this: heroes = [['super', 'clark'], ['spider', 'peter'], ['bat', 'bruce']] name2hero = dict((hero[1], hero) for hero in heroes) fullnames = [['clark', 'kent'], ['peter', 'parker'], ['bruce', 'wayne']] for name, surname in fullnames: name2hero[name].append(surname) for hero in heroes: print 'Hello %s a.k.a %s %s' % tuple(hero) IMHO you shouldn't try to program C++ in Python. Take a step back and describe *what* you want to achieve and not *how* you do it in another language. And then implement it in Python. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Legitimate use of the "is" comparison operator?
Gary Herron wrote: > > >>> 100 is (99+1) > False > > >>> 2 is (1+1) > True > > >>> 100 is 100 > True > > This is highly implementation dependent. The current (C) implementation > of Python has a cache for small integers, so the attempt to compare > values with "is" works for some small integers, and fails for some large > integers, but curiously, not all instances of comparing large integers. > Ahh, thank you. That explains why Fredrick's and Jean-Paul's example did not work, but mine did (I was using *small* integers). Ok, well I definitely get the picture. Use the "is" operator for what it was intended for, or deal with broken code ;-) Thanks a lot guys. -- http://mail.python.org/mailman/listinfo/python-list
any subway experiences
thanks for reading -- http://mail.python.org/mailman/listinfo/python-list
Re: a good programming text editor (not IDE)
Istvan Albert wrote: > Scott David Daniels wrote: > > > To paraphrase someone else (their identity lost in my mental fog) about > > learning VI: > > "The two weeks you'll spend hating vi (or vim) as you learn it will > > be repaid in another month, ad the rest is pure profit." > > Time and again I hear this (no shortage of Vim fans, same with Emacs), > and I know I should know better but always believe them yet again. > Invariably I download Vim play with it for an hour, get increasingly > frustrated and give up. Most likely I'm greatly spoiled by using > EditPlus (Windows only), it just makes it so easy to do the basic > programming tasks that I need, everywhere else I turn I see far more > functionality but at the price of not being able to do basic tasks as > efficiently as I need them. > > Say I want to be able to execute the python program I'm currently > editing. Nothing simpler in EditPlus, Tools->Configure Tools->Add Tool > then specify which program you want to run, what parameters it takes > and whether to capture the output or not ... total time it took me > first time I wanted to do this ... about 3 minutes ... from now on > pressing Ctrl-1 while editing the source will execute the python on the > current source *and* it displays the output in a lower pane as it runs > *and* it allows me to simultanously edit the file *while* the program > is running. Outstanding. > > Yet after searching and reading stuff for more than an hour I was > unable to accomplish the same thing in Vim though I'm already familiar > enough with basic editing and setup (through my previous trials and > tribulations) ... I have a few solutions that end up doing something > similar but are quite a few keypresses longer both to invoke or to get > back to the source that I'm writing, or I lose editing control while > the program is running ... etc... > > So if the OP is on windows just head over and get EditPlus (UltraEdit > and TextPad seem to be similar), and just accept the fact that you are > already using an editor that as good as an editor can get ... I know > I'd pay that registration once again for an editor that works the same > way on Linux... > > i. I'm a huge EditPlus fan and there are not enough good things I can say about it. The main thing about GUIs which unix people don't seem to get is discoverability is key. Every time I've tried using x-emacs or x-anything (or even Scite as it seems to be popular), there is very little that is intuitive or obvious about the interface, and even though you have a GUI right there in front of you, things are still controlled in dot whatever files, with some special syntax and magic words for everything! Even doing a search and replace in x-emacs is f*cked up. I was trying to use it for something a few years ago (I dunno, maybe 2002 or 2003 on debian or 2000 on redhat), and it just didn't work the way I expected it to work, ie it didn't follow what has become the standard GUI (read: windows) way of doing things. There should be a dialog for search and replace. If it doesn't do it that way, then don't pretend to be a gui, because you're not, you're pandering to the "we want a gui crowd" while still stickin' it to 'em by forcing them to remember commands for shit like changing word wrapping (oh my god there's a *mode* for word wrapping? m-x-wtf change-the-mode-to-something-I-forget-what) and reminding everyone what a privilege it is to learn f***king lisp to enable some obscure little tweak which could just as easily have shown up in a checkbox. Scite was jacked because the main window didn't have anything discoverable on it, and one of the main menus just had a list of syntaxes you could use to highlight your code... and the other menu opened up your dot whatever file to change the settings. That's just retarded. I think there is a fine line between being too dumbed down to do anything (point click ooh aahh), and so "flexible", "customizable", and "free" that it feels you have to roll-your-own text editor each time you want to start a new project. This is the best article on guis and stuff I've read in a while. http://www.joelonsoftware.com/uibook/fog000249.html Anyway, the only thing editplus doesn't do that I wish it did is code folding. All the stuff you guys are talking about: line numbers, syntax highlighting, custom tools (running the interpreter), regexp search and replace, keeping your environment the same between sessions, soft word wrap, tab-vs-spaces, auto-indent, braces-matching, bla bla... it does it all in an appropriately gui manner without making you feel like a moron for not psychically knowing the command ahead of time, or for not having someone to copy a dot whatever file from, or not Reading TFM (which of course never tells you what you want to know anyway -- it's either a patronizingly simple-minded 3rd grade tutorial, or it tells you what a command does if you already know its f***king name!). And of course all these editp
Re: Legitimate use of the "is" comparison operator?
Mike Duffy wrote: > Ahh, thank you. That explains why Fredrick's and Jean-Paul's example > did not work, but mine did (I was using *small* integers). "small integers" is what the phrase "small integers" in the "small integers" and "small integers" parts of my reply referred too, of course. -- http://mail.python.org/mailman/listinfo/python-list
Iterating generator from C
Does messing with signal handlers and longjmp affect Python interpreter? I'm trying to find solution for problem, described in http://groups.google.com/group/comp.lang.python/browse_thread/thread/98cbae94ca4beefb/9d4d96fd0dd9fbc3 and came up with test application. It works well but i'm not sure it is ok for long-running python interpreter? #include #include #include const char *py_source = "def fn():\n" "yield 1\n"; jmp_buf env; enum _ { detect, no, yes } has_buggy_gen_iternext = detect; static sighandler_t old_abrt = SIG_DFL; void signal_handler (int sig) { if (sig == SIGABRT) longjmp(env, 1); } int main (int argc, char *argv[]) { Py_Initialize(); PyObject *globals = PyDict_New(); // insert function code into interpreter PyObject *code = PyRun_String(py_source, Py_file_input, globals, NULL); Py_DECREF(code); // compile call to the function code = Py_CompileString("fn()", "", Py_eval_input); // do call PyObject *gen = PyEval_EvalCode((PyCodeObject *)code, globals, NULL); gen = PyObject_GetIter((PyObject *)gen); // detect if we are using bad Python interpreter if (has_buggy_gen_iternext == detect) { if (setjmp(env) == 0) // first time, set signal handler old_abrt = signal(SIGABRT, signal_handler); else { // jumped here from signal handler -- bad Python has_buggy_gen_iternext = yes; signal(SIGABRT, old_abrt); } } if (has_buggy_gen_iternext == yes) printf("generators are disabled\n"); else { // iterate result PyObject *item; while ((item = PyIter_Next(gen))) { printf("> %ld\n", PyInt_AsLong(item)); Py_DECREF(item); } if (has_buggy_gen_iternext == detect) { // ok, restore old signal handler has_buggy_gen_iternext = no; signal(SIGABRT, old_abrt); } } Py_DECREF(gen); Py_DECREF(code); Py_DECREF(globals); Py_Finalize(); return 0; } -- http://mail.python.org/mailman/listinfo/python-list
Re: Which compiler will Python 2.5 / Windows (Intel) be built with?
[EMAIL PROTECTED] schreef: > * The code created by the Windows GCC is not as good as the one created > by the Microsoft compiler Isn't Python for other platforms built with GCC? Seems to me that if it GCC is good enough for other platforms, it's good enough for Windows. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Re: a good programming text editor (not IDE)
Tim Chase wrote: | > No need to argue. I started with vim, and finally switched to | > emacs less than one year later. | | Both are very-much-so good editors. I made the opposite switch | from emacs to vim in less than a year. Both are good^Wgreat | editors, so one's decision to use one over the other is more a | matter of working style. I don't grok LISP, and just never felt | at home in emacs, despite all the power I could see that was | there. I grok vim (and its similar power/extensibility), so I | migrated to it. I have to laugh at the whole holy-war thing, as | it's somewhat like arguing about a favorite color. "But blue is | so better than green! The sky is blue!" "Nuh, uh! Green is far | better than blue! Grass is green!" (okay, here in Texas, that | doesn't always hold as true...maybe personality #2 should be | arguing for brown instead). | | My best friend is an emacs user, and I'm a vimmer...it doesn't | come between us. :) You guys are not gonna believe this - I keep a low grade PC specially so that I can do my programming with Brief (yes the one by Underware) - and yes I know Emacs has a so called *crisp* emulator - but IMNSHO it sucks! I like the macros, I do some stuff with the macro language, and as a mostly assembler programmer, I adore the way it copies and pastes columns with minimal keystrokes And I switch between buffers (different files - "modules" in Python ) - with an alt n or alt - . and worse - like the confirmed Vi or Emacs user - the problem is that you get used to it, and ya dont wanna change... - Hendrik I wish I could run this on my Linux box -- http://mail.python.org/mailman/listinfo/python-list
Re: python texts?
Dave Cook wrote: > On 2006-06-17, nate <[EMAIL PROTECTED]> wrote: >> reading Learning Python 2nd edition by O'Reilly. I am enjoying it at the > I'd get the Python Cookbook, next. There's a jump. The Cookbook is quite advanced. I'd write code next. Then, I'd read through the docs for all the provided modules (fast, the idea is to know where to go back for detail, not to understand each module in depth), and write more code. If you want paper for going through the modules, next I'd read either Beazley's "Python Essential Reference" or Alex Martelli's "Python in a Nutshell." Choosing between P.E.R. and Nutshell is really quite individual. They are both great, thorough jobs that leave you with a wonderful reference work after you've read them. I'd say P.E.R. is terser, going for density and brevity, while the Nutshell is a bit more elaborative on what it covers. The choice between Martelli and Beazley is, I suspect, one of your learning style. Find somewhere to look at each (any edition) and read twenty pages from the middle. One of them will seem much better than the other, and it has everything to do with what you prefer. The Cookbook comes later. As does getting all the way through the challenge, but for puzzle lovers, it can be great fun. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
Raffael Cavallaro schrieb: > On 2006-06-16 17:59:07 -0400, Joachim Durchholz <[EMAIL PROTECTED]> said: > >> I think it's easier to start with a good (!) statically-typed language >> and relax the checking, than to start with a dynamically-typed one and >> add static checks. > > This is purely a matter of programming style. For explorative > programming it is easier to start with dynamic typing and add static > guarantees later rather than having to make decisions about > representation and have stubs for everything right from the start. Sorry for being ambiguous - I meant to talk about language evolution. I agree that static checking could (and probably should) be slightly relaxed: compilers should still do all the diagnostics that current-day technology allows, but any problems shouldn't abort the compilation. It's always possible to generate code that will throw an exception as soon as a problematic piece of code becomes actually relevant; depending on the kind of run-time support, this might abort the program, abort just the computation, or open an interactive facility to correct and/or modify the program on the spot (the latter is the norm in highly dynamic systems like those for Lisp and Smalltalk, and I consider this actually useful). I don't see static checking and explorative programming as opposites. Of course, in practice, environments that combine these don't seem to exist (except maybe in experimental or little-known state). Regards, Jo -- http://mail.python.org/mailman/listinfo/python-list
Re: msvcr71.dll necessary? - Re: Which compiler will Python 2.5 / Windows (Intel) be built with?
robert wrote: > hmm, yet msvcrt4 is obviously preinstalled on each Windows - and its in > Windows Update Process. Its tagged: "4.20 - OS use only. DO NOT > DISTRIBUTE") > Think, in principle its possible to compile against that with > VS2003/2005... ? > ( think msvcrt4 is not delivered extra even in the python2.3 installer ) Unfortunately, you also need the header files and an import library to link against this library. Likewise, for applications that bundle MFC, you need the corresponding set of header files and libraries. Microsoft does not provide import libraries for msvcrt4.dll anymore. >> Making more users happy? Certainly not, either. Some users request that >> VS2005 is being used, not that VC6 is being used. Other users request >> that Python 2.5 continues to be built with VS 2003. You can't please >> everybody. > > Yet if the C runtime lib (distribution) problem is solved, the question > of the compiler becomes irrelevant. Everybody could use his compiler > without worry - a soft recommendation could be in the Python2.5 doc's to > link extensions also against the same common basic ctrl in order to keep > the numer of libs small. Unfortunately, that is a real technological challenge. Where do you get the header files and import libraries, and how do you explain to your compiler to use those instead of the ones it comes with? > there is also a "msvcrt.dll" - also updated by the Windows system. maybe > its on each Windows ? On XP it has version 7. What is this? It used to be possible to link with it. See http://msdn2.microsoft.com/en-us/library/abx4dbyh(VS.80).aspx This is now a "known DLL", and meant for use by system-level components only. > Maybe most a most simple cutoff criteria with "costs" does it magically. > Basic proposal: > > cost = (C1 * module-size - C2 * frequency-of-module-usage) Unfortunately, that criterion cannot be determined in an objective manner. It's not possible to determine frequency-of-module-usage in any meaningful way for existing modules, let alone for modules that are contributed and to be included only in the upcoming release. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: any subway experiences
The berlin subway is great - especially during the worldcup the sheer amount of people from all over the world makes things interesting. HTH, Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting values from text file
Thus spoke Mirco Wahab (on 2006-06-16 21:21): > I used your example just to try that in python > (i have to improve my python skills), but waved > the white flag after realizing that there's no > easy string/var-into-string interpolation. I did another try on it, using all my Python resources available (and several cups of coffee) ;-) This scans your text for rules provided and extracts values and variable names and prints them at the end. I had some issues with python then: - no comment # after line continuation \\ - regular expressions (as I said before) ==> DATA = ''' An example text file: --- Some text that can span some lines. Apples 34 56 Ducks Some more text. 0.5 g butter -''' # data must show up before usage filter = [ # define filter table 'Apples (apples)', '(ducks) Ducks', '(butter) g butter', ] varname = {}# variable names to be found in filter varscanner = r'\\b(\S+?)\\b'# expression used to extract values example = DATA # read the appended example text, import re for rule in filter: # iterate over filter rules, rules will be in 'rule' k = re.search(r'\((.+)\)', rule) # pull out variable names ->k if k.group(1): # pull their values from text varname[k.group(1)] = \ re.search( re.sub(r'\((.+)\)', varscanner, rule), \ example ).group(1) # use regex in modified 'rule' for key, val in varname.items(): print key, "\t= ", val # print what's found <== I think, the source is quite comprehensible in Python, as is in Perl - if there weren't 'regex issues' ;-) Maybe some folks could have a look at it and convert it to contemporary Python Below ist the Perl program that was modified to correspond roughly 1:1 to the Python source above. Both will print: butter = 0.5 apples = 34 ducks= 56 Regards & thanks in advance Mirco ==> #/usr/bin/perl use strict; use warnings; my @filter = ( # define filter table 'Apples (apples)', '(ducks) Ducks', '(butter) g butter', ); my ($v, %varname) = ( '', () ); # variable names to be found in filter my $varscanner = qr{\b(\S+?)\b}; # expression used to extract values my $example = do { local$/; }; # read the appended example text, # change to <> for std input for (@filter) { # iterate over filter rules, rule line will be implicit ($_) $v = $1 if s/\((.+)\)/$varscanner/;# pull out variable names ->$1 $varname{$v} = $1 if $example =~ /$_/; # pull their values from text } # by using modified regex rule $_ print map { "$_\t= $varname{$_}\n"; } keys %varname; # print what's found __DATA__ An example text file: --- Some text that can span some lines. Apples 34 56 Ducks Some more text. 0.5 g butter - <== -- http://mail.python.org/mailman/listinfo/python-list
Re: Need Help comparing dates
> I will try to work through Tim's response. I tried using it > yesterday but I was really confused on what I was doing. I'll put my plug in for entering the code directly at the shell prompt while you're trying to grok new code or toy with an idea. It makes it much easier to see what is going on as you enter it. You can ask for any variables' value at any time. It's a small pain when you're entering some nested code, and biff up on the interior of it (throwing an exception, and having to restart the function-definition/loop/class-definition statement all over), but it certainly has its advantages for learning the language. On top of that, you can usually ask for help on any object, so if you wanted to know about the datetime module or the date object in the datetime module, you can just use >>> import datetime >>> help(datetime) >>> help(datetime.date) which will give you all sorts of documentation on a date object. I'm also partial to learning about what methods the object exposes via the dir() function: >>> dir(datetime.date) or >>> print "\n".join(dir(datetime.date)) IMHO, help() and dir() at the command-line combine to make one of Python's best selling points...ease of learning. I understand Perl and Ruby might have something similar, but I've never liked their idioms. Java/C/C++, you have the edit/compile/run cycle, so if you just want to explore some simple code ideas, you've got a 3-step process, not just a simple "try it out right here and now" method. I even stopped using "bc" as my command-line calculator, preferring the power of command-line python. :) Just a few thoughts on what made learning python easier for me. Again, if you have questions, and can't figure out the answers by stepping through the code in the command shell (or some strategically placed print statements), this is certainly the forum for asking those questions. It's full of smart and helpful folks. -tkc -- http://mail.python.org/mailman/listinfo/python-list
[OT] code is data
With the inclusion of ElementTree (an XML-parser) in Python25 and recent developments concerning JSON (a very Pythonesque but somewhat limited XML notation scheme, let's call it statically typed XML) Python seems to have reached a stage where it now seems to be possible to completely swallow lesser languages code, modify it, and spit out new source code targeting the original language the code was written in, or even make a translation to other languages. The idea is that we now have a fast parser (ElementTree) with a reasonable 'API' and a data type (XML or JSON) that can be used as an intermediate form to store parsing trees. Especially statically typed little languages seem to be very swallow-able. Maybe I will be able to reimplement GFABasic (my first love computer language, although not my first relationship) someday, just for fun. Then there are things like cTypes (calling functions from native DLL's) and PyPy (implementing Python in Python). All this taken together, to me it starts looking like we're now entering a territory that traditionally was exclusively in the Lisp domain. Yes, Python had eval and exec for a long time already, and metatypes and generators are having some strange unexplored possibilities too, but the day will come soon (and at last when PyPy is reaching execution speeds close to cPython) where Python will be able to swallow smaller languages, and finally it will be able to swallow its own tail, like Lisp but then more powerful (because of the widely used standard data types and the code exchange between languages that that makes possible). Your thoughts please. Anton -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
On 2006-06-17 07:03:19 -0400, Joachim Durchholz <[EMAIL PROTECTED]> said: > I don't see static checking and explorative programming as opposites. > Of course, in practice, environments that combine these don't seem to > exist (except maybe in experimental or little-known state). Right. Unfortunately the philosophical leanings of those who design these two types of languages tend to show themselves as different tastes in development style - for example, static type advocates don't often want a very dynamic development environment that would allow a program to run for testing even when parts of it arent defined yet, and dynamic type advocates don't want a compiler preventing them from doing so because the program can't yet be proven statically correct. Dynamic typing advocates don't generally want a compiler error for ambiguous typing - for example, adding a float and an int - but static typing advocates generally do. Of course there's little reason one couldn't have a language that allowed the full range to be switchable so that programmers could tighten up compiler warnings and errors as the program becomes more fully formed. Unfortunately we're not quite there yet. For my tastes something like sbcl*, with its type inference and very detailed warnings and notes is as good as it gets for now. I can basically ignore warnings and notes early on, but use them to allow the compiler to improve the code it generates once the program is doing what I want correctly. [*] I don't mean to exclude other common lisp implementations that do type inference here - I just happen to use sbcl. -- http://mail.python.org/mailman/listinfo/python-list
Re: Pycrypto
[EMAIL PROTECTED] wrote: > ValueError: Input strings must be a multiple of 16 in length As James Stroud noted, a CBC mode cipher is still a block cipher, and the input *must* be a multiple of the block size. OpenSSL provides a standard padding mechanism so that there are no input size limitations for any cipher. Have a look at http://tachyon.in/ncrypt/ It provides access to the OpenSSL ciphers (including padding). Regards Sreeram signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: wxpython: how do i write this without the id parameter?
Scott David Daniels: > John Salerno wrote: >> I was reading in the wxPython wiki that most of the time you don't have >> to include the id parameter at all, and you can just use keyword >> arguments for other parameters. But I'm having trouble converting this >> code into that method (i.e., without the id parameter) >> >> import wx >> >> class InputForm(wx.Frame): >> def __init__(self, parent, id, title): >> wx.Frame.__init__(self, parent, id, title) I usually do it like this: class InputForm(wx.Frame): def __init__(self, *args, **kwargs): super(InputForm, self).__init__(*args, **kwargs) ... Cheers, Frank -- http://mail.python.org/mailman/listinfo/python-list
Re: Which compiler will Python 2.5 / Windows (Intel) be built with?
Martin, Martin v. Löwis wrote: > > * In a professional environment, it opens up another can of potential > > problems, where one would rather like to stay with one single > > compiler/build system. > That's a theoretic argument to me: Can you name four or five problems > out of that can? In bigger (i.e. real-world) projects, it can be a lot of hassle switching to another compiler, even from the same vendor. Of course, in theory C and C++ compilers should be compatible, but in practice there's lots of small things that are implemented differently. Among them are #pragmas, the support for precompiled headers, template instantiation, different semantics for "half-legal" constructs etc. Also, some syntactic constructs which compile on one compiler are rejected by another compiler. Further, often code implicitely depends on the behaviour of one single compiler, although the developer doesn't really know that. Of course you can cry fool on the developer that wrote the code and blame him for not following the C-whatever spec, or not using the "correct" way to do X, but fact is, there's always stuff that will not work when switching to another compiler. And there's a bunch of other stuff that will appear to work but "activate" bugs in the control structure that were there previously but luckily did not manifest with the other compiler. Btw, the same goes for different versions of libraries, say different versions of wxWidgets, MFC, Visual Basic (anyone tried to switch from VB6 to VB.NET?) and of course also for different versions of Java and its libraries. > > * The Makefiles/build system will need to be changed to work with the > > GCC toolchain > > If you are using distutils, you don't need a Makefile, and the > setup.py won't have to be tweaked. If you are not using distutils, > but, say, nmake already, then you will already have an earlier version > of the compiler - how else did you create the nmake files in the first > place? We have lots of stuff written in VC++6 which is not distutils-compatible, and we can't really switch that code over to GCC anytime soon, see above. All in all, we would end up compiling something with VC, linking it with GCC to another VC app (Python). No, thanks. > Still, if you really cannot use gcc, then go ahead and compile with > VS 2005. Just make sure you link with mscvr71.dll. If you absolutely > need that to work, you will find a way to make it work. The question is, is it cheaper and more hassle-free to spend the time to "find a way to make it work" and hope everything goes smoothly (remember, the fact, that it says "Linker results: 0 errors / 0 warnings" does not mean that the app will work as expected and as tested before) or to buy VC (which costs a mere few hundred dollars). Bottom Line: As I said before, I don't have a problem using VC2003 or anything. It's by far the cheapest and easiest way just to buy VC2003 and be done with it, than to fiddle around with GCC or anything. I just think that Python should use the best technology available at the time of release, which is VC2005 on Windows. But as I indicated before, of course I do understand the argument that the release cycle has already been planned and should not be changed, so we'll just live with it as it is now. Markus -- http://mail.python.org/mailman/listinfo/python-list
Re: any subway experiences
a wrote: > thanks for reading Yah, the mass transit systems are, um, challenging but workable in many US cities. Canada's much better BUT the Subway framework that's not developed anymore had a dev mailing list: http://groups.google.com/group/subway-devel Google for "subway web framework". And, yeah, read http://catb.org/~esr/faqs/smart-questions.html -- http://mail.python.org/mailman/listinfo/python-list
Re: code is data
Anton Vredegoor wrote: > With the inclusion of ElementTree (an XML-parser) in Python25 and recent > developments concerning JSON (a very Pythonesque but somewhat limited > XML notation scheme, let's call it statically typed XML) Python seems to > have reached a stage where it now seems to be possible to completely > swallow lesser languages code, modify it, and spit out new source code > targeting the original language the code was written in, or even make a > translation to other languages. When I heard of the new AST based compiler, I thought it would finally be possible to extend things cleanly. Then I learned that they weren't going to allow modification of the AST. There are a lot of things you can't do in source if the language doesn't allow it. Python is pretty good compared to other languages, but it's still not possible to create new control structures with short circuit semantics. And that's one example. I saw the "make" statement as a breath of fresh air. Then it got shot down for what were, to me, totally trivial reasons. That's a second one. Sigh. John Roth > > > Your thoughts please. > > Anton -- http://mail.python.org/mailman/listinfo/python-list
Re: any subway experiences
a wrote: > thanks for reading > Too long experience with Paris (France) subway... Left Paris, feel better now !-) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: Legitimate use of the "is" comparison operator?
Mike Duffy wrote: > I just recently realized that the comparison operator "is" actually > works for comparing numeric values. It's only an implementation detail of CPython (and is only true for small integers - you'll find the limit in the CPython source code), not part of the language specifications. You should *not* relie on this behaviour. > Now, I know that its intended use > is for testing object identity, but I have used it for a few other > things, such as type checking, Don't use it for this neither unless you know exactly what you do. Use isinstance(obj, klass) instead - and yet better, don't check type at all if you can avoid it. > and I was just wondering whether or not > it is considered bad practice in the Python Community to use it for > numerics as well. It's even worse than a bad practice : it's an error. > Example: > > a = range(5) > b = range(5) > > if len(a) is len(b): > print "They're the same size!" > else: > print "They're not the same size!" > >>> a = range(32000) >>> b = range(32000) >>> len(a) is len(b) False -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: any subway experiences
a wrote: > thanks for reading Their bread is awful. -- http://mail.python.org/mailman/listinfo/python-list
Re: a good programming text editor (not IDE)
Hi 63q2o4i02 :-) Cream is a package built on top of vim that presents a more "Windows friendly" face to the vim/gvim editor. It is avaiable for Windows and Linux and might give you a single editor that you can use on more platforms, but maybe you might like the interface better. It does syntax hilighting for Python and code foding. http://cream.sourceforge.net/ - Paddy. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is fun (useless social thread) ;-)
John Salerno wrote: (snip) > So out of curiosity, I'm just wondering how everyone else came to learn > it. If you feel like responding, I'll ask my questions for easy quoting: > > Did you have to learn it for a job? It has never been an official requirement for any of the jobs I got since I'm a programmer, if that's what you mean. I discovered it while learning C++ / wxWidgets (someone talked me about Python as being pretty good for rapid prototyping). > Or did you just like what you saw and decided to learn it for fun? Well, I haven't be really impressed the first time - note that it was at the very end of the last century, with v1.5.2. But still I found the language suprisingly simple to get up and running with - seemed like the language was almost always reading my mind about how I would have named a librairy, function or whatever !-) So I ended up using it more and more when wanting to play with an idea or write a quick script... Until I realised than it was not the toy language I first thought it was (my, no access restrictors, not static typing, this just could not be a serious language, could it ?-), but a fantastic application programming language - far better than anything I had seen before (mostly 'modern' basics, C, C++, Pascal and Java...). > Also, how did you go about learning it? (i.e., like I described above, I > started with the main stuff then moved on to the different available > frameworks) Just used it, played with it, and lurked here. > Was there any necessity in the specifics you learned, or did you just > dabble in something (e.g. wxPython) for fun? I first used it for scripts, then turned to web programming (job opportunity), so I never really went very far in GUI programming with Python. > Are there still some things you feel you need to learn or improve? Yes - all and everything... -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list
Re: any subway experiences
On 2006-06-17, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > a wrote: >> thanks for reading > > Their bread is awful. At least they actually slice it now. Around here they used to just cut a shallow V-shaped notch in the top. -- Grant Edwards grante Yow! ... this must be what at it's like to be a COLLEGE visi.comGRADUATE!! -- http://mail.python.org/mailman/listinfo/python-list
Popen3 on Windows
I have an application that has been working fine on Linux, but now I need to port it to Windows XP. The program uses Popen3 to run another program. I use Popen3 so that I can access the pid attribute, which I use to kill the auxiliary program when necessary. Popen3 does not exist on Windows. I see os.popen2 and os.popen3, but they provide only file objects for stdin, stdout, and stderr so I don't see a way to kill the auxiliary program that I start. Is there a way to do this on Windows? -- Jeffrey Barish -- http://mail.python.org/mailman/listinfo/python-list
Re: File read and writing in binary mode...
> > Solution: only use binary files, and do the newline-translation yourself > if needed. > > Diez The probelm is if I can't use only binary files... How can I do the newline-translation myself ? if check the text and found the diferrence between binary and text is the '\r' instead of '\'n' . I can't change every '\n' because it will change the real '\n' ones -- http://mail.python.org/mailman/listinfo/python-list
Re: code is data
Anton Vredegoor wrote: > With the inclusion of ElementTree (an XML-parser) in Python25 and recent > developments concerning JSON (a very Pythonesque but somewhat limited > XML notation scheme, let's call it statically typed XML) > Your thoughts please. > > Anton Hi Anton. If you mean this JSON: http://www.json.org/example.html then I'd just point out that JSON isn't XML-like at all. In fact the examples look like valid Python nested dictionaries. - Pad. P.S. This is good too: http://en.wikipedia.org/wiki/JSON -- http://mail.python.org/mailman/listinfo/python-list
Re: Which compiler will Python 2.5 / Windows (Intel) be built with?
Roel Schroeven wrote: > Isn't Python for other platforms built with GCC? Seems to me that if it > GCC is good enough for other platforms, it's good enough for Windows. You clearly misunderstand the interface to the Windows OS & GUI system. Microsoft provides that interface through its language systems, and has used that edge to knock off other compilers (such as WatCom) by providing header files that are not standard C compatible. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Which compiler will Python 2.5 / Windows (Intel) be built with?
Scott David Daniels schreef: > Roel Schroeven wrote: >> Isn't Python for other platforms built with GCC? Seems to me that if it >> GCC is good enough for other platforms, it's good enough for Windows. > > You clearly misunderstand the interface to the Windows OS & GUI system. Very well possible. > Microsoft provides that interface through its language systems, and has > used that edge to knock off other compilers (such as WatCom) by > providing header files that are not standard C compatible. It seems that many people successfully use mingw. At work I use a Borland compiler all the time, without compatibility problems with Windows' APIs. But what I meant was not related to interface compatibilities, but to the performance of the generated code: many people say that the code generated by gcc is not as well optimized as code generated by Microsoft's compilers. Yet I never hear complaints about that from people who use Python on e.g. Linux, where Python is compiled with gcc. So, while there might be valid reasons not to use mingw, as far as I can see the optimization capabilities of the compiler are not a compelling reason. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
PyObject_SetItem(..) *always* requires a Py_INCREF or not?
I would think everytime you add an item to a list you must increase reference count of that item. http://docs.python.org/api/refcountDetails.html has an example that seems to contradict that int set_all(PyObject *target, PyObject *item) { int i, n; n = PyObject_Length(target); if (n < 0) return -1; for (i = 0; i < n; i++) { if (PyObject_SetItem(target, i, item) < 0) return -1; } return 0; } *WHY* don't you need a Py_INCREF(item); in the for loop!?!?!? Thanks! Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: PyObject_SetItem(..) *always* requires a Py_INCREF or not?
[EMAIL PROTECTED] > I would think everytime you add an item to a list you must increase > reference count of that item. _Someone_ needs to. When the function called to add the item does the incref itself, then it would be wrong for the caller to also incref the item. > http://docs.python.org/api/refcountDetails.html has an example that > seems to contradict that > > int > set_all(PyObject *target, PyObject *item) > { > int i, n; > > n = PyObject_Length(target); > if (n < 0) > return -1; > for (i = 0; i < n; i++) { > if (PyObject_SetItem(target, i, item) < 0) > return -1; > } > return 0; > } > > *WHY* don't you need a Py_INCREF(item); in the for loop!?!?!? You should take a break, and read that section again later ;-) The _point_ of that example is in fact to illustrate that you don't need to incref when calling PyObject_SetItem(). While I can't know, I'm guessing that you're still "seeing" PyList_SetItem() here, which has radically different behavior. PyList_SetItem() steals a reference to its second argument, but PyObject_SetItem() does not. Read the whole section again from its start, and this should be much clearer the second time through. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyObject_SetItem(..) *always* requires a Py_INCREF or not?
[EMAIL PROTECTED] wrote: > int > set_all(PyObject *target, PyObject *item) > { > int i, n; > > n = PyObject_Length(target); > if (n < 0) > return -1; > for (i = 0; i < n; i++) { > if (PyObject_SetItem(target, i, item) < 0) > return -1; > } > return 0; > } > > *WHY* don't you need a Py_INCREF(item); in the for loop!?!?!? Thats because PyObject_SetItem automatically increases the refcount of the 'item' that you pass. Whereas, PyTuple_SetItem and PyList_SetItem *DONT* automatically increment the refcount. Sreeram signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: code is data
Paddy wrote: > Anton Vredegoor wrote: > > With the inclusion of ElementTree (an XML-parser) in Python25 and recent > > developments concerning JSON (a very Pythonesque but somewhat limited > > XML notation scheme, let's call it statically typed XML) > > > > Your thoughts please. > > > > Anton > > Hi Anton. > If you mean this JSON: http://www.json.org/example.html > then I'd just point out that JSON isn't XML-like at all. In fact the > examples look like valid Python nested dictionaries. It is the same JSON. JSON is typically seen as a human friendly replacement for some of the functions that XML is otherwise used for, where the full blown XML spec is an overkill and JSON does not need complicated parsers in some common languages because it can express hierarchical data just like XML. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is fun (useless social thread) ;-)
In 2002, I was in need of a multi-platform language. My choice became Python, in spite of friends fiercly defending Perl and some interesting Slashdot-articles on Ruby. But back on university, I met a very, very pretty C++ girl who said many favourable things about Python. She never became mine, but the sympathy for Python that she implanted in my mind, turned out to make me immune against the Perl propaganda. So Python (for me) could be said to be either a substitute for the prettiest of the (many) pretty girls of Norway or a mindchild of the same. I found a script demonstrating search/replace in files. And even if I hadn't coded in a year, I found Python surprisingly easy to read, understand and change. So there I was. > Did you have to learn it for a job? No, but I use it as often as possible in work contexts. > Or did you just like what you saw and decided to learn it for fun? That's more like it. > Also, how did you go about learning it? I ported som other scripts (Bash, PHP, and DOS bat-files) to Python while searching the net each time I became lost. Porting is a good learning method. > Was there any necessity in the specifics you learned, > or did you just dabble in something > (e.g. wxPython) for fun? Mostly fun and some practical problems. Later I've used Boa Constructor to make GUI's for some customers. > Are there still some things you feel you need to learn or improve? Sure, I struggle with OO when it gets complicated and new features like decorators. And idioms. But generally it's programming skills and algorithmic scent I need. > Additional comments/complains here: :) I'm a bit afraid that the new features and the turning to concepts like iterators and generators are making Python elitistic. Old python code floating around the net is generally easy to read, while newer often is harder to grasp. I don't like it when my own inherent stupidity becomes to obvious to hide. -- http://mail.python.org/mailman/listinfo/python-list
Re: code is data
Anton Vredegoor wrote: > With the inclusion of ElementTree (an XML-parser) in Python25 and recent > developments concerning JSON (a very Pythonesque but somewhat limited > XML notation scheme, let's call it statically typed XML) Python seems to > have reached a stage where it now seems to be possible to completely > swallow lesser languages code, modify it, and spit out new source code > targeting the original language the code was written in, or even make a > translation to other languages. > > The idea is that we now have a fast parser (ElementTree) with a > reasonable 'API' and a data type (XML or JSON) that can be used as an > intermediate form to store parsing trees. Especially statically typed > little languages seem to be very swallow-able. Maybe I will be able to > reimplement GFABasic (my first love computer language, although not my > first relationship) someday, just for fun. > > Then there are things like cTypes (calling functions from native DLL's) > and PyPy (implementing Python in Python). > > All this taken together, to me it starts looking like we're now entering > a territory that traditionally was exclusively in the Lisp domain. > > Yes, Python had eval and exec for a long time already, and metatypes and > generators are having some strange unexplored possibilities too, but the > day will come soon (and at last when PyPy is reaching execution speeds > close to cPython) where Python will be able to swallow smaller > languages, and finally it will be able to swallow its own tail, like > Lisp but then more powerful (because of the widely used standard data > types and the code exchange between languages that that makes possible). > > Your thoughts please. I don't share your optimism at all. Most of the things you mentioned have existed for long. Just because some of them are now included in the standard library isn't going to change things drastically. Installing them earlier was never hard at all. People like to call everything with the lightest semblence, a DSL. That gives the feel that the language is more powerful. Ruby people do it all the time. Python cannot be called a DSL language until, creating them is a natural language feature (like Lisp). And that does not seem to be happening anytime soon. Boo for example allows you to write new constructs with it's AST library. It still cannot be called a DSL "language". People have however written various language interpreters (Scheme, Forth and yes, even Basic) in Python, just for kicks. Still does not make it a DSL language anymore than it makes C a DSL language. At present, the closest thing to writing a DSL in Python is Logix http://livelogix.net/logix/ Too bad though, the project is defunct and there has never been enough interest in it. Personally, I would like to see macros in Python (actually Logix succeeding is good enough). But I am no language designer and the community has no interest in it. When I absolutely need macros, I will go elsewhere. -- http://mail.python.org/mailman/listinfo/python-list
Re: Which compiler will Python 2.5 / Windows (Intel) be built with?
[EMAIL PROTECTED] wrote: > Bottom Line: As I said before, I don't have a problem using VC2003 or > anything. It's by far the cheapest and easiest way just to buy VC2003 > and be done with it, than to fiddle around with GCC or anything. I just > think that Python should use the best technology available at the time > of release, which is VC2005 on Windows. But as I indicated before, of > course I do understand the argument that the release cycle has already > been planned and should not be changed, so we'll just live with it as > it is now. Thanks for the confirmation; that's good enough for me. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Popen3 on Windows
Dennis Lee Bieber wrote: > On Sat, 17 Jun 2006 11:46:29 -0600, Jeffrey Barish > <[EMAIL PROTECTED]> declaimed the following in comp.lang.python: > >> I start. Is there a way to do this on Windows? > > There is no safe, easy, way to reliably kill a program on Windows... > > Hmmm, there's one I hadn't know about... > http://www.tech-recipes.com/windows_tips446.html > Ah, not supplied in WinXP Home (my desktop is Pro) > > Seems besides taskkill, there is also a tskill with different > arguments... > > The M$ response > http://support.microsoft.com/default.aspx?scid=KB;en-us;178893&; > > > Granted, these don't explain how to get the PID in the first place > from Python. > > If possible, try using the subprocess module... It seems to have a > PID attribute. > from http://docs.python.org/dev/lib/module-subprocess.html """ 16.1 subprocess -- Subprocess management New in version 2.4. The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module *intends to replace* several other, older modules and functions, such as: os.system os.spawn* os.popen* popen2.* commands.* """ -- http://mail.python.org/mailman/listinfo/python-list
Re: [OT] Python Argentina T-shirt to exchange
Hi! You can post your message on fr.comp.lang.python Bon voyage en France ! @-salutations -- Michel Claveau sites : http://mclaveau.com http://bergoiata.org http://ponx.org -- http://mail.python.org/mailman/listinfo/python-list
Re: a good programming text editor (not IDE)
> > Cream is a package built on top of vim that presents a more "Windows > friendly" face to the vim/gvim editor. Cool thanks, I'll check it out. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is fun (useless social thread) ;-)
Thus spoke Sybren Stuvel (on 2006-06-17 22:01): > Rune Strand enlightened us with: >> But back on university, I met a very, very pretty C++ girl who said >> many favourable things about Python. > > Rr a very, very pretty girl that likes C++ and Python. > Does it get better? It does: http://www.cafepress.com/buy/python/-/pv_design_prod/p_stickem.23651835/pNo_23651835/id_7539588/ Regards Mirco -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting values from text file
On Sat, 17 Jun 2006 14:20:44 +0200 Mirco Wahab <[EMAIL PROTECTED]> wrote: > Thus spoke Mirco Wahab (on 2006-06-16 21:21): > > > I used your example just to try that in python > > (i have to improve my python skills), but waved > > the white flag after realizing that there's no > > easy string/var-into-string interpolation. > > I did another try on it, using all my Python > resources available (and several cups of coffee) > ;-) > > This scans your text for rules provided > and extracts values and variable names > and prints them at the end. > > I had some issues with python then: > - no comment # after line continuation \\ > - regular expressions (as I said before) Thanks! The code is a very good starting point for me! I already managed to change it and I see I need to make it a bit more robust. And the next challange I have is to extract n values from one line. I mean: 23 Apples 234 Lemons 4 Eggs for example. Again thanks. And thanks to all others for the suggestions. I have looked at all and learned a lot of python. I probably will end up with a mixture of several approaches. Preben -- http://mail.python.org/mailman/listinfo/python-list
Cycles between package imports
Hi I'm a tad confused over a problem involving cycles between packages. Assume the following sets of files:: driver.py a/__init__.py a/alice.py b/__init__.py b/bob.py Basically, two packages a and b. Driver simply imports one of the two. This is the file that gets run:: , (driver.py) | | import a.alice | ` The package initialization files (__init__.py) both contain nothing. a.alice imports b.bob, and b.bob imports a.alice. The following works fine: , (a/alice.py) | | import b.bob | ` , (b/bob.py) | | import a.alice | ` However, if I change b/bob.py to import using "from" syntax, i.e.: , (b/bob.py) | | from a import alice | ` It does not work anymore:: Traceback (most recent call last): File "driver.py", line 3, in ? import a.alice File "/tmp/experiments/import-cycle/a/alice.py", line 9, in ? import b.bob File "/tmp/experiments/import-cycle/b/bob.py", line 9, in ? from a import alice ImportError: cannot import name alice So cycles between packages do not behave as cycles between modules--there is a subtlety. At the time that b/bob.py attempts to import a.alice, a.alice is still being imported (i.e. executed), and there is a difference between import a.alice and from a import alice I don't see why the reference to module a.alice could not be available via the "from" syntax, even if it is still incompletely initialized at the time of import. Can anyone shed some light onto this? Is there a rule for determining when a module becomes available to import from a package using the "from" syntax? -- http://mail.python.org/mailman/listinfo/python-list
Standard Yes / No Windows Dialog box creation
I found a way to create "Open File" or "Open Folder" windows dialog boxes, but not to create an easier Yes / No dialog box... Maybe someone has a solution for this? -- http://mail.python.org/mailman/listinfo/python-list
Re: Standard Yes / No Windows Dialog box creation
[EMAIL PROTECTED] wrote: > I found a way to create "Open File" or "Open Folder" windows dialog > boxes, but not to create an easier Yes / No dialog box... > Maybe someone has a solution for this? > Do it just the same way as you did it with the "Open File" or "Open Folder" windows dialog. What is your problem with it? Claudio -- http://mail.python.org/mailman/listinfo/python-list
statically linked python
Hi: I have searched the docs and google but have not totally figured out how to accomplish my task: On a linux box, I want to compile and link python so that it uses no shared libraries, but does support import of some "extra" modules. I have made a few attempts but with limited success. In particular, I have tried things like adding -static to the compiler options in the Makefile. At one point I managed to build a python that was close to what I wanted, e.g. when I ran "ldd python", it said: not a dynamic executable In that version, when I do some imports, e.g. sys, os, etc. they load fine. But, when I try to import some other modules, e.g. time, they are not found. I have tried similar procedures while also altering Modules/Setup.local (produced by configure) to contain: time timemodule.c # -lm # time operations and variables There has to be a simple, "elegant" way to accomplish this which I am simply overlooking. Any help would be appreciated. Thanks. --ralph -- http://mail.python.org/mailman/listinfo/python-list
Re: Standard Yes / No Windows Dialog box creation
Claudio Grondi wrote: > [EMAIL PROTECTED] wrote: >> I found a way to create "Open File" or "Open Folder" windows dialog >> boxes, but not to create an easier Yes / No dialog box... >> Maybe someone has a solution for this? I've never seen "easier" way to do it, but my solution for you if you want to create a GUI application without learning any GUI programming would be to consider Glade, wxGlade and such... >> > Do it just the same way as you did it with the "Open File" or "Open > Folder" windows dialog. What is your problem with it? > I think what he means by "create" is somethink like win32ui.CreateFileDialog() because of the "easier" part. > Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: Standard Yes / No Windows Dialog box creation
[EMAIL PROTECTED] wrote: > I found a way to create "Open File" or "Open Folder" windows dialog > boxes, but not to create an easier Yes / No dialog box... > Maybe someone has a solution for this? Assuming you are on MS Windows. import win32api, win32con win32api.MessageBox(0, "Question", "Title", win32con.MB_YESNO) -- http://mail.python.org/mailman/listinfo/python-list
Re: statically linked python
Ralph Butler wrote: > Hi: > > I have searched the docs and google but have not totally figured > out how to accomplish my task: On a linux box, I want to compile > and link python so that it uses no shared libraries, but does support > import of some "extra" modules. I have made a few attempts but > with limited success. In particular, I have tried things like > adding -static to the compiler options in the Makefile. > > At one point I managed to build a python that was close to what I > wanted, e.g. when I ran "ldd python", it said: > not a dynamic executable > In that version, when I do some imports, e.g. sys, os, etc. they > load fine. But, when I try to import some other modules, e.g. time, > they are not found. I have tried similar procedures while also > altering Modules/Setup.local (produced by configure) to contain: > time timemodule.c # -lm # time operations and variables > > There has to be a simple, "elegant" way to accomplish this which I am > simply overlooking. Any help would be appreciated. This has nothing to do with python. glibc doesn't support loading shared libraries into statically linked executables. At least it didn't support in 2002: http://www.cygwin.com/ml/libc-alpha/2002-06/msg00079.html Since it still doesn't work most likely it is still not supported, but you may ask glibc developers what is the problem. -- http://mail.python.org/mailman/listinfo/python-list
Re: Which compiler will Python 2.5 / Windows (Intel) be built with?
Roel Schroeven wrote: > ... But what I meant was not related to interface compatibilities, but to > the performance of the generated code: many people say that the code > generated by gcc is not as well optimized as code generated by > Microsoft's compilers. Yet I never hear complaints about that from > people who use Python on e.g. Linux, where Python is compiled with gcc. > So, while there might be valid reasons not to use mingw, as far as I can > see the optimization capabilities of the compiler are not a compelling > reason. I musunderstood you. I thought you were advocating that Python itself be built on gcc, obviating many compiler access issues. That wouldn't work because gcc cannot, by itself (as I understand it) get to all the nooks and crannies a windows developer may need to traverse. I know I just repeated my argument here against a strawman, but that was really for other readers, not for you. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: File read and writing in binary mode...
Hi, I'm sorry, but you have a conceptual error there. Text files differ from binary files because they are not considered raw. When you say that this or that file is a text file, python and/or the operating system takes the liberty to insert and or remove semantics from the file, according to some formatting agreed/imposed by them. Text files are formatted files. Binary files are raw files. You can't expect by any means that python will respect your raw data when writing text files. The solution to the question "how can I write a binary file into a text file" requires that you convert the binary file to a format suitable for textual access. For example, you can "uuencode" the binary file inside your text file. In simple terms: mytext = serialize(binary_file.read()) text_file.write(mytext) ... mydata = deserialize(text_file.read()) The functions "serialize" and "deserialize" are responsible for converting the binary data to/from some textual representation. HOWEVER, why would you want to put binary data into a text file ? Is this some information that will be used by your application ? Or will you transfer it to some other person in a portable way ? Maybe you should leave those files alone and not try to merge them. If it is a complex structure you should put it into a database instead of doing those strange things. In the worst case, you could just write a text file, write a binary file and concatenate them later. See if this really is a requirement for your project. [EMAIL PROTECTED] wrote: > Hi, > > I'm trying to open a file (any file) in binary mode and save it inside > a new text file. > After that I want to read the source from the text file and save it > back to the disk with its original form. The problem is tha the binary > source that I extract from the text file seems to be diferent from the > source I saved. Here is my code: > 1) > handle=file('image.gif','rb') > source=handle.read() > handle.close() > > if I save the file directly everything is well : > 2A) > handle=file('imageDuplicated.gif','wb') > handle.write(source) > handle.close() > > the file imageDuplicated.gif will be exactly the same as the original > image.gif. > But if I save the source to a text file I have porblem : > 2B) > handle=file('text.txt','w') > handle.write(source) > handle.close() > > handle=file('text.txt','r') > source2=handle.read() > handle.close() > > handle=file('imageDuplicated.gif','wb') > handle.write(source2) > handle.close() > > the files are completly different and I even cant display the image > from the imageDuplicated.gif . > > something changes when I save the source in the text file because in > 2B) source == source2 returns a False . > I suspect that maybe the encoding is making a conflict but I don't know > how to manipulate it... > Every help is welcome, thanks. -- http://mail.python.org/mailman/listinfo/python-list
Tkinter question.
Hi, I'd like to create buttons on the fly that will call the same function, and the function in question has to know what was the name of the button that called it. Unless there is a preferred way for doing this.. Perhaps creating a new function on the fly along with the new button? Please help.. thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter question.
Update: I found a way to do what I want with RadioButton with option indicatoron=0 which creates a bunch of what looks like regular buttons except that when one is pressed the other one is depressed and the value of the same variable is changed. Thanks dear me. [EMAIL PROTECTED] wrote: > Hi, I'd like to create buttons on the fly that will call the same > function, and the function in question has to know what was the name of > the button that called it. Unless there is a preferred way for doing > this.. Perhaps creating a new function on the fly along with the new > button? Please help.. thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting values from text file
Thus spoke Preben Randhol (on 2006-06-17 23:25): > The code is a very good starting point for me! I already > managed to change it and I see I need to make it a bit more robust. I think, the only thing you have to look at - is the congruence of the regex-based filter rule and the text. suppose you have a text: Apples 34 23 Apples, 234 Lemons 4 Eggs (note the comma!) and some rules: ... '(apples) Apples', 'Apples (apples)', ... the former program would handle that alright after changing the variable assignment from: if k.group(1): varname[k.group(1)] = to if k.group(1): varname[k.group(1)] += (note the +=) and the result would be: 'apples = 57'. It would add up all values corresponding to one variable. aehhm ... would be so in Perl, but Python throws another stone at you: - you have to explicitly instantiate a dictionary value (with 0) if/before you want in-place add to it (why is that?) - you can't have a return value from a regex object auto-converted to a number even if it _is_ a number and smells like a number (???) with these two nasty surprises, out extractor-loop looks like this: for rule in filter: k = re.search(r'\((.+)\)', rule) # pull out variable names ->k if k.group(1): # pull their values from text if not varname.has_key(k.group(1)): varname[k.group(1)] = 0; varname[k.group(1)] += float( \ re.search( re.sub(r'\((.+)\)', varscanner, rule), \ example ).group(1) ) # use regex in modified 'rule' whereas the in Perl-loop, only + to += would change for (@filter) { $v = $1 if s/\((.+)\)/$varscanner/; # pull out variable names ->$1 $varname{$v} += $1 if $example =~ /$_/; # pull their values from text } I'll add the complete python program which handles all cases you mentioned. Regards Mirco ==> DATA = ''' An example text file: --- Some text that can span some lines. Apples 34 23 Apples, 234 Lemons 4 Eggs 56 Ducks Some more text. 0.5 g butter --''' # data must show up before usage filter = [ # define filter table '(apples) Apples', 'Apples (apples)', '(ducks) Ducks', '(lemons) Lemons', '(eggs) Eggs', '(butter) g butter', ] varname = {}# variable names to be found in filter varscanner = r'\\b(\S+?)\\b'# expression used to extract values example = DATA # read the appended example text, import re for rule in filter: # iterate over filter rules, rules will be in 'rule' k = re.search(r'\((.+)\)', rule) # pull out variable names ->k if k.group(1): # pull their values from text if not varname.has_key(k.group(1)): varname[k.group(1)] = 0; varname[k.group(1)] += float( \ re.search( re.sub(r'\((.+)\)', varscanner, rule), \ example ).group(1) ) # use regex in modified 'rule' for key, val in varname.items(): print key, "\t= ", val # print what's found <== -- http://mail.python.org/mailman/listinfo/python-list
Re: python texts?
>> I'd say P.E.R. is terser, going for >> density and brevity, while the Nutshell is a bit more elaborative >> on what it covers. The choice between Martelli and Beazley is, I >> suspect, one of your learning style. Yes, sometimes Beazley is too terse if you're reading about something for the first time. But he's the best when you need to freshen your knowledge on a module or function you used three months ago. When in doubt, get both Beazley & Martelli. And follow with the Cookbook. Note the Martelli Nutshell is coming out in a new edition in early July. You can preorder. http://tinyurl.com/pkczm rd -- http://mail.python.org/mailman/listinfo/python-list
Re: code is data
> Personally, I would like to see macros in Python (actually Logix > succeeding is good enough). But I am no language designer and the > community has no interest in it. When I absolutely need macros, I will > go elsewhere. One must wonder, when is that? When do you absolutely need macros? -- mvh Björn -- http://mail.python.org/mailman/listinfo/python-list
Easy question on minidom
I am using minidom to parse a 20,000 line XML file. I have a few instances where the number of child nodes of a particular node can be variable in number. To access them I am doing something like the following... xmldoc = minidom.parseString(r) results = xmldoc.childNodes[0] for myNode in results.childNodes[1].childNodes: do Stuff with myNode... problem is I am having a heck of a time trying to access the value of the node. For instance I get things like this But I need the values... any help here? -- http://mail.python.org/mailman/listinfo/python-list
how can get the module global symbol table from a function or method which it is called?
when a function or method is called,how can get the module global symbol table from which it is called,not the module where it is defined(this is easy). thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: statically linked python
Serge Orlov wrote: > Ralph Butler wrote: >> Hi: >> >> I have searched the docs and google but have not totally figured >> out how to accomplish my task: On a linux box, I want to compile >> and link python so that it uses no shared libraries, but does support >> import of some "extra" modules. I have made a few attempts but >> with limited success. In particular, I have tried things like >> adding -static to the compiler options in the Makefile. >> >> At one point I managed to build a python that was close to what I >> wanted, e.g. when I ran "ldd python", it said: >> not a dynamic executable >> In that version, when I do some imports, e.g. sys, os, etc. they >> load fine. But, when I try to import some other modules, e.g. time, >> they are not found. I have tried similar procedures while also >> altering Modules/Setup.local (produced by configure) to contain: >> time timemodule.c # -lm # time operations and variables >> >> There has to be a simple, "elegant" way to accomplish this which I am >> simply overlooking. Any help would be appreciated. > > This has nothing to do with python. glibc doesn't support loading > shared libraries into statically linked executables. At least it didn't > support in 2002: > http://www.cygwin.com/ml/libc-alpha/2002-06/msg00079.html > Since it still doesn't work most likely it is still not supported, but > you may ask glibc developers what is the problem. > I do not want to load them. I want to statically link the code for a module (e.g. time) directly into the statically linked executable. Sorry if that was not clear. -- http://mail.python.org/mailman/listinfo/python-list
Re: how can get the module global symbol table from a function or method which it is called?
I mean the way not passing parameter to the fonction or the method. ygao wrote: > when a function or method is called,how can get the module global > symbol table from which > it is called,not the module where it is defined(this is easy). > thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython question
[EMAIL PROTECTED] wrote: > >I tried to follow wxPython Demo examples to understand it better. I >used wxGlade to generate my code from the GUI builder. > >When I try to see the code for Menu and Menubar I see a little mismatch >in the way functions are being used. > >For example, wxGlade produces code like this > >self.Action = wx.Menu() >self.AddComputer = wx.MenuItem(self.Action, wx.NewId(), _("Add >Computer"), "",wx.ITEM_NORMAL) >self.Action.AppendItem(self.AddComputer) >## Code end > >and in the demo it is gives as > >self.Action = wx.Menu() >Action.append(201, "Add Computer") ># Code end > >Can somebody please explain this discrepancy ? It's not really a "discrepancy". It's just that the latter example is a shortcut for the first. (Well, it would be a shortcut if you used "201" instead of "wx.NewId() in the first.) wxPython has, over the years, developed sensible shortcuts for many common operations. The GUI generators tend to use the "long" way, since that tends to be the original method that will work with any version. Also note that, in the first example, you are given a wx.MenuItem object to work with, should you need it. The second example hides it. It is rarely necessary to access a wx.MenuItem directly, so this is not usually an issue. -- - Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: add elements to indexed list locations
levent wrote: > Thanks for the answers. Enumerating in reverse is indeed quite a smart > idea. > > The fact is though, I overly simplified the task in the super-hero > example. In the real case, the dictionary keys are not necessarily the > indices for inserts; that is to say, the inserts do not necessarily > take place in some sorted order. > > I think I was thinking more of a linked-list idea, where you do not > store the indices as integers to some random access array but rather as > pointers into list's nodes. Then the subsequent inserts would not hurt > previously stored pointers. For those who know a bit C++/STL here is a > sketch of the idea: Sorry, I don't know C++/STL, so I don't understand the example you gave. If your dict doesn't already come with the indices, can't you just create a dict that does? >>> heros = ["super", "clark", "spider", "peter", "bat", "bruce"] >>> names = dict(clark="kent", peter="parker", bruce="wayne") >>> heros_indices = {} >>> for index, hero_word in enumerate(heros): ... if hero_word in names: ... heros_indices[index + 1] = names[hero_word] ... >>> for index in sorted(heros_indices, reverse=True): ... heros.insert(index, heros_indices[index]) ... >>> heros ['super', 'clark', 'kent', 'spider', 'peter', 'parker', 'bat', 'bruce', 'wayne'] STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: code is data
BJörn Lindqvist wrote: > > Personally, I would like to see macros in Python (actually Logix > > succeeding is good enough). But I am no language designer and the > > community has no interest in it. When I absolutely need macros, I will > > go elsewhere. > > One must wonder, when is that? When do you absolutely need macros? Whenever there is significant boiler plate code that functions and classes cannot eliminate alone. Whenever there is a more elegant way to express your code. Python 2.5 introduced conditional expressions and with statement. With macros, one would not have to wait for the language team to implement them. More so for features which only a small part of the community has an interest in. I *like* 1..5 (ada, ruby) instead of range(5). If I had macros, I would have done it myself for *my* code. I would like special behaviour code blocks in my programs, for say DBC (I am aware of the work arounds). -- http://mail.python.org/mailman/listinfo/python-list
Detecting key presses
Ok, I'm pretty new to python, so this might be a stupid question. I'm trying to write a simple text-based pong clone, and I can't figure out how to read key presses to move the paddles. I just need something that does the same thing as getch() and kbhit(). I can't use those because their windows only, and I'm running Linux. Someone suggested using curses, but that does crazy things with my output, and leaves the terminal unusable after the program closes. -- http://mail.python.org/mailman/listinfo/python-list
Re: Easy question on minidom
Dean Card <[EMAIL PROTECTED]> wrote: > I am using minidom to parse a 20,000 line XML file. I have a few instances > where the number of child nodes of a particular node can be variable in > number. To access them I am doing something like the following... > > xmldoc = minidom.parseString(r) > results = xmldoc.childNodes[0] > > for myNode in results.childNodes[1].childNodes: > do Stuff with myNode... > > problem is I am having a heck of a time trying to access the value of the > node. For instance I get things like this > > > > > > > > But I need the values... any help here? Not sure what you mean by "the values" -- if you mean for example the contents of text data lying under the node, you can access them...: >>> from xml.dom import minidom >>> s='unodos' >>> xmldoc = minidom.parseString(s) >>> xmldoc.childNodes[0] >>> xmldoc.childNodes[0].childNodes [, ] >>> for node in xmldoc.childNodes[0].childNodes: print node ... >>> for node in xmldoc.childNodes[0].childNodes: print node.childNodes[0] ... >>> for node in xmldoc.childNodes[0].childNodes: print node.childNodes[0].data ... uno dos >>> i.e., the text node is the .childNodes[0] (or more elegantly the .firstChild, of course) of the element node containing it, and if you need that text node's text data, that's its .data attribute. If you need something else, I suggest you post a small example (like mine here) with a clear explanation of what exactly it is that you need! Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: how can get the module global symbol table from a function or method which it is called?
ygao <[EMAIL PROTECTED]> wrote: > when a function or method is called,how can get the module global > symbol table from which > it is called,not the module where it is defined(this is easy). > thanks! You can play with module inspect, or sys._getframe, but they're meant essentially for *debugging* purposes -- if what you have in mind is not related to debugging, but rather some hack to design a highly unPythonic API, I earnestly urge you to reconsider your design intent. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: any subway experiences
a <[EMAIL PROTECTED]> wrote: > thanks for reading Yah, I got a sandwich there once, it was very large but not all that good... Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Detecting key presses
On 2006-06-18 13:20:06, tylertacky write: >Ok, I'm pretty new to python, so this might be a stupid question. I'm >trying to write a simple text-based pong clone, and I can't figure out >how to read key presses to move the paddles. I just need something that >does the same thing as getch() and kbhit(). I can't use those because >their windows only, and I'm running Linux. > >Someone suggested using curses, but that does crazy things with my >output, and leaves the terminal unusable after the program closes. > >-- >http://mail.python.org/mailman/listinfo/python-list The python.org site has a faq about getting keystroke. It uses termios and fcntl modules. Here's the link: http://www.python.org/doc/faq/library/#how-do-i-get-a-single-keypress-at-a-time Hope it can help you! - Fan Zhang -- http://mail.python.org/mailman/listinfo/python-list
setting cookies in quixote
# I write a quixote demo like this: equest = get_request() request.response.set_cookie('usr_name', 'Jim', path='/') request.response.set_cookie('usr_id', '1', path='/') #but only usr_name can be setted successfully, and usr_id is none. Why ? Help me ! Thanks -- http://mail.python.org/mailman/listinfo/python-list