Re: Rename file without overwriting existing files

2017-02-01 Thread Steve D'Aprano
On Tue, 31 Jan 2017 02:56 am, Grant Edwards wrote: > On 2017-01-30, Terry Reedy wrote: >> On 1/30/2017 8:58 AM, Peter Otten wrote: >>> Jussi Piitulainen wrote: >> It doesn't seem to be documented. >>> >>> For functions with a C equivalent a look into the man page is

Re: Is shutil.get_terminal_size useless?

2017-02-01 Thread Steve D'Aprano
On Sun, 29 Jan 2017 04:58 am, Chris Angelico wrote: > On Sun, Jan 29, 2017 at 3:15 AM, Steve D'Aprano > <steve+pyt...@pearwood.info> wrote: >> On Sat, 28 Jan 2017 10:50 pm, Chris Angelico wrote: >> >>> On Sat, Jan 28, 2017 at 9:49 PM, Steve D'Aprano >&

Re: Is shutil.get_terminal_size useless?

2017-02-01 Thread Steve D'Aprano
On Sat, 28 Jan 2017 11:53 pm, Peter Otten wrote: [...] >> I see that as "Hey look, we can fool shutil into returning >> absolute garbage instead of the terminal size!" > > There are valid reasons for temporarily altering the number of columns, > like writing to a file or preparing a code sample.

Re: best way to ensure './' is at beginning of sys.path?

2017-02-03 Thread Steve D'Aprano
On Sat, 4 Feb 2017 03:06 am, Neal Becker wrote: > I want to make sure any modules I build in the current directory overide > any > others. To do this, I'd like sys.path to always have './' at the > beginning. > > What's the best way to ensure this is always true whenever I run python3? For

Re: best way to ensure './' is at beginning of sys.path?

2017-02-03 Thread Steve D'Aprano
On Sat, 4 Feb 2017 01:13 pm, Cameron Simpson wrote: >>1. In your .bashrc file, or equivalent, set the environment >> variable PYTHONPATH: >>export PYTHONPATH='./;$PYTHONPATH' > > You want double quotes (allowing parameter substitution) instead of single > quotes here. Or, of course, no quotes

Re: best way to ensure './' is at beginning of sys.path?

2017-02-03 Thread Steve D'Aprano
On Sat, 4 Feb 2017 10:13 am, Ben Finney wrote: > So, for the past ten years and more, Python supports import of modules > from the current directory with an explicit *relative* path:: > > # Absolute imports, searching ‘sys.path’. > import datetime > from collections import namedtuple

Re: best way to ensure './' is at beginning of sys.path?

2017-02-03 Thread Steve D'Aprano
On Sat, 4 Feb 2017 10:13 am, Ben Finney wrote: > Neal Becker writes: > >> I want to make sure any modules I build in the current directory >> overide any others. To do this, I'd like sys.path to always have './' >> at the beginning. > > The ‘sys.path’ list is used only for

Re: best way to ensure './' is at beginning of sys.path?

2017-02-05 Thread Steve D'Aprano
On Sun, 5 Feb 2017 07:01 pm, Wildman wrote: > Sure, you > could trick someone into running a program that could > mess with $HOME but that is all.  For anyone, like me, > that makes regular backups, that is not a big problem. > To do any real damage to the system or install a key > logger or some

Re: best way to ensure './' is at beginning of sys.path?

2017-02-05 Thread Steve D'Aprano
On Mon, 6 Feb 2017 09:26 am, Chris Angelico wrote: > On Mon, Feb 6, 2017 at 9:07 AM, Steve D'Aprano > <steve+pyt...@pearwood.info> wrote: >> As far as "regular backups", well, you're just not thinking deviously >> enough. If I were to write a ransomware applicati

Re: PEP 393 vs UTF-8 Everywhere

2017-01-22 Thread Steve D'Aprano
On Mon, 23 Jan 2017 02:19 am, Marko Rauhamaa wrote: > Steve D'Aprano <steve+pyt...@pearwood.info>: > >> On Sun, 22 Jan 2017 07:34 pm, Marko Rauhamaa wrote: >> >>> Steve D'Aprano <steve+pyt...@pearwood.info>: >>> >>>> On Sun, 22 Jan

Re: PEP 393 vs UTF-8 Everywhere

2017-01-21 Thread Steve D'Aprano
On Sat, 21 Jan 2017 11:45 pm, Tim Chase wrote: > but I'm hard-pressed to come up with any use case where direct > indexing into a (non-byte)string makes sense unless you've already > processed/searched up to that point and can use a recorded index > from that processing/search. Let's take a

Re: PEP 393 vs UTF-8 Everywhere

2017-01-21 Thread Steve D'Aprano
On Sat, 21 Jan 2017 09:35 am, Pete Forman wrote: > Can anyone point me at a rationale for PEP 393 being incorporated in > Python 3.3 over using UTF-8 as an internal string representation? I've read over the PEP, and the email discussion, and there is very little mention of UTF-8, and as far as I

Re: How coding in Python is bad for you

2017-01-24 Thread Steve D'Aprano
On Wed, 25 Jan 2017 03:21 am, Ben Bacarisse wrote: > Chris Angelico writes: > >> On Wed, Jan 25, 2017 at 2:51 AM, Ben Bacarisse >> wrote: [...] >>> Can I ask what editor(s) your students have available? I ask because >>> I've not given a moment's

Re: How coding in Python is bad for you

2017-01-24 Thread Steve D'Aprano
On Tue, 24 Jan 2017 10:52 pm, BartC wrote: >> if condition: >> statement >> endif >> statement >> endif >> >> What's this code meant to do? Can't know. > > But whatever it does, a language that enforces 'endif' would report an > error, so requiring further investigation. Without the

Re: How coding in Python is bad for you

2017-01-23 Thread Steve D'Aprano
On Tue, 24 Jan 2017 08:55 am, BartC wrote: > On 23/01/2017 17:34, Chris Angelico wrote: >> On Tue, Jan 24, 2017 at 4:24 AM, wrote: >>> The article is here http://lenkaspace.net/index.php/blog/show/111 >> >> I would respond point-by-point if I thought the author had a

Re: How an editor can help with block nesting (was Re: How coding in Python is bad for you)

2017-01-24 Thread Steve D'Aprano
On Wed, 25 Jan 2017 08:19 am, Chris Angelico wrote: > I kinda like the idea of showing what the innermost active block > heading is for any given line of code. That would be fairly > straight-forward: scroll up till you find a non-blank line with less > indentation than the one you're on, and put

Re: Rename file without overwriting existing files

2017-01-30 Thread Steve D'Aprano
On Mon, 30 Jan 2017 03:33 pm, Cameron Simpson wrote: > On 30Jan2017 13:49, Steve D'Aprano <steve+pyt...@pearwood.info> wrote: >>This code contains a Time Of Check to Time Of Use bug: >> >>if os.path.exists(destination) >>raise ValueError('destination

Re: Overriding True and False ?

2017-01-30 Thread Steve D'Aprano
On Tue, 31 Jan 2017 03:12 am, Ian Kelly wrote: > On Jan 30, 2017 1:32 AM, "Irv Kalb" wrote: > > I teach intro to programming using Python. In my first assignment, > students are asked to assign variables of different types and print out > the values. [...] Hey Ian, Your

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Steve D'Aprano
On Sat, 28 Jan 2017 07:39 pm, Peter Otten wrote: > One potential advantage of shutil.get_terminal_size() is that you can > affect it with an environment variable: > > $ python3 test_gts.py | cat > shutil: os.terminal_size(columns=999, lines=999) > os: os.terminal_size(columns=72, lines=48) > >

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Steve D'Aprano
On Sat, 28 Jan 2017 10:50 pm, Chris Angelico wrote: > On Sat, Jan 28, 2017 at 9:49 PM, Steve D'Aprano > <steve+pyt...@pearwood.info> wrote: >> The terminal size doesn't change just because I'm piping output to >> another process. Using the terminal size as a proxy for &

Re: Is shutil.get_terminal_size useless?

2017-01-28 Thread Steve D'Aprano
On Sat, 28 Jan 2017 07:27 pm, Chris Angelico wrote: > On Sat, Jan 28, 2017 at 7:03 PM, Steve D'Aprano > <steve+pyt...@pearwood.info> wrote: >> But if I pipe the output to something else, the shutil version fails to >> determine the correct terminal size, and f

Re: Need reviews for my book on introductory python

2017-01-27 Thread Steve D'Aprano
On Sat, 28 Jan 2017 03:12 pm, D'Arcy Cain wrote: > I can't believe how many typos and grammar errors there are in this > thread by people correcting typos and grammar. That's practically a law of physics: the Iron Law of Nitpicking, better known as Muphry's Law.

Is shutil.get_terminal_size useless?

2017-01-28 Thread Steve D'Aprano
shutil.get_terminal_size returns the wrong values when you pipe your output to another process, even it you do so in a terminal. Consider this script: import os import shutil print('shutil:', shutil.get_terminal_size(fallback=(999, 999))) print('os:', os.get_terminal_size(0)) That uses two

Re: How coding in Python is bad for you

2017-01-29 Thread Steve D'Aprano
On Mon, 30 Jan 2017 10:52 am, Erik wrote: > On 29/01/17 14:42, Steve D'Aprano wrote: >> 1. for...else is misspelled, and should be for...then; >> >> 2. Same for while...else; > > I don't think I'll ever agree with you on this one. > > "then", to

Re: Is shutil.get_terminal_size useless?

2017-01-29 Thread Steve D'Aprano
On Mon, 30 Jan 2017 08:12 am, Serhiy Storchaka wrote: > On 28.01.17 10:03, Steve D'Aprano wrote: >> Is shutil.get_terminal_size useless? When, if ever, should I use it in >> preference to the os version? If the shutil version is broken, can it be >> fixed?

Rename file without overwriting existing files

2017-01-29 Thread Steve D'Aprano
This code contains a Time Of Check to Time Of Use bug: if os.path.exists(destination) raise ValueError('destination already exists') os.rename(oldname, destination) In the microsecond between checking for the existence of the destination and actually doing the rename, it is

Re: PEP 393 vs UTF-8 Everywhere

2017-01-21 Thread Steve D'Aprano
On Sun, 22 Jan 2017 07:21 am, Pete Forman wrote: > Marko Rauhamaa writes: > >>> py> low = '\uDC37' >> >> That should raise a SyntaxError exception. > > Quite. My point was that with older Python on a narrow build (Windows > and Mac) you need to understand that you are using

Re: PEP 393 vs UTF-8 Everywhere

2017-01-21 Thread Steve D'Aprano
On Sun, 22 Jan 2017 06:52 am, Marko Rauhamaa wrote: > Pete Forman : > >> Surrogates only exist in UTF-16. They are expressly forbidden in UTF-8 >> and UTF-32. > > Also, they don't exist as Unicode code points. Python shouldn't allow > surrogate characters in strings.

Re: PEP 393 vs UTF-8 Everywhere

2017-01-22 Thread Steve D'Aprano
On Sun, 22 Jan 2017 07:34 pm, Marko Rauhamaa wrote: > Steve D'Aprano <steve+pyt...@pearwood.info>: > >> On Sun, 22 Jan 2017 06:52 am, Marko Rauhamaa wrote: >>> Also, [surrogates] don't exist as Unicode code points. Python >>> shouldn't allow surrogate ch

Re: How coding in Python is bad for you

2017-01-29 Thread Steve D'Aprano
On Mon, 30 Jan 2017 12:05 am, BartC wrote: > What might be unreasonable is to criticise it in a Python group full > of language aficionados who are going to view every feature and quirk of > the language in a good light; It's all about the trade-offs we choose to make. Its not that we don't

Re: python decorator

2017-02-22 Thread Steve D'Aprano
On Wed, 22 Feb 2017 08:47 pm, Cecil Westerhof wrote: > On Wednesday 22 Feb 2017 08:49 CET, Argentinian Black ops lll wrote: > >> *** SOLVED *** > > It would be nice if you shared the solution. I believe Cameron's post contains the bones of a solution. Here's my untested solution. def

RE: Python application launcher (for Python code)

2017-02-20 Thread Steve D'Aprano
On Tue, 21 Feb 2017 04:04 am, Deborah Swanson wrote: > That's a good idea, you can do just about anything from a shell, and I > read that Linus Torvalds never uses anything except the shell. [...] > Since I will be in Windows for yet awhile, it would be ideal to find an > application that will

Re: Python - decode('hex')

2017-02-20 Thread Steve D'Aprano
On Tue, 21 Feb 2017 06:43 am, Ganesh Pal wrote: > How can I make my program 2 look like program 1 I don't understand the question. If you want program 2 to look like program 1, you can edit program 2 and change it to look like program 1. But why not just use program 1? It already looks like

RE: Python application launcher (for Python code)

2017-02-20 Thread Steve D'Aprano
On Tue, 21 Feb 2017 02:44 am, Deborah Swanson wrote: [...] > Basically, I now have quite a few Python programs I use frequently, and > as time goes on my collection and uses of it will grow. Right now I just > want a way to select which one I'd like to run and run it. I'd like it > to be a

Re: Disallowing instantiation of super class

2017-02-24 Thread Steve D'Aprano
On Fri, 24 Feb 2017 11:19 am, Irv Kalb wrote: > Hi, > > I have built a set of three classes: > > - A super class, let's call it: Base [...] > I would like to add is some "insurance" that I (or someone else who uses > my code) never instantiates my Base class, It is not intended to be >

Re: Disallowing instantiation of super class

2017-02-24 Thread Steve D'Aprano
On Sat, 25 Feb 2017 05:40 am, MRAB wrote: >> class Base: >> def __init__(self): >> if type(self) is Base: >> raise TypeError("cannot instantiate Base class") >> >> >> Does that help? >> > D'oh! Never thought of that! :-) > > The OP is using Python 2.7, so you'll need to

Re: Namedtuples problem

2017-02-23 Thread Steve D'Aprano
On Thu, 23 Feb 2017 08:38 pm, Deborah Swanson wrote: > However, > > group[[idx][records_idx[label]]] > gets an Index Error: list index out of range That's not very helpful: judging from that line alone, there could be as many as THREE places in that line of code that might generate IndexError.

Re: int vs. float

2017-02-11 Thread Steve D'Aprano
On Sat, 11 Feb 2017 07:24 pm, Marko Rauhamaa wrote: > boB Stepp : > >> According to the OP's professor's challenge, the OP needs to recognize >> an input of "4.0" as a float and "4" as an integer, and to respond >> with an error message in the float case, or "decimal

Re: int vs. float

2017-02-11 Thread Steve D'Aprano
On Sat, 11 Feb 2017 06:00 pm, Amit Yaron wrote: > Another option: > Use 'float' instead of 'int'. and check using the method 'is_integer' > of floating point numbers: > > >>> 3.5.is_integer() > False > >>> 4.0.is_integer() > True A bad option... py> float('12345678901234567')

Re: os.path.isfile

2017-02-11 Thread Steve D'Aprano
On Sat, 11 Feb 2017 05:11 am, epro...@gmail.com wrote: > Hello NG > > Python 3.5.2 > > Windows 10 > > os.path.isfile() no recognise file with double dot? > > eg. match.cpython-35.pyc I doubt that very much. I expect you are probably writing something like this: path = 'My

Re: os.path.isfile

2017-02-11 Thread Steve D'Aprano
On Sat, 11 Feb 2017 06:50 am, Vincent Vande Vyvre wrote: > Le 10/02/17 à 19:11, epro...@gmail.com a écrit : >> Hello NG >> >> Python 3.5.2 >> >> Windows 10 >> >> os.path.isfile() no recognise file with double dot? >> >> eg. match.cpython-35.pyc >> >> Please somebody know something about that? >>

Re: int vs. float

2017-02-11 Thread Steve D'Aprano
On Sun, 12 Feb 2017 02:34 pm, Chris Angelico wrote: > On Sun, Feb 12, 2017 at 2:27 PM, Steve D'Aprano > <steve+pyt...@pearwood.info> wrote: >>> >>> For example: >>> >>>>>> ast.literal_eval("( 1.0, 3 )").__class__.__name

Re: Rename file without overwriting existing files

2017-02-11 Thread Steve D'Aprano
On Fri, 10 Feb 2017 12:07 am, eryk sun wrote: > On Thu, Feb 9, 2017 at 11:46 AM, Steve D'Aprano > <steve+pyt...@pearwood.info> wrote: >> >> So to summarise, os.rename(source, destination): >> >> - is atomic on POSIX systems, if source and destination a

Re: os.path.isfile

2017-02-11 Thread Steve D'Aprano
On Sun, 12 Feb 2017 03:20 pm, eryk sun wrote: > On Sun, Feb 12, 2017 at 3:52 AM, Steve D'Aprano > <steve+pyt...@pearwood.info> wrote: >> In Python, you should always use forward slashes for paths, even on >> Windows. > > There are cases where slash doesn't

Re: Problems with scripts

2017-02-13 Thread Steve D'Aprano
On Tue, 14 Feb 2017 03:30 am, lauren.sophia1...@gmail.com wrote: > Hello! I have 2 python assignments that I just can't figure out. The first > one returns the same thing no matter what I input and the second won't > accept "done" to stop the program and return answers. Please help! Hi Lauren,

Re: WANT: bad code in python (for refactoring example)

2017-02-15 Thread Steve D'Aprano
On Wed, 15 Feb 2017 09:49 pm, Antoon Pardon wrote: > Op 15-02-17 om 07:28 schreef Steven D'Aprano: [...] >> Why not use sys.stdout.write directly? Or print? If I saw somebody using >> this recipe in production code, in the way shown, I'd refactor it to just >> use print. There's no advantage to

Re: Problems with scp script in Python

2017-02-13 Thread Steve D'Aprano
On Mon, 13 Feb 2017 11:17 pm, jhlo...@gmail.com wrote: > I have an SCP script that auto completes just fine from the terminal > window in Pi.  When I use either subprocess or os to try and have it run > under Python it does not do the file transfer from Pi to my Ubuntu > machine.  What am I doing

Re: os.path.isfile

2017-02-12 Thread Steve D'Aprano
On Mon, 13 Feb 2017 11:43 am, Chris Angelico wrote: > On Mon, Feb 13, 2017 at 11:40 AM, Erik wrote: >> FWIW, if you'd have written the above as your first response I wouldn't >> have argued ;) You alluded to it, for sure ... :D > > Nothing wrong with respectfully

Re: Rename file without overwriting existing files

2017-02-09 Thread Steve D'Aprano
On Mon, 30 Jan 2017 09:39 pm, Peter Otten wrote: def rename(source, dest): > ... os.link(source, dest) > ... os.unlink(source) > ... rename("foo", "baz") os.listdir() > ['bar', 'baz'] rename("bar", "baz") > Traceback (most recent call last): > File "", line 1, in >

Re: Rename file without overwriting existing files

2017-02-09 Thread Steve D'Aprano
On Tue, 31 Jan 2017 11:17 am, Ben Finney wrote: > Peter Otten <__pete...@web.de> writes: > >> http://stackoverflow.com/questions/3222341/how-to-rename-without-race-conditions >> >> and from a quick test it appears to work on Linux: > > By “works on Linux”, I assume you mean “works on

Re: PTH files: Abs paths not working as expected. Symlinks needed?

2017-02-15 Thread Steve D'Aprano
On Wed, 15 Feb 2017 11:42 pm, poseidon wrote: > Yes, removed it (symlink still there) and it still works. But then, what > are pth files for? Good question. I don't actually know anyone that uses pth files, so perhaps they're unnecessary. But the principle behind them is that they can be used

Re: Emulating Final classes in Python

2017-01-18 Thread Steve D'Aprano
On Thu, 19 Jan 2017 09:02 am, Ethan Furman wrote: [...] > One problem with the above is existing instances won't be modified to > inherit from the updated class. I am unsure if that is solvable before > 3.6, but in 3.6 one can use the new __init_subclass__ to avoid a Final > base class, a

Re: Emulating Final classes in Python

2017-01-17 Thread Steve D'Aprano
On Wed, 18 Jan 2017 06:14 am, Ethan Furman wrote: > On 01/16/2017 11:32 PM, Steven D'Aprano wrote: >> On Tuesday 17 January 2017 18:05, Steven D'Aprano wrote: >> >>> I wish to emulate a "final" class using Python, similar to bool: >> >> I may have a solution: here's a singleton (so more like None

Re: Emulating Final classes in Python

2017-01-17 Thread Steve D'Aprano
On Tue, 17 Jan 2017 08:54 pm, Erik wrote: > Hi Steven, > > On 17/01/17 07:05, Steven D'Aprano wrote: >> I wish to emulate a "final" class using Python, similar to bool: > > [snip] > >> It doesn't have to be absolutely bulletproof, but anyone wanting to >> subclass my class should need to work

Re: multiprocessing.Process call blocks other processes from running

2017-01-14 Thread Steve D'Aprano
On Sun, 15 Jan 2017 05:46 am, Rodrick Brown wrote: > at some point the forking was working Then whatever you changed, you should change back to the way it was. That's the most important lesson here: never make two or more unrelated changes to a program unless you have a backup of the working

Re: Error handling in context managers

2017-01-16 Thread Steve D'Aprano
On Tue, 17 Jan 2017 05:06 am, Israel Brewster wrote: > I generally use context managers for my SQL database connections, so I can > just write code like: > > with psql_cursor() as cursor: > > > And the context manager takes care of making a connection (or getting a > connection from a

Re: ipython2 does not work anymore

2017-01-19 Thread Steve D'Aprano
On Fri, 20 Jan 2017 02:06 am, Cecil Westerhof wrote: > I did not work with ipython2 for a long time. Most of my work is done > with python3. I just tried to start ipython2 and got: > Traceback (most recent call last): [...] > ImportError: No module named path > > > What could be the problem

Re: Does This Scare You?

2016-08-21 Thread Steve D'Aprano
On Mon, 22 Aug 2016 10:38 am, eryk sun wrote: > To me it's scary that this check misses cases because it's trying to > be cross-platform instead of simply relying on GetFullPathName to do > the work. For example, it misses at least the following cases: Instead of shaking in your boots over a

Re: type lookuperror

2016-08-19 Thread Steve D'Aprano
On Fri, 19 Aug 2016 02:30 am, Chris Angelico wrote: > On Fri, Aug 19, 2016 at 2:21 AM, Marko Rauhamaa wrote: >> >> Yeah, I believe truly conscious machines will arise without being >> designed through technological evolution. First they'll develop >> electronics that can

Re: integer's methods

2016-08-19 Thread Steve D'Aprano
On Thu, 18 Aug 2016 10:58 pm, ast wrote: > Hello > > I wonder why calling a method on an integer > doesn't work ? > 123.bit_length() > SyntaxError: invalid syntax Because Python thinks you are writing a float, and "b" is not a valid digit. Try: (123).bit_length() 123 .bit_length()

Re: type lookuperror

2016-08-19 Thread Steve D'Aprano
On Fri, 19 Aug 2016 11:43 am, meInvent bbird wrote: > a company which write siri in iphone, has already wrote a program > which can write program itself after the program talks with users > > it seems possible, You are asking about self-modifying code, which is a terrible idea. Siri uses

Re: index for regex.search() beyond which the RE engine will not go.

2016-08-19 Thread Steve D'Aprano
On Fri, 19 Aug 2016 09:14 pm, iMath wrote: > > for > regex.search(string[, pos[, endpos]]) > The optional parameter endpos is the index into the string beyond which > the RE engine will not go, while this lead me to believe the RE engine > will still search on till the endpos position even after

Re: Nuitka Release 0.5.22

2016-08-19 Thread Steve D'Aprano
On Thu, 18 Aug 2016 06:58 am, breamore...@gmail.com wrote: > As Kay (him) is less than useless at sales and marketing, somebody has to > do it, so here you are folks > http://nuitka.net/posts/nuitka-release-0522.html Thanks for the link. -- Steve “Cheer up,” they said, “things could be

Re: index for regex.search() beyond which the RE engine will not go.

2016-08-19 Thread Steve D'Aprano
On Fri, 19 Aug 2016 09:21 pm, Jon Ribbens wrote: > On 2016-08-19, iMath wrote: >> for >> regex.search(string[, pos[, endpos]]) >> The optional parameter endpos is the index into the string beyond >> which the RE engine will not go, while this lead me to believe the >> RE

Re: saving octet-stream png file

2016-08-19 Thread Steve D'Aprano
On Sat, 20 Aug 2016 06:51 am, Lawrence D’Oliveiro wrote: > On Saturday, August 20, 2016 at 6:03:53 AM UTC+12, Terry Reedy wrote: >> >> An 'octet' is a byte of 8 bits. > > Is there any other size of byte? Depends what you mean by "byte", but the short answer is "Yes". In the C/C++ standard,

Re: Holding until next value change

2016-08-20 Thread Steve D'Aprano
On Sat, 20 Aug 2016 02:53 pm, Arshpreet Singh wrote: > I am writing a function as main_call() which is continuously producing > values. (+ve or -ve) I want to print on screen only for first +ve value > and hold until -ve value comes around. here is my code: > > > def main_call(): > while

Re: Two-Dimensional Expression Layout

2016-08-20 Thread Steve D'Aprano
On Sun, 21 Aug 2016 08:22 am, Lawrence D’Oliveiro wrote: > Another example, from : the sequence of > values is laid out to allow easy additions/modifications in future. When replying, I normally try to trim unnecessary code snippets down to the critical line or

Re: Two-Dimensional Expression Layout

2016-08-20 Thread Steve D'Aprano
On Sun, 21 Aug 2016 10:43 am, Michael Selik wrote: > On Sat, Aug 20, 2016 at 6:21 PM Lawrence D’Oliveiro > wrote: > >> > p0 = (0, 0) >> > p1 = (major_dim, 0) >> > colour_stops = (0, rect_1_colour), (1, complement(rect_1_colour)) >> > rect_1_pattern =

Re: Two-Dimensional Expression Layout

2016-08-20 Thread Steve D'Aprano
On Sun, 21 Aug 2016 09:44 am, Lawrence D’Oliveiro wrote: > Why do you think I put in those “#end” lines? Do you really want us to answer that? I don't think you will like the answer. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got

Re: Two-Dimensional Expression Layout

2016-08-20 Thread Steve D'Aprano
Oh wait! The penny drops! On Sun, 21 Aug 2016 10:43 am, Michael Selik wrote: > On Sat, Aug 20, 2016 at 6:21 PM Lawrence D’Oliveiro >> >> if ( >> >> not isinstance(src, Image) >> >> or >> >> mask != None and not isinstance(mask, Image) >> >> or >> >>

Re: Does This Scare You?

2016-08-22 Thread Steve D'Aprano
On Mon, 22 Aug 2016 08:33 pm, Jon Ribbens wrote: > On 2016-08-22, Steve D'Aprano <steve+pyt...@pearwood.info> wrote: >> On Mon, 22 Aug 2016 10:38 am, eryk sun wrote: >>> To me it's scary that this check misses cases because it's trying to >>> be cross-p

Re: PEP suggestion: Uniform way to indicate Python language version

2016-08-22 Thread Steve D'Aprano
On Mon, 22 Aug 2016 08:32 pm, rocky wrote: > On Monday, August 22, 2016 at 1:36:07 AM UTC-4, Steven D'Aprano wrote: [...] >> But... I don't understand what this proposal actually is. We already have >> a uniform way to indicate the Python language version: check sys.version, >> or

Re: Does This Scare You?

2016-08-22 Thread Steve D'Aprano
On Mon, 22 Aug 2016 10:56 pm, Random832 wrote: > On Mon, Aug 22, 2016, at 08:39, Chris Angelico wrote: >> Nope. On Windows, you would try/except it. > > No, you can't, because the failure mode often isn't "file refuses to > open" but "data is written to a serial port". Ah, that's a good point.

Re: Does This Scare You?

2016-08-22 Thread Steve D'Aprano
On Mon, 22 Aug 2016 09:50 pm, Jon Ribbens wrote: > On 2016-08-22, Chris Angelico <ros...@gmail.com> wrote: >> On Mon, Aug 22, 2016 at 8:33 PM, Jon Ribbens <jon+use...@unequivocal.eu> >> wrote: >>> On 2016-08-22, Steve D'Aprano <steve+pyt...@pearwood.info>

Re: PEP suggestion: Uniform way to indicate Python language version

2016-08-22 Thread Steve D'Aprano
On Mon, 22 Aug 2016 10:52 pm, Random832 wrote: > On Mon, Aug 22, 2016, at 08:44, Chris Angelico wrote: >> However, I don't think it's particularly necessary. Explicit version >> number checks should be very rare, and shouldn't be encouraged. >> Instead, encourage feature checks, as Steve gave

Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-03 Thread Steve D'Aprano
On Sun, 4 Sep 2016 12:19 pm, Chris Angelico wrote: [...] >> Please either comply, or give up your stupid and pointless obsession with >> trying to be the Internet Police for something that isn't even a real >> rule. > > His posts aren't making it across the news->list gateway any more. >

Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-03 Thread Steve D'Aprano
On Sun, 4 Sep 2016 06:47 am, Thomas 'PointedEars' Lahn wrote: > Your posting is lacking a real name in the “From” header field. Thomas, if that is really your name, how do we know that: Thomas 'PointedEars' Lahn is a real name? Is sounds made up to me. I'm afraid that we're going to have

Re: manually sorting images?

2016-09-04 Thread Steve D'Aprano
On Sun, 4 Sep 2016 06:53 pm, Ulli Horlacher wrote: > I need to sort images (*.jpg), visually, not by file name. I don't even understand this. What does it mean to sort images visually? Which comes first, a 400x500 image of a cat climbing a tree, or a 300x600 image of a toddler playing with a

Why doesn't my finaliser run here?

2016-09-04 Thread Steve D'Aprano
Here's a finaliser that runs: class Spam(object): def __new__(cls): instance = object.__new__(cls) print("instance created successfully") return instance def __del__(self): print("deleting", repr(self)) An example: py> s = Spam(); del s instance

Re: Extend unicodedata with a name/pattern/regex search for character entity references?

2016-09-04 Thread Steve D'Aprano
On Sun, 4 Sep 2016 06:53 pm, Thomas 'PointedEars' Lahn wrote: >> Regarding the name (From field), my name *is* Veek.M […] > > Liar. *plonk* You have crossed a line now Thomas. That is absolutely uncalled for. You have absolutely no legitimate reason to believe that Veek is not his or her real

Re: Why doesn't my finaliser run here?

2016-09-04 Thread Steve D'Aprano
On Sun, 4 Sep 2016 10:37 pm, Ben Finney wrote: > Steve D'Aprano <steve+pyt...@pearwood.info> writes: > >> Why doesn't __del__ run here? > > Short anser: because nothing has removed the reference to the instance. Hmmm. You're probably right, but not for the reason you t

Re: Pythons for .Net

2016-09-03 Thread Steve D'Aprano
On Sat, 3 Sep 2016 12:34 pm, Denis Akhiyarov wrote: > Finally if anyone can contact Christian Heimes (Python Core Developer), > then please ask him to reply on request to update the license to MIT: > > https://github.com/pythonnet/pythonnet/issues/234 > > He is the only contributor that

Re: PEP 492: isn't the "await" redundant?

2016-09-09 Thread Steve D'Aprano
On Fri, 9 Sep 2016 07:28 pm, Chris Angelico wrote: > We don't > have a problem with threading and multiprocessing having very similar > APIs, do we? Yet they exist to solve distinctly different problems. Surely not? I would think that threading and multiprocessing are two distinct

Re: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies]

2016-09-14 Thread Steve D'Aprano
On Thu, 15 Sep 2016 03:43 am, Dale Marvin wrote: > On 9/14/16 12:20 AM, Steven D'Aprano wrote: >> On Wednesday 14 September 2016 16:54, Rustom Mody wrote: >> >>> everything we know will be negated in 5-50-500 years >> >> I'm pretty sure that in 5, 50, 500 or even 5000 years, the sun will still >>

Re: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies]

2016-09-14 Thread Steve D'Aprano
On Thu, 15 Sep 2016 06:19 am, breamore...@gmail.com wrote: > It is so blantantly obvious that the world is not flat I find this > discussion flabbergasting. You wouldn't say that if you lived in Kanvas, or the west coast of Ireland. I'm told that a few years ago somebody accidentally dumped a

Re: How could I implement a virtual method and override it in python?

2016-09-14 Thread Steve D'Aprano
On Thu, 15 Sep 2016 08:16 am, wesley.keel...@iugome.com wrote: > Hey guys, I will show the code first: > > Helper.py: > > def Foo( *args ): > print ("This is a callback") > > def Run: > Foo() > > > MyModule.py: > > import Helper > > def Foo( *args ): > print ("I want to be the new

Re: What you can do about legalese nonsense on email (was: How to split value where is comma ?)

2016-09-10 Thread Steve D'Aprano
On Fri, 9 Sep 2016 08:13 am, Grant Edwards wrote: > After all, that boilerplate just makes the corporation look stupid and > incompetent. I wish that were true. Unfortunately, in the corporate world, it *doesn't* make them look stupid and incompetent. It makes them look conventional, careful,

collect2: ld returned 1 exit status when building from source

2016-09-10 Thread Steve D'Aprano
I'm trying to build from source using: ./configure --with-pydebug && make -s -j2 At first the output is okay, then I get a whole heap of similar errors: Python/dtrace_stubs.o: In function `PyDTrace_LINE': /home/steve/python/python-dev/cpython/Include/pydtrace.h:25: multiple definition of

Python source repo

2016-09-10 Thread Steve D'Aprano
I ran hg fetch to update the CPython repo. It has been stuck on "adding changesets" for half an hour. I don't know if that's because the process has locked up, or because there really are that many new changesets and it will simply take a long time to process them. (With the 3.6 beta just around

Re: collect2: ld returned 1 exit status when building from source

2016-09-10 Thread Steve D'Aprano
On Sun, 11 Sep 2016 03:34 am, Zachary Ware wrote: > Try make distclean, then configure and build again. If that fails, try > another make distclean, then configure, do 'make touch', then build again. I worked around the failed hg touch by running it manually: python2.7 /usr/bin/hg --config

Re: collect2: ld returned 1 exit status when building from source

2016-09-10 Thread Steve D'Aprano
On Sun, 11 Sep 2016 03:34 am, Zachary Ware wrote: > On Sep 10, 2016 09:56, "Steve D'Aprano" <steve+pyt...@pearwood.info> > wrote: >> >> I'm trying to build from source using: >> >> ./configure --with-pydebug && make -s -j2 [...] >&

Re: Tkinter file dialog screwed

2016-09-13 Thread Steve D'Aprano
On Wed, 14 Sep 2016 06:08 am, kerbingamer376 wrote: > The tkinter file dialog is, for me, unusable. Whenever I try to use it, it > opens, but all the text is white on a white background (see this > http://xomf.com/qzhgy) making it unusable. This has happened on 2 linux > systems, both KDE plasma

Re: Why don't we call the for loop what it really is, a foreach loop?

2016-09-13 Thread Steve D'Aprano
On Wed, 14 Sep 2016 06:57 am, rgrigo...@gmail.com wrote: > It would help newbies and prevent confusion. No it wouldn't. Claims-which-are-made-without-evidence-can-be-rejected-without-evidence-ly y'rs, -- Steve -- https://mail.python.org/mailman/listinfo/python-list

Re: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies]

2016-09-15 Thread Steve D'Aprano
On Thu, 15 Sep 2016 04:02 pm, Random832 wrote: > On Wed, Sep 14, 2016, at 23:12, Steve D'Aprano wrote: >> Yes it does. Even an infinitely large flat plane has a horizon almost >> identical to the actual horizon. > > Your link actually doesn't support the latter claim, it go

Re: Playing an audio file, but not waiting for it to finish?

2016-09-15 Thread Steve D'Aprano
On Fri, 16 Sep 2016 04:06 am, kerbingamer376 wrote: > Hi, > I have a library that allows me to play sound files. However, the play > function waits for the sound to finish before it returns, and I'd like to > be able to start the sound playing, and then have it return immediately so > my program

Re: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies]

2016-09-15 Thread Steve D'Aprano
On Thu, 15 Sep 2016 11:45 pm, Grant Edwards wrote: > On 2016-09-15, Steve D'Aprano <steve+pyt...@pearwood.info> wrote: >> On Thu, 15 Sep 2016 06:19 am, breamore...@gmail.com wrote: >> >>> It is so blantantly obvious that the world is not flat I find this >>&g

Re: Oh gods can we get any more off-topic *wink* [was Re: [Python-ideas] Inconsistencies]

2016-09-15 Thread Steve D'Aprano
On Fri, 16 Sep 2016 05:19 am, Random832 wrote: > On Thu, Sep 15, 2016, at 15:06, Steve D'Aprano wrote: >> No, the horizon would still be horizontal. It merely wouldn't *look* >> horizontal, an optical illusion. > > I guess that depends on your definition of what a

Re: What you can do about legalese nonsense on email (was: How to split value where is comma ?)

2016-09-09 Thread Steve D'Aprano
On Fri, 9 Sep 2016 04:59 pm, Rustom Mody wrote: > On Friday, September 9, 2016 at 2:37:48 AM UTC+5:30, Ben Finney wrote: >> Joaquin Alzola writes: >> > Added by the MTA of the company not by my client. >> >> Right. So, here are things you can do (that we cannot) about this: >> * Switch to a

Re: How to extend a tuple of tuples?

2016-09-09 Thread Steve D'Aprano
On Fri, 9 Sep 2016 04:47 pm, Frank Millman wrote: > Hi all > > This should be easy, but I cannot figure it out. > > Assume you have a tuple of tuples - > > a = ((1, 2), (3, 4)) > > You want to add a new tuple to it, so that it becomes - > > ((1, 2), (3, 4), (5, 6)) a = a + ((5, 6),)

Re: PEP suggestion: Uniform way to indicate Python language version

2016-09-09 Thread Steve D'Aprano
On Tue, 23 Aug 2016 12:29 am, Random832 wrote: > Receiving a SyntaxError or whatever other exception, which provides no > suggestion about how to actually fix the issue (install a later version > of python / run with "python3" instead of "python"), is a bad user > experience. Er wot? If I run

  1   2   3   4   5   6   7   8   9   10   >