Re: Terminal Emulator (Posting On Python-List Prohibited)

2024-05-19 Thread Dan Sommers via Python-list
On 2024-05-19 at 18:13:23 +, Gilmeh Serda via Python-list wrote: > Was there a reason they chose the name Pip? Package Installer for Python https://pip.pypa.io/en/stable/index.html -- https://mail.python.org/mailman/listinfo/python-list

Re: Terminal Emulator (Posting On Python-List Prohibited)

2024-05-19 Thread Dan Sommers via Python-list
On 2024-05-19 at 18:13:23 +, Gilmeh Serda via Python-list wrote: > Was there a reason they chose the name Pip? Package Installer for Python https://pip.pypa.io/en/stable/index.html Every time I see PIP, I think Peripheral Interchange Program, but I'm old. --

Re: how to discover what values produced an exception?

2024-05-04 Thread Dan Sommers via Python-list
On 2024-05-03 at 10:56:39 -0300, Johanne Fairchild via Python-list wrote: > How to discover what values produced an exception? Or perhaps---why > doesn't the Python traceback show the values involved in the TypeError? > For instance: > >

Re: Configuring an object via a dictionary

2024-03-20 Thread Dan Sommers via Python-list
On 2024-03-20 at 09:49:54 +0100, Roel Schroeven via Python-list wrote: > You haven't only checked for None! You have rejected *every* falsish value, > even though they may very well be acceptable values. OTOH, only you can answer these questions about your situations. Every application, every

Re: Configuring an object via a dictionary

2024-03-15 Thread Dan Sommers via Python-list
On 2024-03-15 at 15:48:17 -0400, Thomas Passin via Python-list wrote: > [...] And I suppose there is always the possibility that sometime in > the future an "or" clause like that will be changed to return a > Boolean, which one would expect anyway. Not only is the current value is way more

Re: Extract lines from file, add to new files

2024-01-13 Thread Dan Sommers via Python-list
On 2024-01-13 at 11:34:29 +0100, Left Right wrote: > > The Python term, at least colloquially, is "tuple unpacking." That quote is from me. Please do preserve attributions. > Well, why use colloquialism if there's a language specification? Also, > there weren't any tuples used in my example,

Re: Extract lines from file, add to new files

2024-01-12 Thread Dan Sommers via Python-list
On 2024-01-13 at 02:02:39 +0100, Left Right via Python-list wrote: > Actually, after some Web search. I think, based on this: > https://docs.python.org/3/reference/simple_stmts.html#grammar-token-python-grammar-augtarget > that in Python you call this "augmented assignment target". The term >

Re: How/where to store calibration values - written by program A, read by program B

2023-12-06 Thread Dan Sommers via Python-list
On 2023-12-06 at 09:32:02 +, Chris Green via Python-list wrote: > Thomas Passin wrote: [...] > > Just go with an .ini file. Simple, well-supported by the standard > > library. And it gives you key/value pairs. > > > My requirement is *slightly* more complex than just key value pairs, >

Re: on writing a number as 2^s * q, where q is odd

2023-11-29 Thread Dan Sommers via Python-list
On 2023-11-29 at 21:44:01 -0300, Julieta Shem via Python-list wrote: > How would you write this procedure? > > --8<---cut here---start->8--- > def powers_of_2_in(n): > s = 0 > while "I still find factors of 2 in n...": > q, r = divmod(n, 2) > if r

Re: Beep on WIndows 11

2023-11-12 Thread Dan Sommers via Python-list
On 2023-11-11 at 23:44:19 +, Y Y via Python-list wrote: > I am curious and humble to ask: What is the purpose of a BEEP? It's a simple way for a terminal-based program to alert (hence '\a') a user or an operator that their attention is requested or required. See also

Re: Why doc call `__init__` as a method rather than function?

2023-09-15 Thread Dan Sommers via Python-list
On 2023-09-15 at 10:49:10 +, scruel tao via Python-list wrote: > ```python > >>> class A: > ... def __init__(self): > ... pass > ... > >>> A.__init__ > > >>> a = A() > >>> a.__init__ > > > ``` > > On many books and even the official documents, it seems that many authors > prefer to

Re: ANN: A new version (0.5.1) of python-gnupg has been released.

2023-07-22 Thread Dan Sommers via Python-list
On 2023-07-22 at 11:04:35 +, Vinay Sajip via Python-list wrote: > What Changed? > = What changed, indeed. Maybe I'm old, and curmudgeonly, but it would be nice if the body of these annoucement emails (not just this one) contained the name of the program and a one-line summary

Re: How to design a class that will listen on stdin?

2020-05-23 Thread Dan Sommers
On Saturday, May 23, 2020, at 07:24 -0400, zljubi...@gmail.com wrote: > I have to talk to outer system by stdin/stdout. > Each line that comes to stdin should be processed and its result returned > back to stdout. Logging should go to stderr. > > How to design a class that will listed to

Re: exiting a while loop

2020-05-22 Thread Dan Sommers
> n += 1 > > print("\n", n, "terms are required.") -- “Atoms are not things.” – Werner Heisenberg Dan Sommers, http://www.tombstonezero.net/dan -- https://mail.python.org/mailman/listinfo/python-list

Re: why no camelCase in PEP 8?

2020-05-18 Thread Dan Sommers
On Tue, 19 May 2020 09:55:04 +1200 Juergen Brendel wrote: > ... he prefers snake-case. That's not snake_case. That's kebab-case.¹ ¹ https://wiki.c2.com/?KebabCase -- https://mail.python.org/mailman/listinfo/python-list

Re: =+ for strings

2020-05-03 Thread Dan Sommers
ay) > > Why can't I do the shortcut on strings? ITYM: dt += "{:02d}".format(day) Note += rather than =+ (which is parsed as an assignment operator followed by a unary plus operator). -- “Atoms are not things.” – Werner Heisenberg Dan Sommers, http://www.tombstonezero.net/dan -- https://mail.python.org/mailman/listinfo/python-list

Re: What user-defined request error levels are recommended?

2020-04-30 Thread Dan Sommers
, this isn't really a Python question; it's either a plain HTTP question, or perhaps one specific to your web server.) -- “Atoms are not things.” – Werner Heisenberg Dan Sommers, http://www.tombstonezero.net/dan -- https://mail.python.org/mailman/listinfo/python-list

Re: Floating point problem

2020-04-18 Thread Dan Sommers
ocs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html; YMMV. Yes, it's highly technical, but well worth the effort. Or an extended session at the feet of the timbot, which is much harder to come by. Dan -- “Atoms are not things.” – Werner Heisenberg Dan Sommers, http://www.tombstonezero.net/dan -- https://mail.python.org/mailman/listinfo/python-list

Re: python script to give a list of prime no.

2020-04-05 Thread Dan Sommers
On Sun, 05 Apr 2020 19:46:00 +0200 Pieter van Oostrum wrote: > Sathvik Babu Veligatla writes: > > > hi, > > I am new to python, and i am trying to output the prime numbers > > beginning from 3 and i cannot get the required output. It stops > > after giving the output "7" and that's it. > >

Re: Confusing textwrap parameters, and request for RE help

2020-03-27 Thread Dan Sommers
72 or 96 pixel per inch display screen, and a handheld 320 pixel per inch screen would all be optimized separately (through one sort of style sheet mechanism or another). But these days, they spend more time and money on ads and SEO than typesetting. Dan -- “Atoms are not things.” – Wern

Re: queue versus list

2020-03-20 Thread Dan Sommers
here are proportionally fewer calls to malloc() and free(). The data blocks of consecutive pointers also improve cache locality. ¹ https://github.com/python/cpython/blob/3.8/Modules/_collectionsmodule.c#L19-L78 Dan -- “Atoms are not things.” – Werner Heisenberg Dan Sommers, http://www.tombst

Re: Suggestions on mechanism or existing code - maintain persistence of file download history

2020-01-30 Thread Dan Sommers
crossed out and Python and ACID Database written in crayon. Dan -- “Atoms are not things.” – Werner Heisenberg Dan Sommers, http://www.tombstonezero.net/dan -- https://mail.python.org/mailman/listinfo/python-list

Re: Was: Dynamic Data type assignment

2020-01-30 Thread Dan Sommers
trings to parser.parse_args instead of letting that function default to the list of command line arguments. ¹ e.g., https://docs.python.org/3/library/argparse.html#parents Dan -- “Atoms are not things.” – Werner Heisenberg Dan Sommers, http://www.tombstonezero.net/dan -- https://mail.pyth

Re: Suggestions on mechanism or existing code - maintain persistence of file download history

2020-01-29 Thread Dan Sommers
me, so > http://some.domain.example/some/path/filename.html might get saved > into "a39321604c - filename.html". That way, if you want to know if > it's been downloaded already, you just hash the URL and see if any > file begins with those digits. > Would that kind of idea work?

Re: Threading

2020-01-24 Thread Dan Sommers
jobs" (for whatever definition of job you have) from a queue. Once > the queue is exhausted, the threads terminate cleanly, and then you > can join() each thread to wait for the entire queue to be completed. Or use a thread pool: https://docs.python.org/3/library/concurrent.futures.html D

Re: Friday Finking: Source code organisation

2019-12-28 Thread Dan Sommers
On 12/28/19 6:52 PM, Greg Ewing wrote: > On 29/12/19 11:49 am, Chris Angelico wrote: >> "Define before use" is a broad principle that I try to follow, even >> when the code itself doesn't mandate this. > But strangely, I tend to do the opposite for methods of a class. I > don't really know

Re: Grepping words for match in a file

2019-12-28 Thread Dan Sommers
On 12/28/19 12:29 AM, Mahmood Naderan via Python-list wrote: Hi I have some lines in a text file like ADD R1, R2 ADD3 R4, R5, R6 ADD.MOV R1, R2, [0x10] If I grep words with this code for line in fp: if my_word in line: Then if my_word is "ADD", I get 3 matches. However, if I grep word with

Re: Grepping words for match in a file

2019-12-28 Thread Dan Sommers
On 12/28/19 12:29 AM, Mahmood Naderan via Python-list wrote: Hi I have some lines in a text file like ADD R1, R2 ADD3 R4, R5, R6 ADD.MOV R1, R2, [0x10] If I grep words with this code for line in fp: if my_word in line: Then if my_word is "ADD", I get 3 matches. However, if I grep word with

Re: urllib unqoute providing string mismatch between string found using os.walk (Python3)

2019-12-21 Thread Dan Sommers
On 12/21/19 4:46 PM, Ben Hearn wrote: import difflib print('\n'.join(difflib.ndiff([a], [b]))) - /Users/macbookpro/Music/tracks_new/_NS_2018/J.Staaf - ¡Móchate! _PromoMix_.wav ? ^^ +

Re: IOError: cannot open resource

2019-12-07 Thread Dan Sommers
On 12/7/19 9:43 AM, RobH wrote: When I run a python project with an oled display on a rasperry pi zero, it calls for the Minecraftia.ttf font. I have the said file in home/pi/.fonts/ Do you mean /home/pi/.fonts (with a leading slash, an absolute path rather than a relative one)? Dan --

Re: low-level csv

2019-11-17 Thread Dan Sommers
On 11/17/19 7:18 AM, Antoon Pardon wrote: This is python 2.6->2.7 and 3.5->3.7 I need to convert a string that is a csv line to a list and vice versa. I thought to find functions doing this in the csv module but that doesn't seem to be the case. I can of course write special classes that would

Re: pathlib

2019-10-03 Thread Dan Sommers
On 10/2/19 6:58 PM, DL Neil via Python-list wrote: > On 3/10/19 12:42 AM, Dan Sommers wrote: > Certainly, although some may have quietly given-up talking to a > non-OOP native - and one so 'slow', I am appreciative of all > help-given! I also speak OO as a second language (usu

Re: pathlib

2019-10-02 Thread Dan Sommers
On 10/2/19 4:14 AM, DL Neil via Python-list wrote: In the case that sparked this enquiry, and in most others, there is no need for a path that doesn't actually lead somewhere. The paths that are used, identify files, open them, rename them, create directories, etc. The idea of a path that just

Re: pathlib

2019-09-30 Thread Dan Sommers
On 9/30/19 3:56 PM, Barry Scott wrote: On 30 Sep 2019, at 16:49, Dan Sommers <2qdxy4rzwzuui...@potatochowder.com <mailto:2qdxy4rzwzuui...@potatochowder.com>> wrote: In the totality of a Path object that claims to represent paths to files, It represents string that *should* i

Re: pathlib

2019-09-30 Thread Dan Sommers
On 9/30/19 12:51 PM, Chris Angelico wrote: On Tue, Oct 1, 2019 at 1:51 AM Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote: In the totality of a Path object that claims to represent paths to files, including the arguably troublesome read_bytes and write_bytes methods, and a rename

Re: pathlib

2019-09-30 Thread Dan Sommers
On 9/30/19 10:33 AM, Barry Scott wrote: On 30 Sep 2019, at 14:20, Dan Sommers <2qdxy4rzwzuui...@potatochowder.com <mailto:2qdxy4rzwzuui...@potatochowder.com>> wrote: That's the wording I read.  I inferred that "path-handling operations which don't actually access a

Re: pathlib

2019-09-30 Thread Dan Sommers
On 9/30/19 8:40 AM, Barry Scott wrote: > > >> On 30 Sep 2019, at 12:51, Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote: >> >> On 9/30/19 4:28 AM, Barry Scott wrote: >>>> On 30 Sep 2019, at 05:40, DL Neil via Python-list wrote: >&

Re: pathlib

2019-09-30 Thread Dan Sommers
On 9/30/19 4:28 AM, Barry Scott wrote: On 30 Sep 2019, at 05:40, DL Neil via Python-list wrote: Should pathlib reflect changes it has made to the file-system? I think it should not. A Path() is the name of a file it is not the file itself. Why should it track changes in the file system

Re: Recursive method in class

2019-09-27 Thread Dan Sommers
On 9/27/19 7:54 AM, ast wrote: Hello Is it feasible to define a recursive method in a class ? (I don't need it, it's just a trial) Here are failing codes: class Test: def fib(self, n): if n < 2: return n return fib(self, n-2) + fib(self, n-1) return self.fib(n

Re: Spread a statement over various lines

2019-09-17 Thread Dan Sommers
On 9/17/19 2:59 PM, Manfred Lotz wrote: > def regex_from_filepat(fpat): > rfpat = fpat.replace('.', '\\.') \ >.replace('%', '.') \ >.replace('*', '.*') > > return '^' + rfpat + '$' > > As I don't want to have the replace() functions in

Re: fileinput module not yielding expected results

2019-09-07 Thread Dan Sommers
On 9/7/19 11:12 AM, Jason Friedman wrote: $ grep "File number" ~/result | sort | uniq File number: 3 I expected that last grep to yield: File number: 1 File number: 2 File number: 3 File number: 4 File number: 5 File number: 6 As per

Re: itertools cycle() docs question

2019-08-21 Thread Dan Sommers
On 8/21/19 2:32 PM, Calvin Spealman wrote: The point is to demonstrate the effect, not the specific implementation. Once you've gone through the iterable once, it's falsey, which means that the while loop will end. But if you copy all the elements to a real list, then the while loop is

Re: String slices

2019-08-09 Thread Dan Sommers
On 8/9/19 10:13 AM, Paul St George wrote: In the code (below) I want a new line like this: Plane rotation X: 0.0 Plane rotation Y: 0.0 Plane rotation Z: 0.0 But not like this: Plane rotation X: 0.0 Plane rotation Y: 0.0 Plane rotation Z: 0.0 Is it possible? (I am using Python 3.5 within

Re: Python help needed

2019-08-08 Thread Dan Sommers
On 8/8/19 12:26 PM, Paolo G. Cantore wrote: > I think the special case treatment could be avoided. > > First: Join all items with ' and ' > Second: Replace all ' and ' with ', ' except the last That works great, until one of the elements of the original list is "spam and eggs": >>> spam =

Re: if bytes != str:

2019-08-04 Thread Dan Sommers
On 8/4/19 10:56 AM, Hongyi Zhao wrote: Hi, I read and learn the the following code now: https://github.com/shadowsocksr-backup/shadowsocksr-libev/blob/master/src/ ssrlink.py In this script, there are the following two customized functions: -- def to_bytes(s): if bytes !=

Re: Boolean comparison & PEP8

2019-07-29 Thread Dan Sommers
On 7/29/19 10:02 AM, David Raymond wrote: > I think the other part of the discussion to be had here is: how do you > name your booleans? Yep. > ... To me the name of a boolean variable should be obvious that it's a > boolean ... Well, yeah, maybe. If it's really only a boolean, and its value

Re: Proper shebang for python3

2019-07-25 Thread Dan Sommers
On 7/24/19 10:24 PM, Michael Torrie wrote: > ... In more recent times, binaries that are mostly applicable to the > super user go there. I don't see why you would want to merge those. > A normal user rarely has need of much in /sbin. Already /bin has way > too much stuff in it (although I

Re: Accumulate , Range and Zeros

2019-07-13 Thread Dan Sommers
On 7/13/19 5:54 AM, Abdur-Rahmaan Janhangeer wrote: > > Greetings, > > > > Given this snippet > > > > from itertools import * > > import operator > > > > > > x = [1, 2, 3] # [0, 1, 2, 3, ..., 10] > > > > y = accumulate(x, operator.mul) > > > > print(list(y)) > > > > why does x = list(range(5))

Re: Function to determine list max without itertools

2019-04-19 Thread Dan Sommers
On 4/19/19 4:01 AM, Sayth Renshaw wrote: Now, what happens when the code is tested with various (different) sets of test-data? (remember the last question from my previous msg!?) It fails on any list entry that isn't a float or an int, giving a TypeError. What if the *first* entry isn't a

Re: How call method from a method in same class?

2019-04-01 Thread Dan Sommers
On 4/1/19 10:02 PM, Dave wrote: def validScale(self, scaleName): if scaleName.upper == 'F' or 'C' or 'K': return True else: return False def convertTemp(self): """ Converts temperature scale if scales valid.""" if

Re: Library for parsing binary structures

2019-03-29 Thread Dan Sommers
On 3/29/19 12:13 PM, Peter J. Holzer wrote: Obviously you need some way to describe the specific binary format you want to parse - in other words, a grammar. The library could then use the grammar to parse the input - either by interpreting it directly, or by generating (Python) code from it.

Re: What does "TypeError: unsupported operand type(s) for +: 'function' and 'int'" mean?

2019-03-25 Thread Dan Sommers
On 3/25/19 2:30 PM, CrazyVideoGamez wrote: I have no idea what "TypeError: unsupported operand type(s) for +: 'function' and 'int'" means It means that you're trying to add an int to a function. > ... and I don't know how to fix it. Help! Don't do that? It's possible that with the correct

Re: Can my python program send me a text message?

2019-03-19 Thread Dan Sommers
On 3/19/19 2:35 PM, Chris Angelico wrote: On Wed, Mar 20, 2019 at 6:31 AM Steve wrote: I have a program that triggers a reminder timer. When that timer is done, I would like to receive a text message on my phone to tell me that it is time to reset the experiment. Can this be done using

Re: subprocess svn checkout password issue

2019-03-16 Thread Dan Sommers
On 3/16/19 1:50 AM, Martin De Kauwe wrote: On Saturday, 16 March 2019 16:50:23 UTC+11, dieter wrote: Martin De Kauwe writes: > I'm trying to write a script that will make a checkout from a svn repo and build the result for the user. However, when I attempt to interface with the shell it asks

Re: Not Defined error in basic code

2019-03-14 Thread Dan Sommers
On 3/14/19 9:05 AM, Jack Dangler wrote: Just getting started with tutorials and such, and don't understand this - class weapon:     weaponId     manufacturerName The previous two lines attempt to refer to existing names, but neither name exists.     def printWeaponInfo(self):  

Re: ANN: Creating GUI Applications with wxPython

2019-02-27 Thread Dan Sommers
On 2/27/19 9:37 AM, Dave wrote: I have two Python 3 (3.6) apps that will get the full GUI treatment very soon. I'm in the process of choosing a GUI, and that may be where you/your book can help. Seems this is not a trivial effort (wishing that Python was like VB6 from the 90's). Anyway, here

Re: revisiting the "What am I running on?" question

2019-02-17 Thread Dan Sommers
On 2/17/19 8:46 PM, songbird wrote: simply put. if i'm running on a computer and i don't easily know why kind of computer how can i answer this in a quick way without getting overly complicated that also will cover most of the easy cases? i came up with this: comments? additions?

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Dan Sommers
On 2/13/19 1:53 PM, Grant Edwards wrote: Floating point is sort of the quantum mechanics of computer science. At first glance, it seems sort of weird. But after you work with it a while, it gets even worse. Yep! :-) -- https://mail.python.org/mailman/listinfo/python-list

Re: Why float('Nan') == float('Nan') is False

2019-02-13 Thread Dan Sommers
On 2/13/19 7:21 AM, ast wrote: Hello >>> float('Nan') == float('Nan') False Why ? Because the IEEE-754 Standard demands it, and people smarter than I worked on the IEEE-754 Standard. is a quick starting point for a deeper dive. --

Re: exit 2 levels of if/else and execute common code

2019-02-11 Thread Dan Sommers
On 2/11/19 9:25 AM, Neal Becker wrote: I have code with structure: ``` if cond1: [some code] if cond2: #where cond2 depends on the above [some code] [ more code] else: [ do xxyy ] else: [ do the same xxyy as above ] ``` So what's the best style to handle this? As coded,

Re: Switch function

2019-02-03 Thread Dan Sommers
On 2/3/19 9:03 PM, Avi Gross wrote: > The example I show above could in many cases be done as you describe > but what are you gaining? > > I mean if I subtract the integer representation of a keyboard > alphabetic letter (ASCII for the example) from letter 'a' or 'A' then > A maps to 0 and B

Re: Switch function

2019-02-03 Thread Dan Sommers
On 2/3/19 5:40 PM, Avi Gross wrote: Bottom line, does anyone bother using anything like this? It is actually a bunch of hidden IF statements matched in order but may meet many needs. I sure don't. In the rare case that I might use a switch statement in another language, I just use a series

Re: Instance of 'dict' has no 'replace' member

2019-02-01 Thread Dan Sommers
On 2/1/19 7:15 AM, sinless...@gmail.com wrote: Hello guys can you help me to solve problem when i compile proram got error like this "Instance of 'dict' has no 'replace' member[no member](67;14)". Python dicts don't have a replace method. It looks like you're trying to replace strings inside

Re: Exercize to understand from three numbers which is more high

2019-01-29 Thread Dan Sommers
On 1/29/19 9:27 AM, Jack Dangler wrote: wow. Seems like a lot going on. You have 3 ints and need to determine the max? Doesn't this work? N1, N2, N3 if N1>N2   if N1>N3     MaxNum = N1 elif N2>N3   MaxNum = N2 elif N1 No. Assuing that you meant to include colons where I think you did,

Re: Are all items in list the same?

2019-01-08 Thread Dan Sommers
On 1/8/19 2:31 PM, Tobiah wrote:> On 1/8/19 9:20 AM, Alister wrote: >> On Tue, 08 Jan 2019 17:15:17 +, Alister wrote: >> >>> On Tue, 08 Jan 2019 16:48:58 +0200, Serhiy Storchaka wrote: >>> 08.01.19 11:07, Peter Otten пише: > Bob van der Poel wrote: > >> I need to see if all

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-11-30 Thread Dan Sommers
On 11/30/18 12:00 PM, Morten W. Petersen wrote: > I guess syntax could be added, so that > > a, b, @c = some sequence > > would initialize a and b, and leave anything remaining in c. We could > then call this @ syntax "teh snek". Close. ;-) Try this: a, b, *c = [4, 5, 6, 7] --

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-11-30 Thread Dan Sommers
On 11/30/18 10:57 AM, Morten W. Petersen wrote: > On Fri, Nov 30, 2018 at 4:25 PM Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote: >> Python validates that the right hand side contains exactly the right >> number of elements before beginning to unpack,

Re: ValueError vs IndexError, unpacking arguments with string.split

2018-11-30 Thread Dan Sommers
On 11/30/18 7:35 AM, Morten W. Petersen wrote: ... but isn't it logical that the string is parsed and split, and then later the unpacking operation fails with an IndexError? With slightly simpler code and the full text of the exception, the details becomes more apparent: >>> x, y = [4]

Re: Odd truth result with in and ==

2018-11-21 Thread Dan Sommers
On 11/21/18 7:09 PM, Chris Angelico wrote: > On Thu, Nov 22, 2018 at 11:04 AM Dan Sommers > <2qdxy4rzwzuui...@potatochowder.com> wrote: >> But the second one has to do an expensive subset operation. If I think >> "is elem in both sets," then I'd never write: &g

Re: Odd truth result with in and ==

2018-11-21 Thread Dan Sommers
On 11/21/18 6:45 PM, Ian Kelly wrote: > On Wed, Nov 21, 2018 at 2:53 PM Serhiy Storchaka wrote: >> >> 21.11.18 22:17, Cameron Simpson пише: >>> Can someone show me a real world, or failing that - sane looking, >>> chained comparison using "in"? >> >> s[0] == s[-1] in '\'"' >> >> Tests

Re: Question about implementing immutability

2018-11-21 Thread Dan Sommers
On 11/21/18 11:45 AM, Iwo Herka wrote: Hello, Let's say I want to implement immutability for user-defined class. More precisely, a class that can be modified only in its (or its super-class') __init__ method. My initial idea was to do it the following fashion: def __setattr__(self, *args,

Re: on the prng behind random.random()

2018-11-19 Thread Dan Sommers
On 11/19/18 6:49 PM, Robert Girault wrote: > I think I disagree with your take here. With mt19937, given ANY seed, > I can eventually predict all the sequence without having to query the > oracle any further. Even if that's true, and I use mt19937 inside my program, you don't

Re: bottledaemon stop/start doesn't work if killed elsewhere

2018-11-18 Thread Dan Sommers
On 11/18/18 1:21 PM, MRAB wrote:> On 2018-11-18 17:50, Adam Funk wrote: >> Hi, >> >> I'm using bottledaemon to run a little REST service on a Pi that takes >> input from other machines on the LAN and stores stuff in a database. >> I have a cron job to call 'stop' and 'start' on it daily, just in

Re: What's an elegant way to test for list index existing?

2018-09-29 Thread Dan Sommers
On 9/28/18 2:00 PM, Chris Green wrote: I have a list created by:- fld = shlex.split(ln) It may contain 3, 4 or 5 entries according to data read into ln. What's the neatest way of setting the fourth and fifth entries to an empty string if they don't (yet) exist? Using 'if len(fld) < 4:'

Re: "glob.glob('weirdness')" Any thoughts?

2018-09-11 Thread Dan Sommers
On 9/11/18 6:24 PM, Gilmeh Serda wrote: I think this is no different than RegEx matching, so the routine really shouldn't be called glob() but the_regex_variations_opus_five(). Maybe your version should be called crippled_glob. Globbing has a long history, longer than many of the people who

Re: Help Needed : script weird result.

2018-09-01 Thread Dan Sommers
On 9/1/18 1:11 PM, moha...@gmail.com wrote: All, I m trying to run this small script to find the lowest of the given array of numbers. The script works fine for various combination of inputs but fails in a weird way for a particular set of inputs, can anyone point the mistake in the script

Re: Pylint false positives

2018-08-20 Thread Dan Sommers
On Mon, 20 Aug 2018 22:55:26 +0300, Marko Rauhamaa wrote: > Dan Sommers : > >> On Mon, 20 Aug 2018 14:39:38 +, Steven D'Aprano wrote: >>> I have often wished Python had proper namespaces, so I didn't have to >>> abuse classes as containers in this way :-( >

Re: Pylint false positives

2018-08-20 Thread Dan Sommers
On Mon, 20 Aug 2018 14:39:38 +, Steven D'Aprano wrote: > If a class' methods don't use self, it probably shouldn't be a class. Agreed. > I have often wished Python had proper namespaces, so I didn't have to > abuse classes as containers in this way :-( > > (Not that I do this using "inner

Re: Pylint false positives

2018-08-17 Thread Dan Sommers
On Fri, 17 Aug 2018 09:46:01 +0200, Frank Millman wrote: > It is just a slight annoyance (to me) that pylint complains about the > subclass methods when they are called from the Field class. I don't > mind adding 10 stub methods to the Field class to keep it happy, but I > do not get the feeling

Re: pattern block expression matching

2018-07-21 Thread Dan Sommers
On Sat, 21 Jul 2018 17:37:00 +0100, MRAB wrote: > On 2018-07-21 15:20, aldi.kr...@gmail.com wrote: >> Hi, >> I have a long text, which tells me which files from a database were >> downloaded and which ones failed. The pattern is as follows (at the end of >> this post). Wrote a tiny program, but

Re: Cult-like behaviour [was Re: Kindness]

2018-07-16 Thread Dan Sommers
On Tue, 17 Jul 2018 08:48:55 +1000, Chris Angelico wrote: > That said, though, the fact that indexing a byte string yields an int > instead of a one-byte string is basically unable to be changed now ... Agreed. > ... and IMO it'd be better to be consistent with text strings than > with

Re: Unicode [was Re: Cult-like behaviour]

2018-07-16 Thread Dan Sommers
On Mon, 16 Jul 2018 10:39:49 +, Steven D'Aprano wrote: > ... people who think that if ISO-8859-7 was good enough for Jesus ... It may have been good enough for his disciples, but Jesus spoke Aramaic. Also, ISO-8859-7 doesn't cover ancient polytonic Greek; it only covers modern monotonic

Re: Python gotcha of the day

2018-03-13 Thread Dan Sommers
On Wed, 14 Mar 2018 04:08:30 +, Steven D'Aprano wrote: > Explain the difference between these two triple-quoted strings: > But remove the spaces, and two of the quotation marks disappear: > > py> """\"" > '"' That's (a) a triple quoted string containing a single escaped quote, followed

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread Dan Sommers
On Wed, 07 Mar 2018 16:57:51 -0500, C W wrote: > class Clock(object): > def __init__(self, time): > self.time = time > def print_time(self): > time = '6:30' > print(self.time) > > clock = Clock('5:30') > clock.print_time() > 5:30 > > I set time to 6:30, but it's

Re: Which part of the loop is it going through in this class frame?

2018-03-07 Thread Dan Sommers
On Wed, 07 Mar 2018 16:57:51 -0500, C W wrote: > Hello, > > I am new to OOP. I'm a bit confused about the following code. > > class Clock(object): > def __init__(self, time): > self.time = time > def print_time(self): > time = '6:30' > print(self.time) > > clock

Re: Where has the practice of sending screen shots as source code come from?

2018-01-28 Thread Dan Sommers
On Mon, 29 Jan 2018 00:27:07 +, Steven D'Aprano wrote: > On Mon, 29 Jan 2018 08:55:54 +1100, Tim Delaney wrote: > >> I got back a Word document containing about 10 screenshots where they'd >> apparently taken a screenshot, moved the horizontal scrollbar one >> screen, taken another

Re: Where is ^ (symmetric_difference) documented in help()?

2017-12-22 Thread Dan Sommers
On Fri, 22 Dec 2017 21:35:53 -0600, Peng Yu wrote: > Hi, I see the following two lines are the same. But I'd like to find > where ^ is documented via the help() function (I am not looking for > the document in html)? Does anybody know? Thanks. > > s.symmetric_difference(t) > s ^ t It's sort of

Re: Coding style in CPython implementation

2017-10-28 Thread Dan Sommers
On Sat, 28 Oct 2017 16:20:54 -0700, Στέφανος Σωφρονίου wrote: > I do believe though that if (!d) is a lot clearer than if (d == NULL) > as it is safer than falsely assigning NULL in d, by pure mistake. Having made my living writing C code for a very long time, I always found if (!d) *harder* to

Re: The "loop and a half"

2017-10-05 Thread Dan Sommers
On Thu, 05 Oct 2017 19:14:33 -0600, Michael Torrie wrote: > It all depends on what the command's purpose is for, and how it's > designed to be chained with other commands (cat for example). They're almost all designed to be chained with other commands. Even diff and ed are designed to work

Re: Beginners and experts (Batchelder blog post)

2017-09-27 Thread Dan Sommers
On Wed, 27 Sep 2017 12:41:24 -0400, leam hall wrote: > The question is, what should a person "know" when hiring out as a > programmer? What is 'know" and what should be "known"? Specifically > with Python. The longer I claim to be a programmer, the more I discover how wide a net that is. Web

Re: Falsey Enums

2017-07-27 Thread Dan Sommers
On Fri, 28 Jul 2017 12:15:20 +1000, Steve D'Aprano wrote: > I has some Enums: > > from enum import Enum > class X(Enum): > Falsey = 0 > Truthy = 1 > Fakey = 2 > > > and I want bool(X.Falsey) to be False, and the others to be True. What should > I > do? Add the following to your

Re: Test 0 and false since false is 0

2017-07-06 Thread Dan Sommers
On Fri, 07 Jul 2017 02:48:45 +, Stefan Ram wrote: def isfalse( x ): > ... return x == 0 and str( type( x )) == "" > ... > Don't depend on string representations of objects, unless you know what you're doing. Do this instead: def isfalse(x): return x == 0 and type(x) is

Re: Test 0 and false since false is 0

2017-07-06 Thread Dan Sommers
On Thu, 06 Jul 2017 19:29:00 -0700, Sayth Renshaw wrote: > I have tried or conditions of v == False etc but then the 0's being > false also aren't moved. How can you check this at once? Maybe this will help: Python 3.5.3+ (default, Jun 7 2017, 23:23:48) [GCC 6.3.0 20170516] on linux

Re: Survey: improving the Python std lib docs

2017-05-12 Thread Dan Sommers
On Fri, 12 May 2017 21:14:01 +1000, Chris Angelico wrote: > On Fri, May 12, 2017 at 8:02 PM, Steve D'Aprano > wrote: >> (2) The PHP documentation allows you to search for a term by typing it into >> the URL after the domain, e.g. to search for "split", go to: >> >>

Re: Quick questions about globals and database connections

2017-04-05 Thread Dan Sommers
On Wed, 05 Apr 2017 22:00:46 -0400, DFS wrote: > I have a simple hard-coded check in place before even trying to connect: > > if dbtype not in ('sqlite postgres'): >print "db type must be sqlite or postgres" >exit() That's not doing what you think it is. Hint: What is ('sqlite

Re: Quick questions about globals and database connections

2017-04-05 Thread Dan Sommers
On Wed, 05 Apr 2017 14:56:12 -0400, DFS wrote: > I split the database connection code and settings into a module, so > the connection and setting values are available to other code modules > I have. Good work. > dbset.py > - > import sqlite3,

Re: Quick questions about globals and database connections

2017-04-05 Thread Dan Sommers
On Wed, 05 Apr 2017 10:54:29 -0400, DFS wrote: > I have identical databases in sqlite and postgres. I want to run the > same code against them, but am having a small issue. > > Current code below throws the dreaded: > > NameError: global name 'db' is not defined > > on line 12 > > How do I

Re: int vs. float

2017-02-10 Thread Dan Sommers
On Fri, 10 Feb 2017 20:46:16 +, Erik wrote: > Python 3.5.2 (default, Nov 17 2016, 17:05:23) > [GCC 5.4.0 20160609] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> 0.5 > 1.0 > >>> f = float("0.5") > >>> i = int(f) >

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

2017-02-04 Thread Dan Sommers
On Sat, 04 Feb 2017 21:19:06 +0200, Marko Rauhamaa wrote: > Now, that's why the distros are careful to place $HOME/bin as the > final entry of PATH; the system commands take precedence over the > user's personal ones. However, the user is free to define the PATH any > way they like. I

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

2017-02-04 Thread Dan Sommers
On Sat, 04 Feb 2017 12:56:58 -0600, Wildman wrote: > On Sat, 04 Feb 2017 18:25:03 +, Grant Edwards wrote: >> It allows a malicous user to put an evil executable someplace public >> like /tmp and have it executed accidentally. For example, let's say >> this executable file was named "sl" and

  1   2   3   4   5   >