Re: Different behaviour in list comps and generator expressions

2014-11-17 Thread Steven D'Aprano
Steven D'Aprano wrote: > The following list comprehension and generator expression are almost, but > not quite, the same: > > [expr for x in iterable] > > list(expr for x in iterable) > > > The difference is in the handling of StopIteration raised inside the

Re: caught in the import web again

2014-11-17 Thread Steven D'Aprano
On Mon, 17 Nov 2014 18:17:13 -0800, Rick Johnson wrote: > BOY I LOVE TROGGING! Yes, we've noticed. http://www.urbandictionary.com/define.php?term=trogging -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: How to fix those errors?

2014-11-18 Thread Steven D'Aprano
Roy Smith wrote: > In article <[email protected]>, > Steven D'Aprano wrote: > >> Chris Angelico wrote: >> >> > You should be able to use two semicolons, that's equivalent to one >> > colon right? >>

Re: How modules work in Python

2014-11-19 Thread Steven D'Aprano
The same thing applies to non-modules too. If you define a function inside the body of a class, it is stored in the class __dict__, but if you store it in the instance __dict__, it never gets converted to a method. You can read up on descriptors here: https://docs.python.org/3/howto/descriptor.html -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Most gratuitous comments

2014-11-19 Thread Steven D'Aprano
And the award for the most gratuitous comments before an import goes to one of my (former) workmates, who wrote this piece of code: # Used for base64-decoding. import base64 # Used for ungzipping. import gzip -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Is StopIteration a singleton?

2014-11-19 Thread Steven D'Aprano
StopIteration itself, but not StopIteration instances: py> marshal.dumps(StopIteration) 'S' py> marshal.dumps(StopIteration()) Traceback (most recent call last): File "", line 1, in ValueError: unmarshallable object -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Beginner

2014-11-19 Thread Steven D'Aprano
nput('Enter an integer : ')) (don't forget to indent it correctly). There may be other problems, please fix these first and if you have any other problems copy and paste the FULL error, everything from the line starting Traceback to the end of the error message. -- Steven -- htt

Re: Python IDE.

2014-11-20 Thread Steven D'Aprano
[email protected] wrote: > Can someone suggest a good python IDE. Yes. Use a UNIX or Linux system: http://blog.sanctum.geek.nz/series/unix-as-ide/ -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Most gratuitous comments

2014-11-20 Thread Steven D'Aprano
meaningful name can be self-documenting and so reduces the need for comments. (By the way, whatever tool you are using to post comments is badly breaking attributions. It is polite to give the person's full name when quoting them, when they provide one, if not give their full email address. Tr

Re: Python docs disappointing

2014-11-20 Thread Steven D'Aprano
e, were a bit heavy handed and more distracting than ironic. Nevertheless, a masterful job. You made me laugh. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: python 2.7 and unicode (one more time)

2014-11-20 Thread Steven D'Aprano
As an English speaker. I have to remind myself that not every grapheme is a single code point, but Devanagari or Navajo writers will never make that mistake. > We shouldn't call strings Unicode any more than we call numbers IEEE or > times ISO. We certainly shouldn't call numbers IEEE, but we might very well call them IEEE-754. Actually, since IEEE-754 covers multiple formats, we have to be more specific: Python floats are IEEE-754 double-precision binary floats. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Using Python for date calculations

2014-11-21 Thread Steven D'Aprano
from ast import literal_eval py> literal_eval('[None, 23, "hello", {0.5: "x"}]') [None, 23, 'hello', {0.5: 'x'}] -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: python 2.7 and unicode (one more time)

2014-11-21 Thread Steven D'Aprano
Chris Angelico wrote: > On Fri, Nov 21, 2014 at 11:32 AM, Steven D'Aprano > wrote: >> (E.g. there are millions of existing files across the world containing >> text which use legacy encodings that are not compatible with Unicode.) > > Not compatible with Unicode

Re: python 2.7 and unicode (one more time)

2014-11-21 Thread Steven D'Aprano
ling with. Are you equally disturbed when people distinguish between tablespoon, teaspoon, dessert spoon and serving spoon? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Infinitely nested containers

2014-11-21 Thread Steven D'Aprano
hon 3.3). py> L = [] py> t = (L, None) py> L.append(L) py> L.append(t) # For good measure. py> print(t) ([[...], (...)], None) but yes, in old versions of Python printing self-recursive containers may break. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: PyWart: "Python's import statement and the history of external dependencies"

2014-11-22 Thread Steven D'Aprano
ok/here', 'and/here'] import something without affecting any other modules. > And after all that, it would still fail if you happened to want to > import both "calendar" modules into the same module. __path__ = [] import calendar __path__ = ['my/python/modules'] import calendar as mycalendar -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: python 2.7 and unicode (one more time)

2014-11-22 Thread Steven D'Aprano
Marko Rauhamaa wrote: > Steven D'Aprano : > >> In Python, we have Unicode strings and byte strings. > > No, you don't. You have strings and bytes: Python has strings of Unicode code points, a.k.a. "Unicode strings", or "text strings", and string

Re: PyWart: "Python's import statement and the history of external dependencies"

2014-11-22 Thread Steven D'Aprano
Tim Chase wrote: > On 2014-11-22 23:25, Steven D'Aprano wrote: >> > And after all that, it would still fail if you happened to want to >> > import both "calendar" modules into the same module. >> >> __path__ = [] >> import calendar >

Re: Infinitely nested containers

2014-11-22 Thread Steven D'Aprano
Ethan Furman wrote: > On 11/21/2014 08:43 PM, Steven D'Aprano wrote: >> [email protected] wrote: >>> >>> I think I tried on at least one python version and printing the tuple >>> crashed with a recursion depth error, since it had no special protectio

Re: python 2.7 and unicode (one more time)

2014-11-22 Thread Steven D'Aprano
[email protected] wrote: > On Fri, Nov 21, 2014, at 23:38, Steven D'Aprano wrote: >> I really don't understand what bothers you about this. In Python, we have >> Unicode strings and byte strings. In computing in general, strings can >> consist of Unicode cha

Re: PyWart: "Python's import statement and the history of external dependencies"

2014-11-22 Thread Steven D'Aprano
Chris Angelico wrote: > On Sat, Nov 22, 2014 at 11:25 PM, Steven D'Aprano > wrote: >> Ian Kelly wrote: >> >> - It's hard to keep track of what modules are in the standard library. >> Which of the following is *not* in Python 3.3's std lib? No cheating

Re: unloading a module created with imp.new_module

2014-11-23 Thread Steven D'Aprano
o for o in gc.get_objects() if isinstance(o, types.ModuleType) ... and o.__name__ == 'mymodule'] [] -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: I have no class

2014-11-23 Thread Steven D'Aprano
l_variables In some of these languages, the use of "this/self/me" is optional, but I'm not aware of *any* OOP language where there is no named reference to the current object at all. In any case, Python is not unusual in this regard. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Comprehension with two variables - explanation needed

2014-11-23 Thread Steven D'Aprano
ion: def primes0(): i = 2 yield i while True: i += 1 composite = False for p in range(2, i): if i%p == 0: composite = True if not composite: # It must be a prime. yield i > Call with sieve [2..] > > Now a pythonification of that [...] -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: "**" in python

2014-11-23 Thread Steven D'Aprano
always returns its left hand argument: py> 0**2 0 py> 0**7 0 py> 0**99 0 Of course, that could be a coincidence, better try a few other things: py> 1**57 1 py> 57**1 57 py> -1**12 -1 :-) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Comprehension with two variables - explanation needed

2014-11-24 Thread Steven D'Aprano
Chris Angelico wrote: > On Mon, Nov 24, 2014 at 3:42 PM, Steven D'Aprano > wrote: >> Today dis() returns the above, tomorrow it may return: >> >> 0 LOAD_GLOBAL 0 (x) >> 3 INCREMENT >> 5 RETURN_VALUE

Re: python 2.7 and unicode (one more time)

2014-11-24 Thread Steven D'Aprano
, user prompts, etc., regardless whether the implementation is an array of 8-bit bytes (as used by Python 2), or the full Unicode character set (as used by Python 3). So in practice, provided you know which version of Python is being discussed, there is never any genuine ambiguity when using the word "string" and no excuse for confusion. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Ducktyping

2014-11-24 Thread Steven D'Aprano
https://pbs.twimg.com/media/B3Fvg-sCYAAkLSV.jpg -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Dictionary error

2014-11-25 Thread Steven D'Aprano
4) Insert a line here: print keys, type(keys) and see what it prints. >values = sheet.cell(row = i,column = 5) >x.append(keys.value) >y.append(values.value) >i +=1 >mydict = dict(zip(keys,values)print mydict -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: FW: Unexpexted behaviot of python operators on list

2014-11-25 Thread Steven D'Aprano
that to the target, the old object is modified instead. https://docs.python.org/2/reference/simple_stmts.html#augmented-assignment-statements > Please find the attached module and execute it on windows python32, See > the difference in output. I cannot see the attached module. Did you forget to at

Re: python 2.7 and unicode (one more time)

2014-11-25 Thread Steven D'Aprano
Marko Rauhamaa wrote: > Steven D'Aprano : > >> Marko Rauhamaa wrote: >> >>>> Py3's byte strings are still strings, though. >>> >>> Hm. I don't think so. In a plain English sense, maybe, but that kind of >>> usage can

Re: Most gratuitous comments

2014-11-25 Thread Steven D'Aprano
with good style. It concentrates on documenting use and > lets the implementation document itself. Thanks for the kind comments :-) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Python Documentation Improvement

2014-11-25 Thread Steven D'Aprano
e documentation is clear enough, but I welcome suggestions for improvement. Can you point us to the parts of the documentation which you think are not clear enough? Do you have some suggested improvements? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Challenge: optimizing isqrt

2014-11-26 Thread Steven D'Aprano
= commented on, so why is it left in? response lacking context Note that the reader may end up having to scroll past many paragraphs (or even pages!) of quoted text to discover the response. Which, all too often, is a single sentence. Thanks for contributing to the discussion. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Issues installing Python 2.7

2014-11-26 Thread Steven D'Aprano
ared object file: No such file or directory > > Please help the newb. He's frustrated. Are you sure that /opt/python2.7/bin/python2.7 even exists? What do "ls -l" and "file" say about them? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Issues installing Python 2.7

2014-11-27 Thread Steven D'Aprano
the default prefix of /usr/local/bin and don't have any trouble. I recommend you try again with just: ./configure make make altinstall then add an alias to your .bashrc alias python=python2.7 and see how that works for you. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Can you use self in __str__

2014-11-27 Thread Steven D'Aprano
on for over 15 years. Either I have no idea what Ma is trying to say, or Ma has no idea what (s)he's trying to say. :-) >>To that end, you need to access the namespace where 'self' is in. `self` is a local variable of the method. Accessing the local namespace is automatic. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Can you use self in __str__

2014-11-28 Thread Steven D'Aprano
x27;ve told them, and can use them any way you like: def __str__(self): template = "%s's hand contains: " return (template % self.name) + "King of Spades" -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: I love assert

2014-11-28 Thread Steven D'Aprano
o have some performance cost. But very cheaply.) [1] Thanks to Python defaulting to __debug__ = True, the problem is getting people to remember to test their software with assertions disabled, not to get them to enable them. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: tabs with tkinter

2014-11-29 Thread Steven D'Aprano
Terry Reedy wrote: > idlelib also has TreeWidget.py which works on all branches. Heh, I see what you did there :-) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: I love assert

2014-11-29 Thread Steven D'Aprano
MRAB wrote: > On 2014-11-29 01:30, Steven D'Aprano wrote: > [snip] >> I stress that assertions aren't a replacement for unit testing, but they >> compliment unit testing: assertions can help cover code missed by your >> unit tests, and check that your unit tes

Re: I love assert

2014-11-30 Thread Steven D'Aprano
Ethan Furman wrote: > On 11/28/2014 05:30 PM, Steven D'Aprano wrote: >> alister wrote: >> >>> And as may wiser people than me have already highlighted Assertions can >>> be switched off in python which means they cannot be relied upon in >>> prod

Re: Python handles globals badly.

2014-12-03 Thread Steven D'Aprano
> object feature, > > Someone with 20 years of programming shouldn't have any problems > understanding objects in Python. Oh if that were only the case. It is amazing how long some people can work in a profession and still avoid learning anything new. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Python handles globals badly.

2014-12-04 Thread Steven D'Aprano
or small scripts. But using dozens of them to avoid passing arguments to functions, that's just awful code. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Python docs disappointing

2014-12-04 Thread Steven D'Aprano
> Plain google is far superior in finding information. Well duh. > And you tell me that writing yet another tutorial would improve that? Apparently people need a tutorial to teach them to search the entire web not just a single website... -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: How is max supposed to work, especially key.

2014-12-04 Thread Steven D'Aprano
ength of the word. Same for calling max() with a key. The result is still the maximum value. The difference is how you decide which of two elements is greater: max(list_of_foods, key=calories) max(list_of_foods, key=weight) max(list_of_foods, key=cost) That is three different ways to decide wh

Re: How is max supposed to work, especially key.

2014-12-04 Thread Steven D'Aprano
Naturally. But this does calculate the maximum, according to the given key function. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: time.monotonic() roll over

2014-12-04 Thread Steven D'Aprano
iately adjust the clock forward an hour (say, due to a daylight savings adjustment), that shouldn't cause sleep to return. It should still suspend for 60 seconds. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: About Modifying Globals

2014-12-04 Thread Steven D'Aprano
]) looks like an assignment, but it's actually a method call! That is approximately equivalent to: a.__setitem__("1", X) with X equal to the right hand side. Since that's a method call, it doesn't count as a binding operation and the compiler doesn't treat a

Re: time.monotonic() roll over

2014-12-04 Thread Steven D'Aprano
Dave Angel wrote: > On 12/04/2014 07:39 PM, Steven D'Aprano wrote: >> Marko Rauhamaa wrote: >> >>> So, if I call >>> >>> time.sleep(86400) >>> >>> and the program is suspended for 24 hours, should time.sleep() return >>> ri

Re: The binding operator, and what gets bound to what (was: About Modifying Globals)

2014-12-05 Thread Steven D'Aprano
Ben Finney wrote: > Steven D'Aprano writes: > >> LJ wrote: >> >> > def gt(l): >> >a["1"] = a["1"] | set([l]) >> >> The difference between this example and your second one: >> >> > def gt2(l): >>

Re: time.monotonic() roll over

2014-12-05 Thread Steven D'Aprano
Lele Gaifax wrote: > Steven D'Aprano writes: > >> The most conservative approach is to assume that while you're suspended, >> *everything else* is suspended too, so when you resume you still have to >> sleep for the full N seconds. > > That's an int

Re: Do you like the current design of python.org?

2014-12-05 Thread Steven D'Aprano
;ve come to the conclusion that Firefox is the absolute worst web browser available, except for all the rest. Firefox has a wonderful plugin, No Script, which lets you block Javascript and other nonsense on a per-site basis. I love me my No Script. Browsing the web is so painful without it. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: The binding operator, and what gets bound to what (was: About Modifying Globals)

2014-12-05 Thread Steven D'Aprano
Chris Angelico wrote: > On Fri, Dec 5, 2014 at 8:53 PM, Steven D'Aprano > wrote: >> Oh, I learned something new: strictly speaking, this is implementation- >> dependent and not guaranteed to work in the future! >> >> def func(): >> global math >&g

Re: The binding operator, and what gets bound to what

2014-12-05 Thread Steven D'Aprano
Ned Batchelder wrote: > On 12/5/14 4:53 AM, Steven D'Aprano wrote: >> Oh, I learned something new: strictly speaking, this is implementation- >> dependent and not guaranteed to work in the future! >> >> def func(): >> global math >> import ma

Re: Tabs for indentation & Spaces for alignment in Python 3?

2014-12-05 Thread Steven D'Aprano
code indented with tabs configured for 8/4/2/1 spaces is *worse* than reading tab indented with 8/4/2/1 spaces. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Python Iterables struggling using map() built-in

2014-12-07 Thread Steven D'Aprano
sed something, I think we could write it like this: def myzip37(*args): iters = list(map(iter, args)) while iters: try: yield tuple([next(i) for i in iters]) except StopIteration: return which I guess is not too horrible. If Python had never supported the c

Re: Python Iterables struggling using map() built-in

2014-12-08 Thread Steven D'Aprano
ix the bugs it's twenty lines and you can't tell what it does any more without studying it for ten minutes. zip() is an exception, you can write zip() in Python beautifully. It breaks my heart that there are people who think that it is improved by adding unnecessary guard clauses to it. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Python Iterables struggling using map() built-in

2014-12-08 Thread Steven D'Aprano
Roy Smith wrote: > Chris Angelico wrote: >> > I'm actually glad PEP 479 will break this kind of code. Gives a good >> > excuse for rewriting it to be more readable. > > Steven D'Aprano wrote: >> What kind of code is that? Short, simple, Pythonic an

Re: Question on lambdas

2014-12-08 Thread Steven D'Aprano
functions created with def have the name you give them; - functions created with lambda are expressions and can be embedded directly in function calls, lists, etc; - functions created with def are statements and must stand alone. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Python Iterables struggling using map() built-in

2014-12-08 Thread Steven D'Aprano
On Tue, 09 Dec 2014 00:03:33 -0500, Terry Reedy wrote: > On 12/8/2014 9:50 PM, Steven D'Aprano wrote: >> Roy Smith wrote: >> >>> Chris Angelico wrote: > >>>> def myzip(*args): >>>> iters = map(iter, args) >>&g

Re: Python Iterables struggling using map() built-in

2014-12-09 Thread Steven D'Aprano
s bothered to give the compiler sufficient smarts, not because it can't be done.) So a good compiler should be able to compile "while iters" into "if iters: while True" so long as iters is not modified in the body of the loop. Still, that's a nice observation: sometimes more complex source code can lead to simpler byte code. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Do you like the current design of python.org?

2014-12-09 Thread Steven D'Aprano
g I'm not a total idiot. Why would I think that https://python.org/some/bla/bla/bla/random/stuff would do anything but give a 404? Even YouTube commentators know that you can't try random stuff into a URL and expect a useful page to appear. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Do you like the current design of python.org?

2014-12-09 Thread Steven D'Aprano
It's actually worse than that. By telling the end user that the maintainers have been notified, they *discourage* people from raising an issue. Why raise an issue for something that is already being attended too? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Nested loops is strangely slow, totally at a loss.

2014-12-09 Thread Steven D'Aprano
ce but space is now exhausted, and it returns False immediately. And so on for the rest of the sparse_cloud iterator. It would be nice if product iterators behaved like xrange() objects and could perform "in" tests without exhausting the iterator, but they don't. That's sad. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Nested loops is strangely slow, totally at a loss.

2014-12-09 Thread Steven D'Aprano
On Wed, 10 Dec 2014 17:53:05 +1100, Chris Angelico wrote: > On Wed, Dec 10, 2014 at 5:44 PM, Steven D'Aprano > wrote: >> It would be nice if product iterators behaved like xrange() objects and >> could perform "in" tests without exhausting the iterator, but the

Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Steven D'Aprano
On Tue, 09 Dec 2014 21:44:54 -0500, Roy Smith wrote: > In article <[email protected]>, > Steven D'Aprano wrote: > >> I really think you guys are trying too hard to make this function seem >> more complicated than it is. If you

Re: Nested loops is strangely slow, totally at a loss.

2014-12-10 Thread Steven D'Aprano
return iterators. Anything you get from the itertools module is likely to be an iterator. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Python script isn't producing text in data file

2014-12-10 Thread Steven D'Aprano
hift them from "yes, I'd love to help" to "fuck 'em, they can solve their own problems". -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Python script isn't producing text in data file

2014-12-10 Thread Steven D'Aprano
Please cut your code down to the smallest self-contained example that demonstrates the problem. Doing so will have two benefits: - it will increase the chances that you will find the bug yourself; - and if you don't, it will increase the chances that others will be willing to help you

Re: When do default parameters get their values set?

2014-12-10 Thread Steven D'Aprano
nce to get a function. b = f() a.attribute = 23 b.attribute # raises AttributeError Or you could inspect the byte-code of f and try to understand it. > Because to me 'is' -- equivalently id -- is a code-smell It is only a code-smell in the sense that caring about object identity should be rare. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Coercing two numbers without coerce()

2014-12-10 Thread Steven D'Aprano
l generality. Do not use A+B-B, since that is *not* numerically equivalent to A. Floats are not real numbers! py> a = 0.01 py> b = 1e5 py> a + b - b 0.009476131 py> a + b - b == a False -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Python Iterables struggling using map() built-in

2014-12-10 Thread Steven D'Aprano
namespaces get dismissed because nobody uses them, and nobody uses them because when they try it gets dismissed :-( Oh well, there's always my own non-stdlib modules :-) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Python script isn't producing text in data file

2014-12-10 Thread Steven D'Aprano
u change the global variable "testing" to True? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Problem with a dialog

2014-12-11 Thread Steven D'Aprano
x". Nothing else can see inner(), since it is local to outer(). As I said, most programming languages work like this. But a small minority use a different system, called "dynamic scoping". In dynamic scoping, it doesn't matter *where* a function is defined, only where it is called. Wi

Re: When do default parameters get their values set?

2014-12-11 Thread Steven D'Aprano
Chris Kaynor wrote: > On Wed, Dec 10, 2014 at 7:15 PM, Steven D'Aprano > wrote: >> Using "is" you are demonstrating that calling the function twice returns >> two distinct objects. That is the purpose of "is", to compare object >> identity.

Re: Problem with a dialog

2014-12-11 Thread Steven D'Aprano
ss, and set a per-instance attribute when the instance is created. Add this method to the class: def __init__(self): self.test = True Generally speaking, the __init__ method approach is more common. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Python Iterables struggling using map() built-in

2014-12-11 Thread Steven D'Aprano
to change is a good thing or a bad thing, but I don't think that there should be any debate about the reality of the Python community being strongly conservative, compared to the "anything goes" attitude of (say) Ruby, Perl and Lisp programmers. We don't like code that does

Re: list comprehension return a list and sum over in loop

2014-12-12 Thread Steven D'Aprano
ut in pure Python, you can do this: def add(alist, blist): if len(blist) != len(alist): raise ValueError for i, x in blist: alist[i] += x results = [0]*4 # Like [0,0,0,0] for sublist in [d2(t[k]) for k in xrange(1000)]: add(results, sublist) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: is_ as method or property?

2014-12-13 Thread Steven D'Aprano
e. That depends partly on the class you are dealing with, and partly on personal taste. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Extension of while syntax

2014-12-13 Thread Steven D'Aprano
e() while value in undesired_values() That is no help at all for the general case where you have a block of code inside the while loop. It certainly isn't worth having syntax for such a special case. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Creating interactive command-line Python app?

2014-12-13 Thread Steven D'Aprano
e the Linux operating system, it will have Python already installed. Otherwise, you will have to install it. If you can't install it, or don't want to, you can't use Python. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Python 2.x and 3.x use survey, 2014 edition

2014-12-13 Thread Steven D'Aprano
Marko Rauhamaa wrote: > At work, Python 2.3 is the version in one environment Good grief! What's the OS you are using for that? -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Creating interactive command-line Python app?

2014-12-13 Thread Steven D'Aprano
Akira Li wrote: > Steven D'Aprano writes: > >> [email protected] wrote: >> >>> um, what if I want to USE a command line for python WITHOUT downloading >>> or installing it >> >> Who are you talking to? What is the context? >&

Re: numpy question (fairly basic, I think)

2014-12-13 Thread Steven D'Aprano
Albert-Jan Roskam wrote: > Hi, > > I am new to numpy. I am reading binary data one record at a time (I have > to) and I would like to store all the records in a numpy array which I > pre-allocate. Below I try to fill the empty array with exactly one record, > but it is filled with as many rows as

Re: which is the right file path format in python3.4 ?

2014-12-14 Thread Steven D'Aprano
rrno 22] Invalid argument: 'F:\\names.txt' Are you sure that you have an F drive? Is it a writable disk? e.g. a hard drive, not a CD drive. Do you have read and write permissions to F drive? Run this code and show us what it prints: import os print(os.stat("F:\\") print(os.a

Re: which is the right file path format in python3.4 ?

2014-12-14 Thread Steven D'Aprano
Chris Angelico wrote: > On Sun, Dec 14, 2014 at 10:03 PM, Steven D'Aprano > wrote: >> Run this code and show us what it prints: >> >> import os >> print(os.stat("F:\\") >> print(os.access("F:\\", os.O_RDWR)) > > (With an

Re: Classes - converting external function to class's method.

2014-12-14 Thread Steven D'Aprano
is for you to tell Python which instance to use: str.upper("hello") # just like "hello".upper() --> returns "HELLO" > So I need to write down an "obj" argument manually. > Why '__self__' exists only in instance "x"? (m

Re: Python console rejects an object reference, having made an object with that reference as its name in previous line

2014-12-14 Thread Steven D'Aprano
(producer_entries.li.div.string) If you don't leave the blank line, then *nothing* in that "with" block will run and consequently the last print line will fail. Until you fix that, we cannot even begin to help with any other issues you might be having. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Classes - converting external function to class's method.

2014-12-14 Thread Steven D'Aprano
320404/creating-classes-dynamically-with-java [...] > If you intend the function to be called as the method of an instance, you > would be well-advised to name the parameter “self”, as recommended. > (Which is probably derived from Smalltalk-80 and Self, some of the first > OOPLs.) Good advice. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: "**" in python

2014-12-15 Thread Steven D'Aprano
Albert van der Horst wrote: > With some perseverance, you can ask the interpreter what `` ** '' > does: > > help(**) > > maybe so? > help('**') > Indeed, a whole description. Yes! Well spotted! -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Portable code: __import__ demands different string types between 2 and 3

2014-12-15 Thread Steven D'Aprano
e of __import__() is also discouraged in favor of importlib.import_module()." https://docs.python.org/3/library/functions.html#__import__ -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Portable code: __import__ demands different string types between 2 and 3

2014-12-15 Thread Steven D'Aprano
n the bug tracker and see what the core devs think. If you don't have and won't open an account on the tracker, if you can come up with a minimal example that demonstrates the issue, I'll open an issue for you. (But I'd rather you did it yourself :-) -- Steven -- https://ma

Re: Is there a way to schedule my script?

2014-12-17 Thread Steven D'Aprano
the answer is No, then your main loop is just killing time, doing nothing but sleeping and waiting, like somebody checking their wristwatch every two seconds. You should simplify your script by getting rid of the main loop completely and let your OS handle the timing: # No loop at all. do_this() -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Classes - "delegation" question.

2014-12-18 Thread Steven D'Aprano
rather-than-inheritance?lq=1 However, be warned that there are two subtly different models for delegation. Here's the one that people seem to forget: http://code.activestate.com/recipes/519639-true-lieberman-style-delegation-in-python/ -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Changing script's search path at install time

2014-12-20 Thread Steven D'Aprano
yapp.py a symlink or hard link to the real myapp/__main__.py. Better still is not to use the same name for the package and the script.) -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Hello World

2014-12-20 Thread Steven D'Aprano
, ___[(lambda _: _).func_code.co_nlocals:]) if ___ else [] ), lambda _: _.func_code.co_argcount, ( lambda _: _, lambda _, __: _, lambda _, __, ___: _, lambda _, __, ___, : _, lambda _, __, ___, , _: _, lambda _, _

Re: very weird pandas behavior

2014-12-20 Thread Steven D'Aprano
do? Anything different from the above? > Any idea what I'm doing wrong? I'm 95% sure it will turn out to be version confusion: you have two versions of Python installed, you used pip to install pandas for version A but then ran version B. Otherwise, 3% that the pip installati

Re: Hello World

2014-12-20 Thread Steven D'Aprano
CM wrote: > On Saturday, December 20, 2014 7:57:19 AM UTC-5, Steven D'Aprano wrote: >> Taken from Ben Kurtovic's blog: >> >> http://benkurtovic.com/2014/06/01/obfuscating-hello-world.html [...] > I ran it in IDLE with Python 2.7.8 and got: > > Traceb

Re: Hello World

2014-12-21 Thread Steven D'Aprano
Tony the Tiger wrote: > On Sat, 20 Dec 2014 23:57:08 +1100, Steven D'Aprano wrote: > >> I am in total awe. > > I'm not. It has no real value. Write your code like that and you'll soon > be looking for a new job. Awww, did da widdle puddy tat get up on th

<    57   58   59   60   61   62   63   64   65   66   >