Re: Windows: setting title of console window

2011-07-30 Thread Ethan Furman
Thomas Jollans wrote: On 30/07/11 20:39, Ethan Furman wrote: How it works: since the sys.argv object does yet exist, I create an object and assign it to sys.argv; then, when Python assigns the actual argv to sys.argv, my object is tossed, and the __del__ method is called; the __del__ method is

Re: What is xrange?

2011-07-30 Thread Ethan Furman
Dennis Lee Bieber wrote: On Sat, 30 Jul 2011 21:36:41 +1000, Steven D'Aprano declaimed the following in gmane.comp.python.general: Probably because nobody thought about it, but if it had been proposed to change xrange into an iterator, I'm pretty confident that the suggestion would have been

test systems

2011-08-01 Thread Ethan Furman
Howdy, I'm going to setup a few linux systems for testing (probably three) as well as the three FreeBSD, OpenBSD, and (possibly) NetBsd. Oh, and Windows. ;) Any recommendations on which linuces to pick? ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list

Re: Community Involvement

2011-08-04 Thread Ethan Furman
Steve Holden wrote: We would ideally like the last project to to be something that demonstrates at least some minimal involvement with the Python community. Something like "get a Python answer upvoted on StackOverflow", for example, or getting a question answered on c.l.p. At the same time it

Re: problem with bcd and a number

2011-08-04 Thread Ethan Furman
nephish wrote: Hey all, I have been trying to get my head around how to do something, but i am missing how to pull it off. I am reading a packet from a radio over a serial port. i have " two bytes containing the value i need. The first byte is the LSB, second is MSB. Both bytes are BCD-encode

Re: problem with bcd and a number

2011-08-04 Thread Ethan Furman
MRAB wrote: On 04/08/2011 19:26, nephish wrote: Hey all, I have been trying to get my head around how to do something, but i am missing how to pull it off. I am reading a packet from a radio over a serial port. i have " two bytes containing the value i need. The first byte is the LSB, second

Re: Docstrings and class Attributes

2011-08-08 Thread Ethan Furman
Steven D'Aprano wrote: Eric Snow wrote: On Mon, Aug 8, 2011 at 6:37 AM, Nick wrote: Is it possible to put a doc string on a class attribute? Something like this You can put a docstring on a property (which is a function): class Test(object): @property def fred(self): "attrib

__all__

2011-08-09 Thread Ethan Furman
Greetings! Does anyone know/recall the original purpose of __all__? I had thought it was primarily to specify what would be imported when `from ... import *` was executed, such as for tk; today, it seems it is also used to specify the API for the module, and so the help() subsystem will only

Re: allow line break at operators

2011-08-11 Thread Ethan Furman
Seebs wrote: We're fully aware of the tradeoffs of significant indentation. You are. A couple of other people I've talked to are. Many others are not. The times that whitespace indentation has bitten me, it was still not difficult to fix -- I just had to look and see which line(s) should/

Re: __all__

2011-08-12 Thread Ethan Furman
Paul Woolcock wrote: The gurus will have to correct me if this is not an accepted practice, but I know some projects (Fabric is the one that comes to mind) will define a submodule specifically for the 'from blah import *' situation. The submodule would be called "api", or something like that, s

Re: allow line break at operators

2011-08-12 Thread Ethan Furman
Chris Angelico wrote: Incidentally, in the original expression, it would be slightly more sane to write it as: a = x + y) * z borrowing from the musical concept that a repeat sign with no corresponding begin-repeat means to repeat from the beginning. But both of these violate XKCD 859. Argh!

Re: allow line break at operators

2011-08-14 Thread Ethan Furman
Ben Finney wrote: Chris Angelico writes: On Sun, Aug 14, 2011 at 8:10 AM, Steven D'Aprano wrote: Do you get worried by books if the last page doesn't include the phrase "The End"? These days, many movies include an extra clip following the credits. When the clip finishes, and the screen go

Re: Why no warnings when re-assigning builtin names?

2011-08-15 Thread Ethan Furman
Gerrat Rickert wrote: What sayest the Python community about having an explicit warning against such un-pythonic behaviour (re-assigning builtin names)? What makes you think this behavior is unpythonic? Python is not about hand-holding. ~Ethan~ -- http://mail.python.org/mailman/listinfo/pyt

Re: Why no warnings when re-assigning builtin names?

2011-08-15 Thread Ethan Furman
Seebs wrote: On 2011-08-15, Ethan Furman wrote: Gerrat Rickert wrote: What sayest the Python community about having an explicit warning against such un-pythonic behaviour (re-assigning builtin names)? What makes you think this behavior is unpythonic? Python is not about hand-holding. It

Re: Why no warnings when re-assigning builtin names?

2011-08-16 Thread Ethan Furman
Philip Semanchuk wrote: On Aug 16, 2011, at 1:15 AM, Steven D'Aprano wrote: Protecting n00bs from their own errors is an admirable aim, but have you considered that warnings for something which may be harmless could do more harm than good? Isn't the whole point of a warning to highlight behavi

Re: Why no warnings when re-assigning builtin names?

2011-08-16 Thread Ethan Furman
Philip Semanchuk wrote: On Aug 16, 2011, at 11:41 AM, Ethan Furman wrote: Philip Semanchuk wrote: If we are to eschew warnings in cases where they might be highlighting something harmless, then we would have no warnings at all. >> Sounds good to me. ;) Keep such things in the IDE&

Re: Why no warnings when re-assigning builtin names?

2011-08-16 Thread Ethan Furman
Philip Semanchuk wrote: I think Python does lots of beneficial hand-holding. Garbage collection > is a good example. $DIETY knows, people have been struggling with manual > memory management in C and its ilk for a long time. Even though there > are good tools to help, memory leaks still happen.

Re: Why no warnings when re-assigning builtin names?

2011-08-16 Thread Ethan Furman
Seebs wrote: On 2011-08-16, Ethan Furman wrote: I think warnings should be reserved for language changes and such (like DeprecationWarning, RuntimeWarning, and FutureWarning), not for possible programmer mistakes. I disagree, on the basis of the following: The quality of C code I have to

Re: Why no warnings when re-assigning builtin names?

2011-08-16 Thread Ethan Furman
Seebs wrote: On 2011-08-16, Ethan Furman wrote: What makes you think it's unintentional? Programming experience. People *often* do things unintentionally. Seems to me the real issue is somebody using a builtin, such as str or int, and that they somehow manage to do this without real

Re: Wait for a keypress before continuing?

2011-08-17 Thread Ethan Furman
Welcome to my killfile. *plonk* -- http://mail.python.org/mailman/listinfo/python-list

Re: Why no warnings when re-assigning builtin names?

2011-08-17 Thread Ethan Furman
Seebs wrote: On 2011-08-17, Steven D'Aprano wrote: On Wed, 17 Aug 2011 01:17 pm Seebs wrote: Hmm. See, I've never reached that, in Python or any other language. I figure it creates a new potential for confusion, and that I would rather avoid any ambiguity. I don't *like* ambiguity in code.

Re: Wait for a keypress before continuing?

2011-08-17 Thread Ethan Furman
Seebs wrote: Pathological narcissism is scary. If you ever find yourself going longer than usual without being wrong, start checking your work more carefully. :) +1 QOTW -- http://mail.python.org/mailman/listinfo/python-list

Re: Why no warnings when re-assigning builtin names?

2011-08-17 Thread Ethan Furman
Seebs wrote: On 2011-08-17, Ethan Furman wrote: Seebs wrote: On 2011-08-17, Steven D'Aprano wrote: Ah, well you see the thing is, this is Python. As soon as you call any function you don't control, you no longer know what your environment is with any certainty. For all you know, th

Re: Syntactic sugar for assignment statements: one value to multiple targets?

2011-08-17 Thread Ethan Furman
gc wrote: Target lists using comma separation are great, but they don't work very well for this task. What I want is something like a,b,c,d,e = *dict() This isn't going to happen. From all the discussion so far I think your best solution is a simple helper function (not tested): def repeat

Word Perfect integration

2011-08-18 Thread Ethan Furman
I have WordPerfect v13 which we are currently using for letter merges. I would like to automate this with Python instead of learning the WP Macro language. Does anyone have any pointers? ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list

Re: Word Perfect integration

2011-08-18 Thread Ethan Furman
Alec Taylor wrote: wow, people still use WordPerfect? Them's fightin' words right there! :) Yes, we still use Word Perfect, and will as long as it is available. The ability to see the codes in use (bold, margins, columns, etc) has so far been unequaled in anything else I have looked at. ~

Re: Word Perfect integration

2011-08-18 Thread Ethan Furman
John Gordon wrote: I suspect that learning how to integrate python with wordperfect will end up being much more work than learning wordperfect macros. Possibly... but I enjoy coding in Python. :) ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list

Re: try... except with unknown error types

2011-08-21 Thread Ethan Furman
Paul Rubin wrote: Steven D'Aprano writes: But there's no way to know what that minimum is. Python libraries throw all sorts of exceptions that their documentation doesn't mention. Yes, you're absolutely correct. But it's also irrelevant. Most of those exceptions should not be caught, even if

Re: truncating strings

2011-08-23 Thread Ethan Furman
Seebs wrote: On 2011-08-23, Roy Smith wrote: I want to log a string but only the first bunch of it, and add "..." to the end if it got truncated. This certainly works: logger.error("FAILED: '%s{50}', '%s', %s, %s" % (message, route, params, e.code)) does anything like this exis

Re: truncating strings

2011-08-23 Thread Ethan Furman
Seebs wrote: On 2011-08-23, Ethan Furman wrote: Seebs wrote: On 2011-08-23, Roy Smith wrote: logger.error("FAILED: '%s{50}', '%s', %s, %s" % (message, route, params, e.code)) does anything like this exist? %.50s That's not working in

Re: Announcing a new podcast: Radio Free Python

2011-08-24 Thread Ethan Furman
Michael Hunter wrote: On Wed, Aug 24, 2011 at 2:50 PM, Terry Reedy wrote: [...] You can find it at http://www.radiofreepython.com/ as of this very minute. >> What a treat. Thank you. Please announce the next one too. No, please don't announce the next one. There should be a RSS feed. But p

Re: Checking Signature of Function Parameter

2011-08-29 Thread Ethan Furman
Travis Parks wrote: I wrote a post a few days ago about how I know the syntax and libraries fairly well, but I don't have the "philosophy". I haven't seen a lot of tricks and I am never sure what is the "norm" in Python. I am sure if an experienced Python programmer looked at my code, they'd imme

Re: Returning a value from exec or a better solution

2011-08-30 Thread Ethan Furman
Jack Trades wrote: On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: If an impementation (as you say up thread) can populate globals or locals with whatever they want, then how do you know that last item added was the function definition the user supplied ? Because the implementation wil

Re: Returning a value from exec or a better solution

2011-08-30 Thread Ethan Furman
Rob Williscroft wrote: Ethan Furman wrote in news:4e5d29c8.8010...@stoneleaf.us in gmane.comp.python.general: Jack Trades wrote: On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote: If an impementation (as you say up thread) can populate globals or locals with whatever they want, then

Re: Returning a value from exec or a better solution

2011-08-30 Thread Ethan Furman
Rob Williscroft wrote: Arnaud Delobelle wrote: That's not an issue. The last statement that is executed will be the "def" statement. You don't know that, an implementation may for example set __bultins__ to None, prior to returning, its not an unreasonable thing to do and the docs don't say

Re: Returning a value from exec or a better solution

2011-08-30 Thread Ethan Furman
Rob Williscroft wrote: Arnaud Delobelle wrote: That's not an issue. The last statement that is executed will be the "def" statement. You don't know that, an implementation may for example set __bultins__ to None, prior to returning, its not an unreasonable thing to do and the docs don't say

slightly OT -- LaTeX

2011-09-01 Thread Ethan Furman
I asked a question a couple weeks ago about scripting WordPerfect with Python, and a couple respondents suggested LaTeX was very good. Where would I start if I wanted to learn about it? ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list

Re: Python fails on math

2011-02-24 Thread Ethan Furman
Steven D'Aprano wrote: On Wed, 23 Feb 2011 13:26:05 -0800, John Nagle wrote: The IEEE 754 compliant FPU on most machines today, though, has an 80-bit internal representation. If you do a sequence of operations that retain all the intermediate results in the FPU registers, you get 16 more bits

3.1 -> 3.2: base64 lost deprecation warning

2011-02-28 Thread Ethan Furman
Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. --> import base64 --> base64.encodestring(b'this is a test') __main__:1: DeprecationWarning: encodestring() is a deprecated alias, use enco

Re: 3.1 -> 3.2: base64 lost deprecation warning

2011-02-28 Thread Ethan Furman
Terry Reedy wrote: On 2/28/2011 3:51 PM, Ethan Furman wrote: The deprecation warning has gone away in 3.2, No, still there: def encodestring(s): """Legacy alias of encodebytes().""" import warnings warnings.warn("encodestring() is a

Re: question about endswith()

2011-03-03 Thread Ethan Furman
Matt Funk wrote: Hi, i have a list of files, some of which end with .hdf and one of them end with hdf5. I want to filter the hdf5 file. Thereforei set extensions: hdf5 I try to filter as below: > -->if (any(filename.endswith(x) for x in extensions)): What is extensions? A string or a tuple?

Re: Defining class attributes + inheritance

2011-03-08 Thread Ethan Furman
Martin De Kauwe wrote: Hi, I think this might be obvious? I have a base class which contains X objects which other classes inherit e.g. class BaseClass(object): def __init__(self, something, something_else): self.something = something self.something_else = something_else

Re: ttk styles

2011-03-17 Thread Ethan Furman
Peter wrote: Thanks for the link Malcolm, I'll have a look at it. What is particularly interesting (at first glance), is that the author has "mixed" Tkinter with ttk as it suited i.e. look at this line: f1 = tkinter.Frame(nb, background="red") If ttk was being used purely (from tkinter import *

Re: email library

2011-03-18 Thread Ethan Furman
peterob wrote: Im completely confinvalided from email library. When you parse email from file it creates object Message. f = open(emailFile, 'r') msg = email.message_from_file(f) f.close() How can I access RAW header of email represented by object msg? I dont wanna access each header field by

Re: class error

2011-03-18 Thread Ethan Furman
monkeys paw wrote: I have the following file: FileInfo.py: import UserDict class FileInfo(UserDict): "store file metadata" def __init__(self, filename=None): UserDict.__init__(self) self["name"] = filename When i import it like so: import FileInfo i get this error

Re: Reading/Writing files

2011-03-18 Thread Ethan Furman
Jon Herman wrote: Hello all, I am pretty new to Python and am trying to write data to a file. However, I seem to be misunderstanding how to do so. For starters, I'm not even sure where Python is looking for these files or storing them. The directories I have added to my PYTHONPATH variable (w

Re: Reading/Writing files

2011-03-18 Thread Ethan Furman
Dan Stromberg wrote: Are you on windows? You probably should use / as your directory separator in Python, not \. In Python, and most other programming languages, \ starts an escape sequence, so to introduce a literal \, you either need to prefix your string with r (r"\foo\bar") or double yo

Re: Problem with re module

2011-03-22 Thread Ethan Furman
John Harrington wrote: Here's a script that illustrates the problem. Any help would be appreciated!: #BEGIN SCRIPT import re outlist = [] myfile = "raw.tex" fin = open(myfile, "r") lineList = fin.readlines() fin.close() for i in range(0,len(lineList)): lineList[i]=re.sub(r'(\\begin{do

Re: Reading/Writing files

2011-03-25 Thread Ethan Furman
On 3/18/2011 6:25 PM, Dan Stromberg wrote: On Fri, Mar 18, 2011 at 4:00 PM, Ethan Furman mailto:et...@stoneleaf.us>> wrote: Dan Stromberg wrote: Are you on windows? You probably should use / as your directory separator in Python, not \. In Python, and most

Re: Why aren't copy and deepcopy in __builtins__?

2011-03-28 Thread Ethan Furman
John Ladasky wrote: On Mar 28, 2:25 am, Andrea Crotti wrote: I noticed some time ago in a program that needed speed that deepcopy in particular is incredibly slow, but I guess is normal since it has to copy every bit of the data structure. That may be, but when it already takes several second

Re: Python problem

2011-03-28 Thread Ethan Furman
John Parker wrote: I have written the following code so far but get an error. infile = open("scores.txt", "r") lines = infile.readlines() infile.close() tokens = lines.split(",") [snip] error: Traceback (most recent call last): File "Score_8.py", line 38, in tokens = lines.split(",")

Re: Directly Executable Files in Python

2011-03-29 Thread Ethan Furman
harrismh777 wrote: Chris Rebert wrote: Yes. py2exe is a tool which generates such Windows executables: http://www.py2exe.org/ Interesting... but it can't possibly be creating .exe files (compiling)... Yes and no. The python program is not being compiled. The Python system, along with all

Re: Data files for tests

2011-03-30 Thread Ethan Furman
Steven D'Aprano wrote: I have a package with some tests. The tests are not part of the package Do you mean they are not importable, as in --> from spam import tests or they are not distributed? Because it seems to me that distributing them would be worthwhile to at least some of the folks d

Re: In List Query -> None Case Sensitive?

2011-03-31 Thread Ethan Furman
Wehe, Marco wrote: I am doing a search through a list of files but the text the casing doesn't match. My list is all upper case but the real files are all different. Is there a smooth way of searching through the list without going full on regular expressions? path = "V:\\Jinsy\\incoming\\ass

Re: [OT] Free software versus software idea patents

2011-04-08 Thread Ethan Furman
Westley Martínez wrote: On Fri, 2011-04-08 at 01:41 -0500, harrismh777 wrote: Freedom isn't free... you have to fight for it... always. Why should a business listen to you? You're not gonna buy any software anyways. From a thread a few months back I can say there are a couple companies wi

Re: Generators and propagation of exceptions

2011-04-08 Thread Ethan Furman
r wrote: The code above implements an interactive session (a REPL). Therefore, what I'd like to get is an error information printed out at the output as soon as it becomes available. Couple ideas: 1) Instead of yielding the error, call some global print function, then continue on; or 2) Col

Re: Argument of the bool function

2011-04-08 Thread Ethan Furman
candide wrote: Le 08/04/2011 18:43, Ian Kelly a écrit : In "bool(x=5)", "x=5" is also not an expression. It's passing the expression "5" in as the parameter x, using a keyword argument. >> You are probably right but how do you deduce this brilliant interpretation from the wording given in th

Re: Argument of the bool function

2011-04-11 Thread Ethan Furman
Mel wrote: Python is a pragmatic language, so all the rules come pre-broken. +1 QOTW -- http://mail.python.org/mailman/listinfo/python-list

Re: Feature suggestion -- return if true

2011-04-12 Thread Ethan Furman
James Mills wrote: Are we done with this discussion yet ? :) *sigh* It was a slow day yesterday and I have a funny feeling it's going to be the same today! Regardless of anyone's subjective opinions as to what was clear - I still stand by what I said. I think I see your point -- the OP said: -

Re: Feature suggestion -- return if true

2011-04-12 Thread Ethan Furman
Westley Martínez wrote: On Tue, 2011-04-12 at 16:06 -0700, Ethan Furman wrote: --> def func(): --> var1 = something() --> var2 = something_else('this') --> return? var1.hobgle(var2) --> var3 = last_resort(var1) --> return var3.wiglat(var2)

Re: Feature suggestion -- return if true

2011-04-12 Thread Ethan Furman
Steven D'Aprano wrote: On Tue, 12 Apr 2011 16:48:31 -0700, Ethan Furman wrote: Westley Martínez wrote: On Tue, 2011-04-12 at 16:06 -0700, Ethan Furman wrote: --> def func(): --> var1 = something() --> var2 = something_else('this') --> return? var

Re: Egos, heartlessness, and limitations

2011-04-13 Thread Ethan Furman
James Mills wrote: On Thu, Apr 14, 2011 at 10:39 AM, rantingrick wrote: [weapon of mass-snippitude] James, *Please* don't re-post his crap. ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list

Re: Free software versus software idea patents

2011-04-14 Thread Ethan Furman
geremy condra wrote: On Wed, Apr 13, 2011 at 10:50 PM, harrismh777 wrote: >> My major professor once told me, "You know you've won the argument when they start calling you names!" I think your professor should have said "you know you've won the argument when you can prove it". If you can

Re: [OT] Free software versus software idea patents

2011-04-14 Thread Ethan Furman
Westley Martínez wrote: Also, why aren't Opera and Google criticized for their proprietary browsers (Chrome is essentially a proprietary front-end)? Is it because their browsers follow web standards, or is it because we have demonized Microsoft? My biggest gripe with Microsoft as that they *don

Re: Pythonic infinite for loop?

2011-04-15 Thread Ethan Furman
Chris Angelico wrote: lst=[] for i in xrange(1,1000): # arbitrary top, don't like this try: lst.append(parse_kwdlist(dct["Keyword%d"%i])) except KeyError: break Possibly overkill: import dbf table = dbf.from_csv("csvfile") # fields get names f0, f1, f2, ... table.rename_field

Re: Namespaces in functions vs classes

2011-04-17 Thread Ethan Furman
Gerald Britton wrote: However, I would like a deeper understanding of why I cannot use "foo" as an unqualified variable inside the method in the class. If Python allowed such a thing, what problems would that cause? 8< "script with possible

Re: Namespaces in functions vs classes

2011-04-17 Thread Ethan Furman
Gerald Britton wrote: For my final attempt, I add the prefix "a." to my use of "foo" class a(): ... foo = 'foo' ... def g(x): ... return a.foo ... The first parameter to any method in a class* is going to be the instance of that class, and is usually named 'self'. So your

Re: Namespaces in functions vs classes

2011-04-19 Thread Ethan Furman
Gerald Britton wrote: I now understand the Python does not consider a class definition as a separate namespace as it does for function definitions. That is a helpful understanding. That is not correct. Classes are separate namespaces -- they just aren't automatically searched. The only name

Re: A question about Python Classes

2011-04-21 Thread Ethan Furman
chad wrote: Let's say I have the following class BaseHandler: def foo(self): print "Hello" class HomeHandler(BaseHandler): pass Then I do the following... test = HomeHandler() test.foo() How can HomeHandler call foo() when I never created an instance of BaseHandler? Yo

Re: A question about Python Classes

2011-04-22 Thread Ethan Furman
Kyle T. Jones wrote: Ethan Furman wrote: chad wrote: Let's say I have the following class BaseHandler: def foo(self): print "Hello" class HomeHandler(BaseHandler): pass Then I do the following... test = HomeHandler() test.foo() How can HomeHandler ca

Re: De-tupleizing a list

2011-04-26 Thread Ethan Furman
Hans Georg Schaathun wrote: List comprehension is understood even by readers with no experience with python. There's nothing magically understandable about a list comp -- the first time I saw one (which was in Python), I had to learn about them. ~Ethan~ -- http://mail.python.org/mailman/li

Composition instead of inheritance

2011-04-28 Thread Ethan Furman
For anybody interested in composition instead of multiple inheritance, I have posted this recipe on ActiveState (for python 2.6/7, not 3.x): http://code.activestate.com/recipes/577658-composition-of-classes-instead-of-multiple-inherit/ Comments welcome! ~Ethan~ -- http://mail.python.org/mailma

Re: Composition instead of inheritance

2011-04-28 Thread Ethan Furman
Carl Banks wrote: That's not what we mean by composition. Composition is when one object > calls upon another object that it owns to implement some of its behavior. > Often used to model a part/whole relationship, hence the name. Hmmm. Okay -- any ideas for a better term? Something that descr

Re: Composition instead of inheritance

2011-04-29 Thread Ethan Furman
James Mills wrote: On Fri, Apr 29, 2011 at 11:43 AM, Ethan Furman wrote: Hmmm. Okay -- any ideas for a better term? Something that describes taking different source classes and fusing them into a new whole, possibly using single-inheritance... Frankenstein, maybe? ;) I'd have to say

Re: Composition instead of inheritance

2011-04-29 Thread Ethan Furman
Carl Banks wrote: Here is my advice on mixins: [snip] Cool. Thanks! ~Ethan -- http://mail.python.org/mailman/listinfo/python-list

Re: Composition instead of inheritance

2011-04-29 Thread Ethan Furman
Ian Kelly wrote: On Thu, Apr 28, 2011 at 11:15 AM, Ethan Furman wrote: For anybody interested in composition instead of multiple inheritance, I have posted this recipe on ActiveState (for python 2.6/7, not 3.x): http://code.activestate.com/recipes/577658-composition-of-classes-instead-of

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2011-05-04 Thread Ethan Furman
Raymond Hettinger wrote: I'm writing-up more guidance on how to use super() and would like to point at some real-world Python examples of cooperative multiple inheritance. Don't know if you are still looking for examples, but I recently came across a thread in Python-Dev which had an example u

Re: What other languages use the same data model as Python?

2011-05-05 Thread Ethan Furman
harrismh777 wrote: Grant Edwards wrote: I give up. You don't seem to understand the C language defintion or what is commonly meant by "pass by reference". ah, don't give up... here is a link that might help to clarify some of these semantics... me thinks: http://en.wikipedia.org/wiki/Pa

Dictionary Views -- good examples? [was Re: Python 3 dict question]

2011-05-06 Thread Ethan Furman
Ian Kelly wrote: On Fri, May 6, 2011 at 1:57 PM, dmitrey wrote: Unfortunately, it doesn't work, it turn out to be dict_items: next({1:2}.items()) Traceback (most recent call last): File "", line 1, in TypeError: dict_items object is not an iterator So call iter() on it first: next(iter(m

Re: checking if a list is empty

2011-05-07 Thread Ethan Furman
harrismh777 wrote: Steven D'Aprano wrote: >>> attribution lost wrote: > and implies in any case that li does not exist It does nothing of the sort. If li doesn't exist, you get a NameError. That was the point. 'not' implies something that is not logical; which is irony extreme sinc

Re: What other languages use the same data model as Python?

2011-05-09 Thread Ethan Furman
Steven D'Aprano wrote: But that's wrong! Names (little boxes) can't point to *slots in a list*, any more than they can point to other names! This doesn't work: --> L = [None, 42, None] --> a = L[0] --> L[0] = 23 --> print(a) # This doesn't work! 23 Minor nitpick -- having a comment saying

Re: Inconsistency with split() - Script, OS, or Package Problem?

2011-05-09 Thread Ethan Furman
James Wright wrote: Hello, Howdy! def create_report_index(report): #Here we are creating a simple index.html file from data in a text file newfile = open(report + '.html', 'w') #Create the index file using report name for each_value in D4[report]: [clean_name, _] = each_value

Re: Inconsistency with split() - Script, OS, or Package Problem?

2011-05-09 Thread Ethan Furman
James Wright wrote: Thank you Ethan, This is what I see now: # python render4.py current each_value is: vsr Traceback (most recent call last): File "render4.py", line 115, in create_report_index(each_item) File "render4.py", line 26, in create_report_index [clean_name, _] = each_va

Re: Inconsistency with split() - Script, OS, or Package Problem?

2011-05-09 Thread Ethan Furman
James Wright wrote: On Mon, May 9, 2011 at 3:36 PM, Ethan Furman wrote: Change your print line to: print("D4[%s] = %s" % (report, each_value)) After that, you'll have to track down how D4 is being created to see where 'vsr' is coming from. It does not appear t

Re: Inconsistency with split() - Script, OS, or Package Problem?

2011-05-09 Thread Ethan Furman
James Wright wrote: On Mon, May 9, 2011 at 4:04 PM, Ethan Furman wrote: James Wright wrote: On Mon, May 9, 2011 at 3:36 PM, Ethan Furman wrote: >>>> Change your print line to: print("D4[%s] = %s" % (report, each_value)) After that, you'll have to track down how

Re: Dictionary Views -- good examples? [was Re: Python 3 dict question]

2011-05-10 Thread Ethan Furman
Ian Kelly wrote: On Fri, May 6, 2011 at 4:49 PM, Ethan Furman wrote: Anybody care to chime in with their usage of this construct? You should start with PEP 3106. The main idea is that dict.keys() and dict.items() can be treated as frozensets, while still being more lightweight than lists

Re: checking if a list is empty

2011-05-11 Thread Ethan Furman
Hans Georg Schaathun wrote: On 11 May 2011 13:36:02 GMT, Steven D'Aprano wrote: : > In this case, the interpretation of an arbitrary object as a boolean is : > peculiar for python. : : Incorrect. It is widespread among many languages. Programmers have been : writing conditional tests usi

Re: checking if a list is empty

2011-05-11 Thread Ethan Furman
Hans Georg Schaathun wrote: On Wed, 11 May 2011 13:50:54 -0400, Prasad, Ramit wrote: : I find this argument to be flawed. Should I stop using built-in : generators instead of range/xrange for looping through lists? : Certainly for loops with loop counting are understood more widely : than g

Re: How to deal with optional argument evaluation

2011-05-11 Thread Ethan Furman
Rodrick Brown wrote: I'm having a hard time dealing with the following scenario My class takes a hash like the following: rdargs = {'env:'prod','feed':'opra','hostname':'host13dkp1','process':'delta','side':'a','zone','ny'} All the keys in this hash can be optional. I'm having a hard time

Re: checking if a list is empty

2011-05-12 Thread Ethan Furman
Chris Angelico wrote: On Thu, May 12, 2011 at 7:02 AM, Ian wrote: In the "real world" lists of zero items do not exist. You don't go shopping with a shopping list of zero items. Actually, yes you do. You maintain your shopping list between trips; whenever you need something, you put it on th

Re: list equal to subclass of list?

2011-05-12 Thread Ethan Furman
Roy Smith wrote: I recently observed in the "checking if a list is empty" thread that a list and a subclass of list can compare equal: class MyList(list): "I'm a subclass" l1 = [] l2 = MyList() print type(l1), type(l2) print type(l1) == type(l2) print l1 == l2

Re: list equal to subclass of list?

2011-05-12 Thread Ethan Furman
Roy Smith wrote: On May 12, 2011, at 11:30 AM, Eric Snow wrote: That definitely makes it unclear. I don't think it's unclear at all. It's very clear. Clearly wrong :-) While it is wrong (it should have 'built-in' precede the word 'types'), it is not wrong in the way you think -- a subcla

Re: Proper way to handle errors in a module

2011-05-12 Thread Ethan Furman
Andrew Berg wrote: On 2011.05.12 02:25 PM, MRAB wrote: You can raise an exception wherever you like! :-) If I raise an exception that isn't a built-in exception, I get something like "NameError: name 'HelloError' is not defined". I don't know how to define the exception. class HelloError(Exce

Re: list equal to subclass of list?

2011-05-12 Thread Ethan Furman
Roy Smith wrote: On May 12, 2:29 pm, Ethan Furman wrote: While it is wrong (it should have 'built-in' precede the word 'types'), it is not wrong in the way you think -- a subclass *is* a type of its superclass. Well, consider this: class List_A(list): "A lis

Re: list equal to subclass of list?

2011-05-12 Thread Ethan Furman
Steven D'Aprano wrote: On Thu, 12 May 2011 09:43:23 -0700, Ethan Furman wrote: MyList is a list -- just a more specific kind of list -- as can be seen from its mro; this is analogous to a square (2 sets of parallel lines joined at 90 degree angles, both sets being the same length) also be

Python 3.x and bytes

2011-05-17 Thread Ethan Furman
In Python 3 one can say --> huh = bytes(5) Since the bytes type is actually a list of integers, I would have expected this to have huh being a bytestring with one element -- the integer 5. Actually, what you get is: --> huh b'\x00\x00\x00\x00\x00' or five null bytes. Note that this is an

Re: if statement on lenght of a list

2011-05-17 Thread Ethan Furman
Joe Leonardo wrote: Totally baffled by this…maybe I need a nap. Writing a small function to reject input that is not a list of 19 fields. def breakLine(value): if value.__class__() != [] and value.__len__() != 19: print 'You must pass a list that contains 19 fields.' else:

Re: Python 3.x and bytes

2011-05-17 Thread Ethan Furman
Felipe Bastos Nunes wrote: 2011/5/17 Ethan Furman wrote: In Python 3 one can say --> huh = bytes(5) Since the bytes type is actually a list of integers, I would have expected this to have huh being a bytestring with one element -- the integer 5. Actually, what you get is: -->

Re: Python 3.x and bytes

2011-05-17 Thread Ethan Furman
Corey Richardson wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 05/17/2011 02:47 PM, Ethan Furman wrote: In Python 3 one can say --> huh = bytes(5) Since the bytes type is actually a list of integers, I would have expected this to have huh being a bytestring with one element --

Re: Python 3.x and bytes

2011-05-17 Thread Ethan Furman
Ian Kelly wrote: On Tue, May 17, 2011 at 2:20 PM, Ethan Furman wrote: The big question, though, is would you do it this way: some_var = bytes(23).replace(b'\x00', b'a') or this way? some_var = bytes(b'a' * 23) Actually, I would just do it this way: some_var

<    1   2   3   4   5   6   7   8   9   10   >