Re: compile error when using override

2016-12-01 Thread Steve D'Aprano
, y = symbols('x y') print( solve([x*y - 1, x - 2], x, y) ) which prints the result: [(2, 1/2)] Perhaps if you explain what you are trying to do, we can help better. But please, cut down your code to only code that is being used! -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: correct way to catch exception with Python 'with' statement

2016-12-01 Thread Steve D'Aprano
un() except IOError: pass time.sleep(0.05) # -- b.py -- filename = 'data' import os, time while True: try: os.remove(filename) except OSError: pass time.sleep(0.05) The time.sleep() calls are just to slow them down slightly. You can leave

Re: Asyncio -- delayed calculation

2016-12-02 Thread Steve D'Aprano
an do everything that concurrency can do, and more, and both of which are significantly easier to understand too. So why do we need asyncio? What is it actually good for? -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-04 Thread Steve D'Aprano
indows, but on Linux it behaves as you describe (and as Linux users will expect): [steve@ando ~]$ python program.py column1=2174 and column2='R' argv: ['program.py', 'column1=2174', 'and', 'column2=R'] column1=2174 and column2=R This is *absolutely n

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-04 Thread Steve D'Aprano
demand powerful tools, and they expect that wildcards like * should be expanded. Windows treats the command line as an afterthought, and until a few years ago you were limited to a DOS shell. Today, your options are not as limited: there's Powershell, and bash for Windows. -- Steve “Chee

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-05 Thread Steve D'Aprano
n argument *.*, what do you do with it? You probably expand it yourself. How does the application know when not to expand the wild cards? You need to support some sort of command-line switch to turn it off, but that will effect the entire command line. So you need some sort of escaping mechanism so that you can pass myprogram *.* *.* and have the first *.* expanded but not the second. (For example.) Congratulations, you've just re-invented your own mini-shell. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-05 Thread Steve D'Aprano
ity risk, if you're getting the arguments from an untrusted source, so don't pass shell=True unless you know what you're doing.) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Printing a generator returns "", need to print its values

2016-12-05 Thread Steve D'Aprano
you like, by writing some code: display_string = '::'.join(str(value).upper() for value in obj) print('[[' + display_string + ']]') -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-05 Thread Steve D'Aprano
On Tue, 6 Dec 2016 10:09 am, eryk sun wrote: > On Mon, Dec 5, 2016 at 4:49 PM, Steve D'Aprano > wrote: >> >> You've never used cmd.com or command.exe? "The DOS prompt"? > > The default Windows shell is "cmd.exe", and it's informally ca

Re: Detect Linux Runlevel

2016-12-05 Thread Steve D'Aprano
just "systemd can't do that", but "you shouldn't do that". Why not? We used to do it, and it is necessary for our application. "Because its wrong." -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-06 Thread Steve D'Aprano
are system dependent limits on globbing expansion and the number of arguments you can pass to a program: http://stackoverflow.com/questions/4185017/maximum-number-of-bash-arguments-max-num-cp-arguments http://www.in-ulm.de/~mascheck/various/argmax/ -- Steve “Cheer up,” they said, “things c

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-06 Thread Steve D'Aprano
en entries, screwing everything up. >> > Now you're suggesting the _shell_ is going to read and process a CVS > file??? Be fair: he's giving an analogy. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-06 Thread Steve D'Aprano
t.com/news/fact-checker/wp/2015/06/29/has-there-been-one-school-shooting-per-week-since-sandy-hook/ In other words, if you ignore 90% of school shootings, you can dismiss concerns of school shootings as a lie. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sur

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-07 Thread Steve D'Aprano
s Fool", the majority of comments I saw were from dual Windows/Linux system administrators saying "At last I can use bash on Windows!". -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-07 Thread Steve D'Aprano
command @files *Requiring* this would be completely unacceptable. Forcing the user to write two lines (one to create a variable, then to use it) every time they needed a glob expansion would go down among sys admins like a lead balloon. But for those times when you really need to repeat a comple

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-07 Thread Steve D'Aprano
On Thu, 8 Dec 2016 02:19 am, BartC wrote: > On 07/12/2016 14:34, Steve D'Aprano wrote: [...] >> I don't know why you are so hung up over the number of characters here, >> or this bogeyman of "one million files" in a directory. > > Because /you/ brought it

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-07 Thread Steve D'Aprano
e expansion, arithmetic expansion, parameter expansion, variable expansion, and I dare say I've forgotten some others. [steve@ando ~]$ echo ~ /home/steve [steve@ando ~]$ echo $((1+7*5)) 36 [steve@ando ~]$ echo $http_proxy http://ando:3128 The echo command doesn't have to understand anythi

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-07 Thread Steve D'Aprano
signed the shell to work the way they want are wrong. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Name resolution and the (wrong?) LEGB rule

2016-12-08 Thread Steve D'Aprano
s expected to behave, *as if* it were following the LEGB rule, not necessarily a statement of the implementation of any specific Python implementation. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-08 Thread Steve D'Aprano
ances) Sounds similar to classic Mac OS, where you had: volume:path where the path uses : as directory separators. Removable media (floppies, removable hard drives) could be unplugged and re-inserted into any physical drive, and the OS would track where the media was and whether it was phys

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-09 Thread Steve D'Aprano
her, and iİ go together. But other languages want iI to go together, meaning that the standard case conversions are lossy: py> 'ıIiİ'.lower() 'ıiii' py> 'ıIiİ'.upper() 'IIIİ' Maybe it would have been better if the standard had kept ıİ together, and iI, so at least the case conversion was lossless. Alas, too late now. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-09 Thread Steve D'Aprano
So is "". That's one way of looking at things... I'm not sure that the empty string counts as a file name. Its more of the LACK of a file name. Besides, that would be ambiguous. Would "/home/steve/" mean my home directory, or the file "" inside my home directory? -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: python 2.7.12 on Linux behaving differently than on Windows

2016-12-09 Thread Steve D'Aprano
On Fri, 9 Dec 2016 09:34 pm, Marko Rauhamaa wrote: > Steve D'Aprano : > >> On Fri, 9 Dec 2016 04:52 pm, Marko Rauhamaa wrote: >>> In Linux, "." and ".." are taboo. >> >> No that's incorrect. It isn't that . and .. are forb

Re: CLP stats: last 500 posts

2016-12-09 Thread Steve D'Aprano
web archive as it contains defamatory material. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Running python from pty without prompt

2016-12-09 Thread Steve D'Aprano
ty libraries, including your script-runner. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: CLP stats: last 500 posts

2016-12-10 Thread Steve D'Aprano
On Sat, 10 Dec 2016 03:15 pm, DFS wrote: > On 12/09/2016 08:39 PM, Steve D'Aprano wrote: >> On Sat, 10 Dec 2016 08:07 am, DFS wrote: >> >>> >>> As of 04:04PM December 09, 2016 >>> >>> Posts 85 Posters >> [...] >> >> &g

Re: % string formatting - what special method is used for %d?

2016-12-10 Thread Steve D'Aprano
ng of length 1 %d %i %u => int(obj), which ends up calling __int__ %x %X => int(obj), then convert to hexadecimal %o => int(obj), then convert to octal %e %E %f %g %G => float(obj), which ends up calling __float__ %% => a literal % sign -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: CLP stats: last 500 posts

2016-12-10 Thread Steve D'Aprano
. Indeed. But although c.l.p is a mirror of the mailing list, it is not a *perfect* mirror. The two do diverge: some things go to the mailing list but apparently never make it to the newsgroup, and some things get to the newsgroup but don't make it to the mailing list. The stats generated by

Re: The right way to 'call' a class attribute inside the same class

2016-12-11 Thread Steve D'Aprano
rmal inheritance rules are get the instance attribute if it exists, otherwise a class or superclass attribute; - use `type(self).attribute` when you want to skip the instance and always return the class or superclass attribute. -- Steve “Cheer up,” they said, “things could be worse.” So I

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Steve D'Aprano
fortunately vars() doesn't understand __slots__, which I think is an oversight. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: The right way to 'call' a class attribute inside the same class

2016-12-12 Thread Steve D'Aprano
ive constructor, MyClass.make_instance(...). Naming things is hard. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Splitting text into lines

2016-12-13 Thread Steve D'Aprano
s)) # Python 3 Personally, this would be my preferred technique, as I (nearly) always end up doing a strip() on data I read from text files, so the extra call to filter is no big deal. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got wor

Re: Running python from pty without prompt

2016-12-13 Thread Steve D'Aprano
run a script *or* in interactive mode, there is an associated tty. Am I wrong? >> python < script.py >> >> The behavior the OP is looking for of course is a way of demarcating the >> end of the script and the beginning of data to feed the script. > > It's more

Re: Running python from pty without prompt

2016-12-13 Thread Steve D'Aprano
x27;ps1') or hasattr(sys, 'ps2') will tell you if you are running in the REPL (interactive interpreter). The ps1 and ps2 variables aren't defined in non-interactive mode. Does that help? > You can get similar behavior with python -c "import > sys;exec(sys.stdin.read())&quo

Re: Name mangling vs qualified access to class attributes

2016-12-14 Thread Steve D'Aprano
.update will fail. I don't know if Raymond has an objective reason for preferring one over the other, or if it is just a matter of personal taste. If you have a Twitter account, perhaps you could ask him to comment? https://twitter.com/raymondh -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Running python from pty without prompt

2016-12-14 Thread Steve D'Aprano
On Thu, 15 Dec 2016 01:28 am, Random832 wrote: > On Tue, Dec 13, 2016, at 19:10, Steve D'Aprano wrote: >> Can you show a simple demonstration of what you are doing? >> >> I'm having difficulty following this thread because I don't know >> what "s

Unicode script

2016-12-15 Thread Steve D'Aprano
"ξ" belongs to the script "GREEK". Is this information available from Python? More about Unicode scripts: http://www.unicode.org/reports/tr24/ http://www.unicode.org/Public/UCD/latest/ucd/Scripts.txt http://www.unicode.org/Public/UCD/latest/ucd/ScriptExtensions.txt --

Mapping with continguous ranges of keys

2016-12-15 Thread Steve D'Aprano
ry from 1 to perhaps a hundred or so. Has anyone dealt with data like this and could give a recommendation of the right data structure to use? The obvious way is to explicitly list each key, in a regular dict. But I wonder whether there are alternatives which may be better (faster, more mem

Re: Python constructors have particular semantics2c and ‘Foo.__init__’ doesn't qualify

2016-12-15 Thread Steve D'Aprano
them "class methods" and "static methods", but in other languages they may not exist at all or have other names. (In Java, the closest equivalent to "class method" is called a "static method".) Adding to the complexity, the __name__ of MethodType is just &q

Re: A routine to calc Shannon's info entropy. I'm open to improvements/suggestions.

2016-12-15 Thread Steve D'Aprano
s, num_symbols) entropies[c] = H total = display_results(frequencies, entropies, num_symbols) if __name__ == "__main__": # Only run when module is being used as a script. main() # --- cut --- -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Mapping with continguous ranges of keys

2016-12-16 Thread Steve D'Aprano
On Fri, 16 Dec 2016 04:06 am, Steve D'Aprano wrote: > I have some key:value data where the keys often are found in contiguous > ranges with identical values. [...] Thank you to everyone who gave suggestions! I have experimented with two solutions, and hope somebody might be able

Re: Cache memory and its effect on list searching

2016-12-16 Thread Steve D'Aprano
t that *in practice* set/dict lookups require only a single hash + equality, in principle (and sometimes in practice too) collisions can be significant. Nevertheless, I mention this only for completeness. In practice, you almost never need to care about hash collisions except for the most patho

Re: Mapping with continguous ranges of keys

2016-12-17 Thread Steve D'Aprano
On Sat, 17 Dec 2016 08:31 pm, Peter Otten wrote: > Steve D'Aprano wrote: > >> I have experimented with two solutions, and hope somebody might be able >> to suggest some improvements. Attached is the test code I ran, >> suggestions for improving the performance will

Re: python list index - an easy question

2016-12-19 Thread Steve D'Aprano
from!) and now it is obvious that the start index is included and the stop index is excluded/ +---+---+---+---+---+---+ | P | y | t | h | o | n | +---+---+---+---+---+---+ ^...^ cut hereand here There's no mental model that makes slicing with non-zero step sizes easy, *especially* if the step size is a non-unit negative number (say, -3). For those you really have to simulate the process of actually iterating over the indexes one by one. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: [OT] Security question

2016-12-23 Thread Steve D'Aprano
On Thu, 22 Dec 2016 09:10 pm, Frank Millman wrote: > If this is the standard of security out there, it is no wonder we hear of > so many attacks (and how many don't we hear of?) Everything is broken: https://medium.com/message/everything-is-broken-81e5f33a24e1 -- Steve “Chee

Re: Another security question

2016-12-23 Thread Steve D'Aprano
tion." Why are using Blake2 when the docs explicitly say not to use them in this way? Have you read the FAQ to see what it says? -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Another security question

2016-12-23 Thread Steve D'Aprano
On Fri, 23 Dec 2016 10:08 pm, Frank Millman wrote: > "Steve D'Aprano" wrote in message > news:585d009f$0$1599$c3e8da3$54964...@news.astraweb.com... >> >> On Fri, 23 Dec 2016 09:19 pm, Frank Millman wrote: >> >> > >> > 3. Generate the pass

Re: Another security question

2016-12-23 Thread Steve D'Aprano
quot;what was your mother's maiden name?"). -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Another security question

2016-12-25 Thread Steve D'Aprano
n my lights off. What. A. Time. To. Be. Alive." https://twitter.com/TweetsByTSD/status/655297659381661696 [1] If any country is foolish enough to put control of the electricity grid on the Internet. Of course nobody would do that. Right? -- Steve -- https://mail.python.org/mailman/listinfo/python-list

Re: windows utf8 & lxml

2016-12-27 Thread Steve D'Aprano
the input file is intended to be UTF-8? How was it created? - Is the second byte 0xFE? If so, that suggests that you actually have UTF-16 with a byte-order mark. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: encoding="utf8" ignored when parsing XML

2016-12-27 Thread Steve D'Aprano
calling xml.etree.ElementTree.parse I > included an XMLParser object: > > parser = xml.etree.ElementTree.XMLParser(encoding="utf8") > root = xml.etree.ElementTree.parse(f, parser=parser).getroot() That's the default, so there's no functional change here. Hence, the same error. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Mock object bug with assert_not_called

2016-12-27 Thread Steve D'Aprano
rsion of Python are you using? (3) Code is better than English. Can you supply a *minimal* (as small and simple as possible) example that shows this bug? -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Re: Mock object bug with assert_not_called (Steve D'Aprano)

2016-12-28 Thread Steve D'Aprano
make it (e.g. since this issue has nothing to do with sending email, your code should not send email -- a simple print should be enough for output); - complete (no missing dependencies, all necessary modules are imported, no uninitialised variables, functions called with all necessary arguments specified); -

Re: UTF-8 Encoding Error

2016-12-29 Thread Steve D'Aprano
f-8 --" at the begining of each document. This is way much easier and works as charm I have no words for how wrong that is. And this comment: ty, this worked for my problem with python throwing UnicodeDecodeError on var = u"""vary large string"""

Simulating int arithmetic with wrap-around

2016-12-30 Thread Steve D'Aprano
efficiently, or at least not too inefficiently, do the calculations in Python? Signed arithmetic also has some gotchas. For example, -x is not necessarily defined, nor is abs(x). Thanks, -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Simulating int arithmetic with wrap-around

2016-12-30 Thread Steve D'Aprano
On Sat, 31 Dec 2016 02:14 am, Serhiy Storchaka wrote: > On 30.12.16 16:47, Steve D'Aprano wrote: >> Again, assume both operands are in range for an N-bit signed integer. >> What's a good way to efficiently, or at least not too inefficiently, do >> the calculations

Re: List comprehension

2016-12-30 Thread Steve D'Aprano
[(1, 2), (3, 4)] py> [a for a in data] [(1, 2), (3, 4)] py> [(x, y) for a in data] Traceback (most recent call last): File "", line 1, in File "", line 1, in NameError: name 'x' is not defined Okay, let's create global variables x and y: py> x

Re: learning and experimenting python.

2016-12-30 Thread Steve D'Aprano
002py> \001\x1b[0m\002' sys.ps2 = '\001\x1b[1m\002... \001\x1b[0m\002' else: sys.ps1 = 'py> ' That gives me a "py>" prompt, bolded in Python 3 and plain in Python 2. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: learning and experimenting python.

2016-12-30 Thread Steve D'Aprano
On Sat, 31 Dec 2016 10:26 am, einstein1...@gmail.com wrote: > That's not the answer. > If you don't have answer, please don't answer like this, because that will > confuse others also. What's not the answer? What's the question? -- Steve “Cheer up,” they s

Re: learning and experimenting python.

2016-12-30 Thread Steve D'Aprano
se many different styles of prompts: Python: >>> iPython:In [1]: Ruby (irb): irb(main):001:0> bash: [steve@ando ~]$ bash (root):[steve@ando ~]# DOS:> rhino: js> lua:> julia: julia> xion: > mutt:

RE: Cleaning up conditionals

2016-12-31 Thread Steve D'Aprano
t] = l1[st] The comments are, of course, redundant, and I probably wouldn't bother putting them in my own code. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: learning and experimenting python.

2016-12-31 Thread Steve D'Aprano
r. Don't just hit send for every trivial thought that enters your mind. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: learning and experimenting python.

2016-12-31 Thread Steve D'Aprano
ay "I'm wondering about..." rather than "I have a question". This is an international forum, and we should make allowances for variant forms of English and those whose grasp of the Queen's English is not perfect. -- Steve “Cheer up,” they said, “things could b

Re: learning and experimenting python.

2016-12-31 Thread Steve D'Aprano
nt, we don't have many examples of text written on the road surface myself. But when I do see them, I find them more distracting than helpful. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

RE: Cleaning up conditionals

2016-12-31 Thread Steve D'Aprano
ue (2) Step Two: add a temporary variable to avoid repeating the assignment if condition: temp = l1 else: temp = l2 temp[v] = new_value (3) Step Three: change the if...else statement to an expression temp = l1 if condition else l2 temp[v] = new_value (4) Step Four: no need for the temporary

Re: Choosing a Python IDE. what is your Pythonish recommendation? I do not know what to choose.

2017-01-02 Thread Steve D'Aprano
loated and slow it couldn't even keep up with my typing. I'm not even a touch typist! I'd start to type a line like: except ValueError as err: and by the time my fingers were hitting the colon, Spyder was displaying `excep` in red flagged with an icon indicating a syntax er

Re: How Best to Coerce Python Objects to Integers?

2017-01-03 Thread Steve D'Aprano
ything whatsoever should be coerced to int". If you have something like: left_margin = int_or_else(ftp_server) that's surely a programming error that needs fixing, rather than something that should just return a default value. -- Steve “Cheer up,” they said, “things could be wors

Re: How Best to Coerce Python Objects to Integers?

2017-01-03 Thread Steve D'Aprano
REPL for an interpreter, where you want the REPL to keep going no matter what exceptions take place. But I don't think this is the right way to do that, and it's not how the Python REPL works either. Other than that, I'm not seeing any use-case where this sort of thing is anything but a

RE: Clickable hyperlinks

2017-01-03 Thread Steve D'Aprano
e of simple formats and see which, if any, your console understands: # HTML http://www.example.com";>Example. # URL in angle brackets Example <http://www.example.com> # URL alone http://www.example.com # I can't remember what these are called http://www.example.com> # M

Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Steve D'Aprano
x = 23 + ) ^ SyntaxError: invalid syntax You should copy and paste *all* of the error message, as much as you can see. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: How Best to Coerce Python Objects to Integers?

2017-01-03 Thread Steve D'Aprano
eed. Another thought: if he is receiving human generated input, there is an argument to be made for accepting "look alikes" -- e.g. maybe the data was entered by Aunt Tilly, who was a typist in the 1960s and can't break the habit of using l or I interchangeably for 1, and O for 0. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Hey, I'm new to python so don't judge.

2017-01-03 Thread Steve D'Aprano
ou get a random number. What you want is: computer_number = random.randint(1, 100) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Screwing Up looping in Generator

2017-01-04 Thread Steve D'Aprano
nt. > for file_name in name_set: > directory = "output" > with open(os.path.join(directory, filename, 'w', newline='') as > csvf: > for file in rootobs: > # create and write csv Your indentation is

RE: Clickable hyperlinks

2017-01-04 Thread Steve D'Aprano
at you do. But when you hit "Reply" to a message, you inherit the "Reference" and "In-Reply-To" headers from the previous message, so at least some people will see it threaded in an existing thread rather than starting a brand new one. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

RE: Clickable hyperlinks

2017-01-04 Thread Steve D'Aprano
re, but if you are working in a console or terminal, just printing the URL is likely to be interpreted by the console as a clickable link: print("http://www.example.com";) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

RE: Clickable hyperlinks

2017-01-04 Thread Steve D'Aprano
m sorry that I can't give you a one-sentence answer "just use such-and-such a function, that does exactly what you want in a platform-independent manner" :-( -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: How Best to Coerce Python Objects to Integers?

2017-01-05 Thread Steve D'Aprano
ot;Anything whatsoever should be coerced to int". If you have something like: left_margin = int_or_else(ftp_server) that's surely a programming error that needs fixing, rather than something that should just return a default value. -- Steve â £Cheer up,â Ø they said, â £things cou

Re: How Best to Coerce Python Objects to Integers?

2017-01-05 Thread Steve D'Aprano
ase might be the REPL for an interpreter, where you want the REPL to keep going no matter what exceptions take place. But I don't think this is the right way to do that, and it's not how the Python REPL works either. Other than that, I'm not seeing any use-case where this sort of thi

RE: Clickable hyperlinks

2017-01-05 Thread Steve D'Aprano
a couple of simple formats and see which, if any, your console understands: # HTML http://www.example.com";>Example. # URL in angle brackets Example <http://www.example.com> # URL alone http://www.example.com # I can't remember what these are called http://www.example.com> #

Re: Hey, I'm new to python so don't judge.

2017-01-05 Thread Steve D'Aprano
ou get a random number. What you want is: computer_number = random.randint(1, 100) -- Steve â £Cheer up,â Ø they said, â £things could be worse.â Ø So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: Hey, I'm new to python so don't judge.

2017-01-06 Thread Steve D'Aprano
x = 23 + ) ^ SyntaxError: invalid syntax You should copy and paste *all* of the error message, as much as you can see. -- Steve â £Cheer up,â Ø they said, â £things could be worse.â Ø So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: How Best to Coerce Python Objects to Integers?

2017-01-06 Thread Steve D'Aprano
eive. Indeed. Another thought: if he is receiving human generated input, there is an argument to be made for accepting "look alikes" -- e.g. maybe the data was entered by Aunt Tilly, who was a typist in the 1960s and can't break the habit of using l or I interchangeably for 1, a

Re: Screwing Up looping in Generator

2017-01-06 Thread Steve D'Aprano
want. > for file_name in name_set: > directory = "output" > with open(os.path.join(directory, filename, 'w', newline='') as > csvf: > for file in rootobs: > # create and write csv Your indentati

RE: Clickable hyperlinks

2017-01-06 Thread Steve D'Aprano
k. I'm sorry that I can't give you a one-sentence answer "just use such-and-such a function, that does exactly what you want in a platform-independent manner" :-( -- Steve â £Cheer up,â Ø they said, â £things could be worse.â Ø So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

RE: Clickable hyperlinks

2017-01-06 Thread Steve D'Aprano
y ever sort by thread, so it is no skin off my nose what you do. But when you hit "Reply" to a message, you inherit the "Reference" and "In-Reply-To" headers from the previous message, so at least some people will see it threaded in an existing thread rather than startin

RE: Clickable hyperlinks

2017-01-06 Thread Steve D'Aprano
rywhere, but if you are working in a console or terminal, just printing the URL is likely to be interpreted by the console as a clickable link: print("http://www.example.com";) -- Steve â £Cheer up,â Ø they said, â £things could be worse.â Ø So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

The hardest problem in computer science...

2017-01-06 Thread Steve D'Aprano
tee corner") default_YYY = XXX("│ ", "├─ ", "└─ ") bold_YYY = XXX("┃ ", "┣━ ", "┗━ ") ascii_YYY = XXX("| ", "|- ", "+- ") def draw_tree(tree, YYY=default_YYY): ... but what do I call XXX and Y

Re: The hardest problem in computer science...

2017-01-06 Thread Steve D'Aprano
On Sat, 7 Jan 2017 12:03 am, Steve D'Aprano wrote: > The second hardest problem in computer science is cache invalidation. > > The *hardest* problem is naming things. Thanks everyone who answered, but I think some of you misunderstood my question. I know that the individ

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Steve D'Aprano
in iterable: yield x if predicate(x): break min(takeuntil(lambda x: x == 0, iterable), key=abs) py> from itertools import count, chain py> iterable = chain(reversed(range(10)), count()) py> min(takeuntil(lambda x: x == 0, iterable), key=abs) 0 py> iterable = cha

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-07 Thread Steve D'Aprano
yield e > if key(e) <= stop: > break > return min(take_until(), key=key) Heh, great minds think alike :-) -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: python 3 dict: .keys(), .values(), and .item()

2017-01-07 Thread Steve D'Aprano
's no longer a snapshot), or "list()" is sprinkled around every > iterator access. Not *every* view access. Only the ones where you insert/delete elements. > In other words, what used to be a completely safe operation now is not. > > Thoughts? The old Python 2 keys/values

Re: Can't match str/unicode

2017-01-07 Thread Steve D'Aprano
it *looks like* 'match'. Hint: s = 'match ' print 'match', s # they look the same print 'match' == s # but they aren't the same Start by printing repr(candidate_text) and see what you really have. -- Steve “Cheer up,” they said, “things could be

RE: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Steve D'Aprano
way to do that is by editing the CSV file in LibreOffice or Excel or another spreadsheet application. If you have a list of records, call .sort() on the list, not the individual records. But if I am wrong, and you absolutely must sort the fields of each record, call the sorted() function, which

Byte-run: a Python interpreter written in Python

2017-01-13 Thread Steve D'Aprano
http://aosabook.org/en/500L/a-python-interpreter-written-in-python.html -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: matrix from matrix

2017-01-13 Thread Steve D'Aprano
: "What's the shortest piece of string to tie two things together?" Um, it depends on which two things, it depends on how secure you need the tie to be... we need more detail. -- Steve “Cheer up,” they said, “things could be worse.” So I cheered up, and sure enough, things got worse. -- https://mail.python.org/mailman/listinfo/python-list

Re: multiprocessing.Process call blocks other processes from running

2017-01-14 Thread Steve D'Aprano
working file. An excellent way to manage this process is by using a revision control system like Mercurial (hg) or equivalent. But at the very least, whenever you change a working program, you should confirm it is still working before making the next change. -- Steve “Cheer up,” they said,

Re: Error handling in context managers

2017-01-16 Thread Steve D'Aprano
Notice that the context manager simply raises an exception on failure, which I can catch or not as I so choose, rather than returning None. I really think that the problem here is the design of psql_cursor(). > Of course, that > might not work, given that I may need to do something d

Re: Emulating Final classes in Python

2017-01-17 Thread Steve D'Aprano
at you - why not > just add it to your documentation? A very good question :-) Why am I doing this? Part of the answer is simply because I can. I want to see how far I can go to lock down the class in pure Python code. -- Steve “Cheer up,” they said, “things could be worse.” So I cheer

Re: Emulating Final classes in Python

2017-01-17 Thread Steve D'Aprano
; cls._instance = inst = super().__new__(cls) >> return inst >> return cls._instance >> def __repr__(self): >> return '' > > And this has to do with single instances, which is not what you asked > about.

Re: Emulating Final classes in Python

2017-01-18 Thread Steve D'Aprano
> > This can be used as a decorator at class creation time, or at any later > date to lock down a class. The downside is it's less obvious that the > class is final... meaning there are no clues in the MRO. Ah nice! I didn't know about __init__subclass__. -- Steve “Cheer up,” t

<    6   7   8   9   10   11   12   13   14   15   >