OSDC 2006 -- CFP closes in 2.5 weeks!
http://www.osdc.com.au/papers/cfp06.html There are two and a half weeks to go to get your paper in for one of the best Australian conferences this year! The deadline for proposals is 12th July 2006. The Open Source Developers' Conference is an Australian conference designed for developers, by developers. It covers numerous programming languages across a range of operating systems. We're seeking papers on Open Source languages, technologies, projects and tools as well as topics of interest to Open Source developers. The conference will be held in Melbourne, Victoria (Monash University's Caulfield Campus) from the 6th to the 8th of December, 2006. Each day includes three streams of talks, social events and is fully catered with buffet lunch and morning, afternoon teas. For a list of conference presentations from last year visit: http://osdc2005.cgpublisher.com/proposals/ If you have any questions, or have never submitted a paper proposal before, please read our FAQ page at http://www.osdc.com.au/faq/ index.html If you don't find an answer there, please contact richard at osdc.com.au To submit a proposal, follow the instructions at http://www.osdc.com.au/papers/cfp06.html This year we're also going to run a day of tutorials. See the CFP for more information. We are also seeking expressions of interest for people to be part of the OSDC 2006 Programme Committee. The Committee's primary responsibility is assessing the proposals submitted by potential speakers. Please email richard at osdc.com.au if you are interested, indicating your open source development interests. We look forward to hearing from you! All the best, The OSDC 2006 committee. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: What is Expressiveness in a Computer Language
Marshall [EMAIL PROTECTED] writes: Yes, an important question (IMHO the *more* important question than the terminology) is what *programs* do we give up if we wish to use static typing? I have never been able to pin this one down at all. Well, given Turing Machine equivalence... I'd mention retrospective software. But you can always implement the wanted retrospective features as a layer above the statically typed language. So the question is how much work the programmer needs to do to implement a given program with static typing or with dynamic typing. The real question is, are there some programs that we can't write *at all* in a statically typed language, because they'll *never* be typable? I think there might be, but I've never been able to find a solid example of one. More than *never* typable, you want to identify some kind of software that is not *economically* statically typable. Was it costlier to develop the software developed in non statically typed programming languages than in a statically typed programming language? -- __Pascal Bourguignon__ http://www.informatimago.com/ I have challenged the entire quality assurance team to a Bat-Leth contest. They will not concern us again. -- http://mail.python.org/mailman/listinfo/python-list
Re: Replace Whole Object Through Object Method
[EMAIL PROTECTED] wrote: I'm working with a team that's doing social modeling, and for example, I need to model workers that at some point in the program may or may not also become employers. Now, I want the workers to take on all behaviors and attributes of an employer in addition to their pre-existing worker behaviors and attributes. Also, as I'm sure you guessed, the workers' attributes need to retain their values at that point in the program, so a brand new worker-employer object wouldn't in itself do the trick. so why not just do that, instead of trying to come up with overly convoluted ways to abuse a class mechanism that you don't fully understand ? I suspect that your team would prefer if you got your inspiration from GoF instead of Goldberg. /F -- http://mail.python.org/mailman/listinfo/python-list
Select in Python
#!/usr/bin/env python2 from sys import stdin from select import select while 1: (rr, wr, er) = select([stdin], [], []) for fd in rr: print fd program block in the first select(), after I type something and enter , it never block in select() again,why? -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
Marshall [EMAIL PROTECTED] wrote: Yes, an important question (IMHO the *more* important question than the terminology) is what *programs* do we give up if we wish to use static typing? I have never been able to pin this one down at all. You'd need to clarify what you mean by use static typing. Clearly, if you use forms of static typing that currently exist for Java, there's considerable limitation in expressiveness. If you mean a hypothetical perfect type system, then there would be no interesting programs you couldn't write, but such a system may not be possible to implement, and certainly isn't feasible. So it seems to me that we have this ideal point at which it is possible to write all correct or interesting programs, and impossible to write buggy programs. Pure static type systems try to approach that point from the conservative side. Pure dynamic systems (and I actually think that design-by-contract languages and such apply here just as well as type tagging) try to approach that point via runtime verification from the liberal side. (No, this has nothing to do with George Bush or Noam Chomsky... :) Either side finds that the closer they get, the more creative they need to be to avoid creating development work that's no longer commensurate with the gains involved (whether in safety or expressiveness). I think I am now convinced that the answer to the question of whether there is a class of type errors in dynamically checked languages is the same as the answer for static type systems: no. In both cases, it's just a question of what systems may be provided for the purposes of verifying (more or less conservatively or selectively) certain program properties. Type tags or other features that look like types are only relevant in that they encapsulate common kinds of constraints on program correctness without requiring the programmer to express those constraints in any more general purpose language. As for what languages to use right now, we are interestingly enough back where Xah Lee started this whole thread. All languages (except a few of the more extreme statically typed languages) are Turing complete, so in order to compare expressiveness, we'd need some other measure that considers some factor or factors beyond which operations are expressible. There are also what I call packaging issues, such as being able to run partly-wrong programs on purpose so that one would have the opportunity to do runtime analysis without having to, say, implement parts of some interface that one isn't interested in testing yet. These could also be solved in a statically typed language. (Although historically it hasn't been done that way.) I'll note veryh briefly that the built-in compiler for the Eclipse IDE has the very nice feature that when a particular method fails to compile, it can still produces a result but replace the implementation of that method with one that just throws an Error. I've taken advantage of that on occasion, though it doesn't allow the same range of options as a language that will just go ahead and try the buggy operations. The real question is, are there some programs that we can't write *at all* in a statically typed language, because they'll *never* be typable? I think there might be, but I've never been able to find a solid example of one. This seems to depend on the specific concept of equivalence of programs that you have in mind. -- Chris Smith - Lead Software Developer / Technical Trainer MindIQ Corporation -- http://mail.python.org/mailman/listinfo/python-list
Re: Select in Python
Dio wrote: from sys import stdin from select import select while 1: (rr, wr, er) = select([stdin], [], []) for fd in rr: print fd program block in the first select(), after I type something and enter , it never block in select() again,why? if there's data waiting to be read from the stream, select() will tell you so every time you ask. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Select in Python
Dio wrote: while 1: (rr, wr, er) = select([stdin], [], []) for fd in rr: print fd program block in the first select(), after I type something and enter , it never block in select() again,why? select blocks until there is some data to read from stdin, but it does not *clear* the data. so once you enter data, select will not block until you read the data. once you're done reading the available data, you can again use select to block until more data is available. Regards Sreeram signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Select in Python
Dio wrote: #!/usr/bin/env python2 from sys import stdin from select import select while 1: (rr, wr, er) = select([stdin], [], []) for fd in rr: print fd program block in the first select(), after I type something and enter , it never block in select() again,why? Because select blocks until there is something to read on stdin, and as long as there is something to be read on stdin, it will not block. Since your program never reads in the data on stdin, your enter\n just sits there waiting to be read, and select always inform you of that fact by returning stdin in the rr list. If you want select to start blocking again, you must read all bytes from stdin whenever select says there are bytes to be read. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list
Re: Select in Python
K.S.Sreeram 写道: Dio wrote: while 1: (rr, wr, er) = select([stdin], [], []) for fd in rr: print fd program block in the first select(), after I type something and enter , it never block in select() again,why? select blocks until there is some data to read from stdin, but it does not *clear* the data. so once you enter data, select will not block until you read the data. once you're done reading the available data, you can again use select to block until more data is available. Regards Sreeram Thanks a lot!I use stdin.readline() after select and it's ok :) -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: Cannot create a consistent method resolution order (MRO) for bases object
[EMAIL PROTECTED] wrote: Maric Michaud wrote: Le lundi 26 juin 2006 20:06, [EMAIL PROTECTED] a écrit : What are the reason one would get this error: TypeError: Cannot create a consistent method resolution order (MRO) for bases object ?? I can provide the code if needed This is the python solution to the diamond problem (cf. wikipedia). In [61]: class a(object) : pass : In [62]: class b(a) : pass : In [63]: class c(object, a) : pass : --- exceptions.TypeError Traceback (most recent call last) /home/maric/ipython console TypeError: Error when calling the metaclass bases Cannot create a consistent method resolution order (MRO) for bases object, a In [64]: b.mro() Out[64]: [class '__main__.b', class '__main__.a', type 'object'] In [65]: class c(a, object) : pass : In [66]: c.mro() Out[66]: [class '__main__.c', class '__main__.a', type 'object'] In [67]: class d(b, c) : pass : In [69]: d.mro() Out[69]: [class '__main__.d', class '__main__.b', class '__main__.c', class '__main__.a', type 'object'] mro means method resolution order, this is the path the interpreter will look for attributes for a given class. You cannot introduce inconsistency in this path, for example duplicate the type object before another type (or any type wich appear to be the ancestor of another). -- Ah, thank you Maric, I see the problem. I diagrammed the flow of class inheritance and I can see the problem clearly. Ruby doesn't have this problem because it uses a single inheritance model complemented by the power of mixins (modules of functionality mixed into classes as needed). So what's the Pythonic solution to this problem? Technically, wait until Python 3.0. Until then, just make sure all your classes inherit from (something that inherits from ...) object. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Love me, love my blog http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: SWIG problems with gcc and Cygwin?
Michael Yanowitz wrote: No response yet. The SWIG test works fine in Linux no problems. However, I still have the problem in Cygwin. Also, not sure if related but I do have a win32 Python 2.4.3 and Cygwin Python 2.4.1. Not sure if there are any conflicts. Any advice in making these two co-exist? The only C/C++ compiler I have presently is Cygwin gcc. I wouldn't claim to be an expert but it looks like you are missing libraries. Shouldn't you at least be loading -l c to get functions defined in libc? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Love me, love my blog http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
How do you use this list ?
Hi everyone , I have join this list for about 4 months , and everyday I receive hundreds of mails . There is no means to read all of them , so I just read something interesting for me . But if so , there are too much mails pile up in my inbox , I want to ask how do you use this list , reading every mail come in or just read what you think interesting ? Thank you ! Best Regard ! -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: Cannot create a consistent method resolution order (MRO) for bases object
[EMAIL PROTECTED] wrote: What are the reason one would get this error: TypeError: Cannot create a consistent method resolution order (MRO) for bases object ?? See http://www.python.org/download/releases/2.3/mro/ Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: logging error with RotatingFileHandler
flupke wrote: File C:\Python24\lib\logging\handlers.py, line 134, in doRollover self.handleError(record) NameError: global name 'record' is not defined There's a bug in doRollover's exception handling, which is masking the true error - which is most probably an exception being thrown in os.rename. I'll look at fixing this bug asap. Most likely, it'll be done by let the exception propagate up from doRollover to its caller. Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Re: Termination and type systems
David Hopwood [EMAIL PROTECTED] wrote: Dirk Thierbach wrote: That's interesting, but linear typing imposes some quite severe restrictions on programming style. From the example of 'h' on page 2, it's clear that the reason for the linearity restriction is just to ensure polynomial-time termination, and is not needed if we only want to prove termination. Yes. It's just an example of what can be actually done with a typesystem. It's already hard enough to guarantee termination with the extra information present in the type annotation. If this information is not present, then the language has to be probably restricted so severely to ensure termination that it is more or less useless. I think you're overestimating the difficulty of the problem. The fact that *in general* it can be arbitrarily hard to prove termination, can obscure the fact that for large parts of a typical program, proving termination is usually trivial. Yes. The problem is the small parts where it's not trivial (and the size of this part depends on the actual problem the program is trying to solve). Either you make the language so restrictive that these parts are hard (see your remark above) or impossible to write, or you'll be left with a language where the compiler cannot prove termination of those small parts, so it's not a type system in the usual sense. Of course one could write an optional tool that automatically proves termination of the easy parts, and leaves the rest to the programmer, but again, that's a different thing. - Dirk -- http://mail.python.org/mailman/listinfo/python-list
Re: break the loop in one object and then return
Alex Pavluck wrote: Peter, Why do you make such claims without any reason to do so? This is my own thing. So, I guess I am a student but just a student of my own accord. So, please don't reply if you don't have anything to contribute. First: This is not YOUR OWN THING. This group really can help, but this group AFAIK does not write homeworks. It is nothing wrong you are just a student, we are all students somehow :) Second: Few other posters were posting similar requests to this group last few days (maybe your classmates :)) so the chance it just a coincidence is very low. If I am wrong, sorry about that. Third: This group can help, but some effort (study, googling this group etc.) on your side is necessary as well. Other posters suggested you the way, where to go, but you didn't try to change your code a bit. Please read the following as well: http://www.albion.com/netiquette/corerules.html To your code: As for the - mynum I guess that could happen but I am just doing this so that they will never match on first try. I guess I should just hardcode it. This is what happens if I step though: mynum = 93***1*** use # sign for your comments in the code followed by the comment text. All the stuff after the # is ignored when the code is executed. Nobody can execute (examine) your code whit your comments like ***1*** To hardcode mynum value is IMHO very bad idea and your code will be useless if the value will be discovered. Other suggested how to generate random number at the beginning of the code. yournum = input(I am thinking of a number between 1 and 100.\n Guess which number: ) ***2*** def strt(): ***3******6*** if yournum == mynum: ***7*** print Wow! You got it! elif yournum mynum: ***8*** print Nope. Too low ***9*** again()***10*** ***15*** elif yournum mynum: print Oh, your too high def again(): ***4*** ***11*** global yournum ***12*** yournum = input(guess again: ) ***13*** strt() ***14*** strt() ***5*** ***15*** is the problem. It doesn't start at the top but rather where is leaves the loop. print statement can help to solve your problem, put it (with some text that will navigate you) on the rows where you are not sure the program is not running properly. Print out the values of the mynum and yournum as well. This will be just for your debugging purposes. Finally you will remove it. For example you can put: print starting the strt function, mynum = , mynum, yournum =, yournum on the first row of your strt function, so you will see the code is going through there. Finally: Try to thing what will happen if the person will input character rather than integer. Again: good luck in your effort Petr Jakes Petr Jakes wrote: It smells like many student are trying to do their homework last few days here ... Can we now the name of your school? :) AFAIK this group does not solve homeworks here :) Just few points: at the beginning try to test the input value you can use in range or using 0 yournum 101 you should test if the input is an integer as well.. http://tinyurl.com/j468c Other suggested here which way to go. Good luck :) Petr Jakes -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you use this list ?
Bo Yang wrote: Hi everyone , I have join this list for about 4 months , and everyday I receive hundreds of mails . There is no means to read all of them , so I just read something interesting for me . But if so , there are too much mails pile up in my inbox , I want to ask how do you use this list , reading every mail come in or just read what you think interesting ? your recieving those emails because you choose (in your My Account settings) to received emails, you can deselect this and then just read any post that interests you and ask questions of your own. Cheers -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
Marshall [EMAIL PROTECTED] writes: There are also what I call packaging issues, such as being able to run partly-wrong programs on purpose so that one would have the opportunity to do runtime analysis without having to, say, implement parts of some interface that one isn't interested in testing yet. These could also be solved in a statically typed language. (Although historically it hasn't been done that way.) I keep hearing this, but I guess I fail to understand it. How partly-wrong do you require the program to be? During development, I frequently sprinkle my (Haskell) program with 'undefined' and 'error implement later' - which then lets me run the implemented parts until execution hits one of the 'undefined's. The cost of static typing for running an incomplete program is thus simply that I have to name entities I refer to. I'd argue that this is good practice anyway, since it's easy to see what remains to be done. (Python doesn't seem to, but presumably a serious dynamically typed system would warn about references to entities not in scope?) -k -- If I haven't seen further, it is by standing in the footprints of giants -- http://mail.python.org/mailman/listinfo/python-list
Re: What technologies should I use for my application manager?
Thanks for the advice, Adam! Turbogears sounds like it does everything I want and looks like a great... except you've made me nervous with your comment on the instability of the Oracle API! Stability, good documentation and a wide user base are priorities. I was delighted by the quality of Tkinter in this regard. Am I wishing for the moon in hoping for the same quality in the framework I choose for this? Anyone else like to try and sell me on Zope or Django?! -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I limit access to objects in Python?
Tommytrojan schrieb: Hi, I have an application that embeds the Python interpreter. My users have access to the interpreter through a console like window and they can run Python scripts. For my application I use some Python modules (say module Restricted) that I don't want to give my users access to. However, the modules that I make public to my users and that I want my users to be able to use themselves use the Restricted module. Any suggestions on how to solve this? I was thinking of instantiating a separate interpreter but I don't think this will solve my problem. I don't think that is possible - how is one to distinguish your code from the code written by a user that calls one method in the restricted module? What you _can_ do is to spawn an interpreter, and expose the allowed objects via Pyro. The question is though: why cripple your users? If someone could reach an otherwise unreachable goal why do yoou hinder him? What is the reasoning behind that? Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: style question
On 26/06/06, Claudio Grondi [EMAIL PROTECTED] wrote: Scott David Daniels wrote: Claudio Grondi wrote: clever stuff to di indentation When necessary to skip first line _and_ indentation: message = This is line 1 This is line 2 This is line 3 .replace('\n', '\n')[1:] # adjust here '\n' to indentation Riffing on this idea: message = This is line 1 This is line 2 This is line 3 .replace( , '\n')[1:] This was intended as an excercise for the OP in case he likes that kindof solution ...Claudio --Scott David Daniels [EMAIL PROTECTED] --http://mail.python.org/mailman/listinfo/python-listI've decided to go with message = (This is line1. This is line2 This is line3\n) since I'm declaring many different messages inside various functions I feel it is important to keep the indentaion and code both aligned properly so the code looks nice and the output looks nice. It is easier than doing replace and splicing since I want to keep it as simple and clean as possible, in true pythonic tradition... Thanks for the input! -h -- http://mail.python.org/mailman/listinfo/python-list
Re: What technologies should I use for my application manager?
MrBlueSky wrote: Anyone else like to try and sell me on Zope or Django?! start here: http://www.djangoproject.com/documentation/tutorial1/ if you're on windows, and just want to tinker a little, http://effbot.org/zone/django.htm#installing might also be helpful. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: A game idea.
defcon8 wrote: I have had what I think is quite a nice game idea, but I don't really have the experience or knowledge to go about it. Would anyone be willing to start a game project? Ideas are a dime a dozen. Implementation is the hard part. If you want something done, you will have to do it yourself. I am not trying to be negative, but I will bet you that every competent programmer on the list has 1+ project that she would love to do, if she just had the time. -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science Phone: +45 66 11 84 94 Mobile: +45 29 93 42 96 -- http://mail.python.org/mailman/listinfo/python-list
to py or not to py ?
HI all I have the following prob.I am to write a parallel vis application .I wud have by default used C++ for the same but somehow thought if py cud help me ..It does as in many things that i would otherwise have written down already exists ... ( like built in classes for sockets , threading etc )I would be doin the following type of tasks .. 1. sending data across the network the data is going to be huge2. once data has been sent i will run some vis algos parallely on them and get the resultsnow one thing that i wud req. is serializing my data structures so that they can be sent across the net.pyton does allow this using cPickle , but it bloats the data like anythin !!! for example a class containing 2 integers which i expect will be 8 bytes long ..cPickle.dumps returns a string thats 86 bytes wide ( this is the binary version protocol 1 )anyway to improve serialization ?? also is it actually a good idea to write high perf applications in python ?thanks in advance- -- http://mail.python.org/mailman/listinfo/python-list
Re: Replace Whole Object Through Object Method
On Mon, 26 Jun 2006 19:40:52 -0700, digitalorganics wrote: A misuse of inheritance eh? Inheritance, like other language features, is merely a tool. I happen to be using this tool to have my virtual persons change roles at different points in their lifetime, as many real people tend to do. Thus, at these points, B is indeed an A. What a person is, whether in real life or in my program, is not static and comes into definition uniquely for each moment (micro-moment, etc.) of existence. Now, please, I have no intention of carrying the conversation in such a silly direction, I wasn't inviting a discussion on philosophy or some such. I seek to work the tools to my needs, not the other way around. But thinking about the problem in the vocabulary provided by the programming language can be helpful in coming up with a solution. If inheritance tells you what an object _is_, and membership tells you what a role _has_, and a role is something that a person has, that suggests that an implementation where roles are members of a person might be simpler than trying to use inheritance. Like, for instance: class Role(object): def __init__(self, person): self.person = person class Worker(Role): def do_work(self): print self.name, is working class Employer(Role): def __init__(self, person): Role.__init__(self, person) self.employees = [] def add_employee(self, worker): self.employees.append(worker) def boss_people_around(self): for employee in employees: print self.name, is telling, employee.name, what to do class Person(object): def __init__(self, name): self.roles = [] self.name = name def add_role(self, role_class): self.roles.append(role_class(self)) def forward_to_role(self, attr): for role in self.roles: try: return getattr(role, attr) except AttributeError: pass raise AttributeError(attr) def __getattr__(self, attr): self.forward_to_role(attr) bill = Person('Bill') bill.add_role(Worker) bob = Person('Bob') bob.add_role(Employer) bill.work() bob.boss_people_around() -- http://mail.python.org/mailman/listinfo/python-list
Re: Replace Whole Object Through Object Method
Maric Michaud wrote: Le lundi 26 juin 2006 22:37, [EMAIL PROTECTED] a écrit : Won't work because there will be employers that aren't workers. And yes, only some workers will become employers, but also only some employers will also be workers (at some point in program). Let me be more clear: workers -- subset of workers --become-- employers employers -- subset of employers --become-- workers It is very important that both should maintain attribute values, regardless of whether they take on new roles. Furthermore, this is a very simple case and ultimately in my program an object should be able to dynamically take on a multitude of roles (classes of behavior) without mucking at all with their pre-existing states. This seem to be a OO design problem Obviously. and you clearly make a misuse of inheritance, Chapter and verse, please ? s/misuse/creative use/ if a person can eventually have many roles, but doesn't have this role for all his lifetime, then the person *is* not his roles. And ? In a dynamically typed language, inheritance is about implementation, not subtyping. The class of an object is nothing more than an attribute, and as such is not necessarily fixed for the lifetime of the object. That the meaning of inheritance, class B(A) means a B is a A. The association between a person and his roles is obviously a 1-n association, which can be rendered by different patterns (delegation, composition, strategy, etc.). You've learned your lessons well. That's fine. Now please understand that there's a huge difference between the book (usually based on static some static language) and dynamic OOPLs. IOW : free your mind. In Python, you can dynamically change the class of an object at runtime. And the attribute lookup rule is to first lookup the object, then the class (which is itself an object FWIW). So you can see the object/class relationship as a somewhat specialised composition/delegation relationship. In fact, in Python, a class is both an object factory and delegatee. You should google on design patterns and make your choice. FWIW, a good part of the canonical design patterns are mostly workaround the lack of flexibility in languages like C++ and Java. The Strategy pattern's simplest Python implementation is to dynamically replace a method on a per-object basis. The State pattern's simplest implementation in Python is to dynamically change the class of an object. Of course, one of the canonical solutions to the OP's problem is to use composition/delegation. But doing it the canonical way would imply creating instances of the role objects and passing them the instance as param so they can access it's attributes. It works, but it creates a cyclic dependancy between the object and it's roles, so you would have to use weakrefs. Dynamically creating new classes with the appropriate bases and assigning them to the object's __class__ attribute is another way to achieve the same result, and it's perfectly legal. Now I do agree that it can become tricky to manage correctly wrt/ mro rules !-) -- 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: replace a method in class: how?
Maric Michaud wrote: Le mardi 27 juin 2006 06:21, Bruno Desthuilliers a écrit : Maric Michaud a écrit : (snip) In OOP Methods are defined in *classes* not in any arbitrary object Chapter and verse, please ? AFAIK, the first O in OOP stands for object, not for class !-) Hard to find it, indeed. Classes are just an implementation convenience, and the fact that the class-based model is the most usual one doesn't imply it's the only valid one. Maybe, never been told of another one, do you think of javascript prototypes ? There other prototype-based languages. And truth is that while having classes, Python's object model is much more closer to javascript's one than to Java or C++. Well, there are no methods in this model, only functions. Nope. There are closures, not simple functions. And FWIW, what do you think methods are in Python ? Yes, functions, wrapped in a special descriptor. So there's no reason one shouldn't override (or add) a method on a per-object basis. As a matter of fact, it's perfectly legal (and can be very convenient) to do so in Python. I never saw the term method used for anything except for what it means for classes, Help on class instancemethod in module __builtin__: class instancemethod(object) | instancemethod(function, instance, class) | | Create an instance method object. and moreover, the class model, even if it's just an implementation, it's the one chosen by python. There's a superficial similarity with mainstream static OOPLs like Java/C++ etc. But Python's classes, and their relation to instances, are as dynamic as can be, and really very different from what's in most books. For the common understanding of the model, IMHO, classes bind methods, instances bind functions. ??? In Python, a class is nothing more than an object that: 1/ act as an object factory 2/ serves as delegatee for instances. FWIW, the proper constructor (__new__, not __init__) is free to return instances of any other class (as long as the initializer signature is compatible). -- 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: Help with conversion VB script to Python : COM objects
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, I need to re-write a VB script into Python (because I really don't like VB). The VB script is used to create a Windows COM object. (I am more of Unix guy, so COM objects are a little bit alien for me). At a certain point in the VB script, I have the following line: objPolTypes = objPmad.Cvar(objPmad.GetPolicyTypeList) Does anybody what the equivalent in Python would be? I tried: objPolTypes = objPmad.Cvar(objPmad.GetPolicyTypeList() ) but then I get the following error: Traceback (most recent call last): File C:\Python24\MyProgs\FodFin\test.py, line 11, in ? objPolTypes = objPmad.cvar(objPmad.GetPolicyTypeList() ) File COMObject PMAD.OvPmdPolicyManager, line 2, in cvar pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 1) I also tried : objPolTypes = objPmad.GetPolicyTypeList() this works but I end of with a list of COM object and have no clue how to query/use them or what methods are defined for those type of objects. Any help really appreciated. With kind regards, KRis If the application has a typelib, you can use makepy to generate a wrapper module that will show you the objects' methods and properties. Otherwise, you'll have to depend on the documentation for the app. Roger == Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News== http://www.newsfeeds.com The #1 Newsgroup Service in the World! 100,000 Newsgroups ---= East/West-Coast Server Farms - Total Privacy via Encryption =--- -- http://mail.python.org/mailman/listinfo/python-list
Re: MSoffice metadata
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] hi is there a module in Python to extract metadata in MS office documents thanks The Pywin32 package (http://sourceforge.net/projects/pywin32/) wraps the interfaces used to read and write document properties. Specifically, you can use pythoncom.StgOpenStorage to retrieve an IPropertySetStorage interface. Roger == Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News== http://www.newsfeeds.com The #1 Newsgroup Service in the World! 100,000 Newsgroups ---= East/West-Coast Server Farms - Total Privacy via Encryption =--- -- http://mail.python.org/mailman/listinfo/python-list
Re: Replace Whole Object Through Object Method
I V wrote: On Mon, 26 Jun 2006 19:40:52 -0700, digitalorganics wrote: A misuse of inheritance eh? Inheritance, like other language features, is merely a tool. I happen to be using this tool to have my virtual persons change roles at different points in their lifetime, as many real people tend to do. Thus, at these points, B is indeed an A. What a person is, whether in real life or in my program, is not static and comes into definition uniquely for each moment (micro-moment, etc.) of existence. Now, please, I have no intention of carrying the conversation in such a silly direction, I wasn't inviting a discussion on philosophy or some such. I seek to work the tools to my needs, not the other way around. But thinking about the problem in the vocabulary provided by the programming language can be helpful in coming up with a solution. If inheritance tells you what an object _is_, It's not so clear in Python, cf my answer to Maric on this point. and membership tells you what a role _has_, and a role is something that a person has, As a matter of fact, in Python, the class is an attribute of an object. So it is really something that an object have. And this relationship is not carved in stone - it's perfectly legal to modify it at runtime. that suggests that an implementation where roles are members of a person might be simpler than trying to use inheritance. Like, for instance: class Role(object): def __init__(self, person): self.person = person (snip) class Person(object): def __init__(self, name): self.roles = [] self.name = name def add_role(self, role_class): self.roles.append(role_class(self)) And here you create a circular reference between object and roles... def forward_to_role(self, attr): for role in self.roles: try: return getattr(role, attr) except AttributeError: pass raise AttributeError(attr) This could as well be directly in __getattr__, and would avoid a useless method call. def __getattr__(self, attr): self.forward_to_role(attr) -- 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
classes and interfaces
hi i come from a non OO environment. now i am learning about classes. can i ask, in JAva, there are things like interface. eg public interface someinterface { public somemethod (); ... } In python , how to implement interface like the above? is it just define a class?? class someinterface: def somemethod: blah thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
Chris Smith schreef: So it seems to me that we have this ideal point at which it is possible to write all correct or interesting programs, and impossible to write buggy programs. I think that is a misconception. Even at the idealest point it will be possible (and easy) to write buggy programs. Gödel! -- Affijn, Ruud Gewoon is een tijger. -- http://mail.python.org/mailman/listinfo/python-list
Re: Replace Whole Object Through Object Method
Bruno Desthuilliers wrote: As a matter of fact, in Python, the class is an attribute of an object. except when it isn't. def add_role(self, role_class): self.roles.append(role_class(self)) And here you create a circular reference between object and roles... and ? Python has a garbage collector, you know... /F -- http://mail.python.org/mailman/listinfo/python-list
Inconsistent float behaviour on inf - current state?
Hello, I've found another inconsistency, and looking through the list archives I can find mentions of funky stuff like print float('inf') giving Infanity with Python 1.5.2 on Solaris 7 in 2001, and a couple closed bug reports on why float('inf') isn't supported everywhere, and I understand the underlying problem: libc simply isn't that good - never mind standard - with regard to floats. However, seeing how Python does a great job with long ints by using something better than standard libc, I fail to see how reliance on libc should be a reason not to provide at least consistency: Why does conversion from a long constant not use the same library function that conversion from a long string would use? a = float(1234298299300)- OverflowError: long int too large to convert to float a = float('1234298299300') - inf, which led to silly errors in SQL (table has no column 'inf') a = inf - NameError: name 'inf' is not defined a = float('inf')- inf Now, I could understand how that may need some changes on lexing the source code, so I'm not actually opening more bugs having found workarounds for my own troubles here (quality guys insisting on entering silly numbers, hah, try that with a 50 character input field limit!). Still, I'm interested to hear what the current state of affairs is on using possibly inconsistent libc for floats? Bye, Peter Knörrich -- http://mail.python.org/mailman/listinfo/python-list
Re: classes and interfaces
[EMAIL PROTECTED] wrote: hi i come from a non OO environment. now i am learning about classes. can i ask, in JAva, there are things like interface. eg public interface someinterface { public somemethod (); ... } In python , how to implement interface like the above? is it just define a class?? Java interfaces are a workaround the combination of static typing (limiting polymorphism) and lack of multiple inheritance. Since Python is dynamically typed (polymorphism does not depend on type), there's no such need: class Foo(object): def doThis(self): print in Foo.doThis class Bar(object): def doThis(self): print in Bar.doThis def doIt(obj): obj.doThis() f = Foo() b = Bar() doIt(f) doIt(b) A you can see, doIt() works for any object having a doThis() method. No need for inheritance or interface here. Note that we do have something like interfaces (in some third-part librairies), but with a somewhat different (and much more powerful) usage: http://peak.telecommunity.com/protocol_ref/ref.html But if you're new to OO, this may not be the best starting point !-) -- 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: Replace Whole Object Through Object Method
Fredrik Lundh wrote: Bruno Desthuilliers wrote: As a matter of fact, in Python, the class is an attribute of an object. except when it isn't. Which are the cases where it isn't ? def add_role(self, role_class): self.roles.append(role_class(self)) And here you create a circular reference between object and roles... and ? Python has a garbage collector, you know... Yes. But garbage collection is not cost-free AFAIK. -- 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
pyrex functions to replace a method (Re: replace a method in class: how?)
Thanks for all who replied to this question about replacing a method. I feel a little sheepish for not having caught that I have to replace it in the class, not the instance, but I have found a very similar problem trying to replace a method using a function defined in pyrex. I post all of the code below, but there are several files. The main code is: import module_py # import a function from a python module import module_pyrex # import a function from a pyrex extension module class This(object): def update1(self,val): print val def update2(self,val): print 2,val def update3(self,val): print 3,val def local_update(obj,val): print local,val This.update1=local_update # replace the method from a local function This.update2=module_py.python_update # replace the method from a python module This.update3=module_pyrex.pyrex_update # replace the method from a pyrex module t=This() t.update1('local') # works fine t.update2('python') # works fine t.update3('pyrex') # gives a typeerror function takes exactly 2 arguments (1 given) #- #module_py.py def python_update(self,val): print python module,val #- #module_pyrex.pyx def pyrex_update(self,val): print pyrex module,val #- any ideas why the pyrex function fails? thanks, bb -- - [EMAIL PROTECTED] http://web.bryant.edu/~bblais -- http://mail.python.org/mailman/listinfo/python-list
Tkinter - Button Overrelief
Hello all, I have some Tkinter buttons that display images. I would like to change these to 'active' images when the mouse is over the button. I see that the button widget can take an 'overrelief' argument in the constructor. What values can this take ? Also - can anyone provide an example of using the equivalent of a 'mouseover' event to change the image used by a button in Tkinter ? I'm afraid google has not helped me much here. Much Appreciated, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is fun (useless social thread) ;-)
BartlebyScrivener wrote: You know what are dicts, right ? That is, containers with keyword-access to values ? Then you probably have dicts with a known, defined structure, and functions working on it. What classes (and hence 00) gives you is a way to associate these functions with the dicts themselves. That is the big intuition about objects, the rest is just details. Bruno, Ever seen this from Fuzzyman? It explicitly uses the dict comparison. http://www.voidspace.org.uk/python/articles/OOP.shtml#introduction Nope - and the site seems to be down actually. But thanks for the pointer anyway. Thanks for the tip, Welcome to OO !-) -- 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
how to do -vv for very verbose?
I'm using optparse.Optionparser to take switches for a script I'm writing, but I can't see how to give it -vv for very verbose. the option for -v is simply set to True by the option parser if present, whereas I really want a numeric value, 1 if there is -v and 2 if there is -vv. Any ideas on how to do this? I think I'll have to stop using action=store_true. -h -- http://mail.python.org/mailman/listinfo/python-list
Re: classes and interfaces
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] hi i come from a non OO environment. now i am learning about classes. can i ask, in JAva, there are things like interface. eg public interface someinterface { public somemethod (); ... } In python , how to implement interface like the above? is it just define a class?? class someinterface: def somemethod: blah thanks This question crops up every week or two on this list. (This is a healthy indicator of people looking to map their Java learnings to Python. Some of the best programming knowledge I've gained has come from comparing features among different languages, and understanding their respective purposes/strengths/shortcomings. In this case, presence of interfaces in Java) Here are some recent threads that cover this topic: http://groups.google.com/group/comp.lang.python/browse_frm/thread/d5da229b0050725d/47411c8c9322821c?q=java+interfacernum=20#47411c8c9322821c http://groups.google.com/group/comp.lang.python/browse_frm/thread/d5da229b0050725d/47411c8c9322821c?q=java+interfacernum=20#47411c8c9322821c Is this in the FAQ? Hmm, these two FAQ's may be related to your question (although you have to know what you're looking for to recognize them): http://www.python.org/doc/faq/general/#how-do-you-specify-and-enforce-an-interface-spec-in-python http://www.python.org/doc/faq/programming/#is-there-a-tool-to-help-find-bugs-or-perform-static-analysis Lastly, you should look into -- http://mail.python.org/mailman/listinfo/python-list
Re: style question
Claudio Grondi wrote: Hari Sekhon wrote: On 26/06/06, *Claudio Grondi* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Scott David Daniels wrote: Claudio Grondi wrote: clever stuff to di indentation When necessary to skip first line _and_ indentation: message = This is line 1 This is line 2 This is line 3 .replace('\n ', '\n')[1:] # adjust here '\n ' to indentation Riffing on this idea: message = This is line 1 This is line 2 This is line 3 .replace( , '\n')[1:] This was intended as an excercise for the OP in case he likes that kind of solution ... Claudio --Scott David Daniels [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list I've decided to go with message = ( This is line1. This is line2 This is line3\n) since I'm declaring many different messages inside various functions I feel it is important to keep the indentaion and code both aligned properly so the code looks nice and the output looks nice. It is easier than doing replace and splicing since I want to keep it as simple and clean as possible, in true pythonic tradition... Thanks for the input! -h Thanks for the reply and the explanation what you finally decided to go with. I am so happy to have the triple quotes in Python, that I use them whenever possible - this has probably something to do with my bias towards plain text files with human readable content, so as readability is very important to me (and probably to many other Pythonistas) I like most the proposed by me triple quote style as the quotation marks in the style you prefer make the text of the 'message' less easy to read. Now we can start a flame war about which style is more 'pythonic' ;-) Claudio I already explained that the triple quotes don't work tidily with indentation, either the code is out of alignment or the printout is. Either way isn't good. Triple quotes are best at top level, but since I had to use many messages inside functions etc, they broke the layout of the code. I think they're both best depending on where you are putting them. I'm doing very custom messages for each different result, so it would be messy to do this at the top level. -h -- http://mail.python.org/mailman/listinfo/python-list
Re: how to do -vv for very verbose?
Hari Sekhon wrote: I'm using optparse.Optionparser to take switches for a script I'm writing, but I can't see how to give it -vv for very verbose. the option for -v is simply set to True by the option parser if present, whereas I really want a numeric value, 1 if there is -v and 2 if there is -vv. action=count ? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: how to do -vv for very verbose?
Fredrik Lundh wrote: Hari Sekhon wrote: I'm using optparse.Optionparser to take switches for a script I'm writing, but I can't see how to give it -vv for very verbose. the option for -v is simply set to True by the option parser if present, whereas I really want a numeric value, 1 if there is -v and 2 if there is -vv. action="" ? /F yeah, I realised this just after I sent it, sort it out. Thanks. -h -- http://mail.python.org/mailman/listinfo/python-list
Re: classes and interfaces
Paul McGuire [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Lastly, you should look into ... this blog post: http://dirtsimple.org/2004/12/python-is-not-java.html, and its partner http://dirtsimple.org/2004/12/python-is-not-java.html. Unfortunately, many who ask How do I implement a Java interface in Python? are met with some defensiveness on this list, as if the OP is asking What's wrong with stupid Python language that it doesn't have something as basic as interfaces?. Sometimes this is attitude on the OP's part, sometimes just presumption on the part of the various readers. Some responses are of an indignant Interfaces? We don't need no stinkin' interfaces! variety - unfortunately, most of these shed more heat than light to the discussion, usually omitting the important details as to *why* Python don't need those malodorous code devices. Java uses interfaces for two purposes: 1. to enforce at compile time whether a particular class implements a set of methods, and correspondingly enforce that only instances of such classes are permitted as arguments to functions/methods that declare arguments to be of the interface type 2. as a workaround for not directly supporting multiple inheritance Informally (and in design practices such as UML class diagrams), interfaces also serve to document expected class capabilities - which in the case of Java and C++, have the added support of compile-time checking to verify the class contains methods corresponding to those in the interface. Note that I've been careful *not* to imply that Java classes that pass this compile-time check actually *implement* the interface, as is often assumed. The only thing one knows for sure when Java accepts a class as being an interface implementer is that the class provides all the corresponding method definitions - but it cannot know if all expectations of behavior and pre- and post-conditions are actually implemented within those methods. While compile-time checking is a decent crutch 95% of the time, it will never catch errors like this: int passBackSomethingImportant() { // be sure to come back and implement this before production release! return 0; } Very few how do I implement Java interfaces in Python posters ever get specific about which purpose they are trying to address with their Python interface renditions. It is entirely possible that the posters don't *know* why the interface is there, they are just trying to directly port some Java code to Python. So specifically: 1. Python does not do any compile-time enforcement of method implementations in classes of objects. While some think this is like trapeze flying without a net, Pythoneers will reply that the net is a false assurance anyway (based on the example I show above). So to port this type of interface, the only thing to do is, well, ignore the interface - Python really doesn't require it. You *could* create a class such as: class ISomethingOrOther: def whatSomethingsDo(blah, blah2): raise NotImplementedError, derived class failed to implement 'whatSomethingsDo' method and then have target classes include ISomethingOrOther in their base class lists. But Python does not do any compile-time enforcement with these definitions. You *still* have to do runtime testing to see if the NotImplemented exceptions get thrown. 2. Python supports multiple inheritance without the indirection of interfaces, so you can just inherit implementation classes directly: class Swimmer: def swim(): pass class Flyer: def fly(): pass class Duck(Swimmer,Flyer): pass and merrily write: dd = Duck() dd.fly() dd.swim() Sorry for the long discourse, I didn't have time to make it shorter. HTH, -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re-loading updated modules
Hi, Shouldn't python recompile a module if there is a later version of the code (.py file)? While i am debuging, i always have to exit python and delete the pyc before every run, then start it again and import the modules. It seems that this is the only way for it to recompile the new code. What is going on? is this normal behaviour? I noticed that on both Windows and linux (Fedora Core 4, and 5 and RHEL 4) -- http://mail.python.org/mailman/listinfo/python-list
no module named win32api using PyWin32-208
Hi. I have Python 2.4 installed on my local machine in c:\Python24. I have also downloaded the python for windows extensions installer pywin32-208.win32-py2.4.exe and installed this to C:\Python24\Lib\site-packages Trying to run a python script through a C# console app is causing me problems: the last line of code in the following block results in a no module named win32ap error. I'm not sure if this is because there is no win32api.py in the win32 fikder off site-packages, just a win32api.pyc file. m_engine = new PythonEngine(); m_engine.AddToPath(C:\\Python24\\DLLs); m_engine.AddToPath(C:\\Python24\\lib); m_engine.AddToPath(C:\\Python24\\lib\\plat-win); m_engine.AddToPath(C:\\Python24\\lib\\lib-tk); m_engine.AddToPath(C:\\Python24\\Lib\\site-packages\\pythonwin); m_engine.AddToPath(C:\\Python24); m_engine.AddToPath(C:\\Python24\\lib\\site-packages); m_engine.AddToPath(C:\\Python24\\lib\\site-packages\\win32); m_engine.AddToPath(C:\\Python24\\lib\\site-packages\\win32\\lib); m_engine.Execute(from win32api import win32api); I have added all the addtopaths to get the path to match the sys.path I see in a normal python console which can successfully import the module. Incidentally, I have tried making the last line m_engine.Execute(import win32api); with no luck. Can the win32 extensions handle compiled python modules? If not how can I get it to work? Thanks, Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you use this list ?
Bo Yang wrote: Hi everyone , I have join this list for about 4 months , and everyday I receive hundreds of mails . There is no means to read all of them , so I just read something interesting for me . But if so , there are too much mails pile up in my inbox , I want to ask how do you use this list , reading every mail come in or just read what you think interesting ? Thank you ! Best Regard ! I use the newsgroup: http://groups.google.com/group/comp.lang.python Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: Having problems with strings in HTML
Lawrence D'Oliveiro [EMAIL PROTECTED] wrote: Kiana Toufighi [EMAIL PROTECTED] wrote: print ''' a href=http://bbc.botany.utoronto.ca/ntools/cgi-bin/ntools_treeview_word.cgi?inp ut=max=2values_off=noremove_bracket=noshow_line_nr=yesshow_link_out=yes [ ... ] GraphicalOutput/a ''' [ ... ] By the way, you _do_ realize that your characters should be escaped as amp;, don't you? No they shouldn't. They part of the url, which is (IIRC) a CDATA attribute of the A element, not PCDATA. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | Frankly I have no feelings towards penguins one way or the other \X/ |-- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list
Re: Re-loading updated modules
Instead of exiting the interpreter, you can use reload() : see the section Built-in functions in the library reference reload( module) Reload a previously imported module. The argument must be a module object, so it must have been successfully imported before. This is useful if you have edited the module source file using an external editor and want to try out the new version without leaving the Python interpreter. The return value is the module object (the same as the module argument). Pierre -- http://mail.python.org/mailman/listinfo/python-list
Re: Re-loading updated modules
fileexit [EMAIL PROTECTED] wrote: Shouldn't python recompile a module if there is a later version of the code (.py file)? it does, when the module is first loaded. While i am debuging, i always have to exit python and delete the pyc before every run deleting the PYC shouldn't be necessary. then start it again and import the modules. It seems that this is the only way for it to recompile the new code. reload(module) however, see the caveats on this page: http://pyref.infogami.com/reload What is going on? is this normal behaviour? yes. and this is tutorial stuff, too: http://pytut.infogami.com/node8.html /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Re-loading updated modules
fileexit [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, Shouldn't python recompile a module if there is a later version of the code (.py file)? While i am debuging, i always have to exit python and delete the pyc before every run, then start it again and import the modules. It seems that this is the only way for it to recompile the new code. What is going on? is this normal behaviour? I noticed that on both Windows and linux (Fedora Core 4, and 5 and RHEL 4) If there is a later .py file, and you restart Python, Python will recompile the modules when you import them. -- Paul -- http://mail.python.org/mailman/listinfo/python-list
using pydoc in an application
Hi all, I'm discovering pydoc, and it seems to me that this is a great way to have online documentation for my application. Are there any examples of using this in some kind of help menu in an application? I've tried to just bind pydoc.gui() to a menu item, but this just brings up the GUI for pydoc, and the user still needs to search for the module before the browser comes up, and when I quit serving pydoc.gui(), my application dies along with it. Also, I need to get out of python to use pydoc.gui again, or I get error: (98, 'Address already in use') I'm sure there's a better way to take advantage of this module and my docstrings to get some online help. I'm using Tkinter and Pmw, but maybe it's time to convert all this to wxWidgets? Thanks for any help. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter - Button Overrelief
On Tue, 27 Jun 2006 14:06:05 +0200, Fuzzyman [EMAIL PROTECTED] wrote: Hello all, I have some Tkinter buttons that display images. I would like to change these to 'active' images when the mouse is over the button. I see that the button widget can take an 'overrelief' argument in the constructor. What values can this take ? The same as the 'relief' option, i.e the ones described here: http://www.tcl.tk/man/tcl8.4/TkCmd/options.htm#M-relief Note that Tkinter contains symbolic constants for these values: 'raised' is Tkinter.RAISED, 'flat' is Tkinter.FLAT, and so on. Also - can anyone provide an example of using the equivalent of a 'mouseover' event to change the image used by a button in Tkinter ? I'm afraid google has not helped me much here. The events you're after are 'Enter' and 'Leave'; see here: http://www.tcl.tk/man/tcl8.3/TkCmd/bind.htm#M7 Here is an example showing how to change the button text (changing the image is similar): from Tkinter import * root = Tk() b = Button(root, width=8, text='foo') b.pack() def enterB(event): b.configure(text='bar') def leaveB(event): b.configure(text='foo') b.bind('Enter', enterB) b.bind('Leave', leaveB) root.mainloop() HTH -- python -c print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-']) -- http://mail.python.org/mailman/listinfo/python-list
Re: Having problems with strings in HTML
Sion Arrowsmith wrote: By the way, you _do_ realize that your characters should be escaped as amp;, don't you? No they shouldn't. They part of the url, which is (IIRC) a CDATA attribute of the A element, not PCDATA. Yes they should. CDATA sections can contain character entities; it's elements that are ignored, not character/entity references. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
Marshall wrote: The real question is, are there some programs that we can't write *at all* in a statically typed language, because they'll *never* be typable? In a statically typed language that has a dynamic type, all dynamically typed programs are straightforwardly expressible. In a statically typed, Turing-complete language that does not have a dynamic type, it is always *possible* to express a dynamically typed program, but this may require a global transformation of the program or use of an interpreter -- i.e. the Felleisen expressiveness of the language is reduced. -- David Hopwood [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Having problems with strings in HTML
Sion Arrowsmith [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] By the way, you _do_ realize that your characters should be escaped as amp;, don't you? No they shouldn't. They part of the url, which is (IIRC) a CDATA attribute of the A element, not PCDATA. It is CDATA but ampersands still need to be escaped. -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you use this list ?
Bo Yang wrote: Hi everyone , I have join this list for about 4 months , and everyday I receive hundreds of mails . There is no means to read all of them , so I just read something interesting for me . But if so , there are too much mails pile up in my inbox , I want to ask how do you use this list , reading every mail come in or just read what you think interesting ? I use digest messages on a gmail account. i read the digests whenever i have time. -- M. http://marius.me.uk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you use this list ?
On 2006-06-27, Bo Yang [EMAIL PROTECTED] wrote: I have join this list for about 4 months , and everyday I receive hundreds of mails . There is no means to read all of them , so I just read something interesting for me . But if so , there are too much mails pile up in my inbox , I want to ask how do you use this list , reading every mail come in or just read what you think interesting ? Find an NNTP server and read it as a newsgroup. If all else fails you can read it via gmane.org. Actually having mailing lists send you mail is insane. -- Grant Edwards grante Yow! I wonder if I ought at to tell them about my visi.comPREVIOUS LIFE as a COMPLETE STRANGER? -- http://mail.python.org/mailman/listinfo/python-list
Unbound Local error? How?
I've got some code as follows: import re re_regexname = re.compile('abc') . . various function defs . def func1(): ... func2() ... def func2(): if re_regexname.match('abc'): do something if __name__ == '__main__': func1() but this returns the Traceback: UnboundLocalError: local variable 're_regexname' referenced before assignment How? It was declared in the zero level indentation near the top of the script! I don't understand this, isn't a function supposed to be able to reference stuff in the containing function or the top level? -- http://mail.python.org/mailman/listinfo/python-list
Re: Unbound Local error? How?
Hari Sekhon wrote: import re re_regexname = re.compile('abc') . . various function defs . def func1(): ... func2() ... def func2(): if re_regexname.match('abc'): do something if __name__ == '__main__': func1() The above clearly is not what you have. See the attached version of the above that works. So - go check for a typo or something like that. Diezimport re re_regexname = re.compile('abc') def func1(): func2() def func2(): if re_regexname.match('abc'): print whohoo! if __name__ == '__main__': func1() -- http://mail.python.org/mailman/listinfo/python-list
Re: Unbound Local error? How?
Diez B. Roggisch wrote: Hari Sekhon wrote: import re re_regexname = re.compile('abc') . . various function defs . def func1(): ... func2() ... def func2(): if re_regexname.match('abc'): do something if __name__ == '__main__': func1() The above clearly is not what you have. See the attached version of the above that works. So - go check for a typo or something like that. Diez import re re_regexname = re.compile('abc') def func1(): func2() def func2(): if re_regexname.match('abc'): print " whohoo!" if __name__ == '__main__': func1() you're right, it wasn't that, I was trying to locally override a regex object as follows: re_somepattern = re.compile('abc') re_someotherpattern = re.compile('def') def func(): if somecondition: re_somepattern = re_someotherpattern code block re_somepattern.match('something') /code.block not sure how to override this the way I want, it'd be quite messy if I had to do huge if blocks to handle this inside the other code blocks that use this re_somepattern.match() or perhaps I'm going about this all wrong -h -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you use this list?
Grant Edwards wrote: Find an NNTP server and read it as a newsgroup. Or Google Groups: http://groups.google.com/group/comp.lang.python Cheers, -- Klaus Alexander Seistrup Dyssegård, Denmark http://surdej.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Queue.Queue.queue.clear() thread-safe?
Thanks guys. This has helped decipher a bit of the Queue mechanics for me. Regarding my initial clear method hopes... to be safe, I've re-organized some things to make this a little easier for me. I will still need to clear out junk from the Queue, but I've switched it so that least I can stop the accumulation of new data in the Queue while I'm clearing it. ie: I can just loop on .get until it is empty without fear of a race, rather than needing a single atomic clear. My next Queue fun is to maybe provide the ability to stuff things back on the queue that were previously popped, although I'll probably try and avoid this, too (maybe with a secondary oops buffer). If curious why I want stuff like this, I've got a case where I'm collecting data that is being asynchronously streamed in from a piece of hardware. Queue is nice because I can just have a collector thread running and stuffing the Queue while other processing happens on a different thread. The incoming data *should* have start and stop indications within the stream to define segments in the stream, but stream/timing irregularities can sometimes either cause junk, or cause you to want to rewind the extraction a bit (eg: in mid stream-assembly you might realize that a stop condition was missed, but can deduce where it should have been). Fun. Russ -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
Ketil Malde wrote: Marshall [EMAIL PROTECTED] writes: There are also what I call packaging issues, such as being able to run partly-wrong programs on purpose so that one would have the opportunity to do runtime analysis without having to, say, implement parts of some interface that one isn't interested in testing yet. These could also be solved in a statically typed language. (Although historically it hasn't been done that way.) I keep hearing this, but I guess I fail to understand it. How partly-wrong do you require the program to be? During development, I frequently sprinkle my (Haskell) program with 'undefined' and 'error implement later' - which then lets me run the implemented parts until execution hits one of the 'undefined's. The cost of static typing for running an incomplete program is thus simply that I have to name entities I refer to. I'd argue that this is good practice anyway, since it's easy to see what remains to be done. (Python doesn't seem to, but presumably a serious dynamically typed system would warn about references to entities not in scope?) I'll give you my understanding of it, but bear in mind that I only program in statically typed languages, and I in fact do exactly what you decribe above: stub out unimplemented methods. The issue is that, while stubbing out things may not be expensive, it is not free either. There is some mental switching cost to being in a state where one writes some code, wants to execute it, but can't, because of type system constraints that are globally applicable but not locally applicable to the task at hand, or to the specific subprogram one is working on right at that moment. Since I'm very used to doing it, it doesn't seem like an issue to me, but programmers in dynamical languages complain bitterly about this. It is my feeling that programming languages should try to be inclusive, and since this feature is easily enough accomodated, (as a 'lenient' switch to execution) it ought to be. Marshall -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you use this list?
On 2006-06-27, Klaus Alexander Seistrup [EMAIL PROTECTED] wrote: Grant Edwards wrote: Find an NNTP server and read it as a newsgroup. Or Google Groups: http://groups.google.com/group/comp.lang.python I did heard a rumor that they finally fixed the follow-up function that had been broken since day 1. Still, it does a bad reputation similar to AOL used to... -- Grant Edwards grante Yow! My EARS are GONE!! at visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
David Hopwood wrote: Marshall wrote: The real question is, are there some programs that we can't write *at all* in a statically typed language, because they'll *never* be typable? In a statically typed language that has a dynamic type, all dynamically typed programs are straightforwardly expressible. So, how does this dynamic type work? It can't simply be the any type, because that type has no/few functions defined on it. It strikes me that *when* exactly binding happens will matter. In a statically typed language, it may be that all binding occurs at compile time, and in a dynamic language, it may be that all binding occurs at runtime. So you might have to change the binding mechanism as well. Does the dynamic type allow this? Marshall -- http://mail.python.org/mailman/listinfo/python-list
Re: Having problems with strings in HTML
Richard Brodie wrote: Sion Arrowsmith [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] By the way, you _do_ realize that your characters should be escaped as amp;, don't you? No they shouldn't. They part of the url, which is (IIRC) a CDATA attribute of the A element, not PCDATA. It is CDATA but ampersands still need to be escaped. Exactly. See http://www.w3.org/TR/html4/appendix/notes.html#ampersands-in-uris Bye, Walter Dörwald -- http://mail.python.org/mailman/listinfo/python-list
Re: Having problems with strings in HTML
[Kiana] a href=http://bbc.botany.utoronto.ca/[...]?input=max=2[...]; [Lawrence] By the way, you _do_ realize that your characters should be escaped as amp;, don't you? [Sion] No they shouldn't. They part of the url, which is (IIRC) a CDATA attribute of the A element, not PCDATA. The W3C validator at http://validator.w3.org/ disagrees with you. It accepts this: !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//ENhttp://www.w3.org/TR/html4/strict.dtd; htmlheadtitleTest/title/head body pa href=http://somewhere.com?a=1amp;b=2;link/a/p /body/html but rejects this: !DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//ENhttp://www.w3.org/TR/html4/strict.dtd; htmlheadtitleTest/title/head body pa href=http://somewhere.com?a=1b=2;link/a/p /body/html saying cannot generate system identifier for general entity b [...] The most common cause of this error is unencoded ampersands in URLs. -- Richie Hindle [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
[W2k, wxPython 2.6.1.0] - MDISashDemo bug?
When i run MDISashDemo and maximize main frame, minimize and maximize again - LayoutMDIFrame in OnSize dont work more... Why? I need this feature for main MDI frame with toolbar and statusbar with panelssizersbitmapbuttons :) Windows 2000, wxPython 2.6.1.0 w.p. -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Unbound Local error? How?
Hari Sekhon wrote: I've got some code as follows: import re re_regexname = re.compile('abc') . . various function defs . def func1(): ... func2() ... def func2(): if re_regexname.match('abc'): do something if __name__ == '__main__': func1() but this returns the Traceback: UnboundLocalError: local variable 're_regexname' referenced before assignment this is *not* the traceback. This is only the error message. The traceback contains all needed informations (or at least all possible information at this point) to know what happened. But you did not post the traceback. Nor did you post the minimal runnable code snippet producing this error. How? How could we know ? -- 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: Unbound Local error? How?
Bruno Desthuilliers wrote: Hari Sekhon wrote: I've got some code as follows: import re re_regexname = re.compile('abc') . . various function defs . def func1(): ... func2() ... def func2(): if re_regexname.match('abc'): do something if __name__ == '__main__': func1() but this returns the Traceback: UnboundLocalError: local variable 're_regexname' referenced before assignment this is *not* the traceback. This is only the error message. The traceback contains all needed informations (or at least all possible information at this point) to know what happened. But you did not post the traceback. Nor did you post the minimal runnable code snippet producing this error. How? How could we know ? sorry, I know it looks like I was being stingy but the traceback was not that helpful, not without seeing more a huge amount more of the code. I was trying to abbreviate. Traceback (most recent call last): File "./backup.py", line 649, in ? backup(machine,share) File "./backup.py", line 364, in backup backupdir(source,destination) File "./backup.py", line 398, in backupdir (dirlist,filelist) = getdirlisting( source ) File "./backup.py", line 445, in getdirlisting if re_skip_dirs.match(x): UnboundLocalError: local variable 're_skip_dirs' referenced before assignment This doesn't really show that much, I figured the problem was the following: def getdirlisting(): re_skip_dirs = re_skip_top_dirs #Here's the culprit where both these regex compiled objects were declared at the top level, it seems that the assignment is trying to use the local variable re_skip_top_dirs which doesn't exist, that's why I'm getting a traceback, commenting out this line it runs fine. -h -- http://mail.python.org/mailman/listinfo/python-list
Re: [Stackless] Suggestion for a Solution ? Re: Blocking Problem with Stackless Python and Twisted
I had a similar problem, and Radix's threadless Twisted snippet proved to be a very viable solutionHave a look at: http://twistedmatrix.com/trac/browser/sandbox/radix/threadless.py?rev=17407 On 6/26/06, Andrew Francis [EMAIL PROTECTED] wrote: Hello Jas, Bob, et al: Twisted isn't designed for Stackless integration, and the approachyou're taking simply will notwork. Twisted does block on reactor.run(), and during each runloop iteration it blocks waiting for a timeout or network activity (viaselect or pollusually).~ What's the deal with this error from stackless.run():...have some reasons to need to be able to run a scheduler on another thread... Did someone discoversome problem? Or is this check just overlyconservative? (A few simple scheduling experimentsseem to run without problem...)From what I can tell, the only time I really care about blocking that cuts down overall concurrency iswhen I have tasklets running in parallel, and one ormore of those tasklets, at some low level will bedoing an IO operation that can block for anindeterminate amount of time ( i.e., an accept()).That said, I beleive the the easiest way to get aroundthis problem is to bite the bullet and run Twisted (orthe programme with blocking IO) in another process.In turn, I : 1. create a simple protocol.2. and have my Stackless process establish aconnection with the process doing the actual IO (someother IPC could also be used).3. Mark the socket as non-blocking (or use MSG_PEEK?) 4. Have tasklets with a network event loop.#requestswhile (some_condition): request = requestChannel.receive() serverSocket.send(request) stackless.schedule()#responses while (some_condition): if (there is data): reply = serverSocket.receive() replyChannel.send(reply) stackless.schedule()you get the idea. Comments? Suggestions? Cheers,Andrew__Do You Yahoo!?Tired of spam?Yahoo! Mail has the best spam protection aroundhttp://mail.yahoo.com ___Stackless mailing list[EMAIL PROTECTED] http://www.stackless.com/mailman/listinfo/stackless -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
On Mon, 26 Jun 2006 13:02:33 -0600, Chris Smith [EMAIL PROTECTED] wrote: George Neuner gneuner2/@comcast.net wrote: I worked in signal and image processing for many years and those are places where narrowing conversions are used all the time - in the form of floating point calculations reduced to integer to value samples or pixels, or to value or index lookup tables. Often the same calculation needs to be done for several different purposes. These are value conversions, not type conversions. Basically, when you convert a floating point number to an integer, you are not simply promising the compiler something about the type; you are actually asking the compiler to convert one value to another -- i.e., see to it that whatever this is now, it /becomes/ an integer by the time we're done. This also results in a type conversion, but you've just converted the value to the appropriate form. There is a narrowing value conversion, but the type conversion is perfectly safe. We're talking at cross purposes. I'm questioning whether a strong type system can be completely static as some people here seem to think. I maintain that it is simply not possible to make compile time guarantees about *all* runtime behavior and that, in particular, narrowing conversions will _always_ require runtime checking. I can know that my conversion of floating point to integer is going to produce a value within a certain range ... but, in general, the compiler can't determine what that range will be. If you mean my compiler can't, then this is probably the case. If you mean no possible compiler could, then I'm not sure this is really very likely at all. Again, the discussion is about narrowing the result. It doesn't matter how much the compiler knows about the ranges. When the computation mixes types, the range of the result can only widen as the compiler determines the types involved. George -- for email reply remove / from address -- http://mail.python.org/mailman/listinfo/python-list
How to disable tk inclusion in py build
Hi folks, I'd like to disable the inclusion of tk graphics lib in my py build. Looked around but couldn't find a clear answer. Which one of the following would I need to use in the configure step: --disable-tkbuild --without-tk Thanks, /venkat -- http://mail.python.org/mailman/listinfo/python-list
Re: What technologies should I use for my application manager?
MrBlueSky wrote: Thanks for the advice, Adam! Turbogears sounds like it does everything I want and looks like a great... except you've made me nervous with your comment on the instability of the Oracle API! It is not impossible to find a stable ORM for access to Oracle, just slightly more difficult. Both of the systems in question are working on perfecting the currently experimental support. Stability, good documentation and a wide user base are priorities. I was delighted by the quality of Tkinter in this regard. Am I wishing for the moon in hoping for the same quality in the framework I choose for this? Anyone else like to try and sell me on Zope or Django?! -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is fun (useless social thread) ;-)
Bruno Desthuilliers wrote: Ever seen this from Fuzzyman? It explicitly uses the dict comparison. http://www.voidspace.org.uk/python/articles/OOP.shtml#introduction Nope - and the site seems to be down actually. But thanks for the pointer anyway. It works for me, at least now. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
Ketil Malde [EMAIL PROTECTED] writes: Marshall [EMAIL PROTECTED] writes: There are also what I call packaging issues, such as being able to run partly-wrong programs on purpose so that one would have the opportunity to do runtime analysis without having to, say, implement parts of some interface that one isn't interested in testing yet. These could also be solved in a statically typed language. (Although historically it hasn't been done that way.) I keep hearing this, but I guess I fail to understand it. How partly-wrong do you require the program to be? This conclusion is false. To be wrong, whether partly or fully, a program needs to specifically not conform to the requirements that the programmer gives it. You are assuming that only a completed program can be right. Let me give a counterexample: Consider this part of a CL program: CL-USER(1): (defun foo (x) (declare (optimize speed (safety 0) (debug 0)) (fixnum x) ) (bar (the fixnum (1+ x FOO CL-USER(2): This is of course not a complete program, because the function BAR is not yet defined. If I try to run it, it will of course get an error. But does that require then that I call this a partly wrong program? No, of course not; it is not a program; it is a function, and for my purposes it is completely correct (I've debugged it already :-) So what can we do with an incomplete program? Nothing? Well, no. Of course, we can't run it (or can we?). But even before talking about running the program, we can at least do some reasoning about it: 1. It seems to have some static type declarations (in a dynamic langiuage? oh my :-). 2. The 1+ operation limits the kinds of operations that would be acceptable, even in the absence of static type declarations. 3. The declarations can be ignored by the CL implementation, so #2 might indeed come into play. I ensured that the declarations would be trusted in Allegro CL, by declaring high speed and low safety. 4. I can compile this function. Note that I get a warning about the incompleteness of the program: CL-USER(2): (compile 'foo) Warning: While compiling these undefined functions were referenced: BAR. FOO NIL NIL CL-USER(3): 5. I can disassemble the function. Note that it is a complete function, despite the fact that BAR is undefined: CL-USER(3): (disassemble 'foo) ;; disassembly of #Function FOO ;; formals: X ;; constant vector: 0: BAR ;; code start: #x406f07ec: 0: 83 c0 04 addl eax,$4 3: 8b 5e 12 movl ebx,[esi+18] ; BAR 6: b1 01 movbcl,$1 8: ff e7 jmp *edi CL-USER(4): 6. I can _even_ run the program! Yes, I get an error: CL-USER(4): (foo 10) Error: attempt to call `BAR' which is an undefined function. [condition type: UNDEFINED-FUNCTION] Restart actions (select using :continue): 0: Try calling BAR again. 1: Return a value instead of calling BAR. 2: Try calling a function other than BAR. 3: Setf the symbol-function of BAR and call it again. 4: Return to Top Level (an abort restart). 5: Abort entirely from this (lisp) process. [1] CL-USER(5): 7. But note first that I have many options, including retrying the call to BAR. What was this call to BAR? I can reason about that as well, by getting a backtrace: [1] CL-USER(5): :zoom Evaluation stack: (ERROR #UNDEFINED-FUNCTION @ #x406f3dfa) -(BAR 11) [... EXCL::%EVAL ] (EVAL (FOO 10)) (TPL:TOP-LEVEL-READ-EVAL-PRINT-LOOP) (TPL:START-INTERACTIVE-TOP-LEVEL #TERMINAL-SIMPLE-STREAM [initial terminal io] fd 0/1 @ #x40120e5a #Function TOP-LEVEL-READ-EVAL-PRINT-LOOP ...) [1] CL-USER(6): 8. If I then define BAR, with or without compiling it, and then take that option to retry the call: [1] CL-USER(6): (defun bar (x) (1- x)) BAR [1] CL-USER(7): :cont 10 CL-USER(8): Hmm, I was able to complete the program dynamically? Who ever heard of doing that? :-) During development, I frequently sprinkle my (Haskell) program with 'undefined' and 'error implement later' - which then lets me run the implemented parts until execution hits one of the 'undefined's. Why do it manually? And what do you do when you've hit the undefined? Start the program over? The cost of static typing for running an incomplete program is thus simply that I have to name entities I refer to. I'd argue that this is good practice anyway, since it's easy to see what remains to be done. Good practice, yes, but why not have the language help you to practice it? -- Duane Rettig[EMAIL PROTECTED]Franz Inc. http://www.franz.com/ 555 12th St., Suite 1450 http://www.555citycenter.com/ Oakland, Ca. 94607Phone: (510) 452-2000; Fax: (510) 452-0182 -- http://mail.python.org/mailman/listinfo/python-list
file writing question
Hi, I am a newbie so not very confident in file handling. I want to write to a file atrributes in this fashion #NameOfComputer:MAC_Address:IP_Address --computer_details.txt begins- IG1:8f00142a123c:192.168.2.101 IG2:8f00142a124d:192.168.2.102 IG3:8f00142a124e:192.168.2.103 IG4:8f00142a124f:192.168.2.104 IG5:8f00142a124a:192.168.2.105 IG6:8f00142a124b:192.168.2.106 --computer_details.txt ends--- While writing this file I insert \n after every line so that details of every new computer goes into next line for readibility. After I have to read this file. While reading this file \n remains which I dont want. Is there a neat way of writing to a file and not having \n ? Please help -- http://mail.python.org/mailman/listinfo/python-list
Re: [W2k, wxPython 2.6.1.0] - MDISashDemo bug?
w.p. wrote: When i run MDISashDemo and maximize main frame, minimize and maximize again - LayoutMDIFrame in OnSize dont work more... Why? I need this feature for main MDI frame with toolbar and statusbar with panelssizersbitmapbuttons :) Windows 2000, wxPython 2.6.1.0 w.p. When i add this code: self.Bind(wx.EVT_ACTIVATE, self.OnActivate) and def OnActivate(self, event): if event.GetActive(): wx.LayoutAlgorithm().LayoutMDIFrame(self) all is ok. Small improvement in demo :) w.p. -- http://mail.python.org/mailman/listinfo/python-list
Re: languages with full unicode support
Oliver Bandel wrote: こんいちわ Xah-Lee san ;-) Uhm, I'd guess that Xah is Chinese. Be careful with such things in real life; Koreans might beat you up for this. Stay alive! Xah Lee wrote: Languages with Full Unicode Support As far as i know, Java and JavaScript are languages with full, complete unicode support. That is, they allow names to be defined using unicode. Can you explain what you mena with the names here? (the JavaScript engine used by FireFox support this) As far as i know, here's few other lang's status: C → No. Well, is this (only) a language issue? On Plan-9 all things seem to be UTF-8 based, and when you use C for programming, I would think that C can handle this also. But I only have read some papers about Plan-9 and did not developed on it Only a try to have a different view on it. If someone knows more, please let us know :) Ciao, Oliver -- Lisp kann nicht kratzen, denn Lisp ist fluessig -- http://mail.python.org/mailman/listinfo/python-list
Re: Inconsistent float behaviour on inf - current state?
Peter Knörrich wrote: why float('inf') isn't supported everywhere, and I understand the underlying problem: libc simply isn't that good - never mind standard - with regard to floats. I think you believe there is an underlying model of floating point numbers that all machines share. That is not true. Many systems (even those that support IEEE 754) make distinct choices about what particular bit patterns in memory represent what particular values. You can take a pickle of a data structure in CPython on one machine, carry it to a different machine with a different CPU FPU and a different OS, and reasonably expect that the unpickled data structure running on the CPython on the other machine will produce essentially the same value. That is _amazing_. You might not have the same number of bits of precision, you might not have the same range of exponents, and the base of the exponent might even be different (well, ... perhaps nobody is running Python on 360s -- I may exaggerate here). This is not accomplished by lots of clever coding of distinct implementations across the range of machines CPython runs on. It is accomplished by staying close to the middle of the road in the C89 standard. And it breaks down for infinities and the various denormals and NaNs that you can at least detect in C99. C89, the standard we go by for CPython, provides pretty good support for floating point numbers in reasonable ranges with reasonable amounts of precision. That is to say, you can calculate with C doubles and get pretty similar results for the same C program running on quite different compilers, operating systems, and hardware _if_ you walk the middle of the road (staying away from rough edges, boundary values, things like calculating sin(1e300) [trigs work better w/in -2pi to 2pi] and the like. C89 does not mention the Not-A-Number group at all, and only says that infinity is something that an implementation may support. That may means that a C89 compiler is free to do nothing for Infinities, and even if it does something, it it doesn't have to behave like some other C89 compiler's version of what to do with Infinities. So it is no wonder that values like plus and minus infinity behave funny across different CPython systems. In the eighties (when C89 was being worked on), it was not clear whether IEEE 754 would be _the_ standard or _a_ standard for floating point. It would have been pointless to force all C implementers (and they included Lifeboat Systems who did C compilers for Z80s as well as Cray Research, who did C compilers for slightly larger machines) to specify how to make positive and negative zeroes, how and when to produce denormalized numbers, how to produce positive and negative infinity (and whether they are distinct from each other), how create the various signaling and quiet NaNs when may systems did not have IEEE 754 floating point hardware. C is kind of a glorified assembler, and (as such) it reveals the hardware it works on. That is why the C expression ((-7) % 4) can be 1 or -1; different hardware solves that problem differently, and C doesn't want to slow down all divisions on some hardware just to get a consistent result. If you stick to positive numbers for division, both kinds of hardware get the same result, and the programmer can put the test in if he needs it. It would not be in the spirit of C to dictate a floating point behavior that would require a lot of code generated on each operation, and without common hardware, the infinity / denormal / NaN behavior would mean code at every floating point operation. The C standards body was not interested in that work. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
Chris F Clark wrote: Very impressive. It looks right to me and simple enough to understand. I must find the time to learn a modern FP language. Can you write a fold for this that prints the data as a binary tree of triples? I have to believe it isn't that hard {- Refactoring this as a fold is left as an exercise to the reader -} data Clark a b c = Nil | Cons a (Clark b c (a,a)) deriving Show clark = (Cons 42 (Cons 3.14 (Cons abc (Cons (1,2) (Cons (1.2,3.4) (Cons (foo,bar) (Cons ((9,8),(7,6)) (Cons ((0.1,0.2),(0.3,0.4)) (Cons ((w,x),(y,z)) Nil) main = print (toTree clark) data Tree a = Empty | Node a (Tree a) (Tree a) deriving Show toTree :: Clark a b c - Tree (a,b,c) toTree (Cons x (Cons y (Cons z rest))) = Node (x,y,z) (toTree (fst (lift_c rest))) (toTree (snd (lift_c rest))) toTree _ = Empty lift_c :: Clark (a,a) (b,b) (c,c) - (Clark a b c, Clark a b c) lift_c Nil = (Nil,Nil) lift_c (Cons (x,y) rest) = (Cons x (fst (lift_c rest)), Cons y (snd (lift_c rest))) -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
Marshall wrote: Yes, an important question (IMHO the *more* important question than the terminology) is what *programs* do we give up if we wish to use static typing? I have never been able to pin this one down at all. It would depend on the type system, naturally. It isn't clear to me which programs we would have to give up, either. I don't have much experience in sophisticated typed languages. It is rather easy to find programs that baffle an unsophisticated typed language (C, C++, Java, etc.). Looking back in comp.lang.lisp, I see these examples: (defun noisy-apply (f arglist) (format t I am now about to apply ~s to ~s f arglist) (apply f arglist)) (defun blackhole (argument) (declare (ignore argument)) #'blackhole) But wait a sec. It seems that these were examples I invented in response to the same question from you! The real question is, are there some programs that we can't write *at all* in a statically typed language, because they'll *never* be typable? Certainly! As soon as you can reflect on the type system you can construct programs that type-check iff they fail to type-check. Perhaps, there is no such beast. Or, perhaps I just can't formulate it. Or, perhaps we have static type checkers which can do computations of unbounded complexity. However, I thought that one of the characteristics of type systems was that they did not allow unbounded complexity and weren't Turing Complete. The C++ type system is Turing complete, although in practical terms it limits how much processing power it will spend on types at compile time. I think templates only have to expand to seven levels, so you are severely limited here. If you allow Turing Complete type systems, then I would say no--every bug can be reforumlated as a type error. If you require your type system to be less powerful, then some bugs must escape it. I don't think so. Even with a Turing complete type system, a program's runtime behavior is still something different from its static behavior. (This is the other side of the types are not tags issue--not only is it the case that there are things static types can do that tags can't, it is also the case that there are things tags can do that static types can't.) I agree. The point of static checking is to *not* run the program. If the type system gets too complicated, it may be a de-facto interpreter. -- http://mail.python.org/mailman/listinfo/python-list
Re: file writing question
[EMAIL PROTECTED] wrote: Hi, I am a newbie so not very confident in file handling. I want to write to a file atrributes in this fashion #NameOfComputer:MAC_Address:IP_Address --computer_details.txt begins- IG1:8f00142a123c:192.168.2.101 IG2:8f00142a124d:192.168.2.102 IG3:8f00142a124e:192.168.2.103 IG4:8f00142a124f:192.168.2.104 IG5:8f00142a124a:192.168.2.105 IG6:8f00142a124b:192.168.2.106 --computer_details.txt ends--- While writing this file I insert \n after every line so that details of every new computer goes into next line for readibility. After I have to read this file. While reading this file \n remains which I dont want. Then strip it: for line in open('computer_details.txt'): name, mac, ip = line.strip().split(':') # ... Is there a neat way of writing to a file and not having \n ? Yes : don't add the newline after every line. But note that this may make the file a bit more difficult to read and parse for both your program and you !-) Also, may I suggest that you read the doc for the CSV module ? -- 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: new python icons for windows
Istvan Albert wrote: [EMAIL PROTECTED] wrote: For example it resembles the icon for text files. This is intentional: to make it obvious that .py files are the readable, editable scripts, contrasting with .pyc's binary gunk - I think this is a mistake, it does not seem obious, all it does is just blends in and does not separate the python files from regular text files. Also the black icons for pyc files are far more visible and stand out much more than the white ones. If anything I wish the pyc had no icons at all or was invisible, I mean how often do you need to do any work with pyc files... I agree with those points after trying out the icons. Something about the icons seems blurry (perhaps it's the yellow snake with the poorly visible white eye. Or it could be the paper that doesn't seem to have enough contrast on the top (I have white background behind them.) To my eyes, the pyc stick out also. I almost want to swap the two since the pyc files look so striking. I do like the egg icons very much. Good work! -Kevin Deenanauth -- http://mail.python.org/mailman/listinfo/python-list
Re: Unbound Local error? How?
Hari Sekhon wrote: Bruno Desthuilliers wrote: Hari Sekhon wrote: I've got some code as follows: import re re_regexname = re.compile('abc') . . various function defs . def func1(): ... func2() ... def func2(): if re_regexname.match('abc'): do something if __name__ == '__main__': func1() but this returns the Traceback: UnboundLocalError: local variable 're_regexname' referenced before assignment this is *not* the traceback. This is only the error message. The traceback contains all needed informations (or at least all possible information at this point) to know what happened. But you did not post the traceback. Nor did you post the minimal runnable code snippet producing this error. How? How could we know ? sorry, I know it looks like I was being stingy but the traceback was not that helpful, not without seeing more a huge amount more of the code. I was trying to abbreviate. Traceback (most recent call last): File ./backup.py, line 649, in ? backup(machine,share) File ./backup.py, line 364, in backup backupdir(source,destination) File ./backup.py, line 398, in backupdir (dirlist,filelist) = getdirlisting( source ) File ./backup.py, line 445, in getdirlisting if re_skip_dirs.match(x): UnboundLocalError: local variable 're_skip_dirs' referenced before assignment This doesn't really show that much, I figured the problem was the following: def getdirlisting(): re_skip_dirs = re_skip_top_dirs #Here's the culprit where both these regex compiled objects were declared at the top level, it seems that the assignment is trying to use the local variable re_skip_top_dirs which doesn't exist, that's why I'm getting a traceback, commenting out this line it runs fine. -h The error is simply that you are making an assignment *somewhere* inside your function body, so the compiler is treating the variable as local, masking the module-level global name. Consequently when you try to read its value you are told that the local variable has not yet been bound to a value. A global statement inside the function body will fix the problem. You could also add a keyword argument (never used except to set a default for it in the def statement). regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Love me, love my blog http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: [W2k, wxPython 2.6.1.0] - MDISashDemo bug?
w.p. wrote: w.p. wrote: When i run MDISashDemo and maximize main frame, minimize and maximize again - LayoutMDIFrame in OnSize dont work more... Why? I need this feature for main MDI frame with toolbar and statusbar with panelssizersbitmapbuttons :) Windows 2000, wxPython 2.6.1.0 w.p. When i add this code: self.Bind(wx.EVT_ACTIVATE, self.OnActivate) and def OnActivate(self, event): if event.GetActive(): wx.LayoutAlgorithm().LayoutMDIFrame(self) all is ok. Small improvement in demo :) Well done! Do you know how to feed this information on to the developers (probably Robin Dunn)? All such changes are valuable. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Love me, love my blog http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
The C++ type system is Turing complete, although in practical terms it limits how much processing power it will spend on types at compile time. I think templates only have to expand to seven levels, so you are severely limited here. You can adjust the iteration-depth. However, as turing-complete implies the potential to create infinite loops - it enforces _some_ boundary. Otherwise the user hitting C-c will do :) Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Python database access
The odbc module is part of the Python Standard Library. Since when? -- damjan -- http://mail.python.org/mailman/listinfo/python-list
Exchanging data with a C program using shared memory (sysV IPC)
Hello, I want my python application to communicate with an legacy C program which read/write data in a shared memory (Unix Sys V IPC). It seems that there are no official shm nor sysV ipc module, and that non-official ones are dead. I can't modify the C code to change its communication method. How would you solve this problem using python ? Is there any reason there is no official shm for python ? I could write a C code which communicates with my python application using mmap or something else and with the old C code using shmat(), but this is a rather ugly solution. Thanks in advance. --- Al -- http://mail.python.org/mailman/listinfo/python-list
Re: file writing question
Thanks BrunoThis helps me. Bruno Desthuilliers wrote: [EMAIL PROTECTED] wrote: Hi, I am a newbie so not very confident in file handling. I want to write to a file atrributes in this fashion #NameOfComputer:MAC_Address:IP_Address --computer_details.txt begins- IG1:8f00142a123c:192.168.2.101 IG2:8f00142a124d:192.168.2.102 IG3:8f00142a124e:192.168.2.103 IG4:8f00142a124f:192.168.2.104 IG5:8f00142a124a:192.168.2.105 IG6:8f00142a124b:192.168.2.106 --computer_details.txt ends--- While writing this file I insert \n after every line so that details of every new computer goes into next line for readibility. After I have to read this file. While reading this file \n remains which I dont want. Then strip it: for line in open('computer_details.txt'): name, mac, ip = line.strip().split(':') # ... Is there a neat way of writing to a file and not having \n ? Yes : don't add the newline after every line. But note that this may make the file a bit more difficult to read and parse for both your program and you !-) Also, may I suggest that you read the doc for the CSV module ? -- 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: [W2k, wxPython 2.6.1.0] - MDISashDemo bug?
Steve Holden wrote: Well done! Do you know how to feed this information on to the developers (probably Robin Dunn)? All such changes are valuable. Hmm... i dont know. wxpython.org - submit a patch or Report a bug ? w.p. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
Joe Marshall wrote: Marshall wrote: Yes, an important question (IMHO the *more* important question than the terminology) is what *programs* do we give up if we wish to use static typing? I have never been able to pin this one down at all. It would depend on the type system, naturally. It isn't clear to me which programs we would have to give up, either. I don't have much experience in sophisticated typed languages. It is rather easy to find programs that baffle an unsophisticated typed language (C, C++, Java, etc.). Looking back in comp.lang.lisp, I see these examples: (defun noisy-apply (f arglist) (format t I am now about to apply ~s to ~s f arglist) (apply f arglist)) (defun blackhole (argument) (declare (ignore argument)) #'blackhole) But wait a sec. It seems that these were examples I invented in response to the same question from you! The real question is, are there some programs that we can't write *at all* in a statically typed language, because they'll *never* be typable? Certainly! As soon as you can reflect on the type system you can construct programs that type-check iff they fail to type-check. Sorry, but can you elaborate on this last point a little? I think I missed something. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
Marshall wrote: David Hopwood wrote: Marshall wrote: The real question is, are there some programs that we can't write *at all* in a statically typed language, because they'll *never* be typable? In a statically typed language that has a dynamic type, all dynamically typed programs are straightforwardly expressible. So, how does this dynamic type work? http://citeseer.ist.psu.edu/abadi89dynamic.html It can't simply be the any type, because that type has no/few functions defined on it. It isn't. From the abstract of the above paper: [...] even in statically typed languages, there is often the need to deal with data whose type cannot be determined at compile time. To handle such situations safely, we propose to add a type Dynamic whose values are pairs of a value v and a type tag T where v has the type denoted by T. Instances of Dynamic are built with an explicit tagging construct and inspected with a type safe typecase construct. Gradual typing as described in http://www.cs.rice.edu/~jgs3847/pubs/pubs/2006/siek06:_gradual.pdf is another alternative. The difference between gradual typing and a dynamic type is one of convenience rather than expressiveness -- gradual typing does not require explicit tagging and typecase constructs. -- David Hopwood [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: How to disable tk inclusion in py build
[EMAIL PROTECTED] wrote: I'd like to disable the inclusion of tk graphics lib in my py build. Looked around but couldn't find a clear answer. Which one of the following would I need to use in the configure step: --disable-tkbuild --without-tk since _tkinter.so is only built if it's found by the setup script, and if built, it's only loaded if you actually use it, why bother disabling it ? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting 3-byte integers
I have some binary data read from a file that is arranged like 3-byte int 3-byte int 3-byte int etc. The ints are big-endian and there are 169 of them. Is there any clever way to convert these to regular Python ints other than (struct) unpack'ing them one at a time and doing the math? Thanks guys! I was looking for a 'one liner' of some kind, but I guess there isn't one (too bad you can't tell array or struct.unpack how many bytes you want an integer to be). Yeah, these are signed ints so I'll have to convert them. To me balancing my checkbook involves higher math. :) Bob -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
George Neuner gneuner2/@comcast.net wrote: We're talking at cross purposes. I'm questioning whether a strong type system can be completely static as some people here seem to think. I maintain that it is simply not possible to make compile time guarantees about *all* runtime behavior and that, in particular, narrowing conversions will _always_ require runtime checking. Nah, we're not at cross-purposes. I'm discussing the same thing you are. My answer is that while narrowing conversion are not (by definition) type-safe, a sufficiently strong type system can remove these type-unsafe narrowing conversions from a program. Again, the discussion is about narrowing the result. It doesn't matter how much the compiler knows about the ranges. When the computation mixes types, the range of the result can only widen as the compiler determines the types involved. Well, there are certain operations that can reduce the range. For example, dividing a number that's known to be in the range 6-10 by the exact constant 2 yields a result that's guaranteed to be in the range 3- 5. That's a smaller range. That said, though, there is a more fundamental point here. When you perform a a narrowing type conversion, one of two things must be true: (a) you know more about the types than the compiler, and thus know that the conversion is safe, or (b) your code is broken. Exluding the possibility that you've written buggy code, you must possess some knowledge that convinces you the conversion is safe. In that case, we need only allow the type system to have that same knowledge, and the problem is solved. (One thing worth pointing out here is that it's quite possible that you want to do something different depending on the kind of data. In that case, the sufficiently powerful type system would need to have rules so that an if statemement creates a modified type environment to take that into account. This is different from a runtime type check, in that you are writing explicit code that provides correct program behavior in either case.) -- Chris Smith - Lead Software Developer / Technical Trainer MindIQ Corporation -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
Dr.Ruud [EMAIL PROTECTED] wrote: So it seems to me that we have this ideal point at which it is possible to write all correct or interesting programs, and impossible to write buggy programs. I think that is a misconception. Even at the idealest point it will be possible (and easy) to write buggy programs. Gödel! I agree. I never said that the ideal point is achievable... only that there is a convergence toward it. (In some cases, that convergence may have stalled at some equilibrium point because of the costs of being near that point.) -- Chris Smith - Lead Software Developer / Technical Trainer MindIQ Corporation -- http://mail.python.org/mailman/listinfo/python-list
Re: What is Expressiveness in a Computer Language
David Hopwood wrote: Marshall wrote: David Hopwood wrote: Marshall wrote: The real question is, are there some programs that we can't write *at all* in a statically typed language, because they'll *never* be typable? In a statically typed language that has a dynamic type, all dynamically typed programs are straightforwardly expressible. So, how does this dynamic type work? http://citeseer.ist.psu.edu/abadi89dynamic.html It can't simply be the any type, because that type has no/few functions defined on it. It isn't. From the abstract of the above paper: [...] even in statically typed languages, there is often the need to deal with data whose type cannot be determined at compile time. To handle such situations safely, we propose to add a type Dynamic whose values are pairs of a value v and a type tag T where v has the type denoted by T. Instances of Dynamic are built with an explicit tagging construct and inspected with a type safe typecase construct. Well, all this says is that the type dynamic is a way to explicitly indicate the inclusion of rtti. But that doesn't address my objection; if a typesafe typecase construct is required, it's not like using a dynamic language. They don't require typecase to inspect values before one can, say, invoke a function. Gradual typing as described in http://www.cs.rice.edu/~jgs3847/pubs/pubs/2006/siek06:_gradual.pdf is another alternative. The difference between gradual typing and a dynamic type is one of convenience rather than expressiveness -- gradual typing does not require explicit tagging and typecase constructs. Perhaps this is the one I should read; it sounds closer to what I'm talking about. Marshall -- http://mail.python.org/mailman/listinfo/python-list