Re: Question about asyncio and blocking operations

2016-01-28 Thread Ian Kelly
On Jan 28, 2016 3:07 PM, "Maxime Steisel" wrote: > > But it is a pretty strange idea to call two fetch*() method concurrently anyways. If you want to process rows concurrently and aren't concerned with processing them in order, it may be attractive to create multiple threads / coroutines, pass th

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Ian Kelly
On Jan 29, 2016 11:04 PM, "Frank Millman" wrote: > > Hi all > > To loop though an iterator one usually uses a higher-level construct such as a 'for' loop. However, if you want to step through it manually you can do so with next(iter). > > I expected the same functionality with the new 'asynchronou

Re: The computer that mastered Go

2016-01-30 Thread Ian Kelly
On Fri, Jan 29, 2016 at 1:38 PM, mm0fmf via Python-list wrote: > On 29/01/2016 19:46, Seymore4Head wrote: >> >> https://www.youtube.com/watch?v=g-dKXOlsf98 >> > > Is it written in Python? Given the game, and the fact that it's Google, I would be very disappointed if it's not written in Go. -- ht

Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Ian Kelly
On Jan 30, 2016 7:13 AM, "Oscar Benjamin" wrote: > > I haven't used PEP 492 yet but what about: > > async def aslice(asynciterator, end): > if end == 0: > return [] >items = [] >async for item in asynciterator: >items.append(item) >if len(items) == end: >

Re: eval( 'import math' )

2016-02-04 Thread Ian Kelly
On Thu, Feb 4, 2016 at 6:33 AM, 阎兆珣 wrote: >Excuse me for the same problem in Python 3.4.2-32bit > >I just discovered that function does not necessarily take the >string input and transfer it to a command to execute. > >So is there a problem with my assumption? eval evaluates an

Re: Multiprocess videoplayer

2016-02-04 Thread Ian Kelly
On Thu, Feb 4, 2016 at 2:45 AM, wrote: > I have coded a program with python and vlc that plays some videos, but > whenever I try to play 3 videos at once, Windows closes the program, I'm > guessing that the reason is that one process can't play 3 videos at once (but > I don't really know). My

Re: Daemon strategy

2016-02-05 Thread Ian Kelly
On Fri, Feb 5, 2016 at 4:10 PM, Ben Finney wrote: > Sorry to learn that. The PyPI metadata for ‘python-daemon’ > https://pypi.python.org/pypi/python-daemon/> explicitly declares > the supported OS limited to “Operating System :: POSIX”, which MS > Windows is not compatible with. Depends on the ve

Re: Daemon strategy

2016-02-06 Thread Ian Kelly
On Sat, Feb 6, 2016 at 1:15 AM, Ben Finney wrote: > Ian Kelly writes: > >> Depends on the version: >> https://en.wikipedia.org/wiki/Windows_Services_for_UNIX >> https://en.wikipedia.org/wiki/POSIX#POSIX_for_Windows >> >> Linux and FreeBSD are also not POSIX-c

Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO

2016-02-08 Thread Ian Kelly
On Sat, Feb 6, 2016 at 1:54 PM, Rick Johnson wrote: > On Wednesday, February 3, 2016 at 12:02:35 AM UTC-6, John Ladasky wrote: > >> Rick, you don't like Python? > > If i didn't like Python, then i would happily let it self- > destruct, yes? The problem is, i *DO* like Python. Python2 > was a great

Re: Set Operations on Dicts

2016-02-08 Thread Ian Kelly
On Mon, Feb 8, 2016 at 5:47 AM, Grobu wrote: > You can use dictionary comprehension : > > Say : > dict1 = {'a': 123, 'b': 456} > set1 = {'a'} > > intersection : { key:dict1[key] for key in dict1 if key in set1 } > {'a': 123} > > difference : { key:dict1[key] for key in dict1 if not key i

Re: A question about imports in wxpython

2016-02-08 Thread Ian Kelly
On Mon, Feb 8, 2016 at 8:44 AM, wrote: > I'm playing with some code that uses the wxpython grid. *Every* > example I have seen starts with the imports:- > > import wx > import wx.grid as Gridlib > > As Gridlib is exactly the same number of characters as wx.grid I > really don't see the p

Re: Confused by wxpython documentation

2016-02-08 Thread Ian Kelly
On Mon, Feb 8, 2016 at 8:36 AM, wrote: > I'm playing around with some existing code that uses wxpython. I've > been trying to understand a basic bit about the import statement and > so went to the beginning of the wxPython on line documents. > > Going from the top to the "Hello World Example" (c

Re: coroutine, throw, yield, call-stack and exception handling

2016-02-08 Thread Ian Kelly
On Mon, Feb 8, 2016 at 2:17 AM, Veek. M wrote: > > Exceptions can be raised inside a coroutine using the throw( > > Exceptions raised in this manner will originate at the currently > executing yield state-ment in the coroutine.A coroutine can elect to > catch exception

Re: Set Operations on Dicts

2016-02-09 Thread Ian Kelly
On Tue, Feb 9, 2016 at 12:21 AM, Grobu wrote: > On 08/02/16 17:12, Ian Kelly wrote: > >> dict does already expose set-like views. How about: >> >> {k: d[k] for k in d.keys() & s} # d & s >> {k: d[k] for k in d.keys() - s} # d - s >> > Inte

Re: ImportError: cannot import name 'RAND_egd'

2016-02-09 Thread Ian Kelly
On Tue, Feb 9, 2016 at 7:55 AM, wrote: > Hi, > > I am trying to run a 60 lines Python code which is running on a mac machine > but on windows machine, I am getting this error when I run on it on > shell(open file and run module). I have Python 3.5 installed. > >from _ssl import RAND_status,

Re: Copying void * string to

2016-02-10 Thread Ian Kelly
On Wed, Feb 10, 2016 at 5:07 AM, Martin Phillips wrote: > I am writing a Python wrapper to go around a C library. I have encountered a > problem that I have been unable to resolve with > countless web searches. > > > > Several functions in the C library return pointers to dynamically allocated >

Re: Passing data across callbacks in ThreadPoolExecutor

2016-02-17 Thread Ian Kelly
On Tue, Feb 16, 2016 at 2:48 PM, Joseph L. Casale wrote: > What is the pattern for chaining execution of tasks with ThreadPoolExecutor? > Callbacks is not an adequate facility as each task I have will generate new > output. Can you specify in more detail what your use case is? If you don't mind

Re: Passing data across callbacks in ThreadPoolExecutor

2016-02-18 Thread Ian Kelly
On Thu, Feb 18, 2016 at 12:06 PM, Joseph L. Casale wrote: > On Thur, Feb 17, 2016 at 9:24 AM, Ian Kelly wrote: >>> What is the pattern for chaining execution of tasks with ThreadPoolExecutor? >>> Callbacks is not an adequate facility as each task I have will generate new

Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO

2016-02-18 Thread Ian Kelly
On Mon, Feb 15, 2016 at 7:02 PM, Rick Johnson wrote: > WxPython is not ported either, much to my chagrin. If wxPython "Classic" had just been ported to Python 3, I'm sure it would be all done by now. But it was decided to rebuild wxPython from the ground up instead. Last I've heard, people gener

Re: Passing data across callbacks in ThreadPoolExecutor

2016-02-19 Thread Ian Kelly
On Fri, Feb 19, 2016 at 10:18 AM, Joseph L. Casale wrote: >> It's still not clear to me specifically what you're trying to do. It >> would really help if you would describe the problem in more detail. >> Here's what I think you're trying to do: >> >> 1) Submit a task to a ThreadPoolExecutor and ge

Re: How to properly override the default factory of defaultdict?

2016-02-19 Thread Ian Kelly
On Thu, Feb 18, 2016 at 10:41 AM, Herman wrote: > From: Ben Finney >> >> you are using the inheritance hierarchy but thwarting it by not using >> ‘super’. Instead:: >> >> super().__init__(self, default_factory, *a, **kw) >> >> and:: >> >> super().__getitem__(self, key) >> -- >> \ "

Re: How the heck does async/await work in Python 3.5

2016-02-19 Thread Ian Kelly
On Fri, Feb 19, 2016 at 10:24 PM, Rustom Mody wrote: > Less snarkily looks like a series of bolt-ons after bolt-ons > > IMHO Guido's (otherwise) uncannily sound intuitions have been wrong right from > 2001 when he overloaded def for generators. > And after that its been slippery-slope down: reusin

Re: How the heck does async/await work in Python 3.5

2016-02-20 Thread Ian Kelly
On Sat, Feb 20, 2016 at 12:57 AM, Chris Angelico wrote: > On Sat, Feb 20, 2016 at 6:48 PM, Ian Kelly wrote: >> As another point that happens to be fresh in my mind, awaiting a >> Future on which an exception gets set is supposed to propagate the >> exception. I recently foun

Re: How the heck does async/await work in Python 3.5

2016-02-20 Thread Ian Kelly
On Sat, Feb 20, 2016 at 1:49 AM, Chris Angelico wrote: > Definitely seems like it should be fixed, then; the current behaviour > is that Future.result() raises RuntimeError if you raise > StopIteration, so having await do the same would make sense. Future.result() itself simply raises the StopIte

Re: How the heck does async/await work in Python 3.5

2016-02-20 Thread Ian Kelly
On Sat, Feb 20, 2016 at 1:49 AM, Chris Angelico wrote: > Actually, that mightn't be a bad thing. Maybe raise that as a tracker > issue? I just tested, and slapping "from __future__ import > generator_stop" at the top of Lib/asyncio/futures.py causes your > example to raise an exception instead of

Re: can try expect have if else.

2016-02-21 Thread Ian Kelly
On Feb 21, 2016 9:13 AM, "Ganesh Pal" wrote: > > Hi Team, > > Iam on python 2.6 , need input on the below piece of code. Python 2.6 isn't supported and hasn't been since October 2013. Is there something preventing you from upgrading to 2.7? > EXIT_STATUS_ERROR=1 > > def create_dataset(): > "

Re: avoid for loop calling Generator function

2016-02-22 Thread Ian Kelly
On Mon, Feb 22, 2016 at 8:38 AM, Arshpreet Singh wrote: > On Monday, 22 February 2016 19:05:24 UTC+5:30, Peter Otten wrote: >> or the slightly less convoluted >> >> sys.stdout.writelines(map("{}\n".format, read_pdf("book.pdf"))) > > Actually I am using this function in Android App which is being

Re: How the heck does async/await work in Python 3.5

2016-02-22 Thread Ian Kelly
On Mon, Feb 22, 2016 at 3:16 PM, Sven R. Kunze wrote: > Is something like shown in 12:50 ( cout << tcp_reader(1000).get() ) possible > with asyncio? (tcp_reader would be async def) loop = asyncio.get_event_loop() print(loop.run_until_complete(tcp_reader(1000))) -- https://mail.python.org/mailman

Re: How the heck does async/await work in Python 3.5

2016-02-23 Thread Ian Kelly
On Tue, Feb 23, 2016 at 9:50 AM, Sven R. Kunze wrote: > On 23.02.2016 01:48, Ian Kelly wrote: >> >> On Mon, Feb 22, 2016 at 3:16 PM, Sven R. Kunze wrote: >>> >>> Is something like shown in 12:50 ( cout << tcp_reader(1000).get() ) >>> possible

Re: How to define what a class is ?

2016-02-24 Thread Ian Kelly
On Wed, Feb 24, 2016 at 1:08 AM, ast wrote: > Hi > > Since a class is an object, I ask myself how to define rigorously what a > class is. > > classes are instances from type, but not all, since > a class may be an instance of a metaclass All metaclasses are subclasses of type, so all classes are

Re: [Python-ideas] How the heck does async/await work in Python 3.5

2016-02-24 Thread Ian Kelly
On Wed, Feb 24, 2016 at 8:23 AM, Marko Rauhamaa wrote: > Tem Pl : > >> Here are some concurrency benchmarks for python vs other languages. >> >> https://github.com/atemerev/skynet/pull/53 >> >> Is there something wrong with this implementation? > > It's a "fork bomb". Isn't that the point of the

Re: [Python-ideas] How the heck does async/await work in Python 3.5

2016-02-24 Thread Ian Kelly
On Wed, Feb 24, 2016 at 9:13 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> On Wed, Feb 24, 2016 at 8:23 AM, Marko Rauhamaa wrote: >>> Tem Pl : >>>> Is there something wrong with this implementation? >>> >>> It's a "fork bomb". >

Re: "from module import data; print(data)" vs "import module; print(module.data)"

2016-02-25 Thread Ian Kelly
On Thu, Feb 25, 2016 at 5:40 PM, Steven D'Aprano wrote: > If you take "Special cases are not special enough" seriously, you will not > use `import os.path` since os is not a package: > > py> os.__package__ > '' > > and os.path is not part of os, it's just a publicly exposed attribute which > merel

Re: Bug in Python?

2016-02-26 Thread Ian Kelly
On Fri, Feb 26, 2016 at 3:08 PM, Sven R. Kunze wrote: > Python sometimes seems not to hop back and forth between C and Python code. C code as a rule tends to ignore dunder methods. Those are used to implement Python operations, not C operations. > _siftup(heap, 0)# that's C Your com

Re: Reason for not allowing import twice but allowing reload()

2016-02-28 Thread Ian Kelly
On Sun, Feb 28, 2016 at 11:40 PM, wrote: > Hello list, > > We can not import a module twice in a session of Python (subsequent attempts > to import same module don't result in any error though, but it is > not-effective). > > However after making change to module, we can reload() it (if not rel

Re: General computer language, syntax question.

2016-02-29 Thread Ian Kelly
On Feb 29, 2016 7:11 AM, wrote: > > Sorry but would not if (array==empty) suffice and be alot clearer? In Python, you can just do "if len(array) == 0" or "if not array". In JavaScript you have "if (array.length === 0)". Is there some problem with that? I would prefer this over your suggestion s

Re: common mistakes in this simple program

2016-02-29 Thread Ian Kelly
On Mon, Feb 29, 2016 at 8:18 AM, Ganesh Pal wrote: > Iam on python 2.6 Python 2.6 has been unsupported since October 2013. Among other things, that means it is no longer receiving security updates like more recent versions. Unless you have an extremely strong reason for wanting to stay to Python

Re: Dynamic object attribute creation

2016-02-29 Thread Ian Kelly
On Mon, Feb 29, 2016 at 9:06 AM, Random832 wrote: > On Mon, Feb 29, 2016, at 10:36, ast wrote: >> but why doesn't it work with built-in classes int, float, list ? >> >> L = [1, 8, 0] >> L.test = 'its a list !' >> >> (however lists are mutable, int, float ... are not) > > Because those classes

Re: [Off-topic] Requests author discusses MentalHealthError exception

2016-02-29 Thread Ian Kelly
On Mon, Feb 29, 2016 at 9:21 AM, Larry Martell wrote: > On Sat, Feb 27, 2016 at 4:37 AM, Steven D'Aprano wrote: >> The author of Requests, Kenneth Reitz, discusses his recent recovery from a >> MentalHealthError exception. >> >> http://www.kennethreitz.org/essays/mentalhealtherror-an-exception-oc

Re: common mistakes in this simple program

2016-02-29 Thread Ian Kelly
On Mon, Feb 29, 2016 at 10:26 AM, Ganesh Pal wrote: > On Mon, Feb 29, 2016 at 9:59 PM, Ian Kelly wrote: >> On Mon, Feb 29, 2016 at 8:18 AM, Ganesh Pal wrote: >>> Iam on python 2.6 > >>> 1. usage of try- expect >> >> try-except in every single funct

Re: Loop awareness

2016-02-29 Thread Ian Kelly
On Mon, Feb 29, 2016 at 1:07 PM, wrote: > This program creates a uniform linktree of x nodes, and it knows when it get > stuck in a loop generating random values. > > Because the networks random generated, only a subset of the permutations will > generate a uniform network most get stuck in loo

Re: common mistakes in this simple program

2016-02-29 Thread Ian Kelly
On Mon, Feb 29, 2016 at 4:14 PM, Cameron Simpson wrote: > Another remark here: if you're going to log, log the exception as well: > > logging.error("something went wrong: %s", e) > > Ian's example code is nice and simple to illustrate "log and then reraise" > but few things are as annoying as

Re: Condition fullfilled to early but only "sometimes"

2016-02-29 Thread Ian Kelly
It's not at all clear what the problem is from your description. What is it that you expect the code to do? What is it doing instead that violates your expectation? Why are you asking for Javascript help on a Python mailing list? On Mon, Feb 29, 2016 at 10:40 PM, wrote: > I've been looking at th

Re: Reason for not allowing import twice but allowing reload()

2016-03-01 Thread Ian Kelly
On Mar 1, 2016 4:41 AM, "Chris Angelico" wrote: > > On Tue, Mar 1, 2016 at 10:18 PM, Steven D'Aprano wrote: > > I cannot imagine why you would want to reload() in production code. That > > would imply that your production code is modifying already-imported > > modules, then wanting to import them

Re: Reason for not allowing import twice but allowing reload()

2016-03-01 Thread Ian Kelly
On Tue, Mar 1, 2016 at 3:02 PM, Chris Angelico wrote: > On Wed, Mar 2, 2016 at 8:53 AM, Ian Kelly wrote: >> I have a hard time understanding the appeal of super-long uptimes. I'm not >> even comfortable running a single kernel version that long. What's so awful >&g

Re: Reason for not allowing import twice but allowing reload()

2016-03-01 Thread Ian Kelly
On Tue, Mar 1, 2016 at 6:19 PM, Steven D'Aprano wrote: > On Wed, 2 Mar 2016 09:29 am, Ian Kelly wrote: > >> There's a big difference between >> that and clocking a year of uptime just because you can, though. > > What other reason is there for having a year

Re: Explaining names vs variables in Python

2016-03-02 Thread Ian Kelly
On Wed, Mar 2, 2016 at 2:35 AM, Jussi Piitulainen wrote: > The following are too delicate for me. I suppose the answers could have > been different, but I can't guess what mechanism actually leads to these > results. Just idle curiosity on my part. > 890 is 890 > True id(890) == id(890)

Re: What arguments are passed to the __new__ method ?

2016-03-02 Thread Ian Kelly
On Wed, Mar 2, 2016 at 10:57 AM, Rob Gaddi wrote: > Peter Pearson wrote: > >> On Tue, 1 Mar 2016 18:24:12 +0100, ast wrote: >>> >>> It's not clear to me what arguments are passed to the >>> __new__ method. Here is a piece of code: >>> >>> >>> class Premiere: >>> >>> def __new__(cls, price): >>

Re: [Off-topic] Requests author discusses MentalHealthError exception

2016-03-02 Thread Ian Kelly
On Mar 2, 2016 9:01 PM, "Rustom Mody" wrote: > > On Thursday, March 3, 2016 at 7:59:13 AM UTC+5:30, Steven D'Aprano wrote: > > On Thu, 3 Mar 2016 04:02 am, Rustom Mody wrote: > > > > > And how is [1]'s starting different from Kenneth's finding his weight > > > to be the weight of the universe? > >

Re: [Off-topic] Requests author discusses MentalHealthError exception

2016-03-03 Thread Ian Kelly
On Thu, Mar 3, 2016 at 10:21 AM, alister wrote: > On Thu, 03 Mar 2016 13:35:12 +1100, Chris Angelico wrote: >> 1) No physical object can have negative mass. >> 2) I am a part of the universe and have positive mass. >> 3) I am not Kenneth. >> 4) The sum of my mass and Kenneth's mass must exceed Ken

Re: Explaining names vs variables in Python

2016-03-03 Thread Ian Kelly
On Thu, Mar 3, 2016 at 10:03 AM, Rustom Mody wrote: > Is it so damn hard to be a bit honest and when asked about is in python to > reply: > > If you dont know what you are doing, dont use 'is' (None excepted) > If you know why are you asking? That seems like a rather unhelpful response. -- http

Re: [Off-topic] Requests author discusses MentalHealthError exception

2016-03-03 Thread Ian Kelly
On Thu, Mar 3, 2016 at 1:20 PM, alister wrote: > On Thu, 03 Mar 2016 11:03:55 -0700, Ian Kelly wrote: > >> On Thu, Mar 3, 2016 at 10:21 AM, alister >> wrote: >>> On Thu, 03 Mar 2016 13:35:12 +1100, Chris Angelico wrote: >>>> 1) No physical object can hav

Re: Caching function results

2016-03-03 Thread Ian Kelly
On Thu, Mar 3, 2016 at 1:28 PM, Pavel Volkov wrote: > Suppose, I have some resource-intensive tasks implemented as functions in > Python. > Those are called repeatedly in my program. > It's guranteed that a call with the same arguments always produces the same > return value. > I want to cache the

Re: Continuing indentation

2016-03-04 Thread Ian Kelly
On Fri, Mar 4, 2016 at 7:03 AM, alister wrote: > On Fri, 04 Mar 2016 10:12:58 +, cl wrote: > >> Steven D'Aprano wrote: >>> On Fri, 4 Mar 2016 12:23 pm, INADA Naoki wrote: >>> >>> >>> >> >>> >> Indeed. I don't understand why, when splitting a condition such as >>> >> this, >>> >> people tend t

Re: creating zipfile with symlinks

2016-03-04 Thread Ian Kelly
On Fri, Mar 4, 2016 at 11:50 AM, crankypuss wrote: > I don't know about that, but you've certainly shown that what I was told > about this group being helpful and non-combative is bullshit. Look in a mirror much? -- https://mail.python.org/mailman/listinfo/python-list

Re: Can I find the class of a method in a decorator.

2016-03-05 Thread Ian Kelly
On Sat, Mar 5, 2016 at 9:21 AM, Antoon Pardon wrote: > Op 05-03-16 om 16:18 schreef Chris Angelico: >> On Sun, Mar 6, 2016 at 2:05 AM, Antoon Pardon >> wrote: >>> Using python 3.4/3.5 >>> >>> Suppose I have the following class: >>> >>> class Tryout: >>> >>> @extern >>> def method(self, ..

Re: Phyton

2016-03-06 Thread Ian Kelly
On Sun, Mar 6, 2016 at 10:05 AM, Mark Lawrence wrote: > Why in the year 2016 are people still giving links to the Luddite Python 2 > docs? Maybe because it's the version that comes up when googling for "python if statement". -- https://mail.python.org/mailman/listinfo/python-list

Re: importing

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 8:54 AM, Tony van der Hoff wrote: > I thought I understood this, but apparently not: > Under py3: > > 1. "import tkinter" imports the whole module into the name space. Any access > to names therein must be prefixed with the module name. > ie top = tkinter.Tk() > But tkinter.

Re: A mistake which almost went me mad

2016-03-07 Thread Ian Kelly
On Thu, Mar 3, 2016 at 11:50 AM, Tim Chase wrote: > I think that relative imports should ameliorate this, as I usually > hit it when I'm using smtplib which in turn imports "email" (and, in > 2.x when it found my local email.py would crash and burn). If it used > a relative import that forced it t

Re: Question

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 9:39 AM, Ben Morales wrote: > I am trying to download Python but I have windows 10 and I do not see a 64 > bit download for my operating system. Do you have a 64 bit for windows? What page are you looking at? https://www.python.org/downloads/release/python-351/ has download

Re: importing

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 10:23 AM, Tony van der Hoff wrote: > However, more generally, how am I supposed to know that a module is part of > a package, and needs a "magic" stanza to get a module loaded? If the import path of the module has a dot in it, then it's part of a package. -- https://mail.p

Re: Question

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 10:25 AM, Mark Lawrence wrote: > On 07/03/2016 16:57, Ian Kelly wrote: >> >> On Mon, Mar 7, 2016 at 9:39 AM, Ben Morales >> wrote: >>> >>> I am trying to download Python but I have windows 10 and I do not see a >>> 64 >>

Re: Question

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 11:51 AM, Jon Ribbens wrote: > I must say that Python on Windows was a very poor experience indeed, > "virtualenv" does not work and "venv" refuses to create the 'activate' > shell script so does not work either I've used both of these on Windows (although not recently) and

Re: Pythonic love

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 3:51 PM, Fillmore wrote: > > learning Python from Perl here. Want to do things as Pythonicly as possible. > > I am reading a TSV, but need to skip the first 5 lines. The following works, > but wonder if there's a more pythonc way to do things. Thanks I'd probably use iterto

Re: breaking out of outer loops

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 4:09 PM, Fillmore wrote: > > I must be missing something simple because I can't find a way to break out > of a nested loop in Python. > > Is there a way to label loops? No, you can't break out of nested loops, apart from structuring your code such that return does what you

Re: Question

2016-03-08 Thread Ian Kelly
On Mon, Mar 7, 2016 at 6:41 PM, Jon Ribbens wrote: > On 2016-03-07, Ian Kelly wrote: >> On Mon, Mar 7, 2016 at 11:51 AM, Jon Ribbens >> wrote: >>> I must say that Python on Windows was a very poor experience indeed, >>> "virtualenv" does not work

Re: Question

2016-03-08 Thread Ian Kelly
On Tue, Mar 8, 2016 at 10:56 AM, Jon Ribbens wrote: > The only things I can think of that are at all 'weird' are that there > are spaces in the filenames, and there's more than one drive. But > the former of those is utterly standard for Windows, and the latter > doesn't really even rise to the le

Re: Question

2016-03-08 Thread Ian Kelly
On Tue, Mar 8, 2016 at 5:13 PM, Chris Angelico wrote: > On Wed, Mar 9, 2016 at 10:52 AM, Steven D'Aprano wrote: >>> Well, running bash on Windows is decidedly non-standard. This is like >>> installing a Python package on a Linux system and then complaining >>> that it won't run under wine. I don'

Re: Pickle __getstate__ __setstate__ and restoring n/w - beazley pg 172

2016-03-09 Thread Ian Kelly
On Wed, Mar 9, 2016 at 2:14 AM, Veek. M wrote: > what i wanted to know was, x = Client('192.168.0.1') will create an > object 'x' with the IP inside it. When I do: > pickle.dump(x) > pickle doesn't know where in the object the IP is, so he'll call > __getstate__ and expect the return value to be t

Re: Encapsulation in Python

2016-03-10 Thread Ian Kelly
On Thu, Mar 10, 2016 at 6:41 AM, Ben Mezger wrote: > Hi all, > > I've been studying Object Oriented Theory using Java. Theoretically, all > attributes should be private, meaning no one except the methods itself > can access the attribute; > > public class Foo { > private int bar; > ... En

Re: context managers inline?

2016-03-10 Thread Ian Kelly
On Thu, Mar 10, 2016 at 11:59 AM, Neal Becker wrote: > sohcahto...@gmail.com wrote: > >> On Thursday, March 10, 2016 at 10:33:47 AM UTC-8, Neal Becker wrote: >>> Is there a way to ensure resource cleanup with a construct such as: >>> >>> x = load (open ('my file', 'rb)) >>> >>> Is there a way to e

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Ian Kelly
On Thu, Mar 10, 2016 at 2:33 PM, Fillmore wrote: > > when I put a Python script in pipe with other commands, it will refuse to > let go silently. Any way I can avoid this? What is your script doing? I don't see this problem. ikelly@queso:~ $ cat somescript.py import sys for i in range(20):

Re: Other difference with Perl: Python scripts in a pipe

2016-03-10 Thread Ian Kelly
On Thu, Mar 10, 2016 at 3:09 PM, Peter Otten <__pete...@web.de> wrote: > I suppose you need to fill the OS-level cache: > > $ cat somescript.py > import sys > > for i in range(int(sys.argv[1])): > sys.stdout.write('line %d\n' % i) > $ python somescript.py 20 | head -n5 > line 0 > line 1 > line

Re: non printable (moving away from Perl)

2016-03-10 Thread Ian Kelly
On Mar 10, 2016 5:15 PM, "Fillmore" wrote: > > > Here's another handy Perl regex which I am not sure how to translate to Python. > > I use it to avoid processing lines that contain funny chars... > > if ($string =~ /[^[:print:]]/) {next OUTER;} Python's re module doesn't support POSIX character c

Re: non printable (moving away from Perl)

2016-03-10 Thread Ian Kelly
On Mar 10, 2016 6:33 PM, "Mark Lawrence" wrote: > > On 11/03/2016 00:25, Ian Kelly wrote: >> >> On Mar 10, 2016 5:15 PM, "Fillmore" wrote: >>> >>> >>> >>> Here's another handy Perl regex which I am not sure how to

Re: Encapsulation in Python

2016-03-11 Thread Ian Kelly
On Fri, Mar 11, 2016 at 2:29 AM, dieter wrote: > If you are really interested to enforce Java encapsulation policies > (access to attributes via "getter/setter" only), you will need > to use your own "metaclass". > > The "metaclass" has a similar relation to a class as a class to > an instance: i.

Re: Encapsulation in Python

2016-03-11 Thread Ian Kelly
ural names -- these naming conventions are more > comprehensible to the user. Good names for methods are *descriptive* verb phrases. Good names for attributes and properties are *descriptive* nouns or noun phrases. Do you really believe that verbs are somehow inherently easier to understand?

Re: non printable (moving away from Perl)

2016-03-11 Thread Ian Kelly
On Fri, Mar 11, 2016 at 9:34 AM, Wolfgang Maier wrote: > On 11.03.2016 15:23, Fillmore wrote: >> >> On 03/11/2016 07:13 AM, Wolfgang Maier wrote: >>> >>> One lesson for Perl regex users is that in Python many things can be >>> solved without regexes. >>> How about defining: >>> >>> printable = {ch

Re: argparse

2016-03-11 Thread Ian Kelly
On Fri, Mar 11, 2016 at 4:18 PM, Fillmore wrote: > > Playing with ArgumentParser. I can't find a way to override the -h and > --help options so that it provides my custom help message. > > -h, --help show this help message and exit > > Here is what I am trying: > > parser = argparse.Argu

Re: Descriptors vs Property

2016-03-11 Thread Ian Kelly
On Fri, Mar 11, 2016 at 10:59 PM, Veek. M wrote: > A property uses the @property decorator and has @foo.setter > @foo.deleter. > > A descriptor follows the descriptor protocol and implements the __get__ > __set__ __delete__ methods. > > But they both do essentially the same thing, allow us to do:

Re: Descriptors vs Property

2016-03-11 Thread Ian Kelly
On Fri, Mar 11, 2016 at 11:24 PM, Veek. M wrote: > Ian Kelly wrote: > >> On Fri, Mar 11, 2016 at 10:59 PM, Veek. M wrote: >>> Also, what's this bit: >>> self.default = default if default else type() >> >> If the default parameter has a truthy value,

Re: Encapsulation in Python

2016-03-12 Thread Ian Kelly
On Fri, Mar 11, 2016 at 7:39 PM, Rick Johnson wrote: > At run-time, i don't care how large a "module namespace" may > be. Sometimes a module namespace will be small, with only a > few exposed symbols, but sometimes, a module namespace will > expose thousands of symbols. Thousands, really? What sy

Re: Interaction between pygame and python

2016-03-14 Thread Ian Kelly
On Mar 14, 2016 2:34 AM, "Tyson" wrote: > > I am having a lot of trouble getting python to find the pygame module; my > operating system is Windows 7. Can you offer any help? . Should I > download pygame into the same folder as Python? . any ideas at all? In what form did you download PyGame?

Re: Is anyone in this group using Python Editor v5 for Chromebooks?

2016-03-14 Thread Ian Kelly
On Sun, Mar 13, 2016 at 5:00 PM, Jeff Schumaker wrote: > I'm trying to use Python Editor v5 for Chromebooks. It works fine, except it > won't read data files. I'm just wondering if anyone else is using this editor > and has found a solution to this problem. Sorry, haven't tried it. On my Chrome

Re: Simple exercise

2016-03-14 Thread Ian Kelly
On Mon, Mar 14, 2016 at 9:06 AM, Oscar Benjamin wrote: > On 14 March 2016 at 14:35, Rick Johnson wrote: >> >> I would strongly warn anyone against using the zip function >> unless > ... >> I meant to say: absolutely, one hundred percent *SURE*, that >> both sequences are of the same length, or, a

Re: Missing something about timezones

2016-03-14 Thread Ian Kelly
On Mon, Mar 14, 2016 at 9:19 AM, Skip Montanaro wrote: > Is this correct (today, with Daylight Savings in effect)? > import pytz i.timezone > 'America/Chicago' pytz.timezone(i.timezone) > ot > datetime.datetime(2016, 3, 14, 9, 30, tzinfo= 'America/New_York' EDT-1 day, 20:00:00

Re: Missing something about timezones

2016-03-14 Thread Ian Kelly
On Mon, Mar 14, 2016 at 9:32 AM, Skip Montanaro wrote: > On Mon, Mar 14, 2016 at 10:26 AM, Ian Kelly wrote: >> Why should it? You only asked pytz for the Chicago timezone. You >> didn't ask for it relative to any specific time. > > Thanks. I thought using Ameri

Re: Interaction between pygame and python

2016-03-14 Thread Ian Kelly
On Mon, Mar 14, 2016 at 10:53 AM, Rick Johnson wrote: > If you download and run an installer, one that is > appropriate for your operating system and Python version, > everything will be taken care of for you. > > Since you are using Python 3.5.1 on a windows box, you'll > want to download and ins

Re: Encapsulation in Python

2016-03-14 Thread Ian Kelly
On Mon, Mar 14, 2016 at 11:32 AM, Rick Johnson wrote: > Ignoring Tkinter, which is a gawd awful mess, how would you > re-organize the 3,656 symbols in OpenGL.GL into smaller > modules, without dividing them up along some random or > arbitrary lines? In that particular case, I wouldn't, except pos

Re: How to waste computer memory?

2016-03-18 Thread Ian Kelly
On Fri, Mar 18, 2016 at 8:56 AM, Random832 wrote: > On Fri, Mar 18, 2016, at 03:00, Ian Kelly wrote: >> jmf has been asked this before, and as I recall he seems to feel that >> UTF-8 should be used for all purposes, ignoring the limitations of >> that encoding such as that i

Re: How to waste computer memory?

2016-03-18 Thread Ian Kelly
On Fri, Mar 18, 2016 at 10:44 AM, Steven D'Aprano wrote: > On Sat, 19 Mar 2016 02:31 am, Random832 wrote: > >> On Fri, Mar 18, 2016, at 11:17, Ian Kelly wrote: >>> If the string is simple UCS-2, that's easy. > > Hmmm, well, nobody uses UCS-2 any more, since th

Re: How to waste computer memory?

2016-03-18 Thread Ian Kelly
On Fri, Mar 18, 2016 at 3:19 PM, Mark Lawrence wrote: > > I have no idea at what the above can mean, other than that you are agreeing > with the RUE. Mark, are you aware that this is a rather classic ad hominem of guilt by association? "I didn't pay any attention to your actual argument, but you

Re: How to waste computer memory?

2016-03-19 Thread Ian Kelly
On Fri, Mar 18, 2016 at 6:37 AM, Chris Angelico wrote: > On Fri, Mar 18, 2016 at 10:46 PM, Steven D'Aprano wrote: >> Technically, UTF-8 doesn't *necessarily* imply indexing is O(n). For >> instance, your UTF-8 string might consist of an array of bytes containing >> the string, plus an array of in

Re: How to waste computer memory?

2016-03-19 Thread Ian Kelly
On Thu, Mar 17, 2016 at 1:21 PM, Rick Johnson wrote: > In the event that i change my mind about Unicode, and/or for > the sake of others, who may want to know, please provide a > list of languages that *YOU* think handle Unicode better than > Python, starting with the best first. Thanks. jmf has

Re: monkey patching __code__

2016-03-19 Thread Ian Kelly
On Fri, Mar 18, 2016 at 5:49 AM, Sven R. Kunze wrote: > Hi, > > we got an interesting problem. We need to monkeypatch Django's reverse > function: > > > First approach: > > urlresolvers.reverse = patched_reverse > > > Problem: some of Django's internal modules import urlresolvers.reverse > before

Re: monkey patching __code__

2016-03-19 Thread Ian Kelly
On Fri, Mar 18, 2016 at 9:01 AM, Sven R. Kunze wrote: > On 18.03.2016 15:48, Ian Kelly wrote: >> >> Well I didn't design it, so I'm not really sure. But it could be argued >> that the defaults are intrinsic to the function declaration, not the code >> obje

Re: monkey patching __code__

2016-03-19 Thread Ian Kelly
On Mar 18, 2016 8:33 AM, "Sven R. Kunze" wrote: > > On 18.03.2016 14:47, Ian Kelly wrote: >> >> Your patched version takes two extra arguments. Did you add the >> defaults for those to the function's __defaults__ attribute? > > > That's it!

Re: monkey patching __code__

2016-03-20 Thread Ian Kelly
On Fri, Mar 18, 2016 at 7:47 AM, Ian Kelly wrote: > Your patched version takes two extra arguments. Did you add the > defaults for those to the function's __defaults__ attribute? And as an afterthought, you'll likely need to replace the function's __globals__ with your o

Re: Static caching property

2016-03-21 Thread Ian Kelly
On Mon, Mar 21, 2016 at 9:38 AM, Joseph L. Casale wrote: > With non static properties, you can use a decorator that overwrites the > method on the instance with an attribute containing the methods return > effectively caching it. Can you give an example of what you mean? > What technique for a s

Re: Static caching property

2016-03-21 Thread Ian Kelly
On Mon, Mar 21, 2016 at 10:36 AM, Steven D'Aprano wrote: > On Tue, 22 Mar 2016 03:15 am, Ian Kelly wrote: >> Why not do the same thing but using a class attribute instead of an >> instance attribute? > > Properties don't work when called from a class: Prop

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