Re: Asynchronous processing is more efficient -- surely not?
Steven D'Apranowrites: > So, I'm, still trying to wrap my brain around async processing, and I > started reading this tutorial: > > http://stackabuse.com/python-async-await-tutorial/ > > and the very first paragraph broke my brain. > > "Asynchronous programming has been gaining a lot of traction in the past > few years, and for good reason. Although it can be more difficult than > the traditional linear style, it is also much more efficient." > > I can agree with the first part of the first sentence (gaining a lot of > traction), and the first part of the second sentence (more difficult than > the traditional style), but the second part? Asynchronous processing is > *more efficient*? It really depends on your definition of "efficient". Using async generally introduces some overhead, so there's a cost. However it also allows for the possibility of making better use of your compute resources by doing useful work rather than idle-waiting for network interactions to complete. As with many things - it's a useful tool and can be used to your advantage, but you can also shoot yourself in the foot if used inappropriately. -- https://mail.python.org/mailman/listinfo/python-list
[issue17972] inspect module docs omits many functions
Paul Rudin <p...@rudin.co.uk> added the comment: Although formatannotation is undocumented, its actually documented as a default value for one of the parameters of formatargspec, so it does form part of the module's public interface. However formatargspec is deprecated, so it's still OK to deprecate formatannotation. formatannotation is also used as a helper within Parameter, which isn't deprecated, but the public interface or docs of Parameter don't mention formatannotation, so using _formatannotation instead is fine. Since I've looked through this and, as far as I can tell, nobody is working on it, I'll make the changes and make a PR. -- ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue17972> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17972] inspect module docs omits many functions
Paul Rudin <p...@rudin.co.uk> added the comment: Documenting and generating a deprecation warning also makes them part of the documented public api. Or are you suggesting just the warning without including in the documentation? Incidentally, there are also the classes BlockFinder and EndOfBlock, which are helpers for getblock and presumably not intended for public consumption. -- ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue17972> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue17972] inspect module docs omits many functions
Paul Rudin <p...@rudin.co.uk> added the comment: If some are to be considered private then the questions are: which ones and how to fix. Presumably renaming to start with "_" might break existing code, so maybe adding an __all__, and just including the public objects is better? That could break code existing relying on * imports I suppose. Deprecation is another possibility, although feels a little odd for things never documented. formatannotation and formatannotationrelativeto look like a helper functions for formatargspec and are probably not intended as part of the public interface. Similarly walktree looks like a helper for getclasstree (and its docstring describes it as such). -- nosy: +PaulRudin ___ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue17972> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: Python
Joaquin Alzolawrites: > This email is confidential and may be subject to privilege. If you are not the > intended recipient, please do not copy or disclose its content but contact the > sender immediately upon receipt. Probably best not to send it to a publicly accessible mailing list then :/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Using namedtuples field names for column indices in a list of lists
"Deborah Swanson"writes: > Peter Otten wrote, on January 08, 2017 3:01 AM >> >> columnA = [record.A for record in records] > > This is very neat. Something like a list comprehension for named tuples? Not something like - this *is* a list comprehension - it creates a list of named tuples. The thing you iterate over within the comprehension can be any iterator. (Of course you're going to run into problems if you try to construct a list from an infinite iterator.) -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do
Tim Johnsonwrites: > * Antonio Caminero Garcia [170102 20:56]: >> Guys really thank you for your answers. Basically now I am more >> emphasizing in learning in depth a tool and get stick to it so I >> can get a fast workflow. Eventually I will learn Vim and its >> python developing setup, I know people who have been programming >> using Vim for almost 20 years and they did not need to change >> editor (that is really awesome). > > Bye the way, one thing I like about the GUI based vim is that it > supports tabs, where emacs does not. M-x package-install tabbar -- https://mail.python.org/mailman/listinfo/python-list
Re: Clickable hyperlinks
"Deborah Swanson"writes: > > I didn't try printing them before, but I just did. Got: > print([Example](http://www.example.com) > > SyntaxError: invalid syntax (arrow pointing at the colon) > With respect, if you typed that at python then it's probably a good idea to take a step back and work through the excellent tutorial. https://docs.python.org/3/tutorial/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do
Tim Johnsonwrites: > * Antonio Caminero Garcia [170102 20:56]: >> Guys really thank you for your answers. Basically now I am more >> emphasizing in learning in depth a tool and get stick to it so I >> can get a fast workflow. Eventually I will learn Vim and its >> python developing setup, I know people who have been programming >> using Vim for almost 20 years and they did not need to change >> editor (that is really awesome). > > Bye the way, one thing I like about the GUI based vim is that it > supports tabs, where emacs does not. M-x package-install tabbar -- https://mail.python.org/mailman/listinfo/python-list
Re: Clickable hyperlinks
"Deborah Swanson"writes: > > I didn't try printing them before, but I just did. Got: > print([Example](http://www.example.com) > > SyntaxError: invalid syntax (arrow pointing at the colon) > With respect, if you typed that at python then it's probably a good idea to take a step back and work through the excellent tutorial. https://docs.python.org/3/tutorial/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.
Tim Johnsonwrites: > * Antonio Caminero Garcia [170102 20:56]: >> Guys really thank you for your answers. Basically now I am more >> emphasizing in learning in depth a tool and get stick to it so I >> can get a fast workflow. Eventually I will learn Vim and its >> python developing setup, I know people who have been programming >> using Vim for almost 20 years and they did not need to change >> editor (that is really awesome). > > Bye the way, one thing I like about the GUI based vim is that it > supports tabs, where emacs does not. M-x package-install tabbar -- https://mail.python.org/mailman/listinfo/python-list
Re: Pyvenv puts both Python 2 and Python 3 in the same environment. Shocked!
Malik Rumiwrites: > I just created a new venv using pyvenv from a 2.7 install. Now I am shocked to > see that I can get both 2.7 and 3.4 in this same venv: > > (memory) malikarumi@Tetuoan2:~/Projects/cannon/New2.7Projects/memory$ python > Python 2.7.12 (default, Nov 19 2016, 06:48:10) > [GCC 5.4.0 20160609] on linux2 > Type "help", "copyright", "credits" or "license" for more information. exit() > (memory) malikarumi@Tetuoan2:~/Projects/cannon/New2.7Projects/memory$ python3 > Python 3.4.2 (default, Apr 17 2015, 18:47:05) > [GCC 4.8.2] on linux > Type "help", "copyright", "credits" or "license" for more information. A venv doesn't remove everything from your path. Presumably python3 is some system installed python. What does "which python3" say? If you just invoke "python" then you'll get the venv one. -- https://mail.python.org/mailman/listinfo/python-list
Re: I am new to python. I have a few questions coming from an armature!
Lawrence D’Oliveiro <lawrenced...@gmail.com> writes: > On Tuesday, August 16, 2016 at 6:26:01 PM UTC+12, Paul Rudin wrote: >> sohcahtoa82 writes: >>> squared_plus_one_list = map(lambda x: x**2 + 1, some_list) >> >> I realise that this is about understanding lambda, but it's worth noting >> in passing that we tend to write this sort of thing as: >> >> squared_plus_one_list = [x**2 + 1 for x in some_list] > > The difference being that the “map” function takes an iterable and returns an > iterator. Ah well - that depends the python version. Since the OP used a name including the substring 'list' I assumed python 2. > Why could this difference be important? The main thing is to understand the difference, and then it's possible to reason about whether it matters in a given context. -- https://mail.python.org/mailman/listinfo/python-list
Re: I am new to python. I have a few questions coming from an armature!
sohcahto...@gmail.com writes: > On Monday, August 15, 2016 at 8:07:32 AM UTC-7, alister wrote: >> On Mon, 15 Aug 2016 07:00:47 -0700, Sickfit92 wrote: >> >> > 1. How long did it take you guys to master the language or, let me put >> > it this way to completely get the hang and start writing code? >> > > >> Some concepts took more time than others before I had the "Light bulb" >> moment, Comprehensions & decorators being the most notable although >> Lambda still escapes me, fortunately these can all be unrolled into >> larger functions so are not essential in the early stages >> > > > What helped me understand Lambdas is figuring out that they're really just a > $1,000 term for a $5 concept. > > A lambda is just a single-line function without a name (Unless you assign it > to one). A syntactic shortcut. > > def square_plus_one(x): > return x ** 2 + 1 > > squared_plus_one_list = map(square_plus_one, some_list) > > is equivalent to: > > squared_plus_one_list = map(lambda x: x**2 + 1, some_list) I realise that this is about understanding lambda, but it's worth noting in passing that we tend to write this sort of thing as: squared_plus_one_list = [x**2 + 1 for x in some_list] -- https://mail.python.org/mailman/listinfo/python-list
Re: Asynchronous programming
Steven D'Apranowrites: > Thanks to everyone who has answered, I think I'm slowly starting to get it > now. Let's see if we can come up with a toy example that doesn't involve > low-level socket programming :-) > > Let me simulate a slow function call: > > > import random, time > > def work(id): > print("starting with id", id) > workload = random.randint(5, 15) > for i in range(workload): > time.sleep(0.2) # pretend to do some real work > print("processing id", id) # let the user see some progress > print("done with id", id) > return 10 + id > > > pending = [1, 2, 3, 4] > > for i, n in enumerate(pending): > pending[i] = work(n) > > > How do I write work() so that it cooperatively multi-tasks with other ... > threads? processes? what the hell do we call these things? What does this > example become in the asynchronous world? > They're not separate processes or threads, just think tasks that suspend and restart cooperatively. You need some kind of event loop to orchestrate running the tasks. Asyncio provides one. You can do your example like this: import asyncio, random async def work(id): print("starting with id", id) workload = random.randint(5, 15) for i in range(workload): await asyncio.sleep(0.2) # pretend to do some real work print("processing id", id) # let the user see some progress print("done with id", id) return 10 + id loop = asyncio.get_event_loop() pending = [1, 2, 3, 4] jobs = [asyncio.ensure_future(work(n)) for n in pending] loop.run_until_complete(asyncio.gather(*jobs)) loop.close() > In this case, all the work is pure computation, so I don't expect to save > any time by doing this, because the work is still all being done in the > same process/thread, not in parallel. It may even take a little bit longer, > due to the overhead of switching from one to another. > Yeah - you're not gaining anything here. All (?) the interesting use cases involve waiting for something (e.g. disk access, network communication, separate process) before you can proceed with your computation. -- https://mail.python.org/mailman/listinfo/python-list
Re: Asynchronous programming
Steven D'Apranowrites: > > But what's the point in doing it asynchronously if I have to just wait for > it to complete? > > begin downloading in an async thread > twiddle thumbs, doing nothing > process download If you have nothing else to do, then there's no point. But suppose you're implementing a web server. A request comes in - in order to respond you need some data from a database. So you do the database bit async. Whilst you're waiting for that you can get on with processing other incoming requests. -- https://mail.python.org/mailman/listinfo/python-list
Re: Asynchronous programming
Chris Angelicowrites: > On Thu, Aug 11, 2016 at 7:45 PM, Steven D'Aprano > wrote: >> I don't know whether you would call that a callback. I suppose it could be, >> in >> the sense that you might say: >> >> button.set_mouseup_function(mouseUp) >> >> but I'm used to thinking of it as a property of the button. > > "Callback" simply means "function that someone else calls". In fact, > most dunder methods could be described as callbacks. > A callback is normally a callable you pass to some other function with the expectation that it will be invoked in certain circumstances. That's not really the same thing as something someone else calls: any function that's part of a published api is intended to be called by someone else; but that doesn't really make it a callback. -- https://mail.python.org/mailman/listinfo/python-list
Re: Asynchronous programming
Steven D'Apranowrites: > > Is there a good beginner's tutorial introducing the basics of asynchronous > programming? Starting with, why and where would you use it? You could do worse than watch Dave Beazley's pycon talk: https://www.youtube.com/watch?v=lYe8W04ERnY -- https://mail.python.org/mailman/listinfo/python-list
Re: log file.
Joaquin Alzolawrites: > This email is confidential and may be subject to privilege. If you are > not the intended recipient, please do not copy or disclose its content > but contact the sender immediately upon receipt. Probably not a good idea to send it to a publicly accessible resource then :) -- https://mail.python.org/mailman/listinfo/python-list
Re: I'm wrong or Will we fix the ducks limp?
Paul Rudin <paul.nos...@rudin.co.uk> writes: > Marko Rauhamaa <ma...@pacujo.net> writes: >> So your "names" are *variables*. > > Informally yes, but "variable" has no meaning in the language reference. > ... err sorry, actually not correct - but irrelevant to the point under discussion. -- https://mail.python.org/mailman/listinfo/python-list
Re: I'm wrong or Will we fix the ducks limp?
Marko Rauhamaa <ma...@pacujo.net> writes: > Paul Rudin <paul.nos...@rudin.co.uk>: > >> Marko Rauhamaa <ma...@pacujo.net> writes: >>> The object is only an intermediate result; what is returned is a >>> pointer (to an object), without an exception. That's not a matter of >>> implementation. It's an essential part of Python's data model. >> >> Well - the language has no explicit notion of "pointer", [...] it's >> better (IMO) to just talk in the terms the language specification >> uses. > > The spec (https://docs.python.org/3/reference/datamodel.html>) > uses the terms *identity* and *reference*, which are one-to-one. identity isn't the same thing as a name, identity is an inherent property of an object - many names may refer to the same object. Similarly reference doesn't mean the same thing as identity. A reference to an object can occur, for example: ["foo"] The list refers to the string. There's no name involved anywhere. Both the list and the string have an identity, but that's essentially irrelevant to the fact that the list has a reference to the string. > >> There are names and objects, and mechanisms by which names come to >> refer to objects according to the execution model. > > The spec as well as Python itself uses the word "name" for various > strings: > >>>> "x".__class__.__name__ >'str' >>>> __name__ >'__main__' > __name__ is not the same thing as what the spec means when it talks of a name. It's certainly true that a class declaration creates a binding from that name to an object representing the class. But other names can equally well refer to the same object: >>> class Foo: ... pass ... >>> Bar = Foo >>> x = Bar() >>> x.__class__.__name__ 'Foo' >>> > > So your "names" are *variables*. Informally yes, but "variable" has no meaning in the language reference. > > Your "mechanisms" are *references*. > Nope - when I spoke of mechanisms I was talking about the different operational semantics by which a given names can be bound to an object. Once such an binding has occured then I agree that the name refers to the object in question. > Your "objects" are *objects*. > I think I probably agree, but I'm not sure what you're saying - "object" means something in the language reference - that's what I'm talking about. >> Talk of pointers is potentially confusing, because it carries baggage >> from other languages which doesn't necessary map precisely onto the >> python execution model. > > Unfortunately, virtually every word is overloaded and full of > preconceived notions. Hence: "pegs", "leashes", "puppies". > > The main thing is to keep those three concepts apart from each other. > Two notions will not suffice. > Well - adding more things is confusing in IMO - we have a language reference, let's just use the terms in the language reference. -- https://mail.python.org/mailman/listinfo/python-list
Re: I'm wrong or Will we fix the ducks limp?
Marko Rauhamaa <ma...@pacujo.net> writes: > Paul Rudin <paul.nos...@rudin.co.uk>: > >> Marko Rauhamaa <ma...@pacujo.net> writes: >>> What is different is that in Python, every expression evaluates to a >>> pointer. Thus, you can only assign pointers to variables. >> >> I don't think that's really right - every expression evaluates to an >> object. > > The object is only an intermediate result; what is returned is a pointer > (to an object), without an exception. That's not a matter of > implementation. It's an essential part of Python's data model. > Well - the language has no explicit notion of "pointer", so I'm not sure it's really correct to say that it's an essential part of the data model. The way variables are used to reference the objects associated with them from time to time has some similarities with pointer semantics in other languages. But actually it's better (IMO) to just talk in the terms the language specification uses. There are names and objects, and mechanisms by which names come to refer to objects according to the execution model. > (However, since "pointer" is evokes passions among crowds, it is better > to use the neutral word "leash".) Talk of pointers is potentially confusing, because it carries baggage from other languages which doesn't necessary map precisely onto the python execution model. (The underlying cpython implementation, is neither here nor there - we could in theory implement python in some other language which lacks a pointer type.) -- https://mail.python.org/mailman/listinfo/python-list
Re: I'm wrong or Will we fix the ducks limp?
Marko Rauhamaawrites: > Antoon Pardon : > >> You can do something like that in simula, but only because >> simula has two kinds of assignments. One kind that is >> simular to python and one that is similar to C. >> The one that is similar that python is the reference assignment. > > I see Python as doing the exact same thing with variables as C. I'm not sure that's a good mental model of what's going on. A variable declaration in C carries semantics of memory allocation to hold the value. This isn't so in python > > What is different is that in Python, every expression evaluates to a > pointer. Thus, you can only assign pointers to variables. > I don't think that's really right - every expression evaluates to an object. Whether or not that object can be accessed through some variable or not depends on how the expression is used. -- https://mail.python.org/mailman/listinfo/python-list
Re: Don't put your software in the public domain
Nobodywrites: > On Sat, 04 Jun 2016 12:28:33 +1000, Steven D'Aprano wrote: > >>> OTOH, a Free software licence is unilateral; the author grants the user >>> certain rights, with the user providing nothing in return. >> >> That's not the case with the GPL. >> >> The GPL requires the user (not the end-user, who merely avails themselves >> of their common law right to run the software, but the developer user, who >> copies, distributes and modifies the code) to do certain things in return >> for the right to copy, distribute and modify the code: > > The GPL places limitations on the granted licence. That isn't the same > thing as requiring the distributor to do something "in return". > The distributor grants the licence. > This is why the (relatively few) cases where GPL infringements have > resulted in litigation, the legal basis of the litigation is copyright > infringement, not breach of contract. Right, but the defence is that the licence grants permission to use; so that's where the law if contract comes into it. You have to figure out whether the use in question falls within the licence terms. So if someone brings an action for copyright infringement you can argue at least some of: 1. Copyright doesn't subsist in the copied material. 2. You didn't copy it. 3. One of the legal defences (fair use etc.) applies. 4. You had the permission of the copyright owner (i.e. a licence to copy in these circumstances). In the last case we're essentially into contract law. -- https://mail.python.org/mailman/listinfo/python-list
Re: Don't put your software in the public domain
Lawrence D’Oliveirowrites: > On Friday, June 3, 2016 at 9:53:47 PM UTC+12, Steven D'Aprano wrote: > >> A licence is something like a contract... > > A licence is quite different from a contract. A contract requires some > indication of explicit agreement by both parties, a licence does not. That’s > why Free Software licences only have to say something like “by using this > software, you agree to the following terms...”, because if the user doesn’t > accept the licence, then they have no licence. But that's exactly what a contract is - an agreement. The licence is an example, on the one side the copyright holder is agreeing not to sue the user for copyright infringment and on the other the user is agreeing to only use the code according to the terms. > > EULAs for proprietary software, on the other hand, try to have it both > ways, by having a clause like the above, as well as requiring you to > click an “I Agree” button or some such. You can agree a contract by conduct... -- https://mail.python.org/mailman/listinfo/python-list
Re: Don't put your software in the public domain
Lawrence D’Oliveirowrites: > I wonder about the point of that, though; I have heard of cases where > the judge ruled that the contract had been breached, and awarded > damages of one pound/dollar/euro. So other than winning a symbolic > victory, what was the point? Damages for breach of contract are supposed to reflect the loss you suffered as a result. A nominal award is basically saying, yes - the other guy has failed to fulfil his contractual promise, but you haven't actually suffered any real loss as a result. -- https://mail.python.org/mailman/listinfo/python-list
Re: Don't put your software in the public domain
Nobodywrites: > On Fri, 03 Jun 2016 09:15:55 -0700, Lawrence D’Oliveiro wrote: > >>> [quoted text muted] >> >> A licence is quite different from a contract. A contract requires some >> indication of explicit agreement by both parties, a licence does not. > > More precisely, it requires "mutual consideration", i.e. each party must > provide something of value to the other. Don't confuse consideration with agreement - they're seperate legal concepts. Agreement is certainly necessary in pretty much all jurisdictions. Consideration is required in most common law jurisdiction (England, the US, most of the commonwealth) but not in many continental legal systems. > OTOH, a Free software licence is unilateral; the author grants the user > certain rights, with the user providing nothing in return. Nope - the user promises to abide by the terms of the licence. This is a very common kind of consideration. -- https://mail.python.org/mailman/listinfo/python-list
Re: I'm wrong or Will we fix the ducks limp?
Sayth Renshawwrites: > Very briefly because I hope to shot down eloquently. > > Python is beautiful and is supposed to be a duck typed language, Yes? > > Then if I create and assign to a new variable with a list action why > does the duck not quack? > > It feels wrong to spend a line writing what is already obvious > The problem is that you think that *variables* have a type. This isn't the case. Objects have a type. A variable is a name by which you can refer to an object. There are various ways in which you can associate a object with a variable, the most obvious being an assignment statement. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python on Windows with linux environment
Deborah Martinwrites: > Try Cygwin at http://www.cygwin.com > Or use the new windows subsystem for linux: https://blogs.windows.com/buildingapps/2016/03/30/run-bash-on-ubuntu-on-windows/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Quote of the day
Marko Rauhamaa <ma...@pacujo.net> writes: > Paul Rudin <paul.nos...@rudin.co.uk>: > >> Marko Rauhamaa <ma...@pacujo.net> writes: >>> The feeling of powerlessness can be crushing when you depend on a >>> third-party component that is broken with no fix in sight. >> >> Presumably it depends on whether you have the source for the third >> party component... > > Just having such an experience. The linux kernel has a critical bug in a > major distribution (who shall be left unnamed here) that has been fixed > in a later kernel version. > > Thanks to linux being free software, I managed to pin down the root > cause after more than a month of debugging. I sent a bug report to the > linux vendor and attached a tiny patch. The vendor has graciously agreed > to consider releasing an update in the summer (we are in the process of > verifying the fix). > > The problem was first detected in December. A semi-reliable reproduction > was discovered in early February. The root cause and proposed fix was > identified mid-March. A vendor fix will likely come out by the end of > June. > > That's a long time to be without a product to sell. > But you do have the option of building a kernel incorporating your fix and using that. -- https://mail.python.org/mailman/listinfo/python-list
Re: Quote of the day
Marko Rauhamaawrites: > Radek Holý : > >> 2016-05-17 9:50 GMT+02:00 Steven D'Aprano < >> steve+comp.lang.pyt...@pearwood.info>: >> >>> Overhead in the office today: >>> >>> "I don't have time to learn an existing library - much faster to make >>> my own mistakes!" >> >> *THUMBS UP* At least they are aware of that "own mistakes" part... Not >> like my employer... > > Also: > >With a third party solution I don't need to fix the bugs. > >But with an in-house solution I at least *can* fix the bugs. > > The feeling of powerlessness can be crushing when you depend on a > third-party component that is broken with no fix in sight. > > Presumably it depends on whether you have the source for the third party component... -- https://mail.python.org/mailman/listinfo/python-list
Re: Guido sees the light: PEP 8 updated
Pete Formanwrites: > Why is it that Python continues to use a fixed width font and therefore > specifies the maximum line width as a character count? Python doesn't require the use of any particular font for editing your code. However programmers tend to use fixed width fonts when editing code because then the visual representation of indentation works consistently. But that's not a python specific thing. -- https://mail.python.org/mailman/listinfo/python-list
Re: [OT] fortran lib which provide python like data type
Marko Rauhamaa ma...@pacujo.net writes: Chris Angelico ros...@gmail.com: On Mon, Feb 2, 2015 at 12:59 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: And there are underspecified rules too. What is the plural of octopus? No fair looking it up in the dictionary. Standard and well-known piece of trivia, and there are several options. Octopodes is one of the most rigorously formal, but octopuses is perfectly acceptable. Octopi is technically incorrect, as the -us ending does not derive from the Latin. Your brain's grammar engine will give you the correct answer. It may not match your English teacher's answer, but the language we are talking about is not standard English but the dialect you have acquired in childhood. Aha - the Humpty Dumpty approach to English usage: When I use a word it means just what I choose it to mean... -- https://mail.python.org/mailman/listinfo/python-list
Re: Random ALL CAPS posts on this group
Rick Johnson rantingrickjohn...@gmail.com writes: No one here would justify a public business refusing to serve or employ a person based on race, religion, sex, or otherwise. Depends on what you mean by or otherwise. So why would you so easily discriminate against speech? People discriminate amongst prospective employees on the basis of what the say all the time. It's the principle method by which you assess candidates. Freedom of expression is not about requiring others to publish your words. It would be completely impractical - where would it end? Your own slot on prime time TV to rant as you choose? -- https://mail.python.org/mailman/listinfo/python-list
Re: Python vs C++
Chris Angelico ros...@gmail.com writes: On Sat, Aug 23, 2014 at 3:56 PM, dieter die...@handshake.de wrote: Chris Angelico ros...@gmail.com writes: Frankly, I wouldn't write OO in anything, because I think the entire concept of a WYSIWYG editor is flawed. That would limit (so called) office applications to experts only. But the success of these applications relies on the fact, that even a complete novice can immediately use them. For non-experts WYSIWYG editors are important. People say that. But WYSIWYG editors are the primary cause of frustrated yelling from the far end of the house, in my experience. I think they're an attractive nuisance. They're complicated to get right (pure WYSIWYG is useless, so you have to balance the visual benefit of being close to the result against the utility of seeing some of the non-printing information), and non-modular. With a text editor + compiler concept (whether the compiler's language is as big and complex as LaTeX or as simple as ReST), you can change editors without breaking anything. You don't like Libre Office Writer? Tough, there's no real alternative if you want to work on LO files. The other problem is that because people are so used to using Word for all text preparation we end up with Word files being used to carry content for which plain text is just fine and would be preferable. The conflation of text editing / word processing / desk top publishing is problematic on a lot of levels. I'm unconvinced is that e.g. LaTeX is inherently more expert that Word for simple document preparation. It's mostly a question of familiarity. -- https://mail.python.org/mailman/listinfo/python-list
Re: Keep one GUI always on TOP while python code is running
Chris Angelico ros...@gmail.com writes: On Fri, Aug 8, 2014 at 3:57 PM, Jaydeep Patil patil.jay2...@gmail.com wrote: I mean to say, One GUI should be always on top from start to end of code running. So that user cant do any other operation. I am using wxpython Ah, that would be called System Modal, and should be reserved for absolutely critical system-wide alerts. It's also a feature that's simply not available to most user-space programs, and not available in most GUI toolkits. Short answer: Don't. There are commercial software packages that do this sort of thing. Examsoft is one - the idea being that people can take exams without access to other software at the same time (so that, for example, they could look at previously prepared notes). -- https://mail.python.org/mailman/listinfo/python-list
Re: OT: usenet reader software
Sturla Molden sturla.mol...@gmail.com writes: c...@isbd.net wrote: That doesn't address the problem at all! :-) You still need a news reader. The problem was that Thunderbird does not support killfiles when used as a newsreader. Leafnode adds filtering capabilities which Thunderbird (supposedly) does not have. There are plenty of non-Thunderbird news clients... -- https://mail.python.org/mailman/listinfo/python-list
Re: OT: usenet reader software
memilanuk memila...@gmail.com writes: Guess where I'm going with this is... is there anything out there worth trying - on Linux - that I'm missing? emacs/gnus. -- https://mail.python.org/mailman/listinfo/python-list
Re: IDE for python
Terry Reedy tjre...@udel.edu writes: On 5/29/2014 5:41 AM, Wolfgang Maier wrote: On 28.05.2014 12:43, Sameer Rathoud wrote: Hello everyone, I am new to python. I am currently using python 3.3 With python I got IDLE, but I am not very comfortable with this. What bothers you the most. Seems like not too many other people on this list share my opinion, but let me just say that IDLE is a nice and sufficient (for my purposes) IDE. If you're used to eclipse, then stick with it, but I prefer IDLE over any text editor although admittedly some of its keyboard shortcuts are unusual choices. I am curious how many of the editors people have been recommending have all of the following Idle features, that I use constantly. 1. Run code in the editor with a single keypress. 2. Display output and traceback in a window that lets you jump from the any line in the traceback to the corresponding file and line, opening the file if necessary. 3. Search unopened files (grep) for a string or re. 4. Display grep output in a window that lets you jump from any 'hit' to the corresponding file and line, opening the file if necessary. Emacs. -- https://mail.python.org/mailman/listinfo/python-list
Re: Teaching python to non-programmers
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: On Thu, 10 Apr 2014 22:42:14 -0700, Rustom Mody wrote: In middle-eastern society women are expected to dress heavier than in the West. A few years ago a girl went to school in France with a scarf and she was penalized. Citation please. I think this is bogus... This is not bogus. France has quite a strong tradition of keeping the education system secular and has passed a law regarding the wearing of ostentatious religious symbols in public schools, which also affects things like the wearing of crosses. Wikipedia has plenty on this... http://en.wikipedia.org/wiki/Islamic_scarf_controversy_in_France -- https://mail.python.org/mailman/listinfo/python-list
Re: Teaching python to non-programmers
Chris Angelico ros...@gmail.com writes: On Fri, Apr 11, 2014 at 2:37 PM, Rustom Mody rustompm...@gmail.com wrote: Right. Its true that when I was at a fairly large corporate, I was not told: Please always top post! What I was very gently and super politely told was: Please dont delete mail context Then you were told that by someone who does not understand email. It's not necessarily a bad idea to retain context in corporate emails. Messages tend to get forwarded to people other than the original recipient(s), and the context can be very helpful. But when you're posting to a mailing list or to a usenet group different considerations apply as there's usually a way of seeing the whole thread. Email is often a poor relatively poor medium for internal communication, because of this problem. Also people who might properly have a something useful to say on the subject matter may never get to see the email. A private news server or web forum is often better. That's not to say that there's no place for email in internal communication, but it's best reserved for occasions where confidentiality is required, or at least politic. -- https://mail.python.org/mailman/listinfo/python-list
Re: Debugging on the Mac question.
Sean Murphy mhysnm1...@gmail.com writes: I am a Vision Impaired programmer on the Mac and Window platforms. I have started to learn Python. The biggest road block I have is the ability of debugging my simple scripts. The IDLE program does not work with the screen readers I use on the Mac or Windows. A screen reader is a program that grabs the text on the screen and converts it into speech output, at least this is the 5 feet explanation. I cannot see the screen at all. I have looked at eclipse and it doesn't work with Voice-Over (the screen reader on the Mac). I have java issues on my windows machine preventing me running this app. If I use $python -d script.py the debugger doesn't seem to trigger on the mac. So how I can perform a debug on a script so I can step through it, set up break points, watch variables, etc. It is really annoying me, since under Perl I just added the -d switch and had a full debugger that worked at the console level. For command line debugging see http://docs.python.org/3/library/pdb.html. More generally you might want to investigate http://emacspeak.sourceforge.net/ (disclaimer - I have never used this, but from what you say you might find it useful). -- https://mail.python.org/mailman/listinfo/python-list
Re: Got a Doubt ! Wanting for your Help ! Plz make it ASAP !
rusi rustompm...@gmail.com writes: Propositionally: All languages are equal -- Turing complete As an aside, not all languages are Turing complete. For example Charity is a language with the property that programs are guaranteed to terminate. http://en.wikipedia.org/wiki/Charity_(programming_language) -- https://mail.python.org/mailman/listinfo/python-list
Re: Automation
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: A few minor errors is one thing, but when you see people whose posts are full of error after error and an apparent inability to get English syntax right, you have to wonder how on earth they expect to be a programmer? The irritating thing is apparent lack of care. A post is written once and will be seen (perhaps not read) by many people. People post with the intention of others reading their words. If they can't be bothered to take a little care in writing, why should we spend time reading? -- https://mail.python.org/mailman/listinfo/python-list
Re: personal library
Chris Angelico ros...@gmail.com writes: On Wed, Oct 30, 2013 at 1:00 PM, Dave Angel da...@davea.name wrote: First, I haven't seen any mention of a source control system. Get one, learn it, and use it. That should always hold your master copy. And the actual repository should be on a system you can access from any of the others. Then, once you can get to such a repository, you use it to sync your various local copies on your individual machines. You could have the synch happen automatically once a day, or whatever. You could also build an auto-synch utility which pushed the synch from the server whenever the server was updated. If you're always going to be using these machines with real-time access to the central server, you could use Windows shares to avoid needing any updates. Just create a share on the server, and mount it on each of the clients. Add it to your system.path and you're done. I don't know about Mercurial, but with git it's pretty easy to set up a post-push hook that gets run whenever new changes hit the server. From there, you could have some registered replicas that get immediately told to pull, which will give fairly immediate replication. It's not actually real-time, but you have a guarantee that they're up-to-date - if any change gets missed, it'll be caught in the next update. It'd take a little work to set up, but you could have something almost as convenient as shared folders but without the messes and risks. *Definitely* use source control. Indeed. Also note that there's nothing per se wrong with putting your repositories on Dropbox or similar - especially in a single user situation. I do this so as to keep things synced across different machines. You don't always want to check stuff in as you move from e.g. laptop to desktop, but you do want to be able to pick up where you left off on the other machine. -- https://mail.python.org/mailman/listinfo/python-list
Re: better and user friendly IDE recommended?
Joshua Landau jos...@landau.ws writes: If the time learning a set of tools is enough to make the choice between tools, I suggest avoiding, say, Vim. That's a big if. If you expect to spend a lot of time editing text, code, etc. over the next few years then it's definitely learning at least one of vim or emacs to a reasonable degree of competency. -- https://mail.python.org/mailman/listinfo/python-list
Re: how to detect comment in source code file ?
Ben Finney ben+pyt...@benfinney.id.au writes: vnkumbh...@gmail.com writes: how works python interpreter for finding comment ? It works as specified in the language reference. In particular, see URL:http://docs.python.org/3/reference/lexical_analysis.html#comments. if possible find nested comment ? Python's comments are line-end comments only. The syntax does not allow multi-line nor nested comments. Although you can use unbound multi-line strings as a kind of comment. But its often better to make the strings into doc strings proper. -- https://mail.python.org/mailman/listinfo/python-list
Re: user interfaces python3.x
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: On Mon, 02 Sep 2013 08:03:02 -0700, Paul Rice wrote: Im new to python3.x (well, programming as a whole. Never done before) and was wondering how do i get a proper interface instead of just writing. A proper interface huh? Well, I'd love to tell you the answer... ...but holy wars would ensue. -- http://mail.python.org/mailman/listinfo/python-list
Re: semicolon at end of python's statements
Jussi Piitulainen jpiit...@ling.helsinki.fi writes: # Option 1.5 for spam in sequence: if not predicate(spam): continue process(spam) This saves an indent level. Just out of interest: is saving an indent level a useful thing? I wouldn't lay out my code like that just because if you're coming back to it later and reading through quickly it's (to my mind at least) easier to miss what's going on. -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I make this piece of code even faster?
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: On Sat, 20 Jul 2013 13:22:03 -0700, pablobarhamalzas asked: How can I make this piece of code even faster? - Use a faster computer. - Put in more memory. - If using Unix or Linux, decrease the nice priority of the process. I mention these because sometimes people forget that if you have a choice between spend 10 hours at $70 per hour to optimize code, and spend $200 to put more memory in, putting more memory in may be more cost effective. Sure - but it's helpful if programmers understand a little bit about the computational complexity of algorithms. If it's just a question of making each basic step of your algorithm a bit faster, then it may well be better to spend money on better hardware than on squeezing more out of your code. OTOH if you've got an n^2 implementation and there's actually an n.log n solution available then you should probably re-code. Of course if what you've got is actually adequate for your use-case then it maybe that you don't actually need to do anything at all... -- http://mail.python.org/mailman/listinfo/python-list
Re: Editor Ergonomics [was: Important features for editors]
Roy Smith r...@panix.com writes: This is why I never understood the attraction of something like xemacs, where you use the mouse to make text selections and run commands out of menus. Menus are good for learning the functionality, and you have them just as much in Gnu emacs as in xemacs. You can even use them absent a windowing system! Text selection with a mouse is a different thing. Sometimes it's more convenient, sometimes it's not. But I agree with your general point - it's often quicker to keep your hands in position, which is where knowing keybinds for everything scores. -- http://mail.python.org/mailman/listinfo/python-list
Re: sympy.nsimplify
Skip Montanaro s...@pobox.com writes: Very cool indeed. In the comments was a link to an XKCD cartoon. Its tool tip mentioned twin primes. Looked that up. Google pointed (of course) at Wikipedia. Read that. Backed up to the Google Search, and noticed there is a news item from 15 hours ago that an unknown mathematician at the University of New Hampshire has proven the twin primes conjecture: http://www.wired.com/wiredscience/2013/05/twin-primes/ This is nothing to do with the original post. It's just amazing to me how short the distance between one very interesting topic on the net and something almost unrelated can be. AIUI the twin primes conjecture hasn't been proved. But a significant related fact - that there's an infinitude of primes no more that N apart where N ~ 70,000,000. That might not sound like a lot of progress - but the point is that the existence of some finite bound is very significant. -- http://mail.python.org/mailman/listinfo/python-list
Re: to a human - about 2to3
Jennifer Butler j.but...@albynschool.co.uk writes: Hiya I have trawled around your various pages and haven’t found what I want. I will start teaching Python to my pupils shortly. I have been looking for materials and have gathered a collection of programs. The problem is they are written in v2 and I have v3 installed in my classroom. I read about the 2to3 conversion program, but I can’t get it to work. Could you possibly give me a Noddy’s guide to do this? Perhaps the first thing you should teach your students is how to ask questions :) When you say you can't get it to work what does that mean? What exactly did you do? What happened as a result? How did that differ from what you expected to happen or hoped would happen? Can you construct a minimal specific example that illustrates your problem? -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterating over files of a huge directory
Chris Angelico ros...@gmail.com writes: On Tue, Dec 18, 2012 at 2:28 AM, Gilles Lenfant gilles.lenf...@gmail.com wrote: Hi, I have googled but did not find an efficient solution to my problem. My customer provides a directory with a hge list of files (flat, potentially 10+) and I cannot reasonably use os.listdir(this_path) unless creating a big memory footprint. So I'm looking for an iterator that yields the file names of a directory and does not make a giant list of what's in. Sounds like you want os.walk. But doesn't os.walk call listdir() and that creates a list of the contents of a directory, which is exactly the initial problem? But... a hundred thousand files? I know the Zen of Python says that flat is better than nested, but surely there's some kind of directory structure that would make this marginally manageable? Sometimes you have to deal with things other people have designed, so the directory structure is not something you can control. I've run up against exactly the same problem and made something in C that implemented an iterator. It would probably be better if listdir() made an iterator rather than a list. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with unittest2
Thomas Bach thb...@students.uni-mainz.de writes: BTW, I actually never used 'assertTypeEqual' I rather call assertEqual and let unittest do the internals. I think assertEqual calls the right method for you depending on the arguments type. The assertTypeEqual methods have the advantage of checking the type of the arguments. assertEqual would be OK with equal numerical arguments, but that would be an inferior test if you were really expecting two lists. If you want to make sure that something is of a certain type use assertIsInstance! Yes, but why do something in 3 lines when there's a perfectly good method provided that allows you do to it directly in one? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python parser problem
Chris Angelico ros...@gmail.com writes: On Fri, Dec 14, 2012 at 6:12 AM, RCU alex.e.s...@gmail.com wrote: Dave, Thanks for the reply. The script was originally edited on Windows with proper \r\n endings, It's worth noting that many Windows-based editors and interpreters are quite happy with \n line endings. You may be able to save yourself some trouble by switching everything to Unix newlines. ... and in particular emacs for windows works well. (holy wars ensue...) -- http://mail.python.org/mailman/listinfo/python-list
Re: python and Open cv
Zero Piraeus sche...@gmail.com writes: There aren't any rules about gmail (except the unwritten rule that to be a real geek you need to use a mail client that takes a whole weekend to configure, and another three years to properly understand). Ha! 3 years? I've been using gnus for nearly 20 years and I still don't understand it! -- http://mail.python.org/mailman/listinfo/python-list
Re: while expression feature proposal
Paul Rubin no.email@nospam.invalid writes: kind of ugly, makes me wish for a few more itertools primitives JOOI, do you have specific primitives in mind? -- http://mail.python.org/mailman/listinfo/python-list
Re: Hiring Python Developer @ CA, USA
nithinm...@gmail.com writes: ...Must be an export in this language... Are you hiring proof readers as well? :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Search and replace text in XML file?
Terry Reedy tjre...@udel.edu writes: ... a proper text-editor* * ... Notepad++ is one such on Windows. Surely emacs is the only such on any platform? :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Finding duplicate file names and modifying them based on elements of the path
larry.mart...@gmail.com larry.mart...@gmail.com writes: It seems that if you do a list(group) you have consumed the list. This screwed me up for a while, and seems very counter-intuitive. You've consumed the *group* which is an iterator, in order to construct a list from its elements. Sorry if this is excessively nit-picking, but it generally helps to keep these things very clear in your own mind. -- http://mail.python.org/mailman/listinfo/python-list
Re: Encapsulation, inheritance and polymorphism
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: For example, both ML and Haskell can, under some circumstances, report a type-error for an infinite loop, *at compile time*. ... and in Charity all programs are guaranteed to terminate. Of course it's not Turing complete. http://en.wikipedia.org/wiki/Charity_(programming_language) -- http://mail.python.org/mailman/listinfo/python-list
Re: code review
Mark Lawrence breamore...@yahoo.co.uk writes: On 03/07/2012 03:25, John O'Hagan wrote: On Tue, 3 Jul 2012 11:22:55 +1000 I agree to some extent, but as a counter-example, when I was a child there a subject called Weights and Measures which is now redundant because of the Metric system. I don't miss hogsheads and fathoms at all. John I weigh 13st 8lb - does this make me redundant? It might mean that you have some redundant weight :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Is that safe to use ramdom.random() for key to encrypt?
elvis-85...@notatla.org.uk writes: On 2012-06-17, Jon Clements jon...@googlemail.com wrote: Whatever you do - *do not* attempt to write your own algorithm. very true If everyone took that advice then we'd have a problem -- http://mail.python.org/mailman/listinfo/python-list
Re: Software Engineer -
Chris Withers ch...@simplistix.co.uk writes: On 11/03/2012 09:00, Blue Line Talent wrote: Blue Line Talent is looking for a mid-level software engineer with experience in a combination of Please don't spam this list with jobs, use the Python job board instead: http://www.python.org/community/jobs/ Just out of interest why do people object to job adverts here? Seems harmless enough... -- http://mail.python.org/mailman/listinfo/python-list
Re: open office in another language?
Stefan Behnel stefan...@behnel.de writes: OOo has been fully scriptable in Python for ages. It even comes with an embedded Python runtime for that purpose (at least on non-package-management systems like Windows). So, Python is actually a standard component in all installations, whereas Java is not, and is therefore not necessarily available in a deployment. Basically, if you want your scripts to run in all OpenOffice/LibreOffice installations, you either have to write it in StarBasic, or use Python. The OOo extension API is called UNO, so look for the PyUNO bridge. Admittedly, it's somewhat badly documented, but it basically works the same way as the other UNO-API incarnations in other languages, so any UNO documentation will generally apply just fine. Also look for LibreOffice, as Ben Finney hinted. Since Oracle dropped Sun's OOo commitment, many regard it as the future of OOo. It's certainly the place where the development happens these days. I have dabbled with PyUNO in the past. One issue is that the api seems rather unpythonic (to me, at least). -- http://mail.python.org/mailman/listinfo/python-list
Re: Test None for an object that does not implement ==
GZ zyzhu2...@gmail.com writes: I run into a weird problem. I have a piece of code that looks like the following: f(, a=None, c=None): assert (a==None)==(c==None) There is only one 'None' - so use 'a is None' rather than 'a == None'. (In common lisp there is a particular language construct that allows you do determine whether an argument was passed in or was defaulted.) -- http://mail.python.org/mailman/listinfo/python-list
Re: % is not an operator
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: The existence of two potential answers for the remainder is certainly correct, but the conclusion that remainder is not a binary operation doesn't follow. It is a binary relation. This depends on your definition of operation. Normally an operation is a function, rather than just a relation. -- http://mail.python.org/mailman/listinfo/python-list
Re: xml, minidom, ElementTree
Ethan Furman et...@stoneleaf.us writes: In the near future I will need to parse and rewrite parts of a xml files created by a third-party program (PrintShopMail, for the curious). It contains both binary and textual data. There has been some strong debate about the merits of minidom vs ElementTree. Recommendations? I tend to start with BeautifulSoup, and think about other things if that doesn't work out. It might just be me, but I find it easier to get stuff done using BeautifulSoup than either minidom or ElementTree. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to insert my own module in front of site eggs?
Roy Smith r...@panix.com writes: But, you're talking about installers. I'm talking about if I've already got something installed, how do I force one particular python process to pull in a local copy of a module in preference to the installed one? In some cases, I own the machine and can make changes to /usr/local/lib if I want to. But what about on a shared machine? I don't want to (or perhaps can't) play with what's in /usr/local/lib just to make my stuff load first. Maybe I'm missing something - but if I want to do this I just mess about with sys.path at the top of my python script/program. Always seems to work... is there a situation in which it doesn't? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to insert my own module in front of site eggs?
Roy Smith r...@panix.com writes: In article 874ny2fzn6@no-fixed-abode.cable.virginmedia.net, Paul Rudin paul.nos...@rudin.co.uk wrote: Maybe I'm missing something - but if I want to do this I just mess about with sys.path at the top of my python script/program. Always seems to work... is there a situation in which it doesn't? What if the first import of a module is happening inside some code you don't have access to? If you change sys.path first - before you do any imports - then any other imports will surely come from the first thing on sys.path (unless something else you import also changes sys.path)? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to isolate a constant?
Gnarlodious gnarlodi...@gmail.com writes: Thanks for all those explanations, I've already fixed it with a tuple. Which is more reliable anyway. neither of lists or tuples are more reliable than the other. They both have perfectly well defined behaviour (which can be gleaned from reading the documentation) and reliably behave as documented. You just have to choose which fits better for the computation you're trying to implement. -- http://mail.python.org/mailman/listinfo/python-list
Re: revive a generator
Yingjie Lan lany...@yahoo.com writes: - Original Message - From: Paul Rudin paul.nos...@rudin.co.uk Generators are like that - you consume them until they run out of values. You could have done [x*x for x in range(3)] and then iterated over that list as many times as you wanted. A generator doesn't have to remember all the values it generates so it can be more memory efficient that a list. Also it can, for example, generate an infinite sequence. Thanks a lot to all who answered my question. I am still not sure why should we enforce that a generator can not be reused after an explicit request to revive it? The language has no explicit notion of a request to revive a generator. You could use the same syntax to make a new generator that yeilds the same values as the one you started with if that's what you want. As we've already discussed if you want to iterate several times over the same values then it probably makes sense to compute them and store them in e.g. a list (although there are always trade-offs between storage use and the cost of computing things again). -- http://mail.python.org/mailman/listinfo/python-list
Re: revive a generator
Yingjie Lan lany...@yahoo.com writes: What if the generator involves a variable from another scope, and before re-generating, the variable changed its value. Also, the generator could be passed in as an argument, so that we don't know its exact expression. vo = 34 g = (vo*x for x in range(3)) def myfun(g): for i in g: print(i) vo += 3 revive(g) #best if revived automatically for i in g: print(i) myfun(g) I'm not really sure whether you intend g to yield the original values after your revive or new values based on the new value of vo. But still you can make a class that supports the iterator protocol and does whatever you want (but you can't use the generator expression syntax). If you want something along these lines you should probably read up on the .send() part of the generator protocol. As an aside you shouldn't really write code that uses a global in that way.. it'll end up biting you eventually. Anyway... we can speculate endlessly about non-existent language constructs, but I think we've probably done this one to death. -- http://mail.python.org/mailman/listinfo/python-list
Re: revive a generator
Yingjie Lan lany...@yahoo.com writes: Hi, it seems a generator expression can be used only once: g = (x*x for x in range(3)) for x in g: print x 0 1 4 for x in g: print x #nothing printed Is there any way to revive g here? Generators are like that - you consume them until they run out of values. You could have done [x*x for x in range(3)] and then iterated over that list as many times as you wanted. A generator doesn't have to remember all the values it generates so it can be more memory efficient that a list. Also it can, for example, generate an infinite sequence. -- http://mail.python.org/mailman/listinfo/python-list
Re: 1/2 evaluates to 0
Laurent Claessens moky.m...@gmail.com writes: Hi all This is well known : 1/2 0 This is because the division is an integer division. My question is : how can I evaluate 1/2 to 0.5 ? Is there some non integer division operator ? Up to now I workarounded writing float(1)/2. Is there an other way ? from __future__ import division Or use operator.truediv Or use python 3. -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggested coding style
Prasad, Ramit ramit.pra...@jpmorgan.com writes: May I suggest a[n] email client that can group mailing list threads? Please do. Bonus points if it handles threading in a Gmail-like style. The answer to any news/mail client with feature X type question is normally gnus - although I don't know what Gmail-like style is. -- http://mail.python.org/mailman/listinfo/python-list
Re: Hierarchical commnd line parsing / help texts
Prasad, Ramit ramit.pra...@jpmorgan.com writes: This email is confidential... Probably a bad idea to post it to a world readable mailing list then :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Operator commutativity
Henrik Faber hfa...@invalid.net writes: How can I make this commutative? Incidentally - this isn't really about commutativity at all - the question is how can you define both left and right versions of add, irrespective of whether they yield the same result. I think __radd__ is what you're after. -- http://mail.python.org/mailman/listinfo/python-list
Re: Processing a large string
goldtech goldt...@worldpost.com writes: Hi, Say I have a very big string with a pattern like: akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn. I want to split the sting into separate parts on the 3 and process each part separately. I might run into memory limitations if I use split and get a big array(?) I wondered if there's a way I could read (stream?) the string from start to finish and read what's delimited by the 3 into a variable, process the smaller string variable then append/build a new string with the processed data? Would I loop it and read it char by char till a 3...? Or? Thanks. s = akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn for k, subs in itertools.groupby(s, lambda x: x==3): print ''.join(subs) what you actually do in the body of the loop depends on what you want to do with the bits. -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I make a program automatically run once per day?
John Salerno johnj...@gmail.com writes: I have a script that does some stuff that I want to run every day for maybe a week, or a month. So far I've been good about running it every night, but is there some way (using Python, of course) that I can make it automatically run at a set time each night? Well - you can make a long lived python process that puts itself to sleep for 24 hours and then wakes up and does stuff, but the normal approach to this kind of thing is to use cron. On windows there's also some kind of scheduler. -- http://mail.python.org/mailman/listinfo/python-list
Re: Does hashlib support a file mode?
Anssi Saari a...@sci.fi writes: Mel mwil...@the-wire.com writes: def file_to_hash(path, m = hashlib.md5()): hashlib.md5 *is* called once; that is when the def statement is executed. Very interesting, I certainly wasn't clear on this. So after that def, the created hashlib object is in the module's scope and can be accessed via file_to_hash.__defaults__[0]. This also why you have to be a bit careful if you use e.g. [] or {} as a default argument - if you then modify these things within the function you might not end up with what you expect - it's the same list or dictionary each time the function is called. So to avoid that kind of thing you end up with code like: def foo(bar=None): if bar is None: bar = [] ... -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError: unbound method DefaultTracer() must be called with MyClass instance as first argument (got str instance instead)
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes: Please don't post code with line numbers. That makes it difficult to copy and paste your function into an interactive session, so that we can run it and see what it does. C-x r d -- http://mail.python.org/mailman/listinfo/python-list
Re: Fibonacci series recursion error
harrismh777 harrismh...@charter.net writes: lalit wrote: The above function return the return (fib(n-1)+fib(n-2)) RuntimeError: maximum recursion depth exceeded in comparison [36355 refs] There is much debate about this generally, but general wisdom is that recursion is to be avoided when possible. Another way to say this is, Only use recursion when there is no other obvious way to handle the problem. Recursion is very tempting to young artists because its a ~cool trick, and because sometimes it requires very little coding (although huge amounts of memory!), Writing recurive code is acceptable and is a nice clear way of expressing things when you have naturally recursive data structures, and can lead to perfectly good compiled code. The problem in CPython is the lack of tail optimization, so it's not a good idea for python . Some language standards guarantee tail optimization... -- http://mail.python.org/mailman/listinfo/python-list
Re: Fibonacci series recursion error
Hans Georg Schaathun h...@schaathun.net writes: On Sat, 30 Apr 2011 06:43:42 +0100, Paul Rudin paul.nos...@rudin.co.uk wrote: : Writing recurive code is acceptable and is a nice clear way of : expressing things when you have naturally recursive data structures, and : can lead to perfectly good compiled code. The problem in CPython is the : lack of tail optimization, so it's not a good idea for python . Some : language standards guarantee tail optimization... Well, if you run into a case where tail optimisation really makes a difference, you probably want to reimplement it for a compiler that guarantees tail optimisation, rather than reimplement it without recursion within python. Clearly it makes a difference in any case where you'd hit the recursion limit. It's no big deal to do your own unwinding of the recursion to a loop, but the code is typically less clear. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fibonacci series recursion error
Hans Georg Schaathun h...@schaathun.net writes: On Sat, 30 Apr 2011 12:29:00 +0100, Paul Rudin paul.nos...@rudin.co.uk wrote: : Clearly it makes a difference in any case where you'd hit the recursion : limit. What kind of problems make you hit the limit? Other than when you forget the base case, I mean. Anytime you have enough data... there are plenty of things that are natural to represent as recursive data structures, and often you don't know in advance how much data your code is going to have to deal with. -- http://mail.python.org/mailman/listinfo/python-list
Re: Feature suggestion -- return if true
Teemu Likonen tliko...@iki.fi writes: I'm a simple Lisp guy who wonders if it is be possible to add some kind of macros to the language... As a (now somewhat lapsed) long-time lisp programmer I sympathise with the sentiment, but suspect that it's not going to gain serious traction in python circles. -- http://mail.python.org/mailman/listinfo/python-list
Re: Directly Executable Files in Python
Benjamin Kaplan benjamin.kap...@case.edu writes: If you can figure out a good way to compile a language like Python, you'll be very rich. Yes, it is running the interpreter and then running the bytecode on the interpreter. It's the same way Java and .NET work. Not exactly AIUI. .NET bytecodes do actually get compiled to executable code before being executed (unless things have changed recently - I haven't really done anything significant with .NET in the last couple of years). -- http://mail.python.org/mailman/listinfo/python-list
Re: best python games?
alex23 wuwe...@gmail.com writes: Paul Rudin paul.nos...@rudin.co.uk wrote: Apparently Eve Online is (stackless) python. I've dropped a ridiculous number of hours into EVE this year alone but I'd be very hesitant to ever mention best in relation to its coding :) It uses way too much floating point incorrectly, the in-game calculator gives the result of 878.53 - 874.20 as 4.32999. I'm pretty sure this is also why occasionally you'll be left with 1 0.01m3 unit out of 39, with the storage container complaining it's full at 38,.99. Floating point arithmetic isn't, in general, precise. I don't know the game, so I can't comment on whether they should have chosen to ensure precision in this context, but presumably that would make things a little slower. -- http://mail.python.org/mailman/listinfo/python-list
Re: best python games?
sogeking99 neilalt300...@gmail.com writes: hey guys, what are some of the best games made in python? free games really. like pygames stuff. i want to see what python is capable of. Apparently Eve Online is (stackless) python. -- http://mail.python.org/mailman/listinfo/python-list
Re: Easy function, please help.
Nanderson mandersonrandersonander...@gmail.com writes: loop would be infinite. I get what is happening in the function, and I understand why this would work, but for some reason it's confusing me as to how it is exiting the loop after a certain number of times. Help is appreciated, thanks. It works because 0 tests false and because integer division yields integers... eventually you'll get something like 1/10 giving 0. It's not necessarily a good thing to rely on. For example if you try it after from __future__ import division - or in python 3 - you'll get a float as the result of the division and it won't test False. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is Eval *always* Evil?
Robert Kern robert.k...@gmail.com writes: On 2010-11-10 17:14 , Christian Heimes wrote: Am 10.11.2010 18:56, schrieb Simon Mullis: Yes, eval is evil, may lead to security issues and it's unnecessary slow, too. Still - it is used in the standard library... -- http://mail.python.org/mailman/listinfo/python-list
Re: Learning Pyhton - Functional Programming - How intersect/difference two dict with dict/values? fast!
Lawrence D'Oliveiro l...@geek-central.gen.new_zealand writes: In message mailman.787.1289336127.2218.python-l...@python.org, Terry Reedy wrote: To echo John Nagle's point, if you want non-masochist volunteers to read your code, write something readable like: dict1 = {'ab': [[1,2,3,'d3','d4',5], 12], 'ac': [[1,3,'78a','79b'], 54], 'ad': [[56,57,58,59], 34], 'ax': [[56,57,58,59], 34]} How come Python itself doesn’t display things that way? try: pprint.pprint(dict1) -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple discontinued ranges
xoff igor.idziejc...@gmail.com writes: I was wondering what the best method was in Python programming for 2 discontinued ranges. e.g. I want to use the range 3 to 7 and 17 to 23. Am I obliged to use 2 for loops defining the 2 ranges like this: for i in range (3,7): do bla for i in range (7,17): do bla or is there a more clever way to do this? for i in itertools.chain(xrange(3,7), xrange(17,23)): print i -- http://mail.python.org/mailman/listinfo/python-list
Re: What is the best way to handle a missing newline in the following case
danmcle...@yahoo.com danmcle...@yahoo.com writes: The problem is when I get to the last line. When the program sees '\n' after the 9, everything works fine. However, when there isn't a '\n', the program doesn't process the last line. What would be the best approach to handle the case of the possible missing '\n' at the end of the file? use readines to read all lines into a list and then iterate thru the list: f = open(r'c:\test.txt', 'rb') print f.readlines() ['1\r\n', '3\r\n', '5\r\n', '7\r\n', '3\r\n', '9'] There's no real point in contructing a list. Just do with open(r'c:\test.txt') as f: for l in f: print int(l) As long as you just have digits and whitespace then that's fine - int() will do as you want. -- http://mail.python.org/mailman/listinfo/python-list
Re: What people are using to access this mailing list
John Bond li...@asd-group.com writes: On 3/11/2010 11:17 AM, Steven D'Aprano wrote: On Wed, 03 Nov 2010 08:02:29 +, John Bond wrote: Hope this isn't too O/T - I was just wondering how people read/send to this mailing list, eg. normal email client, gmane, some other software or online service? Usenet via my ISP, on comp.lang.python. Using what client (or web client)? Emacs, of course :-; -- http://mail.python.org/mailman/listinfo/python-list
Re: Python documentation too difficult for beginners
Steven D'Aprano st...@remove-this-cybersource.com.au writes: A fair point -- the built-in open comes up as hit #30, whereas searching for open in the PHP page brings up fopen as hit #1. But the PHP search also brings up many, many hits -- ten pages worth. OTOH googling for python open gives you the correct (for 2.7) page as hit #1 - although you then have to use your browser's find facilty to actually get to the description of the function in question. -- http://mail.python.org/mailman/listinfo/python-list
Re: functions, list, default parameters
Terry Reedy tjre...@udel.edu writes: Suppose I write an nasty C extension that mutates tuples. What then would be illegal about... Depends on exactly what we mean by legal. If immutability is part of the language spec (rather than an artifact of a particular implementation) then a compiler could assume immutability. -- http://mail.python.org/mailman/listinfo/python-list
Re: embarrassing class question
Gregory Ewing greg.ew...@canterbury.ac.nz writes: Brendan wrote: I use Python sporadically, and frequently use the dir command to learn or remind myself of class methods. You can clean up dir() by defining __all__ as a list of names that you want to officially export. Other names will still be there, but they won't show up in the dir() listing. I'm not sure that's necessarily a good idea... when you're trying to figure out why something behaves in a certain way you want to check for the presence of methods with special names. -- http://mail.python.org/mailman/listinfo/python-list
Re: is list comprehension necessary?
Andre Alexander Bell p...@andre-bell.de writes: I occasionally use LCs, if they seem useful. However, what I don't like about LCs is that they 'look-like' being a closed scope, while actually they are in the scope of there call. Example: i = 5 l = [i**2 for i in range(3)] i 2 Although: p...@sleeper-service:~$ python3 Python 3.1.2 (r312:79147, Sep 27 2010, 09:57:50) [GCC 4.4.3] on linux2 Type help, copyright, credits or license for more information. i = 5 l = [i**2 for i in range(3)] i 5 -- http://mail.python.org/mailman/listinfo/python-list