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
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
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
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
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)
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
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: "...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
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
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.
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
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.
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
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
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
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:
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
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:
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
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.
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
"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
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
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
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;
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
>>> 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,
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
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
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
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
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".
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
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
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
> 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
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
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
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
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: ">> 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: " 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
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
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
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
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.
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,
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
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
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-
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,
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
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
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,
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
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
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.
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
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
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: "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:
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
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
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)
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)
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
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
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
68 matches
Mail list logo