Re: Static caching property

2016-03-21 Thread Ian Kelly
On Mon, Mar 21, 2016 at 10:54 AM, Chris Angelico wrote: > On Tue, Mar 22, 2016 at 3:49 AM, Joseph L. Casale > wrote: >> Right, but _private refers to an api call that is expensive and may not even >> be accessed, >> so while I may new up three instances of Test across a, b and c, if none of >>

Re: multiprocessing, pool, queue length

2016-03-21 Thread Ian Kelly
On Mon, Mar 21, 2016 at 4:25 AM, Michael Welle wrote: > Hello, > > I use a multiprocessing pool. My producer calls pool.map_async() > to fill the pool's job queue. It can do that quite fast, while the > consumer processes need much more time to empty the job queue. Since the > producer can create

Re: Convert list to another form but providing same information

2016-03-21 Thread Ian Kelly
On Mon, Mar 21, 2016 at 2:03 PM, Ben Bacarisse wrote: > For experts here: why can't I write a lambda that has a statement in it > (actually I wanted two: lambda l, i: l[i] += 1; return l)? https://docs.python.org/3/faq/design.html#why-can-t-lambda-expressions-contain-statements -- https://mail.p

Re: Convert list to another form but providing same information

2016-03-21 Thread Ian Kelly
On Mon, Mar 21, 2016 at 2:12 PM, Ian Kelly wrote: > On Mon, Mar 21, 2016 at 2:03 PM, Ben Bacarisse wrote: >> For experts here: why can't I write a lambda that has a statement in it >> (actually I wanted two: lambda l, i: l[i] += 1; return l)? > > https://docs.python.org

Re: multiprocessing, pool, queue length

2016-03-21 Thread Ian Kelly
On Mon, Mar 21, 2016 at 1:46 PM, Michael Welle wrote: > Wait on the result means to set a multiprocessing.Event if one of the > consumers finds the sentinel task and wait for it on the producer? Hmm, > that might be better than incrementing a counter. But still, it couples > the consumers and the

Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-22 Thread Ian Foote
... Regards, Ian F -- https://mail.python.org/mailman/listinfo/python-list

Re: Static caching property

2016-03-22 Thread Ian Kelly
On Mon, Mar 21, 2016 at 6:05 PM, Steven D'Aprano wrote: > On Tue, 22 Mar 2016 04:48 am, Ian Kelly wrote: > >> You don't actually need a metaclass for this: >> >>>>> class Desc: >> ... def __get__(self, obj, type=None): >> ...

Re: [OT'ish] Is there a list as good as this for Javascript

2016-03-24 Thread Ian Kelly
On Thu, Mar 24, 2016 at 4:58 PM, Mark Lawrence wrote: > No. While this idiot, BartC, is let loose on this forum, I'll say what I > like. Good to know. I've been on the fence about this for a long time, but lately the frequency of your outbursts seems to have increased, and you're being more of a

Re: I am out of trial and error again Lists

2014-10-23 Thread Ian Kelly
On Thu, Oct 23, 2014 at 1:20 AM, Mark Lawrence wrote: > If you were to read and digest what is written it would help. You're trying > to run IDLE. We're talking the interactive interpreter. IDLE includes the interactive interpreter. > If (at least on > Windows) you run a command prompt and th

Re: (test) ? a:b

2014-10-23 Thread Ian Kelly
On Thu, Oct 23, 2014 at 7:44 AM, Marko Rauhamaa wrote: > However, the "[f, g][cond]()" technique is how pure lambda calculus > implements conditional branching so it is interesting in its own right. I wasn't aware that lambda calculus had lists and indexing built in. > IOW, you can do "short-cir

Re: Truthiness

2014-10-23 Thread Ian Kelly
On Thu, Oct 23, 2014 at 8:30 AM, Simon Kennedy wrote: > Just out of academic interest, is there somewhere in the Python docs where > the following is explained? https://docs.python.org/3/reference/expressions.html#booleans 3 == True > False if 3: > print("It's Twue") > > It's

Re: I am out of trial and error again Lists

2014-10-23 Thread Ian Kelly
On Thu, Oct 23, 2014 at 11:07 AM, Seymore4Head wrote: > BTW I forgot to add that example 2 and 3 don't seem to be too useful > in Python 3, but they are in Python 2. I don't understand how the > Python 3 is an improved version. In Python 2, range returns a list containing all the requested eleme

Re: I am out of trial and error again Lists

2014-10-24 Thread Ian Kelly
On Fri, Oct 24, 2014 at 9:56 AM, Rustom Mody wrote: >> Range(10) stores the min max values and loads each number in between >> when needed. > > It loads?? As in 'load-up-a-van'?? As in loads into memory. > When you see: > 10 > 10 > > 1. Does someone (a clerk maybe) in the computer count to

Re: I am out of trial and error again Lists

2014-10-24 Thread Ian Kelly
On Fri, Oct 24, 2014 at 10:37 AM, Seymore4Head wrote: > If I could explain to you why something doesn't work then I could fix > it myself. I don't understand why it doesn't work. The best I can do > is repost the code. You don't need to be able to explain why it doesn't work. You just need to b

Re: I am out of trial and error again Lists

2014-10-24 Thread Ian Kelly
On Fri, Oct 24, 2014 at 11:03 AM, Seymore4Head wrote: > Actually I was a little frustrated when I added that line back in as > the other lines all work. > Using list(range(10)) Doesn't throw an error but it doesn't work. > > http://i.imgur.com/DTc5zoL.jpg > > The interpreter. I don't know how to

Re: (test) ? a:b

2014-10-24 Thread Ian Kelly
On Fri, Oct 24, 2014 at 7:07 AM, Steven D'Aprano >> if j < 10: >> j += 1 >> else: >> j = 3 >> >> or: >> >> j = j + 1 if j < 10 else 3 >> >> or: >> >> j = (lambda: 3, lambda: j + 1)[j < 10]() > > Certainly not the third one. That's needlessly obfuscated for the sake

Re: I am out of trial and error again Lists

2014-10-24 Thread Ian Kelly
On Fri, Oct 24, 2014 at 2:58 PM, Seymore4Head wrote: > name="123-xyz-abc" > for x in name: > if x in range(10): > print ("Range",(x)) > if x in str(range(10)): > print ("String range",(x)) > > It doesn't throw an error but it doesn't print what you would expect. That print

Re: (test) ? a:b

2014-10-25 Thread Ian Kelly
On Sat, Oct 25, 2014 at 5:58 AM, Ned Batchelder wrote: > You mention "standard Python idioms." I think this style of > conditional-via-indexing is becoming quite uncommon, and is no longer one of > the standard Python idioms. This is now in the category of "outdated hack." I think that's probab

Re: I am out of trial and error again Lists

2014-10-25 Thread Ian Kelly
On Sat, Oct 25, 2014 at 12:46 AM, Larry Hudson wrote: >> name="123-xyz-abc" >> for x in name: >> if x in range(10): > > x is a character (a one-element string). range(10) is a list of ints. A > string will never match an int. BTW, as it is used here, range(10) is for > Py2, for Py3 it need

Re: A bug?

2014-10-27 Thread Ian Kelly
On Mon, Oct 27, 2014 at 10:17 AM, Wolfgang Maier wrote: > See > https://docs.python.org/3/library/stdtypes.html?highlight=list#common-sequence-operations > under Note 2 . > > Also asked and answered multiple times at stackoverflow, e.g., > http://stackoverflow.com/questions/6688223/ Also see htt

Emulating py2exe for python version 3 and above

2014-10-29 Thread Ian Dickinson
Can i emulate py2exe for python version 3 and above i also use pygame any suggestions for a basic staring script would be greatly appreciated Thanks Ian -- https://mail.python.org/mailman/listinfo/python-list

Re: Finding way around ABCs (was What for -- for? (was A bug?))

2014-10-30 Thread Ian Kelly
On Thu, Oct 30, 2014 at 11:01 AM, Rustom Mody wrote: > On Wednesday, October 29, 2014 11:49:27 AM UTC+5:30, Zachary Ware wrote: >> On Wed, Oct 29, 2014 at 1:11 AM, Rustom Mody wrote: >> > On Wednesday, October 29, 2014 11:10:06 AM UTC+5:30, Zachary Ware wrote: >> >> Of course, that's 3 (progressiv

Re: Finding way around ABCs (was What for -- for? (was A bug?))

2014-10-30 Thread Ian Kelly
On Thu, Oct 30, 2014 at 11:09 AM, Ian Kelly wrote: > On Thu, Oct 30, 2014 at 11:01 AM, Rustom Mody wrote: >> On Wednesday, October 29, 2014 11:49:27 AM UTC+5:30, Zachary Ware wrote: >>> On Wed, Oct 29, 2014 at 1:11 AM, Rustom Mody wrote: >>> > On Wednesday, October

Re: Classes

2014-10-31 Thread Ian Kelly
On Fri, Oct 31, 2014 at 8:05 AM, Seymore4Head wrote: > Because the topic of that lesson was getter setter. > I can construct an __init___ but I was practicing get/set. Doesn't sound like a very good lesson to me. Getters and setters are the Java way of doing things. The Pythonic way is to just u

Re: Classes

2014-10-31 Thread Ian Kelly
On Fri, Oct 31, 2014 at 7:06 PM, Steven D'Aprano wrote: > And there are times when using getters and setters is the right choice. > Properties should only be used for quite lightweight calculations, because > attribute access is supposed to be fast. If your calculation is complex, > time-consuming

Re: Classes

2014-11-03 Thread Ian Kelly
On Nov 2, 2014 5:31 AM, "Denis McMahon" wrote: > And perhaps that also addresses the square - rectangle (or circle - > ellipse) issue - square, rectangle and rhombus are all forms of > quadrilateral, and perhaps should all inherit a base class Quadrilateral, > rather than trying (and partially fai

Re: Real-world use of Counter

2014-11-06 Thread Ian Kelly
On Nov 6, 2014 1:06 AM, "Rustom Mody" wrote: > In studying (somewhat theoretically) the general world of > collection data structures we see > - sets -- neither order nor repetition > - bags -- no order, repetition significant > - lists -- both order and repetition > > Sometimes 'bag' is called

Re: Python has arrived!

2014-11-06 Thread Ian Kelly
On Nov 6, 2014 10:47 PM, "Sturla Molden" wrote: > > Grant Edwards wrote: > > According to > > http://www.theregister.co.uk/2014/11/06/hackers_use_gmail_drafts_as_dead_drops_to_control_malware_bots : > > > > "Attacks occur in two phases. Hackers first infect a targeted > >machine via simple

Re: Real-world use of Counter

2014-11-06 Thread Ian Kelly
On Nov 6, 2014 10:51 AM, "Ian Kelly" wrote: > > On Nov 6, 2014 1:06 AM, "Rustom Mody" wrote: > > Calling a bag as counter is inappropriate for an analogous reason > > to why calling a dictionary as a 'hash' is inappropriate -- > > it confu

Re: functools documentation - help with funny words

2014-11-09 Thread Ian Kelly
On Sun, Nov 9, 2014 at 2:06 AM, Veek M wrote: > https://docs.python.org/3.4/library/functools.html > > 1. "A key function is a callable that accepts one argument and returns > another value indicating the position in the desired collation sequence." > > x = ['x','z','q']; sort(key=str.upper) This

Re: "Natural" use of cmp= in sort

2014-11-10 Thread Ian Kelly
On Mon, Nov 10, 2014 at 12:19 PM, Peter Otten <__pete...@web.de> wrote: > I'm not sure this works. I tried: Here's a simpler failure case. >>> ineq = """f2 > f3 ... f3 > f1""" [Previously posted code elided] >>> greater_thans set([('f3', 'f1'), ('f2', 'f3')]) >>> sorted(all_f, cmp=lambda t1, t2

Re: I don't read docs and don't know how to use Google. What does the print function do?

2014-11-10 Thread Ian Kelly
On Mon, Nov 10, 2014 at 2:45 PM, wrote: > On Monday, November 10, 2014 1:01:05 PM UTC-8, Grant Edwards wrote: >> On 2014-11-10, sohcahtoa82 wrote: >> >> > Please help me this assignment is due in an hour. Don't give me >> > hints, just give me the answer because I only want a grade. I'm not >>

Re: "Natural" use of cmp= in sort

2014-11-10 Thread Ian Kelly
t; >> The question is about merging given inequalities to make 1 inequality such >> that the inequalities also stays true. >> >> > > Thanks Peter, Ian. I have modified my code to expand transitive relations and > ask you to view it on stackoverflow via the ori

Re: [Python-Dev] Dinamically set __call__ method

2014-11-10 Thread Ian Kelly
On Sat, Nov 8, 2014 at 3:31 PM, Gregory Ewing wrote: > (BTW, I'm actually surprised that this technique makes c callable. > There must be more going on that just "look up __call__ in the class > object", because evaluating C.__call__ just returns the descriptor > and doesn't invoking the descripto

Re: "Natural" use of cmp= in sort

2014-11-11 Thread Ian Kelly
On Tue, Nov 11, 2014 at 12:44 AM, Paddy wrote: > Thanks Ian. The original author states "...and it is sure that the given > inputs will give an output, i.e., the inputs will always be valid.", which > could be taken as meaning that all inputs are sufficient, well formed,

Re: "Natural" use of cmp= in sort

2014-11-11 Thread Ian Kelly
On Tue, Nov 11, 2014 at 2:21 AM, Paddy wrote: > On Tuesday, 11 November 2014 09:07:14 UTC, Ian wrote: >> On Tue, Nov 11, 2014 at 12:44 AM, Paddy wrote: >> > Thanks Ian. The original author states "...and it is sure that the given >> > inputs will give an output,

Re: Advice

2014-11-11 Thread Ian Kelly
On Tue, Nov 11, 2014 at 9:53 AM, Mary-Frances McNamee < maryfrances.mcna...@epas-ltd.com> wrote: > > I am currently working on a bit of coding for a raspberry pi, I was wondering maybe I could get some advice? I want my program to run for a certain time, for example 7am-2.30am everyday. Is this pos

Re: [Python-Dev] Dinamically set __call__ method

2014-11-12 Thread Ian Kelly
On Wed, Nov 12, 2014 at 8:33 AM, Fabio Zadrozny wrote: > As a reference, I recently found a blog post related to that: > http://lucumr.pocoo.org/2014/8/16/the-python-i-would-like-to-see/ (the Slots > part comments on that). > > It does seem a bit counter-intuitive that this happens the way it does

Re: How about some syntactic sugar for " __name__ == '__main__' "?

2014-11-12 Thread Ian Kelly
On Wed, Nov 12, 2014 at 2:33 PM, Chris Kaynor wrote: > A decorator is an interesting idea, and should be easy to implement (only > lightly tested): > > def main(func): > if func.__module__ == "__main__": > func() > return func # The return could be omitted to block the function

Re: I love assert

2014-11-12 Thread Ian Kelly
On Wed, Nov 12, 2014 at 2:56 PM, Marko Rauhamaa wrote: > Ethan Furman : > >> On 11/12/2014 01:41 PM, Marko Rauhamaa wrote: >>> >>> Or I might indicate the exhaustion of possibilities: >>> >>> if status == OK: >>> ... >>> elif status == ERROR: >>> ... >>> else:

Re: I love assert

2014-11-12 Thread Ian Kelly
On Wed, Nov 12, 2014 at 3:04 PM, Ian Kelly wrote: > On Wed, Nov 12, 2014 at 2:56 PM, Marko Rauhamaa wrote: >> How would it be better if you removed the assert then? > > You don't need to remove it. Just reorganize it to make sure it > indicates actual exhaustion of possib

Re: How about some syntactic sugar for " __name__ == '__main__' "?

2014-11-12 Thread Ian Kelly
On Wed, Nov 12, 2014 at 3:09 PM, Chris Kaynor wrote: > I was thinking along the lines of replacing: > > if __name__ == "__main__": > <<>> > > with > > @main > def myFunction() > <<<> > > Both blocks of code will be called at the same time. 99% of the time the content of <<>> is just "main

Re: I love assert

2014-11-12 Thread Ian Kelly
On Wed, Nov 12, 2014 at 3:13 PM, Anton wrote: > On Wednesday, November 12, 2014 2:05:17 PM UTC-8, Ian wrote: >> You don't need to remove it. Just reorganize it to make sure it >> indicates actual exhaustion of possibilities. E.g. using the "assert >> False" pat

Re: I love assert

2014-11-12 Thread Ian Kelly
On Wed, Nov 12, 2014 at 3:48 PM, Anton wrote: > On Wednesday, November 12, 2014 2:42:19 PM UTC-8, Ian wrote: >> On Wed, Nov 12, 2014 at 3:13 PM, Anton wrote: >> > If the code is run optimized and asserts are ignore CONFUSED statement >> > would still not be handled

Re: I love assert

2014-11-12 Thread Ian Kelly
On Wed, Nov 12, 2014 at 3:47 PM, Marko Rauhamaa wrote: > Ian Kelly : > >> Although to be honest I'd rather use something like "raise >> RuntimeError('Unreachable code reached')" than "assert False" here. If >> the expectation is that th

Re: How about some syntactic sugar for " __name__ == '__main__' "?

2014-11-13 Thread Ian Kelly
On Thu, Nov 13, 2014 at 11:32 AM, Ethan Furman wrote: > On 11/12/2014 01:51 PM, Ian Kelly wrote: >> >> On Wed, Nov 12, 2014 at 2:33 PM, Chris Kaynor wrote: >>> >>> A decorator is an interesting idea, and should be easy to implement (only >>> lightly te

Re: How about some syntactic sugar for " __name__ == '__main__' "?

2014-11-13 Thread Ian Kelly
On Thu, Nov 13, 2014 at 1:44 PM, Skip Montanaro wrote: > On Thu, Nov 13, 2014 at 2:33 PM, Ian Kelly wrote: >> ... other things decorated with atexit.register >> might actually be called before the main function > > I don't think that will happen. The atexit module is d

Re: How about some syntactic sugar for " __name__ == '__main__' "?

2014-11-13 Thread Ian Kelly
On Thu, Nov 13, 2014 at 1:53 PM, Skip Montanaro wrote: > On Thu, Nov 13, 2014 at 2:44 PM, Skip Montanaro > wrote: >> What's not documented is >> the behavior of calling atexit.register() while atexit._run_exitfuncs >> is running. That's an implementation detail, and though unlikely to >> change,

Re: fileno() not supported in Python 3.1

2014-11-14 Thread Ian Kelly
On Fri, Nov 14, 2014 at 12:36 AM, Cameron Simpson wrote: > On 13Nov2014 15:48, satishmlm...@gmail.com wrote: >> >> import sys >> for stream in (sys.stdin, sys.stdout, sys.stderr): >> print(stream.fileno()) >> >> >> io.UnsupportedOperation: fileno >> >> Is there a workaround? > > > The f

Re: I love assert

2014-11-14 Thread Ian Kelly
On Fri, Nov 14, 2014 at 4:37 AM, Steven D'Aprano wrote: > Ethan Furman wrote: > >>> There's no way to make the CONFUSED status be handled without actually >>> changing the code. The difference is that this version will not >>> incorrectly treat CONFUSED as WARNING; it just won't do anything at >>>

Re: Array of Functions

2014-11-14 Thread Ian Kelly
On Fri, Nov 14, 2014 at 3:17 PM, Richard Riehle wrote: > In C, C++, Ada, and functional languages, I can create an array of functions, > albeit with the nastiness of pointers in the C family. For example, an > array of functions where each function is an active button, or an array of > functi

Re: Strange result with timeit execution time measurment

2014-11-15 Thread Ian Kelly
On Sat, Nov 15, 2014 at 10:07 AM, ast wrote: > Hi > > I needed a function f(x) which looks like sinus(2pi.x) but faster. > I wrote this one: > > -- > from math import floor > > def sinusLite(x): >x = x - floor(x) >return -16*(x-0.25)**2 + 1 if x < 0.5 else 16*(x-0.7

Re: How about some syntactic sugar for " __name__ == '__main__' "?

2014-11-16 Thread Ian Kelly
On Sun, Nov 16, 2014 at 3:39 AM, Vito De Tullio wrote: > for the "right time" you can choose to spin a thread and wait to the end of > the load of the module Yuck. "Just add threads" is /not/ the answer to everything. This case looks fairly harmless on the surface, although I could imagine it br

Re: import math error

2014-11-16 Thread Ian Kelly
On Sun, Nov 16, 2014 at 1:07 PM, ryguy7272 wrote: > When I type 'import math', it seems like my Python recognizes this library. > Great. When I try to run the following script, I get an error, which > suggests (to me) the math library is not working correctly. > > Script: > import math > def m

Re: How modules work in Python

2014-11-16 Thread Ian Kelly
On Sun, Nov 16, 2014 at 12:36 PM, Abdul Abdul wrote: > My question is, where did PIL go here? Can a module have another module > inside it? Yes, a module that contains other modules is usually called a package. -- https://mail.python.org/mailman/listinfo/python-list

Re: What does this line of code mean?

2014-11-16 Thread Ian Kelly
On Sun, Nov 16, 2014 at 2:45 PM, Abdul Abdul wrote: > I just came across the following line of code: > > outputfile = os.path.splitext(infile)[0] + ".jpg" > > Can you kindly explain to me what those parts mean? >>> import os.path >>> help(os.path.splitext) Help on function splitext in module ntpa

Re: How to fix those errors?

2014-11-16 Thread Ian Kelly
On Sun, Nov 16, 2014 at 2:32 PM, Abdul Abdul wrote: > Hello, > > I'm walking through an example that goes as follows: > > from PIL import Image > import os > > for inputfile in filelist > outputfile = os.path.splitext(inputfile)[0]+".jpg" > if inputfile != outputfile: > try: >

Re: Using map()

2014-11-16 Thread Ian Kelly
On Sun, Nov 16, 2014 at 4:22 PM, Terry Reedy wrote: > If pylint sees 'map(lambda ...: ', it would be appropriate to suggest using > a comprehension or generator expression instead. This avoids the unneeded > creation and repeated call of a new function. There's actually a separate warning for th

Re: import graphics library; causes error

2014-11-16 Thread Ian Kelly
On Sun, Nov 16, 2014 at 1:39 PM, ryguy7272 wrote: > Anyway, I open the cmd window, and typed this: 'easy_install python > graphics'. So, it starts up and runs/downloads the appropriate library from > the web. I get confirmation (in the cmd window) that it finishes, then I try > to run this sc

Re: caught in the import web again

2014-11-17 Thread Ian Kelly
On Mon, Nov 17, 2014 at 3:17 PM, Dave Angel wrote: > "Charles T. Smith" Wrote in message: > >> Well, I guess that's the definitive answer... the tips for delaying >> import are good, I'll try to leverage them. >> >> I was hoping there would be a way to have python postpone evaluation >> similar t

Re: caught in the import web again

2014-11-18 Thread Ian Kelly
On Mon, Nov 17, 2014 at 6:20 PM, Dave Angel wrote: > Ian Kelly Wrote in message: >> On Mon, Nov 17, 2014 at 3:17 PM, Dave Angel wrote: > >>> In a module that might get tangled in a cycle, avoid global code >>> that depends on other modules. Instead of putting s

Re: python 2.7 and unicode (one more time)

2014-11-20 Thread Ian Kelly
On Thu, Nov 20, 2014 at 10:42 AM, wrote: > and it means you can't safely > blindly use %s with an unknown object. You can't safely do this anyway. Whether it's %s with a str and a unicode, or %s with a unicode and a str, *something* is going to have to be implicitly encoded or decoded, and if as

Re: python 2.7 and unicode (one more time)

2014-11-20 Thread Ian Kelly
On Thu, Nov 20, 2014 at 11:06 AM, Ian Kelly wrote: > On Thu, Nov 20, 2014 at 10:42 AM, wrote: >> and it means you can't safely >> blindly use %s with an unknown object. > > You can't safely do this anyway. Whether it's %s with a str and a > unicode, or

Re: Working with HTML5 documents

2014-11-20 Thread Ian Kelly
On Thu, Nov 20, 2014 at 12:02 PM, Stefan Behnel wrote: > There's also the E-factory for creating (sub-)trees and a nicely objectish > way: > > http://lxml.de/lxmlhtml.html#creating-html-with-the-e-factory That looks ugly with all those caps and also hard to extend. Notably it seems to be missing

Re: Help with an 8th grade science project

2014-11-20 Thread Ian Kelly
On Thu, Nov 20, 2014 at 1:13 PM, Dave Angel wrote: > dave em Wrote in message: >> 1. In the factorial() function we call the CPU_Percent() function and write >> the CPU utilization value to a file. >> - Is this a correct value or will the CPU utilization below lower because >> the factorial()

Re: Working with HTML5 documents

2014-11-20 Thread Ian Kelly
On Thu, Nov 20, 2014 at 1:10 PM, Stefan Behnel wrote: > Ian Kelly schrieb am 20.11.2014 um 20:44: >> On Thu, Nov 20, 2014 at 12:02 PM, Stefan Behnel wrote: >>> There's also the E-factory for creating (sub-)trees and a nicely objectish >>> way: >>> >&

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

2014-11-21 Thread Ian Kelly
On Thu, Nov 20, 2014 at 8:53 PM, Rick Johnson wrote: > FOR INSTANCE: Let's say i write a module that presents a > reusable GUI calendar widget, and then i name the module > "calender.py". > > Then Later, when i try to import *MY* GUI widget named > "calendar", i will not get *MY* calendar widget,

Re: Infinitely nested containers

2014-11-21 Thread Ian Kelly
On Thu, Nov 20, 2014 at 10:54 PM, Gill Shen wrote: > How is this behavior implemented under the hood? And why is this allowed at > all? Is it just a curiosity or can you do something useful with it? Reference cycles are common in Python and other OO languages. For example, adding a widget to a w

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

2014-11-21 Thread Ian Kelly
On Fri, Nov 21, 2014 at 9:12 AM, Tim Chase wrote: > The only time I've been stung by name overloading is in the indirect > case of creating a local email.py file and then importing smtplib > only to have things break in unforeseen ways. If smtplib used > relative imports for $STDLIB/email.py I su

Re: Infinitely nested containers

2014-11-21 Thread Ian Kelly
On Fri, Nov 21, 2014 at 10:39 AM, wrote: > On Fri, Nov 21, 2014, at 02:00, Marko Rauhamaa wrote: >> Gill Shen : >> >> > How is this [nesting] behavior implemented under the hood? >> >> Pointers. >> >> > And why is this allowed at all? >> >> There's no reason not to. > > There's no reason not to a

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

2014-11-21 Thread Ian Kelly
On Fri, Nov 21, 2014 at 11:24 AM, Rick Johnson wrote: > Are you also going to call drivers "fools" because they bought > a "certain brand" of car only to have the airbag explode in > their face? No, but I'll call them fools if they buy a car and the engine catches fire because they never bothered

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

2014-11-21 Thread Ian Kelly
On Fri, Nov 21, 2014 at 3:25 PM, Rick Johnson wrote: >> The only exception is if you're doing "import calendar" from inside >> the ricklib package, and you're using Python 2, and you don't have >> "from __future__ import absolute_import" at the top of your module. >> The solution to this is easy:

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

2014-11-22 Thread Ian Kelly
On Fri, Nov 21, 2014 at 6:07 PM, Rick Johnson wrote: > On Friday, November 21, 2014 5:59:44 PM UTC-6, Chris Angelico wrote: >> In other words, what you want is: >> >> # today's method, import based on search path >> import sys >> # new explicit path method >> import '/usr/local/lib/python3.5/lib-d

Re: unloading a module created with imp.new_module

2014-11-23 Thread Ian Kelly
On Sat, Nov 22, 2014 at 11:49 PM, Patrick Stinson wrote: > If I create a module with imp.new_module(name), how can I unload it so that > all the references contained in it are set to zero and the module is deleted? > deleting the reference that is returned doesn’t seem to do the job, and it’s >

Re: unloading a module created with imp.new_module

2014-11-23 Thread Ian Kelly
On Sun, Nov 23, 2014 at 2:48 AM, Ian Kelly wrote: > On Sat, Nov 22, 2014 at 11:49 PM, Patrick Stinson > wrote: >> If I create a module with imp.new_module(name), how can I unload it so that >> all the references contained in it are set to zero and the module is >&g

Re: unloading a module created with imp.new_module

2014-11-23 Thread Ian Kelly
On Nov 23, 2014 4:10 AM, "Patrick Stinson" wrote: > m = types.ModuleType('mine') > exec(s, m.__dict__) > print('deleting...') > m = None > print('done') > > and the output is: > > deleting... > done > __del__ > > I the “__del__" to come between “deleting…” and “done”. This is not being run from th

Re: unloading a module created with imp.new_module

2014-11-24 Thread Ian Kelly
On Nov 24, 2014 1:27 AM, "Patrick Stinson" wrote: > > How does the __del__ method have a reference to the module’s globals dict? because it references the print function? The module's dict becomes the __globals__ dict used by the function for looking up globals and builtins. > Crazy. Is there an

Re: GUI toolkit(s) status

2014-11-24 Thread Ian Kelly
On Nov 21, 2014 10:09 PM, "Michael Torrie" wrote: > I can't speak for wxWidgets, but when I last looked at it years ago it > fairly reeked of MFC-style GUI programming with event tables instead of > a nice, flexible signal/callback interface. Has this changed? I recall the C++ implementation use

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

2014-11-24 Thread Ian Kelly
On Nov 23, 2014 4:41 PM, "Gregory Ewing" wrote: > > Chris Angelico wrote: >> >> Just out of curiosity, why does the stdlib need modules for >> manipulating .wav and other sound files, but we have to go to PyPI to >> get a PostgreSQL client? > > > I suspect it's mainly for historical reasons. The w

Re: Db transactions and locking

2014-11-27 Thread Ian Kelly
On Nov 27, 2014 4:26 AM, "Frank Millman" wrote: > All Python database adaptors that I have used start a transaction when you > open a cursor. I have just re-read DB-API 2.0, and I cannot see anything > that specifies this behaviour, but AFAICT this is what happens. I don't know how others work, b

Re: Db transactions and locking

2014-11-28 Thread Ian Kelly
On Nov 27, 2014 4:39 PM, "Chris Angelico" wrote: > > On Fri, Nov 28, 2014 at 5:02 AM, Ian Kelly wrote: > > On Nov 27, 2014 4:26 AM, "Frank Millman" wrote: > >> All Python database adaptors that I have used start a transaction when you > >> op

Re: Setting default_factory of defaultdict to key

2014-12-01 Thread Ian Kelly
On Mon, Dec 1, 2014 at 11:05 AM, Larry Martell wrote: > Is there a way to set the default_factory of defaultdict so that > accesses to undefined keys get to set to the key? > > i.e. if d['xxx'] were accessed and there was no key 'xxx' then > d['xxx'] would get set to 'xxx' > > I know I can define

Re: Setting default_factory of defaultdict to key

2014-12-01 Thread Ian Kelly
On Mon, Dec 1, 2014 at 11:29 AM, Larry Martell wrote: > I spoke too soon: > class defaultdictkey(defaultdict): > ... def __missing__(self, key): > ... self[key] = self.default_factory(key) > ... x = defaultdictkey(lambda k: k) print x['aaa'] > None print x['aaa'] > aaa

Re: Style question: Importing modules from packages - 'from' vs 'as'

2014-12-03 Thread Ian Kelly
On Dec 3, 2014 4:34 AM, "Chris Angelico" wrote: > > On Wed, Dec 3, 2014 at 10:27 PM, Peter Otten <__pete...@web.de> wrote: > > Don't repeat yourself, so > > > > from os import path > > > > always. On the other hand I have never thought about actual renames, e. g. > > > > from os import path as std

Re: PyEval_GetLocals and unreferenced variables

2014-12-04 Thread Ian Kelly
On Wed, Dec 3, 2014 at 5:28 AM, Gregory Ewing wrote: > > Kasper Peeters wrote: >> >> That may have been the design plan, but in Python 2.7.6, I definitely >> am able to inject locals via PyEval_GetLocals() and have them be visible >> both from the C and Python side; > > What seems to be happening

Re: time.monotonic() roll over

2014-12-04 Thread Ian Kelly
On Dec 4, 2014 8:56 AM, "Marko Rauhamaa" wrote: > > "ast" : > > > Does any body know when time.monotonic() rolls over ? > > Never, according to the documentation you linked. > > Admittedly, the documentation confuses the reader by chatting about some > irrelevant internal Windows details. Not ent

Re: time.monotonic() roll over

2014-12-04 Thread Ian Kelly
On Thu, Dec 4, 2014 at 11:09 AM, Marko Rauhamaa wrote: > > Chris Angelico : > > > It's not a Python issue. Python can't do anything more than ask the > > system, and if the system's value rolls over several times a year, > > Python can't magically cure that. The information has already been > > lo

Re: About Modifying Globals

2014-12-04 Thread Ian Kelly
On Thu, Dec 4, 2014 at 1:09 PM, LJ wrote: > > Hi All, > > I have a quick question regarding the modification of global variables within functions. To illustrate, consider the following toy example: > > a={"1": set()} > b=9 > > def gt(l): >a["1"] = a["1"] | set([l]) > > When calling this last f

Re: time.monotonic() roll over

2014-12-04 Thread Ian Kelly
On Thu, Dec 4, 2014 at 1:24 PM, Akira Li <4kir4...@gmail.com> wrote: > > Ian Kelly writes: > > This seems like a lot of effort to unreliably design around a problem that > > will matter to only a tiny fraction of users. > > - people's computers are mo

Re: time.monotonic() roll over

2014-12-05 Thread Ian Kelly
On Thu, Dec 4, 2014 at 3:44 PM, Marko Rauhamaa wrote: > > Ian Kelly : > > > It's not clear to me whether those cases are relevant to the rollover > > concern anyway. I wouldn't be shocked if the GetTickCount() function > > simply stopped increasing while

Re: concat string and dict in print statement

2014-12-05 Thread Ian Kelly
On Fri, Dec 5, 2014 at 10:31 AM, wrote: > > Hi Guys, > > I am trying to combine string and dict in the print statement, however getting an error. Would someone let me know what will be correct way to do that. > > stats={'lname': 'shah', 'fname': 'gaurang'} > a=test > > print "%s %(fname)s %(lname)

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

2014-12-05 Thread Ian Kelly
On Fri, Dec 5, 2014 at 10:40 AM, Aahan Krish wrote: > Q2. PEP 8 also reads, "Python 3 disallows mixing the use of tabs and spaces for indentation." > > So, if I am using tabs for indentation and spaces for alignment, is it still considered "mixing the use of tabs and spaces" in Python 3? (Please s

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

2014-12-05 Thread Ian Kelly
On Fri, Dec 5, 2014 at 11:49 AM, Aahan Krish wrote: > > Hello Ian, > > So, wrt Q2, what you are saying is, the following would cause issues in Python 3? > > int f(int x, > ..int y) { > --->return g(x, > --->.y); > } &g

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

2014-12-05 Thread Ian Kelly
On Fri, Dec 5, 2014 at 4:30 AM, Fetchinson . wrote: > > The formatting of long text essays get completely mangled towards the > > bottom > > of the page, e.g.: > > > > https://www.python.org/download/releases/2.2/descrintro > > It doesn't look mangled to me (firefox 22). That's quite old at this

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

2014-12-05 Thread Ian Kelly
On Fri, Dec 5, 2014 at 3:43 AM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > It requires Javascript or else basic functionality fails. In what way does basic functionality fail? I just tried loading the page with Javascript disabled and it seemed fine. > With Javascript, > bas

Re: Setting default_factory of defaultdict to key

2014-12-07 Thread Ian Kelly
On Dec 7, 2014 9:33 AM, "Dave Angel" wrote: > > On 12/05/2014 03:51 PM, John J Posner wrote: >> >> At the beginning of this thread, Ian Kelly said: > > > Since this clearly is intended to be part of the earlier thread, please make it so by using reply-l

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

2014-12-07 Thread Ian Kelly
On Dec 7, 2014 8:31 AM, "Ned Batchelder" wrote: > NOTE: THIS EXAMPLE IS HORRIBLE. This code is crazy-confusing, and should never have been used as an example of iteration. It layers at least three iterations on top of each other, making it very difficult to see what is going on. It uses "while i

Re: module import questions and question about pytest and module imports

2014-12-08 Thread Ian Kelly
On Sun, Dec 7, 2014 at 9:50 AM, sam pendleton wrote: > Having to put the garage package on the sys.path seems a little off, > why wouldn't relative imports work? Relative imports are relative to a package's hierarchy of namespaces, not relative to the file system. As such, you can't perform a rel

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

2014-12-09 Thread Ian Kelly
On Fri, Dec 5, 2014 at 4:30 AM, Fetchinson . wrote: > > Many links are broken. When you click on the broken link, it says that it > > has been reported and will be fixed, but weeks later it remains broken, > > e.g.: > > > > https://www.python.org/doc/essays/metaclasses/Eiffel.py > > What makes you

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

2014-12-09 Thread Ian Kelly
On Tue, Dec 9, 2014 at 11:30 PM, Chris Angelico wrote: > Are you sure it isn't? Your 'space' is an iterable cubic > cross-product. Your first loop checks (0,0,0) which is the first > element returned, and is thus fast... but it also *consumes* that > first element. The next time you test it, the e

<    16   17   18   19   20   21   22   23   24   25   >