Re: New to python, open source Mac OS X IDE?

2009-01-27 Thread Joe Strout
joseph.a.mar...@gmail.com wrote: Greetings! I've heard enough raving about Python, I'm going to see for myself what all the praise is for! I'm on a Mac. I use Netbeans for Java, PHP, and C if needed. Do you even use an IDE for Python? I don't -- I just use TextWrangler and a Terminal window.

Re: English-like Python

2009-01-22 Thread Joe Strout
Steven D'Aprano wrote: Foo Is that legal RB syntax? You betcha! How do you know? I haven't specified what Foo does. You haven't specified whether Foo is a valid identifier at all, so I'm assuming that it is both valid and used correctly here. The syntax is certainly valid -- it

Re: English-like Python

2009-01-21 Thread Joe Strout
Steven D'Aprano wrote: LogError Walk has gotten too silly, CurrentTime Here, LogError is a method call that takes two arguments, and CurrentTime is a method call that takes none. That seems ambiguous to me. As a non-RealBasic programmer, I can see at least four meanings it could have.

Re: English-like Python

2009-01-21 Thread Joe Strout
Aaron Brady wrote: Where functions are first-class objects, a bare function object isn't distinguishable either from its call. That depends not on whether functions are first-class objects, but on the *syntax* of function invocation vs. function reference. It just so happens than in

Re: English-like Python

2009-01-20 Thread Joe Strout
Aaron Brady wrote: I think it would be a good step if you could make some sensible interpretation of a typical statement without its parentheses. f abc 123 -- f( abc, 123 ) It would be just the thing in a couple of situations... Such a language is possible -- take a look at REALbasic

Re: English-like Python

2009-01-20 Thread Joe Strout
Aaron Brady wrote: Unambiguity and readability are two different things. (This should be a quasi-tangent, neither agreed, nor opposed, nor unrelated to what you said.) If you have f abc 123 it's unambiguous, but, if you have g f abc 123 def there's no sure way to determine where the call

function to find the modification date of the project

2009-01-19 Thread Joe Strout
This isn't a question, but something I thought others may find useful (and if somebody can spot any errors with it, I'll be grateful). We had a case recently where the client was running an older version of our app, and didn't realize it. In other languages I've avoided this by displaying

Re: function to find the modification date of the project

2009-01-19 Thread Joe Strout
James Mills wrote: You know you could just store a __version__ attribute in your main library (__init__.py). :) What, and update it manually? I don't trust myself to remember to do that every time! Best, - Joe -- http://mail.python.org/mailman/listinfo/python-list

Re: function to find the modification date of the project

2009-01-19 Thread Joe Strout
James Mills wrote: Also I'd like to point out that your method is not very reliable as the modification time of those files could change at any moment. Consider unix systems for instnace where you could do: touch * And poof, you're modification times are now the current time! Yes, and

Re: function to find the modification date of the project

2009-01-19 Thread Joe Strout
Terry Reedy wrote: Yes, and presumably if some power user did this, then that would be the intended effect. Not sure why they'd do that, but they must have a good reason -- who am I to stop them? What if a curious user simple looks at a file with an editor and saves it without change?

Re: why cannot assign to function call

2009-01-10 Thread Joe Strout
ru...@yahoo.com wrote: What is the observable difference between converting an array to a reference (pointer) to that array and passing the reference by value, and passing the array by reference? The difference is whether an assignment to the formal parameter (within the function) affects

Re: why cannot assign to function call

2009-01-10 Thread Joe Strout
Aaron Brady wrote: Aaron Brady wrote: Possible compromise. You can think of functions as mutation-only. You pass the object, and it gets a new (additional) name. The old name doesn't go in. /compromise That's correct. The reference itself is passed in, not the variable (or expression)

Re: why cannot assign to function call

2009-01-09 Thread Joe Strout
ru...@yahoo.com wrote: a = array (1,2,3) b = a a[1] = 4 print b C, C++, VBA, Fortran, Perl: 1, 2, 3 Python: 1, 4, 3 You are mistaken I don't think so. See http://groups.google.com/group/comp.lang.python/msg/f99d5a0d8f869b96 The code I quoted there was tested. In the C/C++ case,

Re: why cannot assign to function call

2009-01-09 Thread Joe Strout
Aaron Brady wrote: Possible compromise. You can think of functions as mutation-only. You pass the object, and it gets a new (additional) name. The old name doesn't go in. /compromise That's correct. The reference itself is passed in, not the variable (or expression) that held or

Re: why cannot assign to function call

2009-01-09 Thread Joe Strout
ru...@yahoo.com wrote: I never claimed that you *couldn't* have copy semantics in C; you can do almost anything you want in C (or C++). But the *normal* usage of an array is via a pointer, in which case the semantics are exactly the same as in Python, Java, REALbasic, .NET, etc. Arrays are

Re: why cannot assign to function call

2009-01-09 Thread Joe Strout
Mark Wooding wrote: As an aside, I don't notice anywhere near as much confusion in Lisp and Scheme groups, which might be surprising since Lisp and Scheme have precisely the same data model, argument passing convention, and assignment semantics, as Python has. Nor is there anywhere near as

Re: why cannot assign to function call

2009-01-08 Thread Joe Strout
Mark Wooding wrote: The `they're just objects' model is very simple, but gets tied up in knots explaining things. The `it's all references' model is only a little more complicated, but explains everything. But it *over* explains, because it implies things that everybody knows about references

Re: why cannot assign to function call

2009-01-08 Thread Joe Strout
ru...@yahoo.com wrote: the same as anyone else's only if [Python's] idea of assignment does not include producing the same results. a = array (1,2,3) b = a a[1] = 4 print b C, C++, VBA, Fortran, Perl: 1, 2, 3 Python: 1, 4, 3 You are mistaken (except perhaps in the Fortran case,

Re: image recogniton?

2009-01-07 Thread Joe Strout
Li Han wrote: Sorry, I oversimplified the question because of my poor english. It is an analog compass whose value we need to read into the computer every second. We use a video camera keep shooting it, and the compass and camera are fixed. If you have any choice about it, it would be

Re: why cannot assign to function call

2009-01-07 Thread Joe Strout
Dan Esch wrote: In essence, the implication of immutability for Python is that there is only one parrot, one spam,in fact one anything. (This seems like it must hold for data primitives - does it hold for complex objects as well? It seems it must...) In addition there is only one 1, and one 2

Re: why cannot assign to function call

2009-01-06 Thread Joe Strout
Mark Wooding wrote: Derek Martin c...@pizzashack.org wrote: I think I have though, not that it matters, since that was never really my point. Python's assignment model requires more explanation than the traditional one, simply to state what it does. That alone is evidence (but not proof).

Re: python is great

2009-01-06 Thread Joe Strout
I've actually been rather frustrated by Python lately. It's great at some things, but rather poor at others. In the latter category is building a neatly packaged executable that can be shipped to users and run reliably on their machine. On the Mac in particular, if you want your app to run

Re: If your were going to program a game...

2009-01-06 Thread Joe Strout
Kay Schluehr wrote: There is no solution to this problem from a Python perspective. Do what everyone does right now: use Flash for the game and manage your site with Python if you like the language. I know this has been discussed before, and the difficulties are many, yadda yadda etc... But

Re: python is great

2009-01-06 Thread Joe Strout
M.-A. Lemburg wrote: On the Mac in particular, if you want your app to run on any PowerPC or Intel machine runing 10.4 or later, and you're using anything not in the standard framework (such as MySQLdb), it's a bit of a nightmare. You're looking for py2app:

Re: embedding python in wxpython

2008-12-30 Thread Joe Strout
Steve Holden wrote: I'd like the console to be a bidirectional representation of what's going on in the gui, plus a general purpose evaluation environment where you can manipulate application data via some api which is automatically exposed to the console when the application opens up. I'm

Re: Python's popularity

2008-12-22 Thread Joe Strout
Alvin ONeal wrote: Also worthy of mention: I've seen python pre-installed on consumer HP desktops (I think as part of a backup/restore script, but I'm not sure) It's pre-installed on every Mac (both desktop and laptop), too. Cheers, - Joe --

Re: encoding problem

2008-12-19 Thread Joe Strout
Marc 'BlackJack' Rintsch wrote: The question is why the Python interpreter use the default encoding instead of utf-8, which I explicitly declared in the source. Because the declaration is only for decoding unicode literals in that very source file. And because strings in Python, unlike in

Re: How to parsing a sequence of integers

2008-12-19 Thread Joe Strout
Peter Otten wrote: If you are using Python 2.x: ... So you better throw in a float(...): Or, add from __future__ import division at the top of the file. I put this at the top of all my Python files, whether I expect to be dividing or not. It just saves grief. Cheers, - Joe --

Re: How to parsing a sequence of integers

2008-12-19 Thread Joe Strout
Mensanator wrote: from __future__ import division at the top of the file. I put this at the top of all my Python files, whether I expect to be dividing or not. It just saves grief. If you want division to be floating point. If, like me, you rarely do floating point division and want the / to

Re: encoding problem

2008-12-19 Thread Joe Strout
Marc 'BlackJack' Rintsch wrote: And because strings in Python, unlike in (say) REALbasic, do not know their encoding -- they're just a string of bytes. If they were a string of bytes PLUS an encoding, then every string would know what it is, and things like conversion to another encoding, or

Re: encoding problem

2008-12-19 Thread Joe Strout
Marc 'BlackJack' Rintsch wrote: I don't see the shortcoming in Python 3.0. If you want real strings with characters instead of just a bunch of bytes simply use `unicode` objects instead of `str`. Fair enough -- that certainly is the best policy. But working with any other encoding (sometimes

AIM client code for Python?

2008-12-16 Thread Joe Strout
I'd like to write an AIM bot in Python. I found and tried http://www.jamwt.com/Py-TOC/, but it doesn't work for me: Connecting... Traceback (most recent call last): File aimbot-1.py, line 17, in module bot.go() File /Users/jstrout/Documents/Python-Dev/AIMbot/toc.py, line 62, in go

How to modify a program while it's running?

2008-12-16 Thread Joe Strout
Here's my situation: I'm making an AIM bot, but the AIM server will get annoyed if you log in too frequently (and then lock you out for a while). So my usual build-a-little, test-a-little methodology doesn't work too well. So I'd like to restructure my app so that it can stay running and

Re: %s place holder does not let me insert ' in an sql query with python.

2008-12-15 Thread Joe Strout
On Dec 15, 2008, at 6:46 AM, Krishnakant wrote: in this case, I get a problem when there is ' in any of the values during insert or update. That's because ' is the SQL string literal delimiter. But any SQL- compliant database allows you to escape an apostrophe within a string literal by

Re: concept of creating structures in python

2008-12-12 Thread Joe Strout
On Dec 11, 2008, at 10:52 PM, navneet khanna wrote: I want to create a structure within a structure i.e. nested structures in python. I tried with everything but its not working. my code is like this: class L(Structure): def __init__(self,Name='ND',Addr=0,ds_obj = D()): Change the

Re: concept of creating structures in python

2008-12-12 Thread Joe Strout
On Dec 12, 2008, at 9:00 AM, Steve Holden wrote: Change the default value of ds_obj here to None. Otherwise, you will certainly confuse yourself (there would be just one default object shared among all instances). Joe missed a piece out here. If you change the signature of your D.__init__()

Re: Call by reference in SWIG?

2008-12-11 Thread Joe Strout
On Dec 10, 2008, at 10:19 PM, Nok wrote: I can't get call-by-reference functions to work in SWIG... Python doesn't have any call-by-reference support at all [1], so I'm not surprised that a straight translation of the call-by-reference C function doesn't work. Unfortunately I don't know

Re: list organization question

2008-12-11 Thread Joe Strout
On Dec 11, 2008, at 4:12 PM, Robocop wrote: I have a list of objects, each object having two relevant attributes: date and id. I'd like not only organize by id, but also by date. I.e. i would like to parse my list into smaller lists such that each new mini-list has a unique date, but consists

any Python developers available in the Denver area?

2008-12-11 Thread Joe Strout
My company is considering a contract job that would require some development staff on the client site in Denver. We'd like to subcontract some of that work. If you're a good Python coder in the Denver area, and would be available at least three days a week starting in January, please

Re: var or inout parm?

2008-12-10 Thread Joe Strout
On Dec 10, 2008, at 4:29 PM, J. Clifford Dyer wrote: [EMAIL PROTECTED] wrote: How can I make a var parm, where the called function can modify the value of the parameter in the caller? See Also: the earlier heated debate thread over what evaluation strategy Python uses (Survey says!:

Re: How to initialize a class variable once

2008-12-09 Thread Joe Strout
On Dec 9, 2008, at 4:31 AM, Brian Allen Vanderburg II wrote: There is one situation where a module can be imported/executed twice, if it is the __main__ module. That's an excellent point -- this is something I've run into, and it always feels a bit awkward to code around it. What's the

Re: A question about reference in Python.

2008-12-08 Thread Joe Strout
On Dec 7, 2008, at 10:26 PM, Group wrote: Now, I want to write a Red-Black Tree, and a List structure. In C/C+ +, I can use pointers to refer to children notes (or next notes). But, in Python, how can I do it? Except the sequence, I know not any way. Any variable in Python is a

Re: A question about reference in Python.

2008-12-08 Thread Joe Strout
On Dec 8, 2008, at 7:43 PM, Steven D'Aprano wrote: On Mon, 08 Dec 2008 08:18:27 -0700, Joe Strout wrote: On Dec 7, 2008, at 10:26 PM, Group wrote: Now, I want to write a Red-Black Tree, and a List structure. In C/C + +, I can use pointers to refer to children notes (or next notes

Re: how to get a beep, OS independent ?

2008-12-07 Thread Joe Strout
On Dec 7, 2008, at 6:36 AM, Duncan Booth wrote: Python is just printing the ascii bell character: some environments will interpret that as a request to make a beep, some will do things like flashing the whole screen, others just output a graphic character. Python doesn't know what your

Re: how to get a beep, OS independent ?

2008-12-07 Thread Joe Strout
On Dec 7, 2008, at 8:48 AM, Grant Edwards wrote: On 2008-12-07, Joe Strout [EMAIL PROTECTED] wrote: But invoking the standard system beep What makes you think there is such a thing as the standard system beep? Because OS X (the platform with which I'm most familiar) certainly has one

Re: how to get a beep, OS independent ?

2008-12-07 Thread Joe Strout
On Dec 7, 2008, at 4:43 PM, Steven D'Aprano wrote: Of course, if you're volunteering to write such a standard system beep for Python, I for one would be grateful. I am. But where should I put it? Assuming we don't want to wait for the (understandably) lengthy and contentious process

Re: Python 3.0 automatic decoding of UTF16

2008-12-05 Thread Joe Strout
On Dec 5, 2008, at 11:36 AM, Johannes Bauer wrote: I suspect that '?' after \n (\u0a00) is indicates not 'question-mark' but 'uninterpretable as a utf16 character'. The traceback below confirms that. It should be an end-of-file marker and should not be passed to Python. I strongly suspect

simplest way to strip a comment from the end of a line?

2008-12-04 Thread Joe Strout
I have lines in a config file which can end with a comment (delimited by # as in Python), but which may also contain string literals (delimited by double quotes). A comment delimiter within a string literal doesn't count. Is there any easy way to strip off such a comment, or do I need to

Re: how to dynamically instantiate an object inheriting from several classes?

2008-11-24 Thread Joe Strout
On Nov 24, 2008, at 11:10 AM, Matimus wrote: I wrote this a while ago. I sort of regret it though. Mixins could (and I will argue should) be avoided most of the time by delegating to other objects with less functionality. Utilizing many mixin classes tends to just make gigantic classes. This is

recommended __future__ imports for 2.5?

2008-11-24 Thread Joe Strout
OK, this will probably be placed into the stupid question category by some, but I really am in need of a bit of guidance here. I just rediscovered the gotcha of integer division in 2.5 and below, and found (to my delight) that this is fixed in 3.0, and fixable in older versions of Python

Re: how to dynamically instantiate an object inheriting from several classes?

2008-11-22 Thread Joe Strout
On Nov 21, 2008, at 7:02 PM, Steven D'Aprano wrote: I have a function that takes a reference to a class, Hmmm... how do you do that from Python code? The simplest way I can think of is to extract the name of the class, and then pass the name as a reference to the class, and hope it hasn't

Re: Official definition of call-by-value (Re: Finding the instance reference...)

2008-11-22 Thread Joe Strout
On Nov 22, 2008, at 4:08 AM, Aaron Brady wrote: Furthermore, to apply c-b-v to Python, you have to introduce the concept of pointers, which is ostensibly non-native for human programmers. Not necessarily pointers per se -- any type of object references will do, and yes, Python has those in

Re: How to read space separated file in python?

2008-11-21 Thread Joe Strout
On Nov 21, 2008, at 2:08 AM, Steven D'Aprano wrote: a, b = line.split() Note that in a case like this, you may want to consider using partition instead of split: a, sep, b = line.partition(' ') This way, if there happens to be more than one space (for example, because the Unicode

Re: Need help converting text to csv format

2008-11-21 Thread Joe Strout
On Nov 21, 2008, at 8:18 AM, Chuck Connors wrote: The first value (large number) is the UPC, the next element is the coupon description, followed by a date in parenthesis. Those are the only three elements I am concerned with. Can someone help me in reformatting this: 40922003 Life

Re: Using eval, or something like it...

2008-11-21 Thread Joe Strout
On Nov 21, 2008, at 8:58 AM, r0g wrote: I hadn't really appreciated the consequences of this till now though e.g. that an instance might do a = a + 1 without affecting it's siblings but that b.append(fish) would affect b for everyone. I don't know if I will find any uses for that kind of

Re: How to read space separated file in python?

2008-11-21 Thread Joe Strout
On Nov 21, 2008, at 9:00 AM, Steve Holden wrote: Joe Strout wrote: On Nov 21, 2008, at 2:08 AM, Steven D'Aprano wrote: a, b = line.split() Note that in a case like this, you may want to consider using partition instead of split: a, sep, b = line.partition(' ') This way

Re: Need help converting text to csv format

2008-11-21 Thread Joe Strout
On Nov 21, 2008, at 9:22 AM, Tim Golden wrote: Tim Chase wrote: qfields = ['' + fld.strip() + '' for fld in (num,desc,date)] out = qfields.join(',') Just a quick note here to prevent the confusion of the OP...this should be ','.join(qfields) Thanks Tim #1, for pointing out my error (my

Re: Need help converting text to csv format

2008-11-21 Thread Joe Strout
On Nov 21, 2008, at 10:26 AM, MRAB wrote: The file will be closed automatically when the file object is garbage-collected. CPython uses reference-counting, so the file object is garbage- collected as soon as there are no references to it. Jython (and IronPython?) are garbage-collected in

how to dynamically instantiate an object inheriting from several classes?

2008-11-21 Thread Joe Strout
I have a function that takes a reference to a class, and then instantiates that class (and then does several other things with the new instance). This is easy enough: item = cls(self, **itemArgs) where cls is the class reference, and itemArgs is obviously a set of keyword arguments

Re: how to dynamically instantiate an object inheriting from several classes?

2008-11-21 Thread Joe Strout
On Nov 21, 2008, at 3:30 PM, Arnaud Delobelle wrote: Of course it's possible: use type(name, bases, dict). Thanks, I never knew about that form of type(). Neither does the 2.5.2 reference manual, whose only index entry for the type() function is

Re: how to dynamically instantiate an object inheriting from several classes?

2008-11-21 Thread Joe Strout
On Nov 21, 2008, at 6:06 PM, Ned Deily wrote: Where would I find documentation on this nifty function? Where built-in functions are documented, the Python Library Reference: http://www.python.org/doc/2.5.2/lib/built-in-funcs.html Perfect, thank you. (Odd that the index entry for type()

Re: Finding the instance reference of an object

2008-11-19 Thread Joe Strout
On Nov 19, 2008, at 11:05 AM, Douglas Alan wrote: Personally, I find this whole debate kind of silly, as it is based on a completely fallacious either/or dichotomy. (1) It is unarguably true that Python and Java use a type of call-by-value. This follows from the standard definition of

Re: Problem with writing a long line in a text file

2008-11-19 Thread Joe Strout
On Nov 19, 2008, at 3:27 PM, Mohsen Akbari wrote: I'm a newbie in python and I have this problem with the code that I'm writing. There is a very long line which I wish to output it to a text file.But when I do this, in the output file, the result appears in two lines. Appears that way

Re: compressed serialization module

2008-11-17 Thread Joe Strout
On Nov 17, 2008, at 10:47 AM, Mark wrote: I used pickle and found the file was saved in text format. I wonder whether anyone is familiar with a good compact off-the-shelf module available that will save in compressed format... or maybe an opinion on a smart approach for making a custom one?

Re: Suggestions for an education programming project

2008-11-17 Thread Joe Strout
On Nov 17, 2008, at 10:53 AM, Eric wrote: My son has an idea for a program to write. Basically he would like to present a window with a small circle on it. The window title would have the instruction to click on the circle. As the mouse approaches the circle, it moves away from the spot. Being

Re: Python-URL! - weekly Python news and links (Nov 17)

2008-11-17 Thread Joe Strout
On Nov 17, 2008, at 4:06 PM, Gabriel Genellina wrote: I don't feel anybody would improve their Python skills chasing what the value of an object is, least to make contortions so some arbitrary definition of call by value be applicable to the language. Actually, contortions are required to

Re: using private parameters as static storage?

2008-11-14 Thread Joe Strout
On Nov 13, 2008, at 3:23 PM, Arnaud Delobelle wrote: Aaron Brady [EMAIL PROTECTED] writes: One way around it, which I like the idea of but I'll be honest, I've never used, is getting a function a 'self' parameter. You could make it a dictionary or a blank container object, or just the

Re: using private parameters as static storage?

2008-11-14 Thread Joe Strout
On Nov 13, 2008, at 8:26 PM, Steven D'Aprano wrote: def spam(_count=[0]): _count[0] += 1 return spam * _count[0] This is a common trick, often used for things like caching. One major advantage is that you are exposing the cache as an *optional* part of the interface, which makes

Re: duck-type-checking?

2008-11-14 Thread Joe Strout
On Nov 14, 2008, at 12:27 PM, [EMAIL PROTECTED] wrote: What would be actually interesting would be an switch to the python interpreter that internally annotated function parameters with how they are used in the function and raised an exception as soon as the function is called instead of later.

Re: duck-type-checking?

2008-11-14 Thread Joe Strout
On Nov 14, 2008, at 2:07 PM, Paul McGuire wrote: Or to be even more thorough: def sub(x: must have getitem, y: must have strip and strip must be callable, and y.strip must return something that has replace and replace must be callable) So even this simple example gets nasty in a hurry, let

Re: object creation

2008-11-14 Thread Joe Strout
On Nov 14, 2008, at 4:33 PM, Jerry Hill wrote: Then add def __init__(self): a = 0 b = 0 to your box class to make a and b instance variables. Doesn't that have to be self.a and self.b? Best, - Joe -- http://mail.python.org/mailman/listinfo/python-list

Re: duck-type-checking?

2008-11-13 Thread Joe Strout
On Nov 12, 2008, at 7:32 PM, Steven D'Aprano wrote: I'm surprised nobody has pointed you at Alex Martelli's recipe here: http://code.activestate.com/recipes/52291/ Thanks for that -- it's clever how he combines binding the methods he'll use with doing the checking. While the recipe is

using private parameters as static storage?

2008-11-13 Thread Joe Strout
One thing I miss as I move from REALbasic to Python is the ability to have static storage within a method -- i.e. storage that is persistent between calls, but not visible outside the method. I frequently use this for such things as caching, or for keeping track of how many objects a

Re: using private parameters as static storage?

2008-11-13 Thread Joe Strout
On Nov 13, 2008, at 10:19 AM, Chris Mellon wrote: Static storage is a way of preserving state. Objects are a way of encapsulating state and behavior. Use an object. Argh. I've been back in the Python community for about a month, and I've been continually amazed at how every single how do I

Re: using private parameters as static storage?

2008-11-13 Thread Joe Strout
Steve wrote: This is a pretty bizarre requirement, IMHO. The normal place to keep such information is either class variables or instance variables. Holy cow, I thought it was just Chris, but there were half a dozen similar responses after that. I'm starting to see a pattern here... any

Re: using private parameters as static storage?

2008-11-13 Thread Joe Strout
On Nov 13, 2008, at 11:15 AM, J. Cliff Dyer wrote: Here are a few essays into the matter def foo(): ... foo._count += 1 ... return (spam * foo.count).rstrip() Simple and straightforward, and _count is still encapsulated in the function, but it's kind of ugly, because when the

Re: using private parameters as static storage?

2008-11-13 Thread Joe Strout
Hi Luis, A lot of languages have ditched the concept of a static variable on a method (how do you parse that sentence, btw?) in favour of using encapsulation. A static variable IS encapsulation. Encapsulation happens at many levels: module, class, instance, and (in languages that support

Re: How can a function know what module it's in?

2008-11-12 Thread Joe Strout
On Nov 11, 2008, at 9:49 PM, Rafe wrote: I'm sure there is a magic identifier somewhere that lets a code get a reference to its own module, but I haven't been able to find it. import sys this_module = sys.modules[__name__] Beautiful! Thanks very much. For the archives, here is my standard

Re: duck-type-checking?

2008-11-12 Thread Joe Strout
On Nov 12, 2008, at 10:45 AM, Tim Rowe wrote: What do you actually mean by Quacks like a string? Supports the 'count()' method? Then you find out if it doesn't when you try to apply the 'count()' method. Supports some method that you don't actually use? Then why do you care? Because if I

Re: duck-type-checking?

2008-11-12 Thread Joe Strout
On Nov 12, 2008, at 11:48 AM, [EMAIL PROTECTED] wrote: It seems to me that what you are describing is exactly what abcs were added for in 2.6, in particular registration: class AnotherClass(metaclass=ABCMeta): pass AnotherClass.register(basestring) assert isinstance(str, AnotherClass)

duck-type-checking?

2008-11-12 Thread Joe Strout
Let me preface this by saying that I think I get the concept of duck- typing. However, I still want to sprinkle my code with assertions that, for example, my parameters are what they're supposed to be -- too often I mistakenly pass in something I didn't intend, and when that happens, I

Re: duck-type-checking?

2008-11-12 Thread Joe Strout
On Nov 12, 2008, at 2:42 PM, Tim Rowe wrote: And then the original class definition changes -- new members added -- but the ones from the factory class don't change, and so are no longer compliant with the the factory class (which doesn't support the new

How can a function know what module it's in?

2008-11-11 Thread Joe Strout
I've been using docstring to exercise each of my modules, with code like this: def _test(): import doctest doctest.testmod() if __name__ == __main__: _test() This works great when I execute each module by itself. However, if I want to call mymodule._test() from

Re: How can a function know what module it's in?

2008-11-11 Thread Joe Strout
Some corrections, to highlight the depth of my confusion... On Nov 11, 2008, at 9:10 PM, Joe Strout wrote: doctest.testmod(mymodule) This actually works fine if I'm importing the module (with the standard name) somewhere else Actually, it does not. I noticed that a function

Python fish simulation?

2008-11-10 Thread Joe Strout
Is there any Python-based fish simulation project? I've tried searching google and pypi, but no luck. No burning need, just seems like it'd be fun. Thanks, - Joe -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding the instance reference of an object

2008-11-10 Thread Joe Strout
On Nov 10, 2008, at 8:30 AM, Terry Reedy wrote: That hinges on what exactly is meant by changes to the arguments. Mutating them, like Python does, which is why calling Python CBV leads people to write buggy code. In Python it can only mean assigning directly to the bare name -- anything

Re: Finding the instance reference of an object [long and probably boring]

2008-11-10 Thread Joe Strout
On Nov 10, 2008, at 2:30 PM, Aaron Brady wrote: I agree with Terry that all calling is call-by-value, and Steven that all calling is call-by-bit-flipping. I agree with Joe that call-by- object is a special case of call-by-value. Woo! Almost sounds like approaching consensus. :) However,

Re: Class v. Instance variables in Python

2008-11-10 Thread Joe Strout
On Nov 10, 2008, at 2:44 PM, Zane Selvans wrote: However, one (and only one) of these instance variables is behaving mysteriously like a class variable: all instances of the class are sharing a single copy of the variable, located at the same place in memory. Is there a common mistake

Re: Finding the instance reference of an object [long and probably boring]

2008-11-08 Thread Joe Strout
On Nov 7, 2008, at 6:21 PM, Aaron Brady wrote: Therefore objects don't need names to exist. Having a name is sufficient but not necessary to exist. Being in a container is neither necessary -nor- sufficient. What do you mean? Being in a container isn't necessary, but it certainly is

Re: Finding the instance reference of an object

2008-11-08 Thread Joe Strout
On Nov 8, 2008, at 2:38 PM, Terry Reedy wrote: So if you then insist that Python uses call by object, you're actually saying it uses call by value! Both Joe and you seem to be engaging in the following bit of sophistry: In order for code A to call code B, some information must be

Re: Finding the instance reference of an object [long and probably boring]

2008-11-07 Thread Joe Strout
On Nov 6, 2008, at 10:35 PM, Steve Holden wrote: That's good to hear. Your arguments are sometimes pretty good, and usually well made, but there's been far too much insistence on all sides about being right and not enough on reaching agreement about how Python's well-defined semantics for

Re: Finding the instance reference of an object [long and probably boring]

2008-11-07 Thread Joe Strout
On Nov 7, 2008, at 10:29 AM, Steven D'Aprano wrote: Note: I tried to say name above instead of variable but I couldn't bring myself to do it -- name seems to generic to do that job. Lots of things have names that are not variables: modules have names, classes have names, methods have

Re: Finding the instance reference of an object [long and probably boring]

2008-11-07 Thread Joe Strout
On Nov 7, 2008, at 12:13 PM, Terry Reedy wrote: Python has two types of names. Some complex objects -- modules, classes, and functions, and wrappers and subclasses thereof, have 'definition names' that are used instead of a 'value' to print a representation. Otherwise, names are

Re: Finding the instance reference of an object [long and probably boring]

2008-11-07 Thread Joe Strout
On Nov 7, 2008, at 12:35 PM, Terry Reedy wrote: http://en.wikipedia.org/wiki/Call_by_something#Call_by_sharing Call by sharing Also known as call by object or call by object-sharing is an evaluation strategy first named by Barbara Liskov et al for the language CLU in 1974[1]. It is used

Re: Finding the instance reference of an object

2008-11-06 Thread Joe Strout
On Nov 5, 2008, at 12:29 AM, Dennis Lee Bieber wrote: C++: void foo(PersonPtr who) { who-zipcode = 12345; } Please show us the type definition of PersonPtr Sorry, that'd be obvious to anyone experienced in C++, but I shouldn't assume. It would be: typedef Person*

Re: Finding the instance reference of an object

2008-11-06 Thread Joe Strout
On Nov 4, 2008, at 12:57 PM, Hendrik van Rooyen wrote: 4. You now see how a mutating an object within a function tells you NOTHING about how the reference to that object was passed. 5. You see that the first three languages above are passing a reference by value and using that to mutate and

Re: Finding the instance reference of an object

2008-11-06 Thread Joe Strout
On Nov 5, 2008, at 2:06 PM, Lie wrote: http://www.strout.net/info/coding/valref/ I'm fed up with you. I'm sorry -- I'm really not trying to be difficult. And it's odd that you're fed up with me, yet you seem to be agreeing with me on at least most points. In Von Neumann Architecture

Re: Finding the instance reference of an object

2008-11-06 Thread Joe Strout
On Nov 6, 2008, at 12:44 PM, Arnaud Delobelle wrote: I know this thread has grown quite personal for some of its participants. I am posting in a spirit of peace and understanding :) Thanks, I'll do the same. Um, no, I've admitted that it's a reference all along. Indeed, that's pretty

Re: Finding the instance reference of an object

2008-11-06 Thread Joe Strout
First, I want to thank everyone for your patience -- I think we're making progress towards a consensus. On Nov 6, 2008, at 8:48 PM, Steven D'Aprano wrote: that's pretty much the whole point: that variables in Python don't contain objects, but merely contain references to objects that are

Re: Which was the best Lib of GUI for python

2008-11-04 Thread Joe Strout
On Nov 3, 2008, at 10:53 PM, 3000 billg wrote: I am a leaner. for your experience. Which GUI Lib will be the best for Python? wxpython, Tkinter or... I'm sure you'll get as many opinions on this as there are libraries. However, I recently faced the same choice, and settled on wxPython.

  1   2   >