questions from a lost sheep

2008-10-02 Thread Joe Strout
Hi all, I used to by a big Python fan, many years ago [1]. I stopped using it after discovering REALbasic, because my main developmental need is to write desktop applications that are as native as possible on each platform, and because I really like a strongly-typed language with a good

help using py2app

2008-10-02 Thread Joe Strout
I'm trying to use py2app to convert the pySketch wxPython example into a stand-alone OS X app. I've found the documentation at http://undefined.org/python/py2app.html , but it wasn't terribly enlightening for me. My setup.py looks like this: #!/usr/bin/env python setup.py - script for

type-checking support in Python?

2008-10-06 Thread Joe Strout
I'm just re-learning Python after nearly a decade away. I've learned a good healthy paranoia about my code in that time, and so one thing I'd like to add to my Python habits is a way to both (a) make intended types clear to the human reader of the code, in a uniform manner; and (b) catch

Re: equivalent of py2exe in other os

2008-10-07 Thread Joe Strout
On Oct 7, 2008, at 8:43 AM, Benjamin Kaplan wrote: I believe that all (or nearly all) Unix variants come with Python preinstalled. Ubuntu, at least, has a lot of system programs written in Python. Even Mac OS X requires Python. Yes, but with significant differences between different Python

distributing apps without the Python source?

2008-10-08 Thread Joe Strout
We have a client who's paranoid about distributing the Python source to his commercial app. Is there some way I can distribute and use just the .pyc files, so as to not give away the source? Thanks, - Joe -- http://mail.python.org/mailman/listinfo/python-list

Re: template strings for matching?

2008-10-09 Thread Joe Strout
On Oct 9, 2008, at 7:05 AM, [EMAIL PROTECTED] wrote: Tino http://docs.python.org/library/stdtypes.html#string-formatting-operations That shows how to use the template formatting as it currently exists. To my knowledge there is no support for the inverse operation, which is what Joe

template strings for matching?

2008-10-09 Thread Joe Strout
Catching up on what's new in Python since I last used it a decade ago, I've just been reading up on template strings. These are pretty cool! However, just as a template string has some advantages over % substitution for building a string, it seems like it would have advantages over

Re: template strings for matching?

2008-10-09 Thread Joe Strout
Wow, this was harder than I thought (at least for a rusty Pythoneer like myself). Here's my stab at an implementation. Remember, the goal is to add a match method to Template which works like Template.substitute, but in reverse: given a string, if that string matches the template, then

book recommendation for Python newbie?

2008-10-09 Thread Joe Strout
I'm trying to (gently) convince my business partner that we should be adding Python to our core toolset. He's never used it before, apart from poking around in the tutorial a bit at my urging. But he's got a birthday coming up, and I'd like to get him a book that will help him make the

Where/how to propose an addition to a standard module?

2008-10-10 Thread Joe Strout
I would like to propose a new method for the string.Template class. What's the proper procedure for doing this? I've joined the python- ideas list, but that seems to be only for proposed language changes, and my idea doesn't require any change to the language at all. From

Re: docpicture

2008-10-13 Thread Joe Strout
On Oct 13, 2008, at 2:43 PM, Benjamin Kaplan wrote: I mean what happens when you type help() into the interactive console on the command line? You will see the docstrings, and there will be a whole bunch of random hex characters there. Good point. It might be better put in a

recommendations for a web CMS (content management system)?

2008-10-15 Thread Joe Strout
We need to set up a content management system that allows nontechnical users to manage the content of their web site. Rather than starting from scratch, I'd prefer to start with an existing CMS that we can extend as needed. So, I'd prefer something with nice clean, easy-to- follow code

Python equivalent to SharePoint?

2008-10-15 Thread Joe Strout
We've got a client who has been planning to use SharePoint for managing their organization documents, but has recently dropped that idea and is looking for an alternative. Is there any Python package with similar functionality? I confess that I've never used SharePoint myself, and what I

Re: Loosely-coupled development environment (was: IDE Question)

2008-10-15 Thread Joe Strout
On Oct 15, 2008, at 2:47 PM, Ben Finney wrote: Because of the inescapable central role in our craft of manipulating text files, essential in this development environment is a highly-customisable text editor with a broad *and* deep library of existing customisations, to maximise the amount of

Re: Finding the instance reference of an object

2008-10-16 Thread Joe Strout
On Oct 16, 2008, at 10:59 AM, Larry Bates wrote: how do i find that the name is 'bob' Short answer is that you can't. This because Python's names (bob) are bound to objects (modulename.objectname()). They are NOT variables as they are in other programming languages. Which other

Re: Finding the instance reference of an object

2008-10-16 Thread Joe Strout
On Oct 16, 2008, at 7:30 PM, Steven D'Aprano wrote: However, 'bob' here really is a variable. It's a variable whose value (at the moment) is a reference to some object. Traditionally, a variable is a named memory location. Agreed. The main objection I have to using variable to describe

Re: Finding the instance reference of an object

2008-10-17 Thread Joe Strout
On Oct 16, 2008, at 11:23 PM, Dennis Lee Bieber wrote: On Thu, 16 Oct 2008 21:19:28 -0600, Joe Strout [EMAIL PROTECTED] declaimed the following in comp.lang.python: Now that IS mysterious. Doesn't calling a function add a frame to a stack? And doesn't that necessitate copying in values

Re: 'Hidden Features of Python'

2008-10-17 Thread Joe Strout
On Oct 17, 2008, at 10:00 AM, coldpizza wrote: http://stackoverflow.com/questions/101268/hidden-features-of-python Thanks, there are a lot of useful nuggets there. However, can anybody explain the Main messages one? It doesn't include any explanatory text at all, just a code snippet:

Re: 'Hidden Features of Python'

2008-10-17 Thread Joe Strout
On Oct 17, 2008, at 10:35 AM, coldpizza wrote: If you are using and IDE, such as Eclipse, PyScripter, etc, then CTR +click on 'this' should do the trick. In ipython you can do 'import this' and then type 'this??' Or if you are *not* lazy, you could try locating the file in the Python tree.

Re: inserting Unicode character in dictionary - Python

2008-10-17 Thread Joe Strout
On Oct 17, 2008, at 11:24 AM, Marc 'BlackJack' Rintsch wrote: kw = 'генских' What do you mean by does not work? And you are aware that the above snipped doesn't involve any unicode characters!? You have a byte string there -- type `str` not `unicode`. Just checking my understanding

Re: Finding the instance reference of an object

2008-10-17 Thread Joe Strout
On Oct 17, 2008, at 1:03 PM, Aaron Castironpi Brady wrote: I'm not fluent in Java so you'll have to be the judge. In Python: b= 0 f( b ) No matter what, b == 0. C doesn't guarantee this. It does, unless f's parameter has been declared a reference parameter. (In C++, you'd do this with

Re: inserting Unicode character in dictionary - Python

2008-10-17 Thread Joe Strout
Thanks for the answers. That clears things up quite a bit. What if your source file is set to utf-8? Do you then have a proper UTF-8 string, but the problem is that none of the standard Python library methods know how to properly interpret UTF-8? Well, the decode method knows how to decode

Re: Finding the instance reference of an object

2008-10-17 Thread Joe Strout
On Oct 17, 2008, at 2:36 PM, Steve Holden wrote: No, a by ref parameter would mean that this: def foo(ByRef x): x = x + [42] a = [1,2,3] foo(a) ...would result in a = [1,2,3,42]. In [8]: def foo(x): ...: x += [42] ...: In [9]: a = [1, 2, 3] In [10]: foo(a) In [11]: a Out[11]:

Re: Finding the instance reference of an object

2008-10-17 Thread Joe Strout
On Oct 17, 2008, at 3:19 PM, Grant Edwards wrote: And my real point is that this is exactly the same as in every other modern language. No, it isn't. In many other languages (C, Pascal, etc.), a variable is commonly thought of as a fixed location in memory into which one can put values.

Re: inserting Unicode character in dictionary - Python

2008-10-19 Thread Joe Strout
On Oct 18, 2008, at 1:20 AM, Martin v. Löwis wrote: Do you then have a proper UTF-8 string, but the problem is that none of the standard Python library methods know how to properly interpret UTF-8? There is (probably) no such thing as a proper UTF-8 string (in the sense in which you

Re: Unicode (UTF8) in dbhas on 2.5

2008-10-21 Thread Joe Strout
On Oct 21, 2008, at 2:39 PM, Martin v. Löwis wrote: It's not possible to fix this - it isn't even broken. The *db modules, by design, support storing of arbitrary bytes, not just character data. Many database engines are encoding-aware, and distinguish between 'text' columns and 'blob'

Re: What's the perfect (OS independent) way of storing filepaths ?

2008-10-22 Thread Joe Strout
On Oct 22, 2008, at 10:00 PM, Steven D'Aprano wrote: It would have been easy to avoid this: just copy the relevant bits of the / directory hierarchy in the user's home directory. Global settings go in /etc and per user settings go in ~/etc. Global temp files go into / tmp and per user temp

Re: ANN: gui_support, a convenience library for wxPython

2008-10-23 Thread Joe Strout
On Oct 23, 2008, at 11:50 AM, Stef Mientki wrote: gui_support is library for easy creation of GUI designs in wxPython. ... Brief documentation can be found here http://oase.uci.kun.nl/~mientki/data_www/pylab_works/pw_gui_support.html That's neat -- thank you for making it available. I've

Re: Finding the instance reference of an object

2008-10-27 Thread Joe Strout
On Oct 27, 2008, at 12:19 PM, [EMAIL PROTECTED] wrote: I think this uncontrived example addresses the C/Python difference fairly directly (both were tested): That's correct, but of course, C is a decades-old language barely a step above assembler. For a fair comparison, pick any modern OOP

Re: How to get an object's name as a string?

2008-10-28 Thread Joe Strout
On Oct 28, 2008, at 8:41 AM, Shannon Mayne wrote: I would like to create objects with algorithmically determined names based on other object names and use object names for general algorithm input. What do you mean by the name of an object? Objects don't generally have names, unless you

Re: Finding the instance reference of an object

2008-10-28 Thread Joe Strout
On Oct 27, 2008, at 11:28 PM, Gabriel Genellina wrote: En Tue, 28 Oct 2008 00:58:10 -0200, greg [EMAIL PROTECTED] escribió: Let's look at the definitions of the terms: (1) Call by value: The actual parameter is an expression. It is evaluated and the result is assigned to the formal

explanation of values, references, assignment, and method calls

2008-10-28 Thread Joe Strout
I've tried to write up this topic in a clear, step-by-step manner, with the help of diagrams and short examples from several different OOP languages. I hope it will help clear up the confusion that seems to be pervading the Python community (and which is far more rare in the other

Re: How to get an object's name as a string?

2008-10-28 Thread Joe Strout
On Oct 28, 2008, at 4:45 PM, Steven D'Aprano wrote: What do you mean by the name of an object? Objects don't generally have names, unless you explicitly define a .name property and assign them names. (Variables have names, of course, but a variable isn't an object -- it's just a reference

Re: How to get an object's name as a string?

2008-10-28 Thread Joe Strout
On Oct 28, 2008, at 6:58 PM, Steve Holden wrote: Objects in Python *don't* have names. Period. In Python we don't normally talk about variables anyway, except when speaking loosely, we talk about binding names. But please don't let this start another round of Python programmers don't know

Re: Finding the instance reference of an object

2008-10-29 Thread Joe Strout
On Oct 29, 2008, at 4:52 PM, Fuzzyman wrote: You're pretty straightforwardly wrong. In Python the 'value' of a variable is not the reference itself. That's the misconception that is leading some folks around here into tangled nots of twisty mislogic, ultimately causing them to make up new

Re: Finding the instance reference of an object

2008-10-30 Thread Joe Strout
On Oct 30, 2008, at 7:56 AM, Dale Roberts wrote: That's the misconception that is leading some folks around here into tangled nots of twisty mislogic, ultimately causing them to make up new terms for what every other modern language is perfectly happy calling Call-By-Value. Doesn't this logic

Re: Single string vs list of strings

2008-10-30 Thread Joe Strout
On Oct 30, 2008, at 8:55 AM, Grant Edwards wrote: The question you might want to asked is whether the parameter is a single string or a sequence of strings. That way your code will also work with an iterator that returns strings. type('asdf') is str True I agree with the general approach,

Re: Finding the instance reference of an object

2008-10-30 Thread Joe Strout
On Oct 30, 2008, at 6:38 PM, greg wrote: The distinction isn't about parameter passing, though, it's about the semantics of *assignment*. Once you understand how assigment works in Python, all you need to know then is that parameters are passed by assigning the actual parameter to the formal

Re: Finding the instance reference of an object

2008-10-30 Thread Joe Strout
On Oct 30, 2008, at 6:58 PM, greg wrote: For what it's worth, I happen to agree that telling someone that Python passes parameters by value without being sure they understand exactly what by value means, is not a good idea -- not because the term isn't well-defined, but because of the

Testing dictionary results with doctest

2008-10-31 Thread Joe Strout
I love doctest -- the way it combines documentation with verification seems elegant and useful, and most of the time it's simple and easy to use. But I've run into a bit of a snag trying to test a method that returns a dictionary, because (of course) the order in which the dictionary

Re: Finding the instance reference of an object

2008-11-03 Thread Joe Strout
On Nov 3, 2008, at 12:00 PM, Aaron Brady wrote: I think we can conclude that Python passes by reference, since a function can modify objects that were passed in to it. Then please write the Python equivalent of the Swap methods shown at http://www.strout.net/info/coding/valref/ (or at

Re: Finding the instance reference of an object

2008-11-03 Thread Joe Strout
On Nov 3, 2008, at 2:36 PM, Aaron Brady wrote: Then please write the Python equivalent of the Swap methods shown at http://www.strout.net/info/coding/valref/ (or at http://javadude.com/articles/passbyvalue.htm , for that matter). And no fair wrapping the two parameters up in an object or

Re: Structures

2008-11-03 Thread Joe Strout
On Nov 3, 2008, at 4:38 PM, Paulo J. Matos wrote: However, I wouldn't dare to say Python needs structures to be a good language, or anything similar. My question was more directed to : if there aren't structures in Python, what do Pythonists use instead? Classes. Best, - Joe --

Re: Finding the instance reference of an object

2008-11-03 Thread Joe Strout
On Nov 3, 2008, at 5:27 PM, Marc 'BlackJack' Rintsch wrote: Maybe this is a surprise for you, because we haven't discussed this in much detail in this group lately, but it applies to Python which does call-by-object or call-by-sharing. ;-) There's no such thing. Those are just terms made up

locating the chorus in a MIDI song?

2008-11-03 Thread Joe Strout
We've got a need to generate short samples of songs that are in MIDI format, to provide a preview function in a web app. We'd like to do something more clever than just taking the middle 20 seconds (or whatever) of the song -- ideally, we'd like to find the chorus, since that's likely to

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.

Re: Finding the instance reference of an object

2008-11-04 Thread Joe Strout
On Nov 4, 2008, at 7:42 AM, Craig Allen wrote: coming from C/C++ Python seemed to me call by reference, for the pragmatic reason you said, modificaitons to function arguments do affect the variable in the caller. The confusing part of this then comes when immutable objects are passed in.

Re: Python on iPhone actually rather good

2008-11-04 Thread Joe Strout
On Nov 4, 2008, at 10:33 AM, Michael Torrie wrote: Are there any good books on python and objc? I doubt you'll be able to make any decent iPhone apps without having a good working knowledge of Objective C and the python-objc bridge. In my mind that's one of the cool parts of doing cocoa

Re: Finding the instance reference of an object

2008-11-04 Thread Joe Strout
On Nov 4, 2008, at 3:42 PM, Steven D'Aprano wrote: This example is also call-by-value, but the value in this case is a type that has no analog in Python. I'm disappointed to see that my prediction that Joe would, yet again, utterly ignore all the arguments against his pet theory was

Re: Finding the instance reference of an object

2008-11-04 Thread Joe Strout
On Nov 4, 2008, at 3:54 PM, Steven D'Aprano wrote: At the level of Python code, Python operates on *objects*. When you call a function with an argument, the argument (an object) is NOT copied, it is passed to the function. If you mutate the argument inside the function, you are changing the

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: 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 [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

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

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

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

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: 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: 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: 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: 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: 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 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

  1   2   >