RE: Top level of a recursive function

2022-12-13 Thread Schachner, Joseph (US)
Reducing repetitiveness has made this code harder to read. I had to think about what it is doing. It might be slightly faster, but in my opinion it is not worth it. --- Joseph S. Teledyne Confidential; Commercially Sensitive Business Data -Original Message- From: Stefan Ram

RE: How to manage python shebang on mixed systems?

2022-11-07 Thread Schachner, Joseph (US)
Maybe you can't do this, but I would suggest only running on the Python 3 systems. Refuse to jump through hoops for the Python 2 system. It is years out of date. It is not hard to upgrade from Python 2 to Python 3. There is a 2to3 utility, and after that there should be very few things you

RE: Are Floating Point Numbers still a Can of Worms?

2022-10-24 Thread Schachner, Joseph (US)
Floating point will always be a can of worms, as long as people expect it to represent real numbers with more precision that float has. Usually this is not an issue, but sometimes it is. And, although this example does not exhibit subtractive cancellation, that is the surest way to have less

RE: A trivial question that I don't know - document a function/method

2022-10-24 Thread Schachner, Joseph (US)
I head a small software team much of whose output is Python. I would gratefully accept any of the formats you show below. My preference is #1. --- Joseph S. Teledyne Confidential; Commercially Sensitive Business Data -Original Message- From: Paulo da Silva Sent: Saturday, October

RE: How to make a variable's late binding crosses the module boundary?

2022-08-30 Thread Schachner, Joseph (US)
The way we do this, is in main.py, call a "globalizer" function in each other file: # call globalizers to get shortcuts as global variables funcs.globalizer(interface, variable_dict) util.globalizer(interface, variable_dict) sd.globalizer(interface, variable_dict)

RE: Parallel(?) programming with python

2022-08-09 Thread Schachner, Joseph (US)
Why would this application *require* parallel programming? This could be done in one, single thread program. Call time to get time and save it as start_time. Keep a count of the number of 6 hour intervals, initialize it to 0. Once a second read data an append to list. At 6 hours after

RE: Python/New/Learn

2022-05-05 Thread Schachner, Joseph
Buy the book "Python 101" and do the examples. When you're done with that buy the book "Python 201" and study it. There is much more than is in both those books that you could learn about Python, but that's a very good way to start. --- Joseph S. Teledyne Confidential; Commercially

RE: lambda issues

2022-04-20 Thread Schachner, Joseph
Re: "...which takes a callable (the lambda here)" Python lamdas have some severe restrictions. In any place that takes a callable, if a lambda can't serve, just use def to write a function and use the function name. Joseph S. Teledyne Confidential; Commercially Sensitive Business Data

RE: Functionality like local static in C

2022-04-14 Thread Schachner, Joseph
Yes, python has something like that. In fact, two things. 1) Generator. Use a "yield" statement. Every call "yields" a new value. The state of the function (local variables) is remembered from each previous call to the next. 2) In a file, declare a variable to be global. In the

RE: Reportlab / platypus bug?

2022-03-14 Thread Schachner, Joseph
I realize this is Python code, but I doubt that the question is a Python question. I have used Python +numpy, scipy, matplotlib for years. I have not used reportlab and have no idea about the reported problem except that I will be very surprised if it turns out to be a Python language issue.

RE: Behavior of the for-else construct

2022-03-07 Thread Schachner, Joseph
Can someone please change the topic of this thread? No longer about for-else. Teledyne Confidential; Commercially Sensitive Business Data -Original Message- From: Dennis Lee Bieber Sent: Sunday, March 6, 2022 1:29 PM To: python-list@python.org Subject: Re: Behavior of the for-else

RE: Behavior of the for-else construct

2022-03-03 Thread Schachner, Joseph
Useful: On rare occasions (when a loop has a "break" in it) Used: Yes Know how it works: Yes Even is such a thing: Yes Your suggestion: Also useful. Will require a different keyword. I don't know what that would be. "finally" is available  Write up a feature request. --- Joseph S.

RE: Problem with concatenating two dataframes

2021-11-08 Thread Schachner, Joseph
The problem I see here is use of Pandas. I know I have he losing opinion, but people who use Python to load Panadas and then only use Pandas are missing out on the functionality of Python. I'll bet you could code combining this data in pure Python, into one dictionary. In fact I'd be shocked

RE: New assignmens ...

2021-10-26 Thread Schachner, Joseph
Why force unpacking? Why not assign a tuple? That would look like a simple assignment: x := (alpha, beta, gamma) And you could access x[0], x[1] and x[2]. I think asking := to support x, y := alpha, beta is a request to address an unnecessary, easily worked around, issue. And as

RE: ANN: Dogelog Runtime, Prolog to the Moon (2021)

2021-09-14 Thread Schachner, Joseph
Opinion: Anyone who is counting on Python for truly fast compute speed is probably using Python for the wrong purpose. Here, we use Python to control Test Equipment, to set up the equipment and ask for a measurement, get it, and proceed to the next measurement; and at the end produce a nice

RE: on floating-point numbers

2021-09-03 Thread Schachner, Joseph
Actually, Python has an fsum function meant to address this issue. >>> math.fsum([1e14, 1, -1e14]) 1.0 >>> Wow it works. --- Joseph S. Teledyne Confidential; Commercially Sensitive Business Data -Original Message- From: Hope Rouselle Sent: Thursday, September 2, 2021 9:51 AM To:

RE: on floating-point numbers

2021-09-03 Thread Schachner, Joseph
What's really going on is that you are printing out more digits than you are entitled to. 39.61 : 16 decimal digits. 4e16 should require 55 binary bits (in the mantissa) to represent, at least as I calculate it. Double precision floating point has 52 bits in the mantissa, plus

RE: matplotlib questions

2021-08-27 Thread Schachner, Joseph
Complete documentation link (this link works) : https://matplotlib.org/stable/contents.html --- Joseph S. Teledyne Confidential; Commercially Sensitive Business Data -Original Message- From: Steve Sent: Thursday, August 26, 2021 11:48 AM To: python-list@python.org Subject:

RE: Defining a Python enum in a C extension - am I doing this right?

2021-07-30 Thread Schachner, Joseph
Instead of struggling to define an enum in C that can be read in Python - I'm assuming you can pass strings back and forth - why not just print whatever you need to give to Python into a string (or maybe 2 strings) and send it to Python as string? Python is a dynamic language, it can quickly

Is there a conference in the US that is similar to EuroPython?

2021-07-19 Thread Schachner, Joseph
I am not going to fly to Europe for a Python conference. But, would consider going if in the U.S.A. Especially if drivable ... NYC area would be ideal. I ask because I have seen ads for EuroPython over several years, and I don't remember seeing similar ads for something similar in the U.S.A.

RE: learning python ...

2021-05-24 Thread Schachner, Joseph
OMG that is awful abuse of Python! You have overloaded two Python keywords by making variables of that name. As a result, float is no longer a type name, it is a variable name that refers to the value 6.67 ! Type(int) is int; type(float) is float, but isinstance(int,float) doesn't work

RE: neoPython : Fastest Python Implementation: Coming Soon

2021-05-06 Thread Schachner, Joseph
"Slow" is in the eye of the beholder and depends on the job the needs to be done. Where I work, we write scripts in Python that control our measuring instruments, make them acquire data and compute results, the Python script reads the results, compares results to limits, and eventually

RE: .title() - annoying mistake

2021-03-19 Thread Schachner, Joseph
I agree. If the documentation notes this issue, and the (possibly new) Python user has to replace the .title() with a different function that uses regular expression and a lambda function to work around the issue, then perhaps it's time for a proposal to address this. Perhaps there needs to

RE: Python cannot count apparently

2021-02-08 Thread Schachner, Joseph
This code works: mystr = "hello" for ch in mystr: print(ch, end="") result is: hello Note that the for loop does not use range. Strings are iterable, that is they support Python's iteration protocol. So, for ch in mystr: assigns one character from mystr to ch each time, each

RE: IDE tools to debug in Python?

2021-02-05 Thread Schachner, Joseph
Indeed there are many. One I have not seen listed here yet, that is quite light, starts quickly, but does have good debugging capability is PyScripter. Completely free, downloadable from SourceForge, 32 or 64 bit versions (must match your Python type). --- Joseph S. Teledyne Confidential;

RE: dict.get(key, default) evaluates default even if key exists

2020-12-18 Thread Schachner, Joseph
Yes. In order to call D.get( ) it needs to pass two arguments. The first is 'a', simple. The second is the result of a call to get_default(). So, that is called. From INSIDE get_default() it prints 'Nobody expects this' but you should expect it, get_default() gets executed. Following

RE: To check if number is in range(x,y)

2020-12-14 Thread Schachner, Joseph
>>> r = range(10) So r is a list containing 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 >>> 2 in r True As expected. >>> 2.5 in r False Also as expected. If you did int(floor(2.5)) in 5 that would be true. >>> r = range(1, 10, 2) >>> 2 in r False >>> list(r) [1, 3, 5, 7, 9] Well, yes,

RE: linear algebric equations

2020-12-08 Thread Schachner, Joseph
Yes. Import os, and use os.system( ) to call your Fortran (or C) executable. If the executable saves results in a file or files, Python can read them in an format a nice overall report. In html or xml, if you like. Using Python as glue, the execution time will be exactly what it was for

RE: Letter replacer - suggestions?

2020-12-07 Thread Schachner, Joseph
The only comment I have is that you didn't check the inputs at all. Suppose the word I type in is "1234". 1234 will turn into an int, not a string. You can't index through an int, it's one thing. So the program will probably throw an error. If the word at least starts with a letter, then it

RE: Question on ABC classes

2020-10-23 Thread Schachner, Joseph
I'm a C++ programmer and Python programmer as well. Python classes are not exactly like C++ classes. If you define a class where every method has an implementation, then it really isn't abstract. It can be instantiated. You can force it to be abstract by doing from abc import ABCMeta and

RE: Python 3..9.0

2020-10-09 Thread Schachner, Joseph
You're not doing anything wrong, but clearly it's not what you want to do. You are running the Python interpreter and not specifying any script to run, so it opens a command prompt and promptly closes it, I'll bet. What you want to do is open a development environment. Try Idle, it's there

RE: What this error want to say? Can't we use return without function?

2020-09-08 Thread Schachner, Joseph
I see. You didn't declare a function, it's just a python script. So you don't need a return in that situation, the script just ends when there are no more lines. By the way: you certainly don't want to return or quit BEFORE you print(nice). But the fix here is simply to delete "return coun".

RE: Output showing "None" in Terminal

2020-08-25 Thread Schachner, Joseph
The very first line of your function km_mi(): ends it: def km_mi(): return answer answer has not been assigned, so it returns None. Advice: remove that "return" line from there. Also get rid of the last line, answer = km_mi which makes answer refer to the function km_mi(). Put the "return

RE: Embedded python: How to debug code in an isolated way

2020-08-24 Thread Schachner, Joseph
Another suggestion: If your Python code only references few things outside of itself, make a simulated environment in Python on your PC, so that you can run your embedded code after importing your simulated environment, which should supply the functions it expects to call and variables it

RE: why no camelCase in PEP 8?

2020-05-19 Thread Schachner, Joseph
I don't actually know, but I can take a guess. CamelCase can be problematic with terms that are abbreviations and always upper case. For example FIRFilter or USBPLL The first violated camelCase because it has no lower case letters before Filter, and the second completely violates camelCase

RE: [RELEASE] Python 3.9.0a6 is now available for testing

2020-04-29 Thread Schachner, Joseph
> norm=lambda m: m+(m and(m[-1]!= '\n'and'\n'or' ')or'\n') Parentheses 1 2 1 0 quotes 1 0 1 0 1 01 0 OK I don't

RE: Floating point problem

2020-04-20 Thread Schachner, Joseph
16 base 10 digits / log base10( 2) = 53.1508495182 bits. Obviously, fractional bits don't exist, so 53 bits. If you note that the first non-zero digit as 4, and the first digit after the 15 zeroes was 2, then you got an extra bit. 54 bits. Where did the extra bit come from? It came from the

RE: Python-list Digest, Vol 189, Issue 17

2019-06-17 Thread Schachner, Joseph
Please see https://docs.python.org/2/library/colorsys.html And follow the links in there, read the FAQ. You'll find that python represents RGB values in three numeric values. Very simple. I believe scale is 0.0 to 1.0. --- Joseph S. -Original Message- From: Python-list On Behalf

RE: Design a function that finds all positive numbers

2019-04-09 Thread Schachner, Joseph
I'm willing to bet "sorted" is a sort of the list of strings. The result is certainly not what I'd expect if the list contained numeric values. So: make a new list that holds the values in your "Array" (which is probably a list) converted to numbers. Sort the new list. That should give

RE: scalable bottleneck

2019-04-04 Thread Schachner, Joseph
If you are using Python 3, range does not create at list, it is a generator. If you're using Python 2.x, use xrange instead of range. xrange is a generator. In Python 3 there is no xrange, they just made range the generator. --- Joseph S. -Original Message- From: Sayth Renshaw

RE: Syntax for one-line "nonymous" functions in "declaration style"

2019-04-01 Thread Schachner, Joseph
Re: ">> Neither i like how a function magically turns into a generator if the >> keyword `yield` appears somewhere within its definition. > I agree, there should have been a required syntactic element on the "def" > line as well to signal it immediately to the reader. It won't stop me from >

RE: Multiprocessing vs subprocess

2019-03-12 Thread Schachner, Joseph
Re: " My understanding (so far) is that the tradeoff of using multiprocessing is that my manager script can not exit until all the work processes it starts finish. If one of the worker scripts locks up, this could be problematic. Is there a way to use multiprocessing where processes are

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

2019-02-13 Thread Schachner, Joseph
Because all comparisons with NAN return false, that's the spec. is NAN > 0? False. Is NAN< 0? False. Is NAN == 0? False. Is NAN == ? False. So: Is NAN == NAN? False. And one more: Is NAN < 1.0e18? False This makes some sense because NAN is Not A Number, so any comparison to a number

RE: The sum of ten numbers inserted from the user

2019-02-07 Thread Schachner, Joseph
removed. --- Joe S. From: Ian Clark Sent: Thursday, February 7, 2019 1:27 PM To: Schachner, Joseph Cc: python-list@python.org Subject: Re: The sum of ten numbers inserted from the user This is my whack at it, I can't wait to hear about it being the wrong big o notation! numbers=[] while len

RE: The sum of ten numbers inserted from the user

2019-02-07 Thread Schachner, Joseph
Well of course that doesn't work. For starters, x is an int or a float value. After the loop It holds the 10th value. It might hold 432.7 ... It is not a list. The default start for range is 0. The stop value, as you already know, is not part of the range. So I will use range(10). In

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

2019-01-29 Thread Schachner, Joseph
Yes, that works. Assuming it was correctly formatted when you ran it. The formatting could not possibly be run in a Python interpreter, I think. --- Joseph S. From: Adrian Ordona Sent: Tuesday, January 29, 2019 2:52 PM To: Schachner, Joseph Cc: Dan Sommers <2qdxy4rzwzuui...@potatochowder.

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

2019-01-29 Thread Schachner, Joseph
Explanation: 5 > 4 so it goes into the first if. 5 is not greater than 6, so it does not assign N1 to MaxNum. The elif (because of the lack of indent) applies to the first if, so nothing further is executed. Nothing has been assigned to MaxNum, so that variable does not exist. You're right,

What is your experience porting Python 2.7.x scripts to Python 3.x?

2019-01-22 Thread Schachner, Joseph
In the company I work for we have a program (free) that runs scripts (that we sell) to test according to particular standards. The program embeds a Python interpreter, and the scripts are Python (which uses functions revealed to Python from within the program). Well, this year must be time

RE: Pythonic Y2K

2019-01-17 Thread Schachner, Joseph
I'd like to add one more thing to your list of what companies will have to consider: 6) The ability to hire and retain employees who will be happy to program in an obsolete version of Python. A version about which new books will probably not be written. A version which new packages will not

RE: get the terminal's size

2019-01-14 Thread Schachner, Joseph
I just tested the fix I proposed, in Python 2.7.13 Code: from win32api import GetSystemMetrics def main(): print "Width =", GetSystemMetrics(0) print "Height =", GetSystemMetrics(1) if __name__ == '__main__': main() Result: Width = 1536 Height = 864 -Original Message-

RE: get the terminal's size

2019-01-14 Thread Schachner, Joseph
Note sure why you couldn't capture $ echo $COLUMNS from a subprocess call. But, how about this (found on the web): from win32api import GetSystemMetrics print "Width =", GetSystemMetrics(0) print "Height =", GetSystemMetrics(1) -Original Message- From: Alex Ternaute Sent: Monday,

RE: Python read text file columnwise

2019-01-14 Thread Schachner, Joseph
About the original question: If I were you, I would put the 3 numbers into a list (or a tuple, if you don't need to modify them) and put this into a dictionary. The key would be the date & time string. Then, if you need to find a particular entry you can look it up by date and time. But I

RE: the python name

2019-01-02 Thread Schachner, Joseph
Python was started in the late 1980s by Guido Van Rossum, who (until quite recently) was the Benevolent Dictator for Life of Python. His recent strong support of Type Annotation was what got it passed - and having to fight for it was what convinced him retire from the role of BDFL. Anyway, at

RE: question on the 'calendar' function

2018-11-20 Thread Schachner, Joseph
It's possible I don't understand the question. The calendar functions are NOT limited to this year or any limited range. Example: import calendar print( calendar.monthcalendar(2022, 12) ) Prints lists of dates in each week of December 2022. It prints: [[0, 0, 0, 1, 2, 3, 4], [5, 6, 7, 8, 9,

RE: Python Enhancement Proposal for List methods

2018-10-22 Thread Schachner, Joseph
I agree with others that I don't see a compelling need to add these to Python, since they are all easy to implement in a few lines. But what I really want to say is that Python tries hard to be easily readable and easily understood, by any reader. List.removeall( ) that does not remove all

RE: [OT] master/slave debate in Python

2018-09-26 Thread Schachner, Joseph
This really is an amazing discussion. I actually do understand why "master" and "slave" might make people uncomfortable, although the meaning is quite clear. Perhaps we need a currently used alternative: 1) Captain and Private 2) Manager and employee 3) CEO and Peon 4) Controller and

RE: Why emumerated list is empty on 2nd round of print?

2018-09-07 Thread Schachner, Joseph
The question "If I do this "aList = enumerate(numList)", isn't it stored permanently in aList now? I see your point to use it directly, but just in case I do need to hang onto it from one loop to another, then how is that done?" Reflects that you are thinking in a C++ kind of way I think.

Guilty as charged

2018-07-27 Thread Schachner, Joseph
Re: "...while thing == None would work perfectly in almost all cases in practice, it's unidiomatic and suggests the writer isn't quite comfortable with the workings of the language" I admit, I've been a C++ programmer for many years and a Python programmer for only about 5 years. But, I

RE: Checking whether type is None

2018-07-25 Thread Schachner, Joseph
While I appreciate that use of "is" in thing is None, I claim this relies on knowledge of how Python works internally, to know that every None actually is the same ID (the same object) - it is singular. That probably works for 0 and 1 also but you probably wouldn't consider testing thing

RE: PEP 526 - var annotations and the spirit of python

2018-07-05 Thread Schachner, Joseph
It is interesting to contemplate how this could transform Python into nearly a statically typed language: x = 3 x = f(x) If you say the type checker should infer that x is an int, and then therefore complain about x=f(x) if f() does not return an int, then we have what in new C++ is auto type

Re: range

2018-06-25 Thread Schachner, Joseph
Re: "I know I'm going to get flak for bringing this up this old issue, but remember when you used to write a for-loop and it involved creating an actual list of N integers from 0 to N-1 in order to iterate through them? Crazy. But that has long been fixed - or so I thought. When I wrote, today:

RE: ironpython not support py3.6

2018-06-22 Thread Schachner, Joseph
Wait. -Original Message- From: fantasywan...@gmail.com Sent: Friday, June 22, 2018 2:45 AM To: python-list@python.org Subject: ironpython not support py3.6 We have a project implemented with c# and python, iron python is a good choice for us to integrate these two tech together but

RE: syntax difference

2018-06-18 Thread Schachner, Joseph
On YouTube you can watch videos of Guido van Rossum presenting at PyCon from a few years ago, in which he makes clear that he has been thinking about this since 2000, that he wants someone else to guide this PEP along its path because he is too close to it, and that NOTHING about having a

RE: syntax difference (type hints)

2018-06-18 Thread Schachner, Joseph
Assuming that we want Python to remain a dynamically typed (but strongly typed) language, I believe the proposed type hints are only necessary for function definitions, where the caller really needs to know the types of arguments to pass in. At the moment that purpose is (I think adequately)

RE: syntax difference

2018-06-18 Thread Schachner, Joseph
As soon as I sent the previous message I realized it's "doc string" not def string. Pardon me. --- Joe S. -Original Message- From: Ed Kellett Sent: Monday, June 18, 2018 8:47 AM To: python-list@python.org Subject: Re: syntax difference On 2018-06-18 13:18, Chris Angelico wrote: > 1)

RE: mutable sequences

2018-06-14 Thread Schachner, Joseph
No, it says lists are mutable and tuples are immutable. Mutable has the same root as "mutation". Mutable means "can be changed in place". Immutable means "cannot be changed in place". Examples: 1) pass your list to a function, the function modifies the list. When the function returns

RE: logging with multiprocessing

2018-06-08 Thread Schachner, Joseph
Multiprocessing, not multithreading. Different processes. This is pretty easy to do. I have done this from a Python script to run an analysis program on many sets of data, at once. To do it: 1) if there is going to be an output file, each output file must have a distinct name. 2) To use

RE: "Data blocks" syntax specification draft

2018-05-23 Thread Schachner, Joseph
I understand that the /// data representation is meant to emphasize data structure (and de-emphasize existing Python syntax for that purpose). It's already been discussed that Python can export to pickle format, JSON, csv, XML and possibly others I can't think of right now. So having a data