Re: What is a type error?
On 13 Jul 2006 08:45:49 -0700, "Marshall" <[EMAIL PROTECTED]> wrote: > >On the other hand, there is no problem domain for which pointers >are a requirement. I agree they are deucedly convenient, though. > I would argue that pointers/references _are_ a requirement for I/O. I know of no workable method for interpreting raw bits as meaningful data other than to overlay a typed template upon them. Categorically disallowing address manipulation functionally cripples the language because an important class of programs (system programs) cannot be written. Of course, languages can go overboard the other way too. IMO, C did not need to provide address arithmetic at the language level, reinterpretable references and array indexing would have sufficed for any use. Modula 3's type safe view is an example of getting it right. It is quite reasonable to say "I don't write _ so I don't need [whatever language feature enables writing it]". It is important, however, to be aware of the limitation and make your choice deliberately. George -- for email reply remove "/" from address -- http://mail.python.org/mailman/listinfo/python-list
Re: TFTP client in python
I saw that in Google too! It is server centric and I was looking for client specific code. The code also doesn't compile due to white space issues. If this is the best available, I will have to get dirty in Python! Thanks, Malahal. Stefan Behnel [EMAIL PROTECTED] wrote: > [EMAIL PROTECTED] wrote: > > Is there a TFTP client python module? I just need "get file" feature. > > I came across two implementations on WEB, but they are kind of > > unfinished (got the code from some mailing list!). > > Second hit in Google ("tftp python"): > > http://mail.python.org/pipermail/python-list/2001-January/024980.html > > Stefan -- http://mail.python.org/mailman/listinfo/python-list
About iServicePro
iServicePro is an innovative approach to offering affordable tools for Java and J2EE developers. in particular, we are a professional team for applying oneself to develop and integrate eclipse plug-in for user applications. Our mission now is to deliver business value and to maximize developers' productivity by consistently delivering reliable products and a true end-to-end seamless J2EE development environment. iServicePro is the eclipse plug-in solution for all your UML, Web, J2EE, JSP, XML, Struts, JSF, Hibernate and application server integration needs. We are committed to the success of your trial. If you need to see a demonstration of Data Service or need assistance during the trial process, please do not hesitate to contact us. www.iservicepro.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessors in Python (getters and setters)
mystilleef wrote: > Marc 'BlackJack' Rintsch wrote: > >>In <[EMAIL PROTECTED]>, mystilleef >>wrote: >> >> >>>Maric Michaud wrote: >>> But that's not python philosophy. >>> >>>Python doesn't have any philosophy with regards to naming identifiers. >> >>But the python community has one. Pythonistas prefer readable source code >>so they tend to think about good names. As The Zen of Python says >>"Readability counts." > > I'm glad I'm in tune with the "python community." > But they are in Python and that is the python's philosophy. All attribute or method not beginning with an '_' *is* API. >>> >>>Right, and what if I want to change a private API to a public one. How >>>does that solve my naming issues. >> >>Then you have to change all references to that private attribute. What's >>the problem here? As it was private I would expect to find all the >>references "nearby" in the same module or class. > > Right, but tmp isn't private. > And in python the reverse can be true : >>> >>>The reverse is hardly ever true. 90% of public APIs in almost all >>>languages are methods or functions. >> >>Except the ones with properties where ordinary "attributes" may be just >>calls in disguise. > > > Crap! Even in Python too most Public APIs are methods and functions. > > >>Python is not almost all other languages and in Python code you usually >>won't find those trivial getters and setters because we have properties if >>the access might become a bit more complex in the future. >> > > > Ha! I bet you haven't read too many Python codes. > > One thing I can more or less guarantee is that if you'd invested the time you've spent on this thread in actually performing whatever trivial but tedious engineering work was required to achieve the renaming of that attribute the job would have been completed long ago. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: About iServicePro
[EMAIL PROTECTED] wrote: > We are committed to the success of your trial. If you need to see a > demonstration by spamming a non-java forum, I think you've just demonstrated what kind of company you're working for quite well, thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
George Neuner wrote: > On 13 Jul 2006 08:45:49 -0700, "Marshall" <[EMAIL PROTECTED]> > wrote: > > > >On the other hand, there is no problem domain for which pointers > >are a requirement. I agree they are deucedly convenient, though. > > > > I would argue that pointers/references _are_ a requirement for I/O. I > know of no workable method for interpreting raw bits as meaningful > data other than to overlay a typed template upon them. I think I know what you mean. I agree that pointers are necessary for, e.g., device drivers. So I have to weaken my earlier statement. > Categorically disallowing address manipulation functionally cripples > the language because an important class of programs (system programs) > cannot be written. That's fair, although I could argue how important systems programming is these days. (And C/C++ are cock-of-the-walk there anyway.) > Of course, languages can go overboard the other way too. IMO, C did > not need to provide address arithmetic at the language level, > reinterpretable references and array indexing would have sufficed for > any use. Modula 3's type safe view is an example of getting it right. > > It is quite reasonable to say "I don't write _ so I don't need > [whatever language feature enables writing it]". It is important, > however, to be aware of the limitation and make your choice > deliberately. Agreed. Marshall -- http://mail.python.org/mailman/listinfo/python-list
Re: TFTP client in python
> Stefan Behnel [EMAIL PROTECTED] wrote: >> [EMAIL PROTECTED] wrote: >>> Is there a TFTP client python module? I just need "get file" feature. >>> I came across two implementations on WEB, but they are kind of >>> unfinished (got the code from some mailing list!). >> Second hit in Google ("tftp python"): >> >> http://mail.python.org/pipermail/python-list/2001-January/024980.html [EMAIL PROTECTED] wrote: > I saw that in Google too! It is server centric and I was looking for > client specific code. Apparently, it has a client included. Just drop the server class and retry. > The code also doesn't compile due to white space issues. I assume you copied it from the web page. Use the "tabnanny" module to find out where the problems are. > If this is the best available, Haven't tested it, so can't tell. > I will have to get dirty in Python! Which is never a bad idea. :) Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: String handling and the percent operator
Tom Plunket wrote: > I have some code to autogenerate some boilerplate code so that I don't > need to do the tedious setup stuff when I want to create a new module. > > So, my script prompts the user for the module name, then opens two > files and those files each get the contents of one of these functions: > > def GetPyContents(module): > boilerplate = \ > """ > class %s: > pass > > if __name__ == '__main__': > import unittest > unittest.main('%s_t') > """ > > return boilerplate % ((module,) * 2) > > def GetTestContents(module): > boilerplate = \ > """from %s import * > import unittest > > class Test%s(unittest.TestCase): > def testConstruction(self): > self.failUnless(%s()) > > def testWriteMoreTests(self): > self.fail('This test should fail.') > > if __name__ == '__main__': > unittest.main() > """ > > return boilerplate % ((module,) * 3) > > My question is, I don't like hardcoding the number of times that the > module name should be repeated in the two return functions. Is there > an straight forward (inline-appropriate) way to count the number of > '%s'es in the 'boilerplate' strings? ...or maybe a different and more > Pythonic way to do this? (Maybe I could somehow use generators?) Python's string formatting comes in two flavours : positional (the one you used in your above example), and keywords: tpls = [ "%(name1)s is %(name1)s and %(name2)s is %(name2)s", "what about %(name2)s for %(name1)s ?", "Now we only deal with %(name1)s", ] data = {'name1' : 'parrot', 'name2': 'dead'} for tpl in tpls: print tpl % data As you can see, the keyword flavour doesn't care about positions nor repetitions. You may also want to look at more featured templating solutions like empy, cheetah, etc... -- 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: String handling and the percent operator
- Original Message -From: "Tom Plunket" <[EMAIL PROTECTED]>Newsgroups: comp.lang.pythonTo:Sent: Friday, July 14, 2006 12:49 AMSubject: String handling and the percent operator> I have some code to autogenerate some boilerplate code so that I don't> need to do the tedious setup stuff when I want to create a new module.>> So, my script prompts the user for the module name, then opens two> files and those files each get the contents of one of these functions:>etc.Tom Might this be an idea? Put symbolic names into your templates, as manyas you want and replace them with the real names:boilerplate = """# Module MODULE# DATE# SUMMARYclass CLASS passif __name__ == '__main__':import unittestunittest.main('CLASS_t')"""names = ''' MODULE=Corner_Cutter "DATE=%s" "SUMMARY=Fast stuff" CLASS=Sharpener''' % time.ctime ()import SEStream_Editor = SE.SE (names)print Stream_Editor (boilerplate)# Module Corner_Cutter# Fri Jul 14 10:16:53 2006# Fast stuffclass Sharpener passif __name__ == '__main__':import unittestunittest.main('Sharpener_t')Will also do files:Stream_Editor ('boilerplates/module_template', 'projects/%s.py' %Stream_Editor ('MODULE'))'projects/Corner_Cutter.py'You'd have to download SE from the Cheese Shop. I managed to upload at leastthe description, but people tell me that the program isn't there. So while Istruggle with the upload (assistance welcome) I send out SE by individualrequest. If you want to try it, just tell me.CheersFrederic -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Chris Smith wrote: > Marshall <[EMAIL PROTECTED]> wrote: > > > What you are asking for is some subset of identity, and I've not yet > > > succeeded in understanding exactly what it is or what its limits are... > > > except that so far, it seems to have everything to do with pointers or > > > aliasing. > > > > Perhaps it is specifically first-class identity, rather than identity > > per se. > > As in: "the value of one variable can (be/refer to/depend on) the > identity of another variable"? I can certainly see this as as > reasonable concept to consider. Yes, I think it's important. We've become so accustomed, in modern languages, to considering variables as first-class, that we cannot see any more that many of the problems attributed to variables (such as aliasing) are actually problems only with *first-class* variables. The historical reality that non-first-class variables are associated with more antique languages (Fortran/pre-OO) makes us shy away from even considering removing first-class status from variables. But I think it's an important point in the design space (although I certainly respect Andreas' reluctance; to paraphrase, "first class or bust." :-) ) After all, what are the alternatives? Purely-functional languages remove themselves from a large class of problems that I consider important: data management. I have explored the OO path to its bitter end and am convinced it is not the way. So what is left? Uniqueness types and logic programming, I suppose. I enjoy logic programming but it doesn't seem quite right. But notice: no pointers there! And it doesn't seem to suffer from the lack. I really don't know enough about uniqueness types to evaluate them. But again, I already have my proposed solution: variables but no first-class variables. (And yes, I'm acutely aware of how problematic that makes closures. :-() > > > I'm not yet convinced that this is any different from a language with > > > standard pointer aliasing. If I have two tables A and B, and a foreign > > > key from A into B, then I run into the same problems with enforcing > > > constraints that I would see with a pointer model... when I update a > > > relation, I need to potentially check every other relation that contains > > > a foreign key into it, in order to ensure that its constraints are not > > > violated by that constraint. That's the same thing that is being > > > pointed out as a negative consequence of aliasing in other languages. > > > > No, that's not the same thing. What you are describing here is > > not an aliasing issue, but simply the consequences of allowing > > constraints to mention more than one variable. > > > A foreign key constraint is a multi-variable constraint. > > Specifically, a foreign key from table A, attribute a > > to table B, attribute b is the constraint: > > > > forall a in A, exists b in B such that a = b. > > > > Note that two variables, A and B, are referenced in > > the constraint. > > There's confusion here coming from different usages of the word > variable. Let us talk instead of values, and of the abstract structures > that gives them meaning. I don't think that will work. We cannot discuss constraints, nor aliasing, without bringing variables in to the picture. (Aliasing may exist without variables but it is a non-problem then.) > In both cases (invariants in a hypothetical > imperative language, and in a relational database), the constraints make > reference to these structures of values (relations, for example, or > various kinds of data structures), and not to the individual values or > objects that they contain. I am not certain what this means. > In both cases, the problem is not that we > don't know what structures to check to verify the invariant; rather, > it's that we have to check ALL of the values in that structure. But not all values in all structures, as you do in the presence of aliasing. > As someone pointed out, this is to be expected in a world of mutable > things with identity that are globally locatable. It is simple fact > that if I tell you "I spoke to Barbara's husband", you may need to trace > down who Barbara's husband is before you could discover that, for > example, maybe I actually spoke to your boss, or to your nephew's best- > friend's father. If databases are capable of modeling these kinds of > relationships (and of course they are), then they are as susceptible to > "aliasing" -- in a logical sense that avoids mention of pointer -- as > anyone else. I don't see that they're the same thing. Similar is some ways, yes, but not the same. As I said much earlier, the terminology is problematic, and it may be that we (or just I) simply lack the precision of terms necessary for the conversation. Marshall -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Search for python in Norway
cyberco wrote: > Although the climate wouldn't make you think so, but searching for > python is hot in Norway: > > http://www.google.com/trends?q=python&ctab=1&geo=all&date=all > > I wonder what the explanation could be. > > Btw: Java seems to be all the rage in India :) > http://www.google.com/trends?q=java&ctab=1&geo=all&date=all So what? That just means those countries are still looking for them, while those not in the list no longer bother asking Google. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: python logging module problem
Ritesh Raj Sarraf wrote: > When I execute the above code, logger.info()'s messages don't get > displayed. And logger.warning()'s messages get displayed twice. > The warning messages are displayed twice because you have two handlers which both output to the console. The reason you don't get the info messages is that you haven't set a level on the logger, so the default of WARNING is used. It's usual to rely on logger levels and to set handler levels for additional refinement of what goes to a particular handler's destination. Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Re: Byte array question
John Machin wrote: > On 14/07/2006 10:41 AM, Dan Winsor wrote: > > Sybren Stuvel wrote: > >> Dan Winsor enlightened us with: > >>> This one "works" in that it runs, but the server on the other end gets > >>> garbage unrelated to the test file. > >> Are you sure it is garbage? Have you tried changing byte order? > > > > Ah, that I hadn't. Any pointers to doing that? > > > > You found array.array.byteswap() in the manual and rejected it because ...? ...you suggested it? :) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to have application-wide global objects
Fredrik Lundh wrote: > if you got some other result, you didn't just import the same thing > twice... I think you may be incorrect, or I have misinterpreted you. Try this: ** In test.py import sys import foo.bar print foo.bar.myvar foo.bar.myvar = 42 print foo.bar.myvar sys.path.insert(0, 'foo') import bar print bar.myvar ** In foo/__init__.py # this is blank ** In foo/bar.py * myvar = 10 If you run test.py, then you get the output 10 42 10 When I would have expected 10, 42, 42. The bar module gets imported twice, once as foo.bar and secondly as bar. The value of 42 in myvar does not get retained, as there are two copies of the module imported. -- Jeremy Sanders http://www.jeremysanders.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to have application-wide global objects
Jeremy Sanders wrote: >> if you got some other result, you didn't just import the same thing >> twice... > > I think you may be incorrect, or I have misinterpreted you. you've misinterpreted what Python means by "a module". > Try this: > import foo.bar here you import the module named "foo.bar" > print foo.bar.myvar > foo.bar.myvar = 42 > print foo.bar.myvar > > sys.path.insert(0, 'foo') > import bar here you import the module named "bar". thanks to your path munging, that happens to point to the same file, but Python's import system doesn't give a damn about that. it identifies modules by their *names*, not their file system location. > When I would have expected 10, 42, 42. The bar module gets imported twice, > once as foo.bar and secondly as bar. The value of 42 in myvar does not get > retained, as there are two copies of the module imported. no, the "bar.py" *file* gets loaded twice, first as the "foo.bar" module, and then as the "bar" module. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Marshall schrieb: > What about my example of SQL? Mutation, no pointers, no aliasing. > Yet: useful. Sorry, but SQL does have aliasing. E.g. if you have records that have name="John", surname="Doe", the statements SELECT * FROM persons WHERE name = "John" and SELECT * FROM persons WHERE name = "Doe" are aliases of each other. The alias is actually in the WHERE clause. And this *can* get you into trouble if you have something that does UPDATE ... WHERE name = "John" and UPDATE ... WHERE surname = "Doe" e.g. doing something with the Johns, then updating the names of all Does, and finally restoring the Johns (but not recognizing that changing the names of all Does might have changed your set of Johns). Conceptually, this is just the same as having two different access path to the same memory cell. Or accessing the same global variable through a call-by-reference parameter and via its global name. BTW with views, you get not just aliasing but what makes aliasing really dangerous. Without views, you can simply survey all the queries that you are working with and lexically compare table and field names to see whether there's aliasing. With views, the names that you see in a lexical scope are not enough to determine aliasing. E.g. if you use a view that builds upon the set of Johns but aren't aware of that (possibly due to abstraction barriers), and you change the name field of all Does, then you're altering the view without a chance to locally catch the bug. That's just as bad as with any pointer aliasing problem. Regards, Jo -- http://mail.python.org/mailman/listinfo/python-list
Re: Byte array question
In <[EMAIL PROTECTED]>, Dan Winsor wrote: > Sybren Stuvel wrote: >> [EMAIL PROTECTED] enlightened us with: >> > I want to send thorugh the API. However, no matter how I try it, >> > Java on the other end doesn't like what I'm passing it there. >> >> What have you tried and how did it fail? > > See below. > >> > How can I mimic a byte array in python? >> >> Strings? > > OK, I'll put that attempt up front. Here's a couple of tries: > > > fileobj = open('testfile.txt', mode='r') > chararray = fileobj.read() > fileobj.close() > > soap.addAttachmentsToIssue(auth,'TST-4','testfile.txt',chararray) > > > SOAPpy.Types.faultType: org.xml.sax.SAXException: Found character data inside an array element > while deserializing: : > {'hostname': '', 'faultData': faultData at -1216226708>: {'exception': None, 'message': 'Found > character data inside an array element while deserializing'}}> In the Java snippet from your initial post the `chararray` argument was an *array* of `Byte` arrays. A string is just an one dimensional "byte array". Maybe it helps if you put `chararray` into a list!? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Darren New wrote: > Andreas Rossberg wrote: > >> Yes, technically you are right. But this makes a pretty weak notion of >> mutability. All stateful data structures had to stay within their >> lexical scope, and could never be passed to a function. > > Not really. The way Hermes handles this is with destructive assignment. > Each variable holds a value, and you (almost) cannot have multiple > variables referring to the same value. OK, this is interesting. I don't know Hermes, is this sort of like a dynamically checked equivalent of linear or uniqueness typing? > If you want to assign Y to X, you use >X := Y > after which Y is considered to be uninitialized. If you want X and Y to > have the same value, you use >X := copy of Y > after which X and Y have the same value but are otherwise unrelated, and > changes to one don't affect the other. Mh, but if I understand correctly, this seems to require performing a deep copy - which is well-known to be problematic, and particularly breaks all kinds of abstractions. Not to mention the issue with uninitialized variables that I would expect occuring all over the place. So unless I'm misunderstanding something, this feels like trading one evil for an even greater one. - Andreas -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Marshall wrote: > > After all, what are the alternatives? Purely-functional > languages remove themselves from a large class of > problems that I consider important: data management. Maybe, but I have yet to see how second-class variables are really more adequate in dealing with it. And note that even with second-class state you can still have aliasing issues - you just need mutable arrays and pass around indices. Keys in databases are a more general form of the same problem. > I have explored the OO path to its bitter end and am > convinced it is not the way. So what is left? Uniqueness > types and logic programming, I suppose. I enjoy logic > programming but it doesn't seem quite right. But notice: > no pointers there! And it doesn't seem to suffer from the > lack. Uh, aliasing all over the place! Actually, I think that logic programming, usually based on deep unification, brings by far the worst incarnation of aliasing issues to the table. - Andreas -- Andreas Rossberg, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Marshall schrieb: > void foo() { > int i = 0; > int j = 0; > j = 1; > i = 2; > // check value of j here. It is still 1, no matter what you filled > // in above. > // The assignment to i cannot be made to affect the value of j. > } > > Those two local primitive variables cannot be made to have the same > identity. Sure. To state it more clearly, they cannot be aliases. > But you can update them, so this is an example of mutability > without the possibility of identity. You're being a bit sloppy with terminology here. "Identity" in the phrase above refers to two entities, in the sense of "i and j cannot be identical". Identity is actually a property of a single entity, namely that what remains constant regardless of what you do with the entity. Regards, Jo -- http://mail.python.org/mailman/listinfo/python-list
Re: How to have application-wide global objects
Fredrik Lundh wrote: > no, the "bar.py" *file* gets loaded twice, first as the "foo.bar" > module, and then as the "bar" module. True and I agree with your email, but suppose there is bar1.py and bar2.py in foo, then they can refer to each other by importing bar2 and bar1, respectively. These module objects will be the same modules that test.py would get by importing foo.bar1 and foo.bar2. By analogy you might expect the path munging example to work, but the details are in the nitty-gritty of how python importing works. The import docs say something like "Details of the module searching and loading process are implementation and platform specific". The results can be a little suprising! It would be include a check so that you could get a warning with debugging switched on. -- Jeremy Sanders http://www.jeremysanders.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Marshall schrieb: > By your definition, "pointer" and "variable" are synonyms. That doesn't > seem like a good idea to me. (What if i and j end up in registers? > I have not heard it said that registers have addresses.) There are no registers in the JVM ;-P More specifically, where Joe said "pointer" he really meant "reference". i refers to a variable, and you really want to make sure that the first i refers to the same variable as the second i, so whatever is referred to by i is really an identity. >>> Those two local primitive variables cannot be made to have the same >>> identity. But you can update them, so this is an example of mutability >>> without the possibility of identity. >> The identity is temporal: You use the same variable name at two >> different times. Do you intend for the second `i' to mean the same >> variable as the first `i'? > > Okay, so "i" and "i" have the same identity. Vacuous but true. > I suppose you could argue that the language's namespace is an > address-space, and variable names are addresses. Correct. > At this point, though, you've made the concept of identity so broad > that it is now necessarily a property of all languages that use named > values, whether updatable or not. I think you would also have to call > "3" a void pointer by this scheme. It's not a void pointer, it's a pointer to an integer, but you're correct: "3", when written in a program text, is a reference to the successor of the successor of the successor of zero. If you find that silly and would like to stick with equality, then you're entirely correct. Natural numbers are entirely immutable by definition, and I'm definitely not the first one to observe that identity and equality are indistinguishable for immutable objects. > Clearly there is *some* difference between a language which allows > explicit pointers and thus aliasing and one that doesn't. You can have aliasing without pointers; e.g. arrays are fully sufficient. If i = j, then a [i] and a [j] are aliases of the same object. (After I observed that, I found it no longer a surprise that array optimizations are what Fortran compiler teams sink most time into. The aliasing problems are *exactly* the same as those with pointers in C - though in practice, the Fortranistas have the advantage that the compiler will usually know that a [i] and b [j] cannot be aliases of each other, so while they have the same problems, the solutions give the Fortranistas more leverage.) > What term would you use? First-class variables? I think it's more a quasi-continuous spectrum. On one side, we have alias-free toy languages (no arrays, no pointers, no call-by-reference, just to name the most common sources of aliasing). SQL is slightly more dangerous: it does have aliases, but they are rarely a problem (mostly because views aren't a very common thing, and even if they are used, they aren't usually so abstract that they really hide the underlying dependencies). Next are languages with arrays and call-by-reference. "Pascal without pointers" would be a candidate. Here, aliasing occurs, and it can and does hide behind abstraction barriers, but it's not a serious problem unless the software becomes *really* large. The end of the line are languages that use references to mutable data everywhere. All OO languages are a typical example of that. Regards, Jo -- http://mail.python.org/mailman/listinfo/python-list
Re: How properly manage memory of this PyObject* array?? (C extension)
On 14/07/2006 4:16 PM, [EMAIL PROTECTED] wrote: >> It's quite simple, really: You malloc it, you free it. > > John - I hope you don't mind that I really want to make sure I > understand your > good wisdom in this area by asking for clarification > > ASSUMPTIONS: > > 1. As long as we properly handle the reference counting of PyObjects > then > memory management is taken care of for us. (i.e. You don't ever > use the 'free' command explicitly on a PyObject* but let Python > garbage collector > do the final freeing.) That's correct: You didn't malloc it, you don't free it. BTW, free is a function, not a "command". > > 2. All malloc'd stuff in C must be freed with free command. (Python > garbage > collector is limited to PyObjects. It won't free non-Python stuff > for us > like int arrays, char* strings, etc.) > Correct. > > Now it would appear that if you **malloc an array of PyObjects** > (call it FOO[]) then you have an ambiguity No, not at all; there is no such action as "malloc an array of PyObjects". Firstly, malloc does not produce an array of anything; it allocates a chunk of memory and returns the address of the start of the chunk. secondly, what you stuffing into that memory is not Python objects but addresses of (a.k.a. pointers to) Python objects. > > The PyObject elements will be freed *for us* eventually by garbage > collector. > Hence, we can't ever do 'free(FOO); ' because we don't know when > garbage collector will free FOO[0], FOO[1], FOO[2], etc. Let's try reductio ad adsurdum on that one. Suppose that instead of filling in a malloced chunk of memory, you had stored those gizmoids in local variables foo0, foo1, foo2, etc. Using your reasoning: we can't ever return from our function (which frees up the stack memory containing foo0 etc) because we don't know when garbage collector will free foo0 etc. Avoiding that problem would require a Python/C API function with a name like Py_AwaitGarbageCollection() ... but there isn't one. HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Re: stdout/stderr for only one thread in a multithreaded python app
On 2006-07-13, notanotheridiot <[EMAIL PROTECTED]> wrote: > Hi- > > I'm trying to exec some arbitrary code in one thread of an application > and read anything it prints to stdout or stderr in another thread. My > question is how? > > I've tried changing sys.stdout, but that changes stdout for the whole > application, not just that one thread, which means that any status > updates that I DO want printed to stdout don't get printed. > > I've also tried running the code in a seperate process in a new python > interpreter using popen* but I can't read data from stdout until the > program has finished. What do you mean by this? Do you mean that the data that is passed between the two processes is so little it is all buffered until the second process finishes, at which time the first process receives it all? It so and this is a problem then maybe the pty module can help you. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: python logging module problem
Vinay Sajip wrote: > > It's usual to rely on logger levels and to set handler levels for > additional refinement of what goes to a particular handler's > destination. > The problem is that for StreamHandler, logging module logs to sys.stderr. I want to use the logging feature for most of the messages my program displays. So some messages would be going to sys.stdout and some to sys.stderr. So, I'm ended up creating two handlers, one for sys.stdout and the other for sys.stderr. I'd then make INFO level messages go to sys.stdout and DEBUG level messages go to sys.stderr. What do you suggest ?? Is it good doing this way ? Ritesh -- http://mail.python.org/mailman/listinfo/python-list
How to start more than one process at the same time?
Hi! How can I start several jobs at the same time with python? I want to collect data from some servers and I don't want to wait until the first server is finished. These jobs should run parallel to save time. What I tried is this: os.popen('regdmp -m server1 "HKEY_LOCAL_MACHINE\\Software\\Intel\\LanDesk\\VirusProtect6\\CurrentVersion\\Clients" >> av_server1.txt') os.popen('regdmp -m server2 "HKEY_LOCAL_MACHINE\\Software\\Intel\\LanDesk\\VirusProtect6\\CurrentVersion\\Clients" >> av_server2.txt') os.popen('regdmp -m server3 "HKEY_LOCAL_MACHINE\\Software\\Intel\\LanDesk\\VirusProtect6\\CurrentVersion\\Clients" >> av_server3.txt') I didn't get an error-message, but I also didn't get a result. No text-file was created. I also tried to do the same thing via batch-files, but that didn't change anything. Is it just not possible or what am I doing wrong? Thanks for any help! Dirk Hagemann -- http://mail.python.org/mailman/listinfo/python-list
Re: Chunking sequential values in a list
[EMAIL PROTECTED] wrote: > Gerard> David Hirschfield wrote: > >> I have this function: > >> > >> def sequentialChunks(l, stride=1): > ... > >> > >> Which takes a list of numerical values "l" and splits it into chunks > >> where each chunk is sequential... > > Gerard> see the groupby example here: > > Gerard> http://docs.python.org/lib/itertools-example.html > > I've never been a fan of the operator module, so I find the example in the > docs ugly even though it's succinct. I'd also never used groupby but > thought it was the solution to the problem. As I was walking home from the > train I realized how it would work. You beat me to the punch with your > reply, but I'll post my solution anyway: > > from itertools import groupby > > class Counter: > def __init__(self): > self.last = None > self.value = True > > def __call__(self, val): > if self.last is not None and self.last+1 != val: > self.value = not self.value > self.last = val > return self.value > > for key, group in groupby([1,2,3, 5,6, 8, 12,13,14], Counter()): > print list(group) > I've no strong feelings about the operator module myself, or the groupby example, but I do prefer your code in this case. I tweaked it a little to take into account the stride, though I'm not sure it gives what the OP wants. all the best Gerard - class Counter: def __init__(self, stride=1): self.last = None self.value = True self.stride = stride def __call__(self, val): if self.last is not None: d = val - self.last if d > self.stride: self.value = not self.value self.last = val return self.value def group(data,stride=1): for key, group in groupby(data, Counter(stride)): yield list(group) --- -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessors in Python (getters and setters)
mystilleef ha scritto: > Methods are used to perform actions. Data attributes usually aren't. We > are on different planes. You aren't thinking pythonic. You should not make any difference between accessing an attribute and accessing a function. They both just need to receive the right data to process (and the module doc must tell you wich is it). There is of course many python code wich doesn't use properties, but that's up to the developer: everybody write the way they like. You could also find code with both getter/setter AND properties. well used properties make your code cleaner, but if you don't find yourself confortable with them, just don't use them, but never forget them. Riccardo -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Marshall schrieb: > Joachim Durchholz wrote: >> It's just that I know that it's viable to give up destructive updates. >> Giving up pointers is a far more massive restriction. > > Oddly, I feel the opposite. While it's true there are many domains > for which purely functional programming is a fine choice, there > are some domains for which it is insufficient. Any kind of data > managament, for example, requires that you be able to update > the information. Sure, the data itself cannot be managed non-destructively. However, the programs that operate on the data need not do destructive updates internally. That way, I can have pointers inside the programs without giving up aliasing. (Aliasing is really, really, really important. It's the reason why mathematicians can handle infinite objects - they copy just the alias, i.e. the name or description, instead of the object itself. It's one of the things that make abstraction useful.) >>> Right. To me the response to this clear: give up pointers. Imperative >>> operations are too useful to give up; indeed they are a requirement >>> for certain problems. >> I don't know any. >> In some cases, you need an additional level of conceptual indirection - >> instead of *doing* the updates, you write a function that *describes* them. > > But then what do you do with that function? I pass it to an engine that's imperative. However, that engine doesn't need to do aliasing anymore. In other words, I'm separating mutability and aliasing, so that they can't combine and explode. > Let's say I have an > employee database. John Smith just got hired on 1/1/2006 with > a salary of $10,000. I need to record this fact somewhere. How > do I do that without variables? Current-employees is a variable. > Even if I have the space to keep all historical data, so I'm not > deleting anything, I still have to have a variable for the latest > version of the accumulated data. I can solve this without > pointers, but I can't solve it without variables. As I said elsewhere, the record has an identity even though it isn't explicit in SQL. (SQL's data manipulation language is generally not considered half as "clean" as the query language; I think the core of the problemsis that DML combines mutability and identity.) > I should like to learn more about these. I have some vague > perception of the existence of linear logic, but not much > else. However, I also already have an excellent solution > to the pointer aliasing problem, so I'm less motivated. Pointers are just the most obvious form of aliasing. As I said elsewhere, there are others: array indexing, by-reference parameters, or even WHERE clauses in SQL statements. In fact, anything that selects an updatable piece of data from a collection is an alias, and incurs the same problems as pointers, though they may come in different disguises. >> Actually SQL has references - they are called "primary keys", but they >> are references nevertheless. > > I strongly object; this is quite incorrect. I grant you that from the > 50,000 foot level they appear identical, but they are not. To > qualify as a reference, there need to be reference and dereference > operations on the reference datatype; there is no such operation > is SQL. > > Would you say the relational algebra has references? Yes. > Or, consider the classic prolog ancestor query. Let's say we're > setting up as follows > > father(bob, joe). > father(joe, john). > > Is "joe" a reference, here? After all, when we do the ancestor > query for john, we'll see his father is joe and then use that to > find joe's father. Keys in SQL are isomorphic to joe in the > above prolog. Agreed. They are both references ;-P >> (Some SQL dialects also offer synthetic >> "ID" fields that are guaranteed to remain stable over the lifetime of a >> record. > > Primary keys are updatable; there is nothing special about them. Right - I was wrong with identifying keys and identities. In fact the identity of an SQL record cannot be directly obtained (unless via those ID fields). The records still have identities. It's possible to have two WHERE clauses that refer to the same record, and if you update the record using one WHERE clause, the record returned by the other WHERE clause will have changed, too. >> With a "repeatable read" isolation level, you actually return to a >> declarative view of the database: whatever you do with it, you won't see >> it until you commit the transaction. (As soon as you commit, the >> declarative peace is over and you better watch out that your data >> doesn't become inconsistent due to aliasing.) > > Alas, transaction isolation levels are a performance hack. > I cannot defend them on any logical basis. (Aside: did you mean > serializable, rather than repeatable read?) Possibly. There are so many isolation levels that I have to look them up whenever I want to get the terminology 100% correct. >> The only thing that can really be done about it is
Re: python logging module problem
Ritesh Raj Sarraf wrote: > Vinay Sajip wrote: >> It's usual to rely on logger levels and to set handler levels for >> additional refinement of what goes to a particular handler's >> destination. > The problem is that for StreamHandler, logging module logs to > sys.stderr. > I want to use the logging feature for most of the messages my program > displays. > > So some messages would be going to sys.stdout and some to sys.stderr. > > So, I'm ended up creating two handlers, one for sys.stdout and the > other for sys.stderr. > I'd then make INFO level messages go to sys.stdout and DEBUG level > messages go to sys.stderr. > > What do you suggest ?? > Is it good doing this way ? You can achieve the desired behaviour by adding a custom Filter: import sys import logging logger = logging.getLogger("my_app") logger.setLevel(logging.DEBUG) class LevelFilter(logging.Filter): def __init__(self, level): self.level = level def filter(self, record): return self.level == record.levelno def make_handler(outstream, format, level): handler = logging.StreamHandler(outstream) formatter = logging.Formatter(format) handler.setFormatter(formatter) handler.addFilter(LevelFilter(level)) return handler logger.addHandler(make_handler(sys.stderr, 'STDERR %(levelname)s %(message)s', logging.WARN)) logger.addHandler(make_handler(sys.stdout, 'STDOUT %(levelname)s %(message)s', logging.INFO)) logger.info("the world is flat") logger.warning("take care not to fall off its rim") Not sure whether this is a good idea. Another way might be to use distinct loggers. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: attaching debugger to runinng python program
Bill Pursell wrote: > Now, in another shell, > % gdb > (gdb) attach 54321 > Thx for the reply. But I wish to debug the python program, not python interpreter itself. -- http://mail.python.org/mailman/listinfo/python-list
Re: Chunking sequential values in a list
David Hirschfield wrote: > I have this function: > > def sequentialChunks(l, stride=1): > chunks = [] > chunk = [] > for i,v in enumerate(l[:-1]): > v2 = l[i+1] > if v2-v == stride: > if not chunk: > chunk.append(v) > chunk.append(v2) > else: > if not chunk: > chunk.append(v) > chunks.append(chunk) > chunk = [] > if chunk: > chunks.append(chunk) > return chunks > > Which takes a list of numerical values "l" and splits it into chunks > where each chunk is sequential, where sequential means each value in a > chunk is > separated from the next by "stride". > > So sequentialChunks([1,2,3,5,6,8,12]) returns: > > [[1,2,3],[5,6],[8],[12]] > > I don't think the code above is the most efficient way to do this, but > it is relatively clear. I tried fiddling with list-comprehension ways of > accomplishing it, but kept losing track of things...so if anyone has a > suggestion, I'd appreciate it. > Gerard wrote: >see the groupby example here: > >http://docs.python.org/lib/itertools-example.html tweaking the example from the docs to take the stride into account: def stride(length): i = 0 while True: yield i i += length def group(data,d=1): for k, g in groupby(zip(stride(d),data), lambda (i,x):i-x): yield map(operator.itemgetter(1), g) data = [1,2,3, 5, 6, 8, 12,13,14] print list( group( data,2 ) ) hth Gerard -- http://mail.python.org/mailman/listinfo/python-list
Re: python logging module problem
Peter Otten wrote: > You can achieve the desired behaviour by adding a custom Filter: > > import sys > import logging > > logger = logging.getLogger("my_app") > logger.setLevel(logging.DEBUG) > > class LevelFilter(logging.Filter): > def __init__(self, level): > self.level = level > def filter(self, record): > return self.level == record.levelno > > def make_handler(outstream, format, level): > handler = logging.StreamHandler(outstream) > formatter = logging.Formatter(format) > handler.setFormatter(formatter) > handler.addFilter(LevelFilter(level)) > return handler > > logger.addHandler(make_handler(sys.stderr, > 'STDERR %(levelname)s %(message)s', logging.WARN)) > logger.addHandler(make_handler(sys.stdout, > 'STDOUT %(levelname)s %(message)s', logging.INFO)) > > logger.info("the world is flat") > logger.warning("take care not to fall off its rim") > > Not sure whether this is a good idea. Another way might be to use distinct > loggers. > > Peter Thanks. This looks similar to what I wanted. I'll try customizing it to my requirements and see if this helps. Thanks, Ritesh -- http://mail.python.org/mailman/listinfo/python-list
Re: Chunking sequential values in a list
[EMAIL PROTECTED] wrote: > If you want something less easy to understand, you can try fixing the > following code that doesn't work: > > from itertools import groupby > l = [1,2,3,5,6,8,12] > keyf = lambda (pos,x): x-l[pos]>1 > [[el[1] for el in gr] for he,gr in groupby(enumerate(l[:-1]), keyf)] >>> from itertools import groupby >>> items = [1, 2, 3, 5, 6, 8, 12] >>> [[v for i, v in group] for key, group in groupby(enumerate(items), lambda (i, v): i-v)] [[1, 2, 3], [5, 6], [8], [12]] which is almost identical to the last example in http://docs.python.org/lib/itertools-example.html Peter -- http://mail.python.org/mailman/listinfo/python-list
look for a module without import it
Hi list, I have to know if a module are present on the system, but I don't want to import it. Only know if it is present. I think that a loop on the site-packages directory can do the work, but is there another solution? Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: look for a module without import it
Michele Petrazzo wrote: > I have to know if a module are present on the system, but I don't want > to import it. Only know if it is present. > > I think that a loop on the site-packages directory can do the work, but > is there another solution? > more module.py print "I'M MODULE!" > python >>> import imp >>> imp.find_module("os") (, 'C:\\python25\\lib\\os.py', ('.py', 'U', 1)) >>> imp.find_module("sys") (None, 'sys', ('', '', 6)) >>> imp.find_module("foobar") Traceback (most recent call last): File "", line 1, in ImportError: No module named foobar >>> imp.find_module("module") (, 'module.py', ('.py', 'U', 1)) >>> import module I'M MODULE! -- http://mail.python.org/mailman/listinfo/python-list
Re: Chunking sequential values in a list
Peter Otten: > which is almost identical to the last example in > http://docs.python.org/lib/itertools-example.html I see, thank you. I haven't had enoug time and brain to fix it (and the OP question seemed like homework, so leaving some other things to do is positive). I think still that too much clever code can be bad, it isn't easy to understand, fix and modify if you need something a little different. To solve such problem in 'production code' I probably prefer a longer function like the one I have shown. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: look for a module without import it
Fredrik Lundh wrote: >> more module.py > print "I'M MODULE!" > >> python import imp imp.find_module("os") It was! Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Python strings outside the 128 range
Gerhard Fiedler schrieb: > On 2006-07-13 12:04:58, Richard Brodie wrote: > >>> s = "é" >>> print s > >>> Is there a standard way to do this? >> Use Unicode strings, with an explicit encoding. Say no to ISO-8859-1 >> centrism. >> See: http://www.amk.ca/python/howto/unicode particularly the >> "Unicode Literals in Python Source Code" section. > > So ... > > # coding: utf-8 > s = u'é' > print s > > (Of course stored with an editor that writes the file in utf-8 encoding.) > > Is this the proper way? > > Will print take care of encoding translation according to the encoding used > in the target console? Of course not. AFAIK there is no way figuring out which encoding the target console supports. The best you can do is to offer an option that allwos selection of the output encoding. And when using print, don't forget to wrap sys.stdout with a codecs.EncodedFile to properly convert the unicode strings. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: EuroPython 2006 and Py3.0
[EMAIL PROTECTED] wrote: > Kay Schluehr: > >>there is nothing really new or interesting or challenging. >>Micro-optimizations and shape lifting. > > > I see. Maybe Python is becoming a commodity used by more than 10e6 > persons, so changellenges aren't much fit anymore. > Guido has tried to avoid the problems of Perl6, making Py3.0 a > improvement and not a revolution. The good thing is that we'll probably > see a beta version in 14-18 months. Py3.0 from being like fantasy is > become something close, this is a good thing. > I may ask you what you would like to see in Py3.0, but remember that > your answer may become ignored by the developers. > The real problems with the Py3k list seem to be associated with a number of people who, despite having had little apparent connection to the language until now, have joined the list and started making inappropriate suggestions, which then have to be (patiently) rejected. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: How can get button's name when cursor move over the button on a web page?
Fredrik Lundh wrote: > 尹祥龙 wrote: > > >>How can get button's name when cursor move over the button on a web page? > > > that sounds like a JavaScript question, doesn't it? so what is it doing > on comp.lang.python ? > > > Questions nowadays have no idea which groups they belong to. When *I* was a lad questions had to know their place. A question that appeared in the wrong group would be torched with flames that could be guaranteed to burn through asbestos. But you tell these young people and they just don't believe you. A Yorkshireman -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Letting a Python application phone home
Hi,I'm working on an educational Python application that collects data about a large group of people (Of course, with the full consent of the students).The application should run on the PC of the participant and send the collected data back home to the server. Furthermore, it is also necessary that the transfer of the data happens during the running of the application, because I don't want the participants to be able to run the program without sending me the data. In fact, as soon as the Internet connection is switched of or is lost, the program should stop running. So far my wishes. Now the question: Is it possible to program this in a secure fashion, both for me and the students. The data should preferably not be visible to every one and it should not be possible to look into the code for passwords etc. Especially the part about the sending of the data worries me a bit.With Kind Regards,Dieter -- http://mail.python.org/mailman/listinfo/python-list
Re: rare error with python at execution
Fredrik Lundh wrote: > Luis Morales wrote: > > >>But now I get this error everytime I run a script and I have no idea. It can >>be a simple print 'hello' that it wont work >> >>This is the error I get >> >>'import site' failed; use -v for traceback >> >>Traceback (most recent call last): >> >> File "D:\Archivos de programa\ActiveState Komodo >>3.5\lib\support\dbgp\bin\pydbgp.py", line 61, in ? >> >> if os.environ.has_key("PYDBGP_PATH"): >> >>AttributeError: 'module' object has no attribute 'environ' > > > have you perhaps added a file named "os.py" to your project ? If not, then run your program with python -v progname.py like the error message tels you. If that doesn't give you enough information to debug the problem, post the output back to this list for further assistance. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: Byte array question
Marc 'BlackJack' Rintsch wrote: > In the Java snippet from your initial post the `chararray` argument was an > *array* of `Byte` arrays. A string is just an one dimensional "byte > array". Maybe it helps if you put `chararray` into a list!? Yup, thanks, that was one that I did try with no improvement: fileobj = open('testfile.txt', mode='r') chararray = fileobj.read() fileobj.close() soap.addAttachmentsToIssue(auth,'TST-4','scriptattach.txt',[chararray]) fails with: SOAPpy.Types.faultType: : {'hostname': ''}> which is an uglier and less informative trace unfortunately. Thanks, though. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie
Stéphane ROCHOY wrote: > Gueorgui Vaskes wrote: > > Could anyone feel me in what do you mostly use python for? > > > > > > > > ___ > > The all-new Yahoo! Mail goes wherever you go - free your email address from > > your Internet provider. http://uk.docs.yahoo.com/nowyoucan.html > > An IMAP backup agent using AES encryption. So far: integrated circuit emulation database interfaces cellular automata control systems for loosly coupled multiprocessing generic shell scripting torturing XEN mapping software system security Curtis -- http://mail.python.org/mailman/listinfo/python-list
imaplib question
Hello, I'm trying to write a very simple program that moves all messages from INBOX into another folder. I'm not sure what am I doing wrong. This is a very simple task. I believe I need to call these methods: - search -> get all message UIDs in the INBOX - copy -> copy all messages to another folder - store -> mark all messages in INBOX as deleted - expunge -> delete them physically Here is what I have now: conn = getnewimapconnection() try: typ,data = conn.select() check_error((typ,data)) #print "Number of messages in INBOX: ",data[0] typ,all_messages = conn.search(None,'(ALL)') check_error((typ,data)) #mailboxes = conn.list()[1] #for mb in mailboxes: #print mb #raise SystemExit # Store all messages into another typ,data = conn.copy(all_messages,'"PublicInbox"') check_error((typ,data)) finally: conn.logout() I get this error: Traceback (most recent call last): File "MailDaemon.py", line 99, in ? check_error((typ,data)) File "MailDaemon.py", line 15, in check_error raise IMAPError((typ,data)) __main__.IMAPError: ('NO', ["[TRYCREATE] Mailbox doesn't exist: 2"]) However, if I comment out the for loop that lists the mailboxes, I see this: (\HasNoChildren) "/" "PublicInbox" I also tried 'PublicInbox' '/PublicInbox' and '/ PublicInbox' etc. but none of them works. Most strangely, if I create a new mailbox with create('TTT') then it creates a new mailbox successfuly. Please help me Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: EuroPython 2006 and Py3.0
On 2006-07-05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Kay Schluehr: >> there is nothing really new or interesting or challenging. >> Micro-optimizations and shape lifting. > > I see. Maybe Python is becoming a commodity used by more than 10e6 > persons, so changellenges aren't much fit anymore. > Guido has tried to avoid the problems of Perl6, making Py3.0 a > improvement and not a revolution. The good thing is that we'll probably > see a beta version in 14-18 months. Py3.0 from being like fantasy is > become something close, this is a good thing. > I may ask you what you would like to see in Py3.0, but remember that > your answer may become ignored by the developers. These are just some ideas. Whether they fit into python or not I will leave to the developers. 1) Literal slices, in a sense we already have these, but they are limited to indexing. You can't do something like fun(::). May be this means the notation used now has to be adapted. 2) Iterable slices. Allow (provided the slice notation stays:) for i in (1:10): ... to do the same as: for i in xrange(1,10): This will allow to get rid of both range and xrange. Xrange is totally unnecessary and range(a,b) becomes list(a:b). 4) Introduce Top and Bottom objects, which will allways compare greater/smaller to other objects. Make them the default values for the start and stop values of slices. 5) Give slices a "&" and "|" operator. 7) Give slices the possibility to include the stop value. My first idea here was that the notation of slices was adapted, so that what is a:b now would become a:|b. A slice to include the b would then be a::b. You could even have a slice that didn't include the a but included the b like: a|:b Now I expect a lot of resitance here, so it this seems not feasable, just drop it. 6) Is this is all asked too much, make slice at least subclassable. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Byte array question
John Machin wrote: > On 14/07/2006 10:41 AM, Dan Winsor wrote: > > Sybren Stuvel wrote: > >> Dan Winsor enlightened us with: > >>> This one "works" in that it runs, but the server on the other end gets > >>> garbage unrelated to the test file. > >> Are you sure it is garbage? Have you tried changing byte order? > > > > Ah, that I hadn't. Any pointers to doing that? > > > > You found array.array.byteswap() in the manual and rejected it because ...? Unfortunately, this yielded similar results as not byte swapping it. Thanks for the pointer, though. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python strings outside the 128 range
Sybren Stuvel schrieb: > Diez B. Roggisch enlightened us with: >> Of course not. AFAIK there is no way figuring out which encoding the >> target console supports. The best you can do is to offer an option >> that allwos selection of the output encoding. > > You can use the LANG environment variable on many systems. On mine, > it's set to en_GB.UTF-8, which causes a lot of software to > automatically choose the right encoding. That might be a good heuristic - but on my Mac no LANG is set. So I should paraphrase my statement to "There is no reliable and cross-platform way figuring out which encoding the console uses". Diez -- http://mail.python.org/mailman/listinfo/python-list
undefined SW_MAXIMIZE for ShowWindow function
Hi! I'm trying to maximize a IE window. I have a handler and I'm trying to call ShowWindow to maximize it: ie = Dispatch('InternetExplorer.Application') handler = ie.HWND ie.Visible = 1 win32gui.ShowWindow(handler, SW_MAXIMIZE) But then I get this error: 'SW_MAXIMIZE' is not defined The function ShowWindow is defined (according to MSDN) as: BOOL ShowWindow( HWND hWnd, int nCmdShow ); How do I get SW_MAXIMIZE to be defined? -- http://mail.python.org/mailman/listinfo/python-list
Re: undefined SW_MAXIMIZE for ShowWindow function
[Etayki] > How do I get SW_MAXIMIZE to be defined? It's in win32con. Like this: >>> from win32con import * >>> SW_MAXIMIZE 3 -- Richie Hindle [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: undefined SW_MAXIMIZE for ShowWindow function
OK, so it it turns out, the window will maximize when SW_MAXIMIZE =3. But where can I find some documentation for that? Etayki wrote: > Hi! > > I'm trying to maximize a IE window. I have a handler and I'm trying to > call ShowWindow to maximize it: > > ie = Dispatch('InternetExplorer.Application') > handler = ie.HWND > ie.Visible = 1 > win32gui.ShowWindow(handler, SW_MAXIMIZE) > > But then I get this error: > 'SW_MAXIMIZE' is not defined > > The function ShowWindow is defined (according to MSDN) as: > > BOOL ShowWindow( HWND hWnd, > int nCmdShow > ); > > How do I get SW_MAXIMIZE to be defined? -- http://mail.python.org/mailman/listinfo/python-list
Re: undefined SW_MAXIMIZE for ShowWindow function
"Etayki" <[EMAIL PROTECTED]> wrote: > I'm trying to maximize a IE window. I have a handler and I'm trying to > call ShowWindow to maximize it: > > ie = Dispatch('InternetExplorer.Application') > handler = ie.HWND > ie.Visible = 1 > win32gui.ShowWindow(handler, SW_MAXIMIZE) > > But then I get this error: > 'SW_MAXIMIZE' is not defined SW_MAXIMIZE is a C preprocessor constant (a define), which means it only exists in a Windows-specific header file (winuser.h, in this case). > How do I get SW_MAXIMIZE to be defined? by grepping through the Windows header files to see what the corresponding value is, and using that value to set a Python variable in your script: > grep SW_MAXIMIZE *.H WINUSER.H:#define SW_MAXIMIZE 3 corresponds to SW_MAXIMIZE = 3 -- http://mail.python.org/mailman/listinfo/python-list
Re: undefined SW_MAXIMIZE for ShowWindow function
>> How do I get SW_MAXIMIZE to be defined? > > by grepping through the Windows header files to see what the corresponding > value is, and using that value to set a Python variable in your script oops. thought you were using ctypes, not the pythonwin extensions. see richie's reply for pythonwin details. -- http://mail.python.org/mailman/listinfo/python-list
Re: undefined SW_MAXIMIZE for ShowWindow function
[Etayki] > OK, so it it turns out, the window will maximize when SW_MAXIMIZE =3. > But where can I find some documentation for that? ShowWindow is a Win32 API call, so Googling within msdn.microsoft.com will usually get you straight to the relevant documentation: http://www.google.com/search?q=ShowWindow+site%3Amsdn.microsoft.com -- Richie Hindle [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: undefined SW_MAXIMIZE for ShowWindow function
[Fredrik] > oops. thought you were using ctypes, not the pythonwin extensions. Even when I'm using ctypes I use win32con for the constants, unless there's some special reason why I need the code to be independent of pywin32. -- Richie Hindle [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: imaplib question
Laszlo Nagy írta: > Hello, > > I'm trying to write a very simple program that moves all messages from > INBOX into another folder. > I'm not sure what am I doing wrong. This is a very simple task. I > believe I need to call these methods: > > - search -> get all message UIDs in the INBOX > - copy -> copy all messages to another folder > - store -> mark all messages in INBOX as deleted > - expunge -> delete them physically > Here is another try: conn = getnewimapconnection() try: typ,data = conn.select('INBOX',True) check_error((typ,data)) # Store all messages into another for uid in all_messages[0].split(): print uid typ,data = conn.uid('COPY',uid,'PublicInbox') check_error((typ,data)) finally: conn.logout() It does not raise any exception, but the messages are NOT copied to PublicInbox. Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: Tix.Grid patch
Fredrik Lundh schrieb: > > if you'd spent enough time clicking around on python.org, you might have ended > up on this page: > > http://sourceforge.net/tracker/?group_id=5470&atid=305470 > > (it's not obvious how to get there, so it's probably easiest if you just > click on the > above link ;-) > > Thanks Fredrik, I just uploaded the patch, hope everything is ok. Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython Grid Cell change question
Never mind, I used 2 different binds for the 2 different situations and it worked. thanks for looking anyhow. -- Kiran Kiran wrote: > Hello All, > I created a grid, where I register events every time the user changes > an existing value inside the grid control. Right now, I am using the > event: EVT_GRID_CELL_CHANGE. However, I realized that I need to > register that same kind of event even if the user doesnt change the > value, but just selects and then deselects. > > I tried creating my own custom event, where i check to see if the > editor is activated and then deactivated, and if so, then set the sell > value. However, this doesnt work because the value that it needs to be > set to is the same previous value that was in the grid. Therefore, I > can never get a new value in the grid. Here is the code for the events: > > in init(): > self.Bind(wx.grid.EVT_GRID_EDITOR_SHOWN, self.EditorShown) > self.Bind(wx.grid.EVT_GRID_EDITOR_HIDDEN, self.EditorHidden) > > > def EditorShown(self, event): > self.editorShown = True > event.Skip() > > def EditorHidden(self, event): > self.editorHidden = True > row = event.GetRow() > col = event.GetCol() > print "VAL = " + str(self.grid.GetCellValue(row, col)) > +str(self.OnTestCellValue(row, col)) > event.Skip() > > def OnTestCellValue(self, row, col): > if self.editorShown and self.editorHidden: > self.editorShown = False > self.editorHidden = False > self.SetCellValue(row, col) > > def SetCellValue(self, row, col): > print "EVENT PROCESSIGN STARTED" > print "RAW VAL = " + str(self.grid.GetCellValue(row, col)) > value = int(self.grid.GetCellValue(row, col), 16) > print "VAL = " + str(value) > # if we need to add a row > if row == (len(self.data)-1): > self.expandGrid() > self.data.append([]) > # if we need to delete a row > if row != 0 and value == '': > self.data[row][3] = 'Delete' > else: > self.addToData(row, col, value, True) > # whether the user intended a read or write > if self.data[row][3] != 'Delete': > if col == 1: > self.data[row][3] = 'Read' > elif col == 2: > self.data[row][3] = 'Write' > > q = copy.deepcopy(self.data) # cloning object > self.requestQueue.put(q) # putting object onto queue > print "EVENT PROCESSIGN ENDED" > > Thanks a lot for your help, and please mind the spacing. > > I should note that before, my bind was: > self.Bind(wx.grid.EVT_GTID_CELL_CHANGE, self.SetCellValue) > > > thanks, > Kiran -- http://mail.python.org/mailman/listinfo/python-list
Re: Python strings outside the 128 range
On 2006-07-14 10:52:22, Diez B. Roggisch wrote: Will print take care of encoding translation according to the encoding used in the target console? >>> >>> Of course not. AFAIK there is no way figuring out which encoding the >>> target console supports. The best you can do is to offer an option >>> that allwos selection of the output encoding. >> >> You can use the LANG environment variable on many systems. On mine, >> it's set to en_GB.UTF-8, which causes a lot of software to >> automatically choose the right encoding. > > That might be a good heuristic - but on my Mac no LANG is set. So I > should paraphrase my statement to "There is no reliable and > cross-platform way figuring out which encoding the console uses". Right... without being a cross-platform specialist, I figured that much :) I just thought that maybe the Python runtime had platform-specific implementations for retrieving the platform-specific information about the encoding used in the runtime environment (which is probably there on many platforms) -- similar to maybe the platform-specific implementations of file access, process and thread handling etc. Anyway, it seems that anything non-ASCII is a bit problematic and needs "manual" handling of the runtime environment encoding. Seems a bit odd, given the worldwide distribution of Python... I would have thought that such a rather basic task like printing an accented character on a console had been solved in a standard way, rather than relying on individual (wheel-reinventing) custom coding. Isn't that something that pretty much everybody (outside the USA, at least) needs? Thanks for sharing your thoughts, Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Tix Tree open/close issue
It works. Thanks Rob. Sorin __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Widestudio Users?
Just curious if anyone out there uses Python programming in the Widestudio (http://www.widestudio.org) GUI IDE toolkit. I have looked into it when running into some portability limitations trying certain GUI tookits for Ruby, but couldn't get immersed into Widestudio. Since I use Python as well I was wondering if Pythonistas have given this a shot. Off hand the widgets look a bit old and ugly, but from a portability and language support standpoint it has still been on my radar. This GUI IDE toolkit comes with support for Ruby, Python, Perl, and other languages and looks like an effective catch-all, as its bundled applications can run on Windows, Linux, Windows Mobile, Embedded Linux, *BSD, Mac OS, etc. But it's primarily geared for a Japanese audience from the looks of it. There are some books out there for it, but there are all on Amazon.Com.Jp and don't have English translations available. Anyone? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python strings outside the 128 range
Gerhard Fiedler wrote: > Anyway, it seems that anything non-ASCII is a bit problematic and needs > "manual" handling of the runtime environment encoding. Seems a bit odd, > given the worldwide distribution of Python... I would have thought that > such a rather basic task like printing an accented character on a console > had been solved in a standard way, rather than relying on individual > (wheel-reinventing) custom coding. Isn't that something that pretty much > everybody (outside the USA, at least) needs? umm. what are we talking about here, really ? $ python >>> import sys >>> sys.platform 'linux2' >>> sys.stdout.encoding 'UTF-8' >>> print unichr(233) é > python >>> import sys >>> sys.platform 'win32' >>> sys.stdout.encoding 'cp850' >>> print unichr(233) é -- http://mail.python.org/mailman/listinfo/python-list
Re: EuroPython 2006 and Py3.0
Antoon Pardon <[EMAIL PROTECTED]> wrote: > These are just some ideas. Whether they fit into python or not I will > leave to the developers. I'm not a Python pro. but: > 1) Literal slices, in a sense we already have these, but they are >limited to indexing. You can't do something like fun(::). May >be this means the notation used now has to be adapted. I don't see the use case for this. > 2) Iterable slices. Allow (provided the slice notation stays:) > > for i in (1:10): > ... > >to do the same as: > > for i in xrange(1,10): > > This will allow to get rid of both range and xrange. Xrange > is totally unnecessary and range(a,b) becomes list(a:b). -1. First: you have to introduce new syntax for an old thing. Second: you overload the meaning of slicing and the slice operator and so on. range is perfectly integrated and the right tool for the job. There's no need to introduce new syntax to iterate over a range of integers. > 4) Introduce Top and Bottom objects, which will allways >compare greater/smaller to other objects. Make them >the default values for the start and stop values of >slices. > 5) Give slices a "&" and "|" operator. > > > 7) Give slices the possibility to include the stop value. > >My first idea here was that the notation of slices >was adapted, so that what is a:b now would become >a:|b. A slice to include the b would then be a::b. >You could even have a slice that didn't include the >a but included the b like: a|:b > >Now I expect a lot of resitance here, so it this >seems not feasable, just drop it. > > > 6) Is this is all asked too much, make slice at least >subclassable. Why do you need power slices? -- Lawrence - http://www.oluyede.org/blog "Nothing is more dangerous than an idea if it's the only one you have" - E. A. Chartier -- http://mail.python.org/mailman/listinfo/python-list
Re: EuroPython 2006 and Py3.0
Steve Holden: > The real problems with the Py3k list seem to be associated with a number > of people who, despite having had little apparent connection to the > language until now, have joined the list and started making > inappropriate suggestions, which then have to be (patiently) rejected. This attitude may have some downsides. The Python developers don't know everything, other people can have some experience of computer languages too. So people coming from different languages, like Erlang, Ruby, Dylan, Io, CommonLisp, C#, Haskell, and Lua can give useful suggestions to update and 'improve' Python. Often their suggestions can be unfit for Python, but if you don't waste a little of time evaluating their ideas, you lose some possibilities. Python 3.0 isn't just an occasion to remove some rust and obsolete things from Python, but a way to invent and adopt different ideas too. So I think wasting some time in that way is positive for Py 3.0 devs. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: attaching debugger to runinng python program
alf wrote: > Bill Pursell wrote: > > Now, in another shell, > > % gdb > > (gdb) attach 54321 > > > > Thx for the reply. But I wish to debug the python program, not python > interpreter itself. I haven't used this, but it looks like it's worth a try: http://hapdebugger.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Joachim Durchholz wrote: > Marshall schrieb: > > What about my example of SQL? Mutation, no pointers, no aliasing. > > Yet: useful. > > Sorry, but SQL does have aliasing. Well. I suppose we do not have an agreed upon definition of aliasing, so it is hard to evaluate either way. I would propose using the same one you used for identity: if there are two variables and modifying one also modifies the other, then there is aliasing between them. I avoided mentioning equality to include, for example, having an array i that is an alias to a subset of array j. Please feel free to critque this definition, and/or supply an alternative. > E.g. if you have records that have name="John", surname="Doe", the > statements >SELECT * FROM persons WHERE name = "John" > and >SELECT * FROM persons WHERE name = "Doe" > are aliases of each other. > > The alias is actually in the WHERE clause. Not by my definition, because there is only one variable here. > And this *can* get you into > trouble if you have something that does >UPDATE ... WHERE name = "John" > and >UPDATE ... WHERE surname = "Doe" > e.g. doing something with the Johns, then updating the names of all > Does, and finally restoring the Johns (but not recognizing that changing > the names of all Does might have changed your set of Johns). The fact that some person might get confused about the semantics of what they are doing does not indicate aliasing. It is easy enough to do an analysis of your updates and understand what will happen; this same analysis is impossible with two arbitrary pointers, unless one has a whole-program trace. That strikes me as a significant difference. > Conceptually, this is just the same as having two different access path > to the same memory cell. Or accessing the same global variable through a > call-by-reference parameter and via its global name. There are similarities, but they are not the same. > BTW with views, you get not just aliasing but what makes aliasing really > dangerous. Without views, you can simply survey all the queries that you > are working with and lexically compare table and field names to see > whether there's aliasing. With views, the names that you see in a > lexical scope are not enough to determine aliasing. > E.g. if you use a view that builds upon the set of Johns but aren't > aware of that (possibly due to abstraction barriers), and you change the > name field of all Does, then you're altering the view without a chance > to locally catch the bug. That's just as bad as with any pointer > aliasing problem. It is certainly aliasing, but I would not call it "just as bad." There are elaborate declarative constraint mechanisms in place, for example. And the definition of the view itsef is a declarative, semantic entity. Whereas a pointer is an opaque, semantics-free address. Marshall -- http://mail.python.org/mailman/listinfo/python-list
Re: How to start more than one process at the same time?
Have you considered a multi-threaded solution? The following websites offer reasonable examples: http://en.wikibooks.org/wiki/Programming:Python/Threading http://www.wellho.net/solutions/python-python-threads-a-first-example.html -Derek Dirk Hagemann wrote: > Hi! > > How can I start several jobs at the same time with python? I want to > collect data from some servers and I don't want to wait until the first > server is finished. These jobs should run parallel to save time. > What I tried is this: > os.popen('regdmp -m server1 > "HKEY_LOCAL_MACHINE\\Software\\Intel\\LanDesk\\VirusProtect6\\CurrentVersion\\Clients" > >> av_server1.txt') > os.popen('regdmp -m server2 > "HKEY_LOCAL_MACHINE\\Software\\Intel\\LanDesk\\VirusProtect6\\CurrentVersion\\Clients" > >> av_server2.txt') > os.popen('regdmp -m server3 > "HKEY_LOCAL_MACHINE\\Software\\Intel\\LanDesk\\VirusProtect6\\CurrentVersion\\Clients" > >> av_server3.txt') > > I didn't get an error-message, but I also didn't get a result. No > text-file was created. > I also tried to do the same thing via batch-files, but that didn't > change anything. > > Is it just not possible or what am I doing wrong? > > Thanks for any help! > Dirk Hagemann -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Andreas Rossberg wrote: > Marshall wrote: > > > > After all, what are the alternatives? Purely-functional > > languages remove themselves from a large class of > > problems that I consider important: data management. > > Maybe, but I have yet to see how second-class variables are really more > adequate in dealing with it. > > And note that even with second-class state you can still have aliasing > issues - you just need mutable arrays and pass around indices. Keys in > databases are a more general form of the same problem. So for array a, you would claim that "a[5]" is an alias for (a part of) "a"? That seems to stretch the idea of aliasing to me. With these two expressions, it is obvious enough what is going on; with two arbitrary pointers, it is not. It seems to me the source of the problem is the opacity of pointers, but perhaps I am missing something. > > I have explored the OO path to its bitter end and am > > convinced it is not the way. So what is left? Uniqueness > > types and logic programming, I suppose. I enjoy logic > > programming but it doesn't seem quite right. But notice: > > no pointers there! And it doesn't seem to suffer from the > > lack. > > Uh, aliasing all over the place! Actually, I think that logic > programming, usually based on deep unification, brings by far the worst > incarnation of aliasing issues to the table. Hmmm. Can you elaborate just a bit? Marshall -- http://mail.python.org/mailman/listinfo/python-list
Weird platform dependent error: Using pty.fork()
Hi, I'm observing some weird behavior and have written the following test program to demonstrate. This works under cygwin/WinXP but not Gentoo(kernel 2.6): huh.py --- import pty,os,sys # Fork ( pid, fd ) = pty.fork() if pid == 0: # Child thread print 'Have a happy day!' print 'Forza Azzurri!' else: # Controlling process # read stdout from child process # and send to stderr stream = os.fdopen( fd ) line = stream.readline() while len( line ) > 0: sys.stderr.write(line) line = stream.readline() stream.close() --- This program runs perfectly under cygwin on Windows XP using python 2.4.3: [EMAIL PROTECTED] ~/proj/plum $ python huh.py Have a happy day! Forza Azzurri! [EMAIL PROTECTED] ~/proj/plum $ python huh.py 2>/dev/null [EMAIL PROTECTED] ~/proj/plum $ python Python 2.4.3 (#1, May 18 2006, 07:40:45) [GCC 3.3.3 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> [EMAIL PROTECTED] ~/proj/plum $ But on Gentoo (2.6 kernel) with Python 2.4.3 it dies with an I/O error when it hits the end of the stream: [EMAIL PROTECTED] ~/proj/plum $ python huh.py Have a happy day! Forza Azzurri! Traceback (most recent call last): File "huh.py", line 19, in ? line = stream.readline() IOError: [Errno 5] Input/output error [EMAIL PROTECTED] ~/proj/plum $ python huh.py 2>/dev/null [EMAIL PROTECTED] ~/proj/plum $ python Python 2.4.3 (#1, Jul 13 2006, 23:02:30) [GCC 3.3.6 (Gentoo 3.3.6, ssp-3.3.6-1.0, pie-8.7.8)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> Anybody have any idea what's going on here? Is there a better way to fork and capture the output of the child process? Thanks, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Joachim Durchholz wrote: > Marshall schrieb: > > void foo() { > > int i = 0; > > int j = 0; > > j = 1; > > i = 2; > > // check value of j here. It is still 1, no matter what you filled > > // in above. > > // The assignment to i cannot be made to affect the value of j. > > } > > > > Those two local primitive variables cannot be made to have the same > > identity. > > Sure. To state it more clearly, they cannot be aliases. Yes. > > But you can update them, so this is an example of mutability > > without the possibility of identity. > > You're being a bit sloppy with terminology here. "Identity" in the > phrase above refers to two entities, in the sense of "i and j cannot be > identical". > Identity is actually a property of a single entity, namely that what > remains constant regardless of what you do with the entity. It is a fair critque. I'll try to be more precise. Marshall -- http://mail.python.org/mailman/listinfo/python-list
wxPython Grid XY Coordinates question
Hello All, I am writing an app in wxPython using a grid. I need to be able to recognize what cell in the grid the user is hovering over with the mouse. How to do this? I tried XYToCell(x, y), but that doesnt work properly because it thinks that mouse position (0, 0) is the first cell in the grid, and then goes from there, so if i move the grid to a differernt area on the screen, the XYToCell is messed up in what it returns. Any ideas on how to get this to work or any other way? thanks, Kiran -- http://mail.python.org/mailman/listinfo/python-list
ie.ExecWB(40004, 2, 0, 0)
Thanks for the previous response. Now I want to do something similar: ie.ExecWB(IDM_SELECTALL, OLECMDEXECOPT_DONTPROMPTUSER) However, I don't have the values for the above constants either, and I don't know how to import them. Any ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Joachim Durchholz wrote: > > You can have aliasing without pointers; e.g. arrays are fully sufficient. > If i = j, then a [i] and a [j] are aliases of the same object. I am having a hard time with this very broad definition of aliasing. Would we also say that a[1+1] and a[2] are aliases? It seems to me, above, that we have only a, and with only one variable there can be no aliasing. A further question: given a 32 bit integer variable x, and offsets i and j (equal as in the above example) would you say that x &= (1 << i) and x &= (1 << j) are aliased expressions for setting a particular bit in x? I am not being facetious; I am trying to understand the limits of your definition for aliasing. > (After I observed that, I found it no longer a surprise that array > optimizations are what Fortran compiler teams sink most time into. The > aliasing problems are *exactly* the same as those with pointers in C - > though in practice, the Fortranistas have the advantage that the > compiler will usually know that a [i] and b [j] cannot be aliases of > each other, so while they have the same problems, the solutions give the > Fortranistas more leverage.) I don't understand this paragraph. On the one hand, it seems you are saying that C and Fortran are identically burdened with the troubles caused by aliasing, and then a moment later it seems you are saying the situation is distinctly better with Fortran. > > What term would you use? First-class variables? > > I think it's more a quasi-continuous spectrum. > > On one side, we have alias-free toy languages (no arrays, no pointers, > no call-by-reference, just to name the most common sources of aliasing). > > SQL is slightly more dangerous: it does have aliases, but they are > rarely a problem (mostly because views aren't a very common thing, and > even if they are used, they aren't usually so abstract that they really > hide the underlying dependencies). > > Next are languages with arrays and call-by-reference. "Pascal without > pointers" would be a candidate. > Here, aliasing occurs, and it can and does hide behind abstraction > barriers, but it's not a serious problem unless the software becomes > *really* large. > > The end of the line are languages that use references to mutable data > everywhere. All OO languages are a typical example of that. Now with this, it appears you are agreeing that SQL has an advantage vis-a-vis aliasing compared to OO languages. Yes? If so, we are agreeing on the part I care about, and the specifics of just what we call aliasing are not so important to me. Marshall -- http://mail.python.org/mailman/listinfo/python-list
Re: searching for strings (in a tuple) in a string
Simon Forman wrote: ... > I usually use this with assert statements when I need to check a > sequence. Rather than: > > for something in something_else: assert expression > > I say > > assert False not in (expression for something in something_else) > > This way the whole assert statement will be removed if you use the '-O' > switch to the python interpreter. (It just occurred to me that that's > just an assumption on my part. I don't know for sure that the > interpreter isn't smart enough to remove the first form as well. I > should check that. ;P ) FWIW I did just check that and it seems valid, the second form gets "optimized" away. File delme.py: import dis N = (True, True, False) def a(): for n in N: assert n def b(): assert False not in (n for n in N) dis.dis(a) print '===' dis.dis(b) Results of running it without '-O': $ python delme.py 8 0 SETUP_LOOP 28 (to 31) 3 LOAD_GLOBAL 0 (N) 6 GET_ITER >>7 FOR_ITER20 (to 30) 10 STORE_FAST 0 (n) 9 13 LOAD_FAST0 (n) 16 JUMP_IF_TRUE 7 (to 26) 19 POP_TOP 20 LOAD_GLOBAL 2 (AssertionError) 23 RAISE_VARARGS1 >> 26 POP_TOP 27 JUMP_ABSOLUTE7 >> 30 POP_BLOCK >> 31 LOAD_CONST 0 (None) 34 RETURN_VALUE === 13 0 LOAD_GLOBAL 0 (False) 3 LOAD_CONST 1 ( at 0xb7d89ca0, file "delme.py", line 13>) 6 MAKE_FUNCTION0 9 LOAD_GLOBAL 1 (N) 12 GET_ITER 13 CALL_FUNCTION1 16 COMPARE_OP 7 (not in) 19 JUMP_IF_TRUE 7 (to 29) 22 POP_TOP 23 LOAD_GLOBAL 2 (AssertionError) 26 RAISE_VARARGS1 >> 29 POP_TOP 30 LOAD_CONST 0 (None) 33 RETURN_VALUE Results of running it with '-O': $ python -O delme.py 8 0 SETUP_LOOP 14 (to 17) 3 LOAD_GLOBAL 0 (N) 6 GET_ITER >>7 FOR_ITER 6 (to 16) 10 STORE_FAST 0 (n) 9 13 JUMP_ABSOLUTE7 >> 16 POP_BLOCK >> 17 LOAD_CONST 0 (None) 20 RETURN_VALUE === 13 0 LOAD_CONST 0 (None) 3 RETURN_VALUE -- http://mail.python.org/mailman/listinfo/python-list
Re: imaplib question - answering my own question
Laszlo Nagy írta: > Laszlo Nagy írta: > >> Hello, >> >> I'm trying to write a very simple program that moves all messages from >> INBOX into another folder. >> I'm not sure what am I doing wrong. This is a very simple task. I >> believe I need to call these methods: >> >> - search -> get all message UIDs in the INBOX >> - copy -> copy all messages to another folder >> - store -> mark all messages in INBOX as deleted >> - expunge -> delete them physically >> >> Here is the solution - code to move all messages from SOURCE_FOLDER to DEST_FOLDER self.logger.info('Connecting to IMAP server...') conn = getnewimapconnection() cnt = 0 try: typ,data = conn.select(local.SOURCE_FOLDER) check_error((typ,data)) cnt = int(data[0]) if cnt > 0: self.logger.info("Moving %s messages from %s to %s",cnt,local.SOURCE_FOLDER,local.DEST_FOLDER) # Get uids for all messages typ,all_messages = conn.uid('SEARCH',None,'ALL') check_error((typ,data)) uids = all_messages[0].split() # Store all messages into another folder for uid in uids: check_error(conn.uid('COPY',uid,local.DEST_FOLDER)) # Delete all messages from inbox for uid in uids: check_error(conn.uid('STORE',uid,'+FLAGS.SILENT','(\\Deleted)')) conn.expunge() else: self.logger.info("No new messages in %s",local.SOURCE_FOLDER) finally: conn.logout() Here is the connection factory: class IMAPError(Exception): pass def check_error((typ,data)): if (typ != 'OK'): raise IMAPError((typ,data)) def getnewimapconnection(): conn = imaplib.IMAP4_SSL(local.IMAP_HOST) check_error(conn.LOGIN(local.IMAP_LOGIN,local.IMAP_PWD)) return conn I should still check if the operations can be done in bulk (e.g. for many uids at the same time). Is this possible? I don't know. Best, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
{} for set notation
I really like the set notation idea. Now that sets are first class "citizens" along with dicts, lists and tuples I think they should be used when it makes sense to use them A keyset of a dictionary should be viewed as a set not a list because it is a key_set_ after all. Also sets should get back their traditional notation of '{' and '}', which dictionaries have been in 'borrowing' for all this time in Python. When defining a non-empty set it could be unambiguous to share the notation. So : {1,2,3} is set([1,2,3]) while {1:'a', 2:'b', 3:'c'} could still be the a dictionary. Of course then {1, 2, 3:'b'} would be undefined and would raise an exception or alternatively be equivalent to {1:None, 2:None, 3:'b'} - a dictionary. As far as the set and dictionary notation being "confusing" it seems that a common notation is actually a _benefit_, after all sets and dictionaries are not that different! A dictionary is a mapping (surgective explicit function?) from a _set_ of keys to a set (actually a bad or multiset in Python) of values. At the same time a set can also be regarded as a degenerate dictionary as in {1:None, 2:None, 3:None}. A similarity of notation does make sense to me. Of course the empty set is the problem since {} could be interpreted ambiguously as both a set or a dictionary. I think it makes sense to give the '{}' notation to the empty _set_ as this will make more sense as far as common sense goes. If the proposal is to have {x} be the a set([x]) then it only makes sense for {} be a set([]). This will break compatibility with old code and that is why it should be in Python 3000 not in 2.x.x The empty dictionary is probably best represented as {:}, it is actually more clear this way as it shows that there is a key and a value separated by ':' and in this case they are both missing so it is an empty dictionary. Also the frozenset, although not used as often, could still probably get its own notation too. For example: 1.({1,2,3}) - a symmetry with tuples, which are also immutable. The problem of a one element tuple i.e. (10,) not (10) will also be present here. So just as there is a need to use a comma to make (10,)=tuple([10]) one would have to use a comma to specify that a tuple is needed and not a a frozenset() but at the same time the ({1,2,3}) could then never be reduced to {1,2,3}. In other words: ({1,2,3},) is tuple({1,2,3}) ({1,2,3}) is a frozenset([1,2,3]) and never just {1,2,3}. This notation would make the parser go 'nuts'. I think the next idea might be better: 2. _{1,2,3}_ - the underscores '_' intuitively could mean that the braces are fixed blocks and will not "move" to accomodate addition or removal of elements i.e. the fact that the frozenset is immutable. Or perhaps a more verbose _{_1,2,3_}_ would be better, not sure... 3. {|1,2,3|} or maybe |{1,2,3}| - same aesthetic rationale as above, '|'s look like 'fences' that will not allow the braces to 'move', but this would look to much like Ruby's blocks so 1 and 2 might be better. In general a 'set' are a fundamental data structure. It has always been secondary in traditional programming languages. For simplicity in implementation arrays and lists have been used to mimic a set. Now that Python has a built in set it only makes sense to give it its own notation and maybe Python 3000 is just the right time for it. - Nick Vatamaniuc [EMAIL PROTECTED] wrote: > >From this interesting blog entry by Lawrence Oluyede: > http://www.oluyede.org/blog/2006/07/05/europython-day-2/ > and the Py3.0 PEPs, I think the people working on Py3.0 are doing a > good job, I am not expert enough (so I don't post this on the Py3.0 > mailing list), but I agree with most of the things they are agreeing > to. Few notes: > > - input() vanishes and raw_input() becomes sys.stdin.readline(). I > think a child that is learning to program with Python can enjoy > something simpler: input() meaning what raw_input() means today. > > > - dict.keys() and items() returns a set view > > This is being discussed here too a lot, I agree that they will just > become equivalent to iterkeys() and iteritems(). > > > - dict.values() a bag (multiset) view > > I think this isn't a good idea, I think bags can be useful but in this > situation they make things too much complex. > > > http://www.python.org/dev/peps/pep-3100/#core-language : > - Set literals and comprehensions: {x} means set([x]); {x, y} means > set([x, y]). {F(x) for x in S if P(x)} means set(F(x) for x in S if > P(x)). NB. {range(x)} means set([range(x)]), NOT set(range(x)). There's > no literal for an empty set; use set() (or {1}&{2} :-). There's no > frozenset literal; they are too rarely needed. > > I like the idea of set literals, but using {1:2} for dicts and {1, 2} > for sets may look a bit confusing. > And using {} for the empty dict is confusing even more, newbies will > use it a lot for empty sets. Maybe the {:} for the empty dict and {} > for the empty set are a bit better. > Mayb
having a problem with an instance of a method.
I wanted to dig a little deeper understanding of Classes, Methods and Instances. However I get this - ' AClassA instance has no attribute' as an error when I call the method I am using as a learning tool. Here's the code, from hammer.py - class AClassA: def __init__(self): self.a = 0 def printit(self): print "done from Class a" class BClassB: def __init__(self): self.a = 0 def printit(self): print "done from Class b" Here is the call - Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from hammer import * >>> x = AClassA() >>> x.printit() Traceback (most recent call last): File "", line 1, in ? AttributeError: AClassA instance has no attribute 'printit' >>> dir(AClassA) ['__doc__', '__init__', '__module__'] >>> - I can see that AClassA has no method defined so the error makes sense. But I can't figure out why 'def printit(self): is not included as a component of the class AClassA. The syntax looks right. Observations on what I am doing wrong? -- http://mail.python.org/mailman/listinfo/python-list
time.clock()
The manual says: On Unix, return the current processor time as a floating point number expressed in seconds. So I ran this program: #!/usr/bin/python import time while 1: print time.clock() This gave me a stream of floats, the integer part of which only updated about every three seconds. Now, the manual also states: The precision, and in fact the very definition of the meaning of ``processor time'', depends on that of the C function of the same name So I "man 3 clock" and notice: The value returned is the CPU time used so far as a clock_t; to get the number of seconds used, divide by CLOCKS_PER_SEC. So, I'm wondering how to get that value from python. All I really want to do is know current time relative to a given point so that I can capture MIDI events, and store the time at which they arrive. Am I barking up the wrong tree? Thanks, Toby -- Posted via a free Usenet account from http://www.teranews.com -- http://mail.python.org/mailman/listinfo/python-list
Re: ie.ExecWB(40004, 2, 0, 0)
Etayki wrote: > Thanks for the previous response. Now I want to do something similar: > > ie.ExecWB(IDM_SELECTALL, OLECMDEXECOPT_DONTPROMPTUSER) > > However, I don't have the values for the above constants either, and I > don't know how to import them. Any ideas? hint: google often picks up source code as well. if you google for the constant names, you'll often find the values on the first result page. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to start more than one process at the same time?
Look into the subprocess module. Possibly relevant link follows: http://docs.python.org/lib/node244.html -- http://mail.python.org/mailman/listinfo/python-list
Re: EuroPython 2006 and Py3.0
> The real problems with the Py3k list seem to be associated with a number > of people who, despite having had little apparent connection to the > language until now, have joined the list and started making > inappropriate suggestions, which then have to be (patiently) rejected. Steve, What does a 'connection to the language' mean? Does it mean 'using' it for years or 'being involved in its actual development' for years? It seems that sometimes a newcomer can actually bring in a fresh idea. What new users think and what bothers them is actually important. The reason Python became so popular is because it attracted so many new users. If anyone has a reasonable suggestion, let them post it to this group, see what the reaction is, then let them write a proposal in the right format using all the procedures and all. Looking forward to Python 3000 this is the time to do it. Rejections do take time but they will just have to happen, out of 10 rejected maybe there will be one good proposal that will make Python a little better. -Nick V. Steve Holden wrote: > [EMAIL PROTECTED] wrote: > > Kay Schluehr: > > > >>there is nothing really new or interesting or challenging. > >>Micro-optimizations and shape lifting. > > > > > > I see. Maybe Python is becoming a commodity used by more than 10e6 > > persons, so changellenges aren't much fit anymore. > > Guido has tried to avoid the problems of Perl6, making Py3.0 a > > improvement and not a revolution. The good thing is that we'll probably > > see a beta version in 14-18 months. Py3.0 from being like fantasy is > > become something close, this is a good thing. > > I may ask you what you would like to see in Py3.0, but remember that > > your answer may become ignored by the developers. > > > The real problems with the Py3k list seem to be associated with a number > of people who, despite having had little apparent connection to the > language until now, have joined the list and started making > inappropriate suggestions, which then have to be (patiently) rejected. > > regards > Steve > -- > Steve Holden +44 150 684 7255 +1 800 494 3119 > Holden Web LLC/Ltd http://www.holdenweb.com > Skype: holdenweb http://holdenweb.blogspot.com > Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: {} for set notation
Nick Vatamaniuc wrote: > I really like the set notation idea. Now that sets are first class > "citizens" along with dicts, lists and tuples I think they should be > used when it makes sense to use them In actual usage, though, how often is it strictly required one uses a set over a list? It is similar to how queue and stack are not in the default namespace. Unless you really need to ensure no one is allowed to make random access changes to your data, a list with push and pop is really all you need. I beleive the same applies in regards to sets. -- http://mail.python.org/mailman/listinfo/python-list
Re: EuroPython 2006 and Py3.0
[EMAIL PROTECTED] wrote: > This attitude may have some downsides. The Python developers don't know > everything, other people can have some experience of computer languages > too. "some experience of computer languages" != "experience of language design and implementation" as long as most of the traffic on py3k is bikeshed stuff and hyper- generalizations, most people who do hard stuff will spend their time elsewhere. -- http://mail.python.org/mailman/listinfo/python-list
Re: time.clock()
Tobiah wrote: > Am I barking up the wrong tree? I don't think so, time.clock() has always worked fine for me. You can also try time.time(). It is not as precise, but it might be sufficient for your needs. -- http://mail.python.org/mailman/listinfo/python-list
Re: time.clock()
Tobiah wrote: > The manual says: > > On Unix, return the current processor time as a > floating point number expressed in seconds. > > So I ran this program: > > #!/usr/bin/python > > import time > > while 1: > print time.clock() > > > > This gave me a stream of floats, the integer part of which > only updated about every three seconds. Now, the manual > also states: > > The precision, and in fact the very definition of the meaning > of ``processor time'', depends on that of the C function of the same name > > So I "man 3 clock" and notice: > > The value returned is the CPU time used so far as a clock_t; to get the > number >of seconds used, divide by CLOCKS_PER_SEC. > > So, I'm wondering how to get that value from python. All I > really want to do is know current time relative to a given > point so that I can capture MIDI events, and store the time > at which they arrive. Am I barking up the wrong tree? What you want sound like the 'wall clock' time. The CPU time is the time that the CPU spent on executing your process. And unless the process uses 100% of the CPU, CPU time will appear to be 'slower' than the wall clock. In your little program above the CPU spent about one third of the time on this process and the rest is used for other processes (e.g. updating the display). What you need is time.time(), if its precision is sufficient. -- Benjamin Niemann Email: pink at odahoda dot de WWW: http://pink.odahoda.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: time.clock()
Tobiah wrote: > import time > > while 1: > print time.clock() > > This gave me a stream of floats, the integer part of which > only updated about every three seconds. Now, the manual > also states: > > The precision, and in fact the very definition of the meaning > of ``processor time'', depends on that of the C function of > the same name > > So I "man 3 clock" and notice: > > The value returned is the CPU time used so far as a clock_t; > to get the number of seconds used, divide by CLOCKS_PER_SEC. > > So, I'm wondering how to get that value from python. by calling clock(), of course. > All I really want to do is know current time relative to a given > point so that I can capture MIDI events, and store the time at > which they arrive. if you want real time, use time.time(). CPU time (processor time) is something different; that's based on how many CPU cycles your program has used up since it started (usually approximated by checking what process is running at regular intervals). if your program doesn't do anything, or, as in your example, spends most of its time waiting for someone else to do something, it won't consume many cycles. -- http://mail.python.org/mailman/listinfo/python-list
Re: EuroPython 2006 and Py3.0
On Fri, 14 Jul 2006 18:45:07 +0200, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > >> This attitude may have some downsides. The Python developers don't know >> everything, other people can have some experience of computer languages >> too. > > "some experience of computer languages" != "experience of language > design and implementation" > > as long as most of the traffic on py3k is bikeshed stuff and hyper- > generalizations, most people who do hard stuff will spend their time > elsewhere. Paul Prescod once wrote in c.l.py: If Python strays into trying to be something completely new it will fail, like Scheme, K and Smalltalk. There are both technical and sociological reasons for this. If you stray too far technically, you make mistakes: either you make modelling mistakes because you don't have an underlying logical model (i.e. C++ inheritance) or you make interface mistakes because you don't understand how your new paradigm will be used by real programmers. Let research languages innovate. Python integrates. If Python 3000 turns into a let's-try-all-sorts-of-goofy-new-ideas language, at least some of those ideas will turn out to have been mistakes, and then we'll need a Python 3000++ to clean things up. --amk -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Marshall wrote: > Andreas Rossberg wrote: > > > > And note that even with second-class state you can still have aliasing > > issues - you just need mutable arrays and pass around indices. Keys in > > databases are a more general form of the same problem. > > So for array a, you would claim that "a[5]" is an alias for > (a part of) "a"? That seems to stretch the idea of aliasing > to me. Not at all, I'd say. In my book, aliasing occurs whenever you have two different "lvalues" that denote the same mutable cell. I think it would be rather artificial to restrict the definition to lvalues that happen to be variables or dereferenced pointers. So of course, a[i] aliases a[j] when i=j, which in fact is a well-known problem in some array or matrix routines (e.g. copying array slices must always consider overlapping slices as special cases). > > Uh, aliasing all over the place! Actually, I think that logic > > programming, usually based on deep unification, brings by far the worst > > incarnation of aliasing issues to the table. > > Hmmm. Can you elaborate just a bit? Logic variables immediately become aliases when you unify them. Afterwards, after you bind one, you also bind the other - or fail, because both got already bound the other way round. Unfortunately, unification also is a deep operation, that is, aliasing can be induced into variables deeply nested into some terms that happen to get unified, possibly without you being aware of any of this (the unification, nor the variable containment). To avoid accidental aliasing you essentially must keep track of all potential unifications performed by any given predicate (including transitively, by its subgoals), which totally runs square to all concerns of modularity and abstraction. I've never been much of a logic programmer myself, but our language group has a dedicated LP and CP background, and people here have developed very strong opinions about the adequateness of unrestricted logic variables and particularly unification in practice. I remember somebody calling Prolog "the worst imperative language ever invented". - Andreas -- http://mail.python.org/mailman/listinfo/python-list
Python for Embedded Systems?
Is there a Python packaging that is specifically for embedded systems? ie, very small and configurable so the user gets to select what modules to install? For Linux-based embedded systems in particular? I'm thinking of running it on the Linksys's Linux-based open source router WRT54G. It has 4MB flash and 16MB RAM. I think another model has 16MB flash. Any possibilities of running Python on these systems? If Python is not the best candidate for embedded systems because of the size, what (scripting) language would you recommend? PHP may fit but I don't quite like the language. Anything else? Loa is small but it does not seem to be powerful enough. -- http://mail.python.org/mailman/listinfo/python-list
activestate vs enpython
does anyone know if the activestate distribution has all of the numpy, numarray, matplotlib, scipy, and scientific python? their website does not say what it includes. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Andreas Rossberg wrote: > OK, this is interesting. I don't know Hermes, is this sort of like a > dynamically checked equivalent of linear or uniqueness typing? I'm not sure what linear or uniqueness typing is. It's typestate, and if I remember correctly the papers I read 10 years ago, the folks at TJWatson that invented Hermes also invented the concept of typestate. They at least claim to have coined the term. It's essentially a dataflow analysis that allows you to do the same sorts of things that "don't read variables that may not yet have been assigned to", except that you could annotate that variables change to the state of "uninitialized" after they've already been initialized. > Mh, but if I understand correctly, this seems to require performing a > deep copy - which is well-known to be problematic, and particularly > breaks all kinds of abstractions. Um, no, because there are no aliases. There's only one name for any given value, so there's no "deep copy" problems. A deep copy and a shallow copy are the same thing. And there are types of values you can assign but not copy, such as callmessages (which are problematic to copy for the same reason a stack frame would be problematic to copy). I believe, internally, that there were cases where the copy was "deep" and cases where it was "shallow", depending on the surrounding code. Making a copy of a table and passing it to another process had to be a "deep" copy (given that a column could contain another table, for example). Making a copy of a table and using it for read-only purposes in the same process would likely make a shallow copy of the table. Iterating over a table and making changes during the iteration made a copy-on-write subtable, then merged it back into the original table when it was done the loop, since the high-level semantic definition of looping over a table is that you iterate over a copy of the table. The only thing close to aliases are references to some other process's input ports (i.e., multiple client-side sockets connected to a server-side socket). If you want to share data (such as a file system or program library), you put the data in a table in a process, and you hand out client-side connections to the process. Mostly, you'd define such connections as accepting a data value (for the file contents) with the parameter being undefined upon return from the call, and the file name as being read-only, for example. If you wanted to store the file, you could just pass a pointer to its data (in the implementation). If you wanted a copy of it, you would either copy it and pass the pointer, or you'd pass the pointer with a flag indicating it's copy-on-write, or you could pass the pointer and have the caller copy it at some point before returning, depending on what the caller did with it. The semantics were high-level with the intent to allow the compiler lots of leeway in implementation, not unlike SQL. > Not to mention the issue with > uninitialized variables that I would expect occuring all over the place. The typestate tracks this, and prevents you from using uninitialized variables. If you do a read (say, from a socket) and it throws an "end of data" exception, the compiler prevents you from using the buffer you just tried but failed to read. Indeed, that's the very point of it all. By doing this, you can run "untrusted" code in the same address space as trusted code, and be assured that the compiler will prevent the untrusted code from messing up the trusted code. The predecessor of Hermes (NIL) was designed to let IBM's customers write efficient networking code and emulations and such that ran in IBM's routers, without the need for expensive (in performance or money) hardware yet with the safety that they couldn't screw up IBM's code and hence cause customer service problems. > So unless I'm misunderstanding something, this feels like trading one > evil for an even greater one. In truth, it was pretty annoying. But more because you wound up having to write extensive declarations and compile the declarations before compiling the code that implements them and such. That you didn't get to use uninitialized variables was a relatively minor thing, especially given that many languages nowadays complain about uninitialized variables, dead code, etc. But for lots of types of programs, it let you do all kinds of things with a good assurance that they'd work safely and efficiently. It was really a language for writing operating systems in, when you get right down to it. -- Darren New / San Diego, CA, USA (PST) This octopus isn't tasty. Too many tentacles, not enough chops. -- http://mail.python.org/mailman/listinfo/python-list
Re: activestate vs enpython
mclaugb wrote: > does anyone know if the activestate distribution has all of the numpy, > numarray, matplotlib, scipy, and scientific python? their website does not > say what it includes. http://www.activestate.com/Products/ActivePython/more_information.plex -- http://mail.python.org/mailman/listinfo/python-list
Re: time.clock()
On 2006-07-14, Tobiah <[EMAIL PROTECTED]> wrote: > So I "man 3 clock" and notice: > > The value returned is the CPU time used so far as a clock_t; to get > the number >of seconds used, divide by CLOCKS_PER_SEC. > > So, I'm wondering how to get that value from python. What value? > All I really want to do is know current time relative to a > given point Which is not at all the same thing as CPU usage. > so that I can capture MIDI events, and store the time at which > they arrive. time.time() > Am I barking up the wrong tree? Yes, but your in the right grove. -- Grant Edwards grante Yow! "THE LITTLE PINK at FLESH SISTERS," I saw them visi.comat th' FLUROESCENT BULB MAKERS CONVENTION... -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for Embedded Systems?
On 2006-07-14, Jack <[EMAIL PROTECTED]> wrote: > Is there a Python packaging that is specifically for > embedded systems? ie, very small and configurable so the > user gets to select what modules to install? > > For Linux-based embedded systems in particular? > > I'm thinking of running it on the Linksys's Linux-based open > source router WRT54G. It has 4MB flash and 16MB RAM. I think > another model has 16MB flash. Any possibilities of running > Python on these systems? A few years back there was a "deeply embedded python" project, but it's been dead for quite a while: http://www.tucs.fi/magazin/output.php?ID=2000.N2.LilDeEmPy http://mail.python.org/pipermail/python-announce-list/1999-August/000157.html -- Grant Edwards grante Yow! My BIOLOGICAL ALARM at CLOCK just went off... It visi.comhas noiseless DOZE FUNCTION and full kitchen!! -- http://mail.python.org/mailman/listinfo/python-list
Re: EuroPython 2006 and Py3.0
On 2006-07-14, Lawrence Oluyede <[EMAIL PROTECTED]> wrote: > Antoon Pardon <[EMAIL PROTECTED]> wrote: > >> These are just some ideas. Whether they fit into python or not I will >> leave to the developers. > > I'm not a Python pro. but: > >> 1) Literal slices, in a sense we already have these, but they are >>limited to indexing. You can't do something like fun(::). May >>be this means the notation used now has to be adapted. > > I don't see the use case for this. You don't think it usefull that when you need a slice as an argument you can use the same notation as when you use when you need a slice as an index? I have a tree class, a tree acts like a dictionary, but when you iterate over it, it always iterates over the keys in order. This makes it usefull to iterate over a slice. So it would be usefull if methods like keys, values and items could take a slice as an argument and use the same notation for it. Something like for k, v in t.items('a':'b'): Which would iterate over all items where the key starts with an 'a'. Sure you don't need it. You could just use for k, v in t.items(slice('a','b')): or you could define the items method with the same signature as range or xrange. But it seems appropiate that the same notation can be used anywhere. >> 2) Iterable slices. Allow (provided the slice notation stays:) >> >> for i in (1:10): >> ... >> >>to do the same as: >> >> for i in xrange(1,10): >> >> This will allow to get rid of both range and xrange. Xrange >> is totally unnecessary and range(a,b) becomes list(a:b). > > -1. First: you have to introduce new syntax for an old thing. That syntax already exists, it just is only available as an index. > Second: > you overload the meaning of slicing and the slice operator and so on. It's meaning is not overloaded, it just gets extra functionality. > range is perfectly integrated and the right tool for the job. Range as it is, is going to disappear. Last time I read the python 3000 Pep range would get the functionality of xrange and xrange would disappear, and those who want a list will have to do: list(range(a,b)) > There's no > need to introduce new syntax to iterate over a range of integers. Need is such a strong word. In the end we don't need python, but it seems very usefull to have it around. I understand that should this be introduced it could make people uneasy, but I also think it could be very usefull. >> 4) Introduce Top and Bottom objects, which will allways >>compare greater/smaller to other objects. Make them >>the default values for the start and stop values of >>slices. >> 5) Give slices a "&" and "|" operator. >> >> >> 7) Give slices the possibility to include the stop value. >> >>My first idea here was that the notation of slices >>was adapted, so that what is a:b now would become >>a:|b. A slice to include the b would then be a::b. >>You could even have a slice that didn't include the >>a but included the b like: a|:b >> >>Now I expect a lot of resitance here, so it this >>seems not feasable, just drop it. >> >> 6) Is this is all asked too much, make slice at least >>subclassable. > > Why do you need power slices? Because it would have made things a lot of easier for me in a number of cases. I have a table class that is like a list but can start at any index, it sure would have been easier to write with some of the possibilities above. I though to just write my own slice class, but slice is not subclassable, and when I just wrote my own from scratch, with a start, stop and step attribute I got an error that it wasn't an integer so couldn't be used as an index. So much for duck taping. But if this idea doesn't catch on, so be it. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
printing raw postscript data on windows
Hi, I am trying to print raw postscript data on windows. win32print should do the work like this: h=win32print.OpenPrinter(name) win32print.StartDocPrinter(h, 1, ("", "", "RAW")) win32print.WritePrinter(h, file("p.ps").read()) win32print.EndDocPrinter(h) win32print.ClosePrinter(h) This works for some printers, but not for all. The problem is, that no error messages or exceptions occur. Is there any other way to print raw data ? I am using wx, but wx does not seem to provide this functionality. Greetings, Uwe -- http://mail.python.org/mailman/listinfo/python-list
Re: activestate vs enpython
Um, i didnt see at the "more information" link whether "numpy, numarray, matplotlib, scipy, and scientific python" was included . "Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > mclaugb wrote: > >> does anyone know if the activestate distribution has all of the numpy, >> numarray, matplotlib, scipy, and scientific python? their website does >> not say what it includes. > > http://www.activestate.com/Products/ActivePython/more_information.plex > > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for Embedded Systems?
Grant Edwards wrote: > On 2006-07-14, Jack <[EMAIL PROTECTED]> wrote: > >> Is there a Python packaging that is specifically for >> embedded systems? ie, very small and configurable so the >> user gets to select what modules to install? >> >> For Linux-based embedded systems in particular? >> >> I'm thinking of running it on the Linksys's Linux-based open >> source router WRT54G. It has 4MB flash and 16MB RAM. I think >> another model has 16MB flash. Any possibilities of running >> Python on these systems? >> > > A few years back there was a "deeply embedded python" project, > but it's been dead for quite a while: > > http://www.tucs.fi/magazin/output.php?ID=2000.N2.LilDeEmPy > http://mail.python.org/pipermail/python-announce-list/1999-August/000157.html > > This raises a good question. Is there a need for python to change somewhat to work better in an embedded profile? Are there many people in the community interested in using python for embedded projects? -- Carl J. Van Arsdall [EMAIL PROTECTED] Build and Release MontaVista Software -- http://mail.python.org/mailman/listinfo/python-list
Re: {} for set notation
tic-tacs, But how often does one use a list or a tuple when a set is actually more meaningful? -- Probably more than expected, because traditionally comming from C and in the older Python versions there were no sets. A prime example are the keys of the dictionary. They are a _set_ not a list. If a list is returned by the keys() method, one might assume that somehow there is a special order to the keys. Or, for example, the other day I looked at some of my old code at some point I was gathering values for removal and I was using a list then I was doing "if deleteme is not in removelist: removelist.append(deleteme)". And I remember doing that more than one time. Looking back I would have used sets a lot more often especially if they had a quick easy notation like {1,2,3}. Another example is typical constant-like parameters. Again coming from Java and C we have been using FLAG1=1, FLAG2=1<<1, FLAG3=1<<2 then setting FLAG=FLAG1|FLAG2. This uses the bit arithmetics along with the bitwise 'or' operator. It is fine for C but in Python it looks odd. What we really want to say is that FLAG={FLAG1, FLAG2, FLAG3}. A new user would be puzzled by FLAG2=1<<1 or how come FLAG2=2 and FLAG3=4?. In general a set is a fundamental datatype. It was fundamental enough to include in Python as a builtin. Even though there was already the dictionary the list and the tuple. For completeness I think a set deserves its own notation. Once it has it, you'd be surprised how many people would more likely to use than if they had to type set([...]). Regards, Nick Vatamaniuc tac-tics wrote: > Nick Vatamaniuc wrote: > > I really like the set notation idea. Now that sets are first class > > "citizens" along with dicts, lists and tuples I think they should be > > used when it makes sense to use them > > In actual usage, though, how often is it strictly required one uses a > set over a list? It is similar to how queue and stack are not in the > default namespace. Unless you really need to ensure no one is allowed > to make random access changes to your data, a list with push and pop is > really all you need. I beleive the same applies in regards to sets. -- http://mail.python.org/mailman/listinfo/python-list