Re: Ann: New Python curses book

2021-03-30 Thread William Ray Wing via Python-list
I’ve ordered the book (physical volume). It will fulfill a need I’ve had for 
some time.  Unfortunately, it is only available in the UK store, so the 
shipping cost by far outweighs the book’s cost.  Hope for other’s sake, it 
migrates to the other Amazon stores fairly quickly.

Thanks,
Bill

> On Mar 30, 2021, at 7:12 AM, Alan Gauld via Python-list 
>  wrote:
> 
> I've just published, in Kindle and paperback formats,
> my book on "Programming curses with Python".
> 
> https://www.amazon.co.uk/dp/B091B85B77/
> 
> (It should be available in most other Amazon stores too)

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-26 Thread William Ray Wing via Python-list



> On Jan 26, 2021, at 2:00 PM, C W  wrote:
> 
> Hello everyone,
> 
> I'm a long time Matlab and R user working on data science. How do you
> troubleshooting/debugging in Python?
> 

Another approach is to run the code in an IDE.  I happen to use Wing, but that 
is a coincidence.  But almost ANY IDE will let you set a break point, then 
single-step through your code starting at the break point and examine the 
values of your variables at each step.  Sometimes this is an awfully big hammer 
for what is a head-slapping mistake.  But it has never failed me.

Good luck,
Bill

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: questions re: calendar module

2020-08-01 Thread William Ray Wing via Python-list

> On Aug 1, 2020, at 10:35 AM, o1bigtenor  wrote:
> 
> On Sat, Aug 1, 2020 at 9:29 AM o1bigtenor  wrote:
>> 
>>> On Sat, Aug 1, 2020 at 6:58 AM Peter Otten <__pete...@web.de> wrote:
>>> 
>>> o1bigtenor wrote:
>>> 
>>> import calendar
>>> print (calendar.calendar(2024,1,1,2,8))
>>> 
 I would like to show something like 2024 through the end of 2028.
>>> 
>>> print("\n".join(cd.calendar(year) for year in range(2024, 2029)))
>> 
>> 
>> Sorry - - - - 1st response was to only Mr Peter - - - hopefully this is
>> useful to more than I so here is that to all.
>>> 
>>> 
>> 
> print("\n".join(cd.calendar(year) for year in range(2024, 2029)))
>> Traceback (most recent call last):
>>  File "", line 1, in 
>>  File "", line 1, in 
>> NameError: name 'cd' is not defined
>> 
>> so 'cd' seems to be a problem.
>> 
>> Tried changing 'cd' to calendar and that gives the desired response.
>> 
>> Except its a neat 3 months wide very very very many rows of calendar.
>> 
>> I'm trying to figure out how to do something like this:
>> 
>>November 2022  December 2022
>>January 2023February 2023
>> March 2023April 2023
>> May 2023
>>   Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa  Su Mo Tu
>> We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
>> Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
>> 1231  2  3  4  5 127  1  2  3
>>132  1  2  3  4  5  6  7  136   1  2  3  4  140
>> 1  2  3  4  1441  149 1  2  3  4  5  6
>> 124  6  7  8  9 10 11 12  128  4  5  6  7  8  9 10  133  8  9 10 11 12
>> 13 14  137  5  6  7  8  9 10 11  141  5  6  7  8  9 10 11  145  2  3
>> 4  5  6  7  8  150  7  8  9 10 11 12 13
>> 125 13 14 15 16 17 18 19  129 11 12 13 14 15 16 17  134 15 16 17 18 19
>> 20 21  138 12 13 14 15 16 17 18  142 12 13 14 15 16 17 18  146  9 10
>> 11 12 13 14 15  151 14 15 16 17 18 19 20
>> 126 20 21 22 23 24 25 26  130 18 19 20 21 22 23 24  135 22 23 24 25 26
>> 27 28  139 19 20 21 22 23 24 25  143 19 20 21 22 23 24 25  147 16 17
>> 18 19 20 21 22  152 21 22 23 24 25 26 27
>> 127 27 28 29 30   131 25 26 27 28 29 30 31  136 29 30 31
>>   140 26 27 28  144 26 27 28 29 30 31 148 23 24
>> 25 26 27 28 29  153 28 29 30 31
>> 
>>   149 30
>> 
>>   June 2023 July 2023August 2023
>>   September 2023 October 2023
>> November 2023 December 2023
>>Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th
>> Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo
>> Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
>> 153  1  2  3  1571  1621  2  3
>> 4  5  166 1  2  171  1  2  3  4  5  6  7  175
>>  1  2  3  4  179 1  2
>> 
>> The formatting here is a mess.
> 
> (Its an even bigger mess now when its truncated to 80 columns. Can't change
> the mess but I can tell you that it doesn't 'look that way'! Don't know how to
> include an example in the body and have it be even a bit accurate - - - please
> advise if there is a way.)
> 

If you want us to see it in its exact form, print to PDF, post/share It on 
Dropbox. 

>> The months are centered. The week numbers are consecutive from the
>> starting date.
>> The dates are centered under the weekday name. If you've ever used
>> ncal its like that except
>> that I can now have up to 7 months wide if the terminal is wide enough
>> (>180 columns IIRC).
>> A mentor was working on this in Perl but as he died some couple months
>> ago its up to me
>> to make what I want.
>> Because it seems like there are a lot of disparate things happening
>> its not very straight
>> forward trying to replicate and extend my friend's efforts except in
>> Python. (My friend
>> preferred to work in Perl rather than Python and I'm wanting to learn
>> Python. I understand
>> that this is not perhaps the easiest way to learn something but it
>> sure is interesting!)
>> 
>> TIA
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Questions

2019-04-08 Thread William Ray Wing via Python-list
Diana, I’m answering you via the Tutor list - please, the accepted protocol is 
to send all questions and answers to the list so answers can be seen by (and 
possibly help) others.

Having said that, I should have paid more attention to your original question, 
which is really going to require answers that are beyond the typical Tutor 
question level, so I’m also forwarding to the main Python list where you should 
be able to get pointers.

But let me ask, how much programming do you know? Python is a full-blown 
programming language, like Java or C.  Have you written programs before that, 
for example can accept a file name from a user, open that file, and read its 
contents?  If yes, then I apologize, and would point you at:


https://medium.freecodecamp.org/how-to-scrape-websites-with-python-and-beautifulsoup-5946935d93fe
 


https://towardsdatascience.com/how-to-web-scrape-with-python-in-4-minutes-bc49186a8460

https://realpython.com/python-web-scraping-practical-introduction/
or
https://docs.python-guide.org/scenarios/scrape/

The next steps would probably involve loading that scraped data into Pandas:


https://pandas.pydata.org/pandas-docs/stable/getting_started/tutorials.html


https://data36.com/pandas-tutorial-1-basics-reading-data-files-dataframes-data-selection/

https://www.tutorialspoint.com/python_pandas

On the other hand, if your answer to my question is: “no” - then you should 
take a look at any of the really vast
collection of web sites devoted to Python learning.  Note that Python was 
originally designed to be a language that would be easy for beginners to learn. 
 It still is - I’d claim it is about the easiest -

>>> print( "Hello world!" ) 
Hello world!

Those lines were lifted from Alan Gauld’s learn to program web site.

Let us know how we can help.

Bill


> On Apr 8, 2019, at 5:40 PM, Diana Katz  wrote:
> 
> Yes - data would need to be scraped from sec.gov  website. 
> I want to be able to pull up segment data from 10-Q filings of individual 
> companies by putting in a ticker (preferably in excel, but an be done 
> elsewhere).  Trying to figure out how to even start setting this up. 
> 
> Thank you!
> 
> On Sun, Apr 7, 2019 at 8:57 PM William Ray Wing  > wrote:
> 
> 
> > On Apr 5, 2019, at 8:01 PM, Diana Katz  > > wrote:
> > 
> > 1) Can you use python from excel? Or just export to excel?
> 
> Simple answer: no.  Python can read and write excel files through libraries:
> 
>  https://www.datacamp.com/community/tutorials/python-excel-tutorial 
>  
> 
> > 2) I am trying to see if there's a way using python to automate all of this
> > work that I need to do. I have to collect quarterly segment data for
> > hundreds of public companies and go back at least 12-16 quarters. We use an
> > aggregator like factset and they actually don't have this option available
> > in an automated way. So I'm trying to see if there's a way to build this.
> 
> We really need more information to be of any help.  Is the starting data 
> coming from a web site?
> Python scripts can interact with web sites, “scrape” data from them or read 
> data from files downloaded in response to the script's interaction with the 
> site. The python library Pandas (named by its originator in the financial 
> field where such data is referred to as “panel” data) is optimized for 
> manipulating spreadsheet-like tables of data (it includes a pivot operation).
> 
> > Basically, I get my data from sec.gov  and they have 
> > interactive data - they
> > even have the data in excel (though it's a messy file and hard to read). I
> > attached some of the steps and the data that i'd want to see.
> > Basically i'd want the excel to look like:
> > old to new quarters - going back 12 to 16 quarters (more if possible but
> > not if it will stop the project).
> > Columns: 3/31/2017, 6/30/2017, 9/30/17, 12/31/17, 3/313/2018...
> > Rows:
> > Sales for segment A
> > Sales for Segment b
> > Sales for SEgment C
> > …(for as many segments as they have)
> > 
> > Earnings for Segment A
> > .Earnings for Segment B
> > 
> > Depreciation for Segment A
> > Depreciation for Segment B
> > Depreciation for Segment C...
> > 
> > I included where I get the data in the attached document.
> 
> Since attachments can contain unknown contents, this list drops them.
> 
> Bill
> 
> > 
> > All the best,
> > 
> > Diana Katz
> > ___
> > Tutor maillist  -  tu...@python.org 
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor 
> > 
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Levenberg-Marquardt non-linear least-squares fitting in Python [follow-on]

2019-03-28 Thread William Ray Wing via Python-list
Below I’ve included the code I ran, reasonably (I think) commented.  Note the 
reference to the example.  The data actually came from a pandas data frame that 
was in turn filled from a 100 MB data file that included lots of other data not 
needed for this, which was a curve fit to a calibration run.

Bill

PS:  If you want, I can probably still find a couple of the plots of the raw 
data and fitted result.
-
import numpy as np, matplotlib.pyplot as plt
#
#  Inverted exponential that axymptotically approaches "a" as x gets large
#
def func2fit(x,a,b,c):
return a - b * np.exp(-c * x)

# Curve fitting below from: 
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html
  
from scipy.optimize import curve_fit
def fit(xdata, ydata, run_num):
ll = len(xdata)
#
#  The next four lines shift and scale the data so that the curve fit routine 
can
#  do its work without needing to use 8 or 16-byte precision. After fitting, we
#  will scale everything back.
#
ltemp = [ydata[i] - ydata[0] for i in range(ll)]
ytemp = [ltemp[i] * .001 for i in range(ll)]
ltemp = [xdata[i] - xdata[0] for i in range(ll)]
xtemp = [ltemp[i] * .001 for i in range(ll)]
#
#  popt is a list of the three optimized fittine parameters [a, b, c]
#  we are interested in the value of a.
#  cov is the 3 x 3 covariance matrix, the standard deviation (error) of the 
fit is
#  the square root of the diagonal.
#
popt,cov = curve_fit(func2fit, xtemp, ytemp)
#
#  Here is what the fitted line looks like for plotting
#
fitted = [popt[0] - popt[1] * np.exp(-popt[2] * xtemp[i]) for i in 
range(ll)]
#
#  And now plot the results to check the fit
#
fig1, ax1 = plt.subplots()
plt.title('Normalized Data ' + str(run_num))
color_dic = {0: "red", 1: "green", 2: "blue", 3: "red", 4: "green", 5: 
"blue"}
ax1.plot(xtemp, ytemp, marker = '.', linestyle  = 'none', color = 
color_dic[run_num])
ax1.plot(xtemp, fitted, linestyle = '-', color = color_dic[run_num])
plt.savefig('Normalized ' + str(run_num))
perr = np.sqrt(np.diag(cov))
return popt, cov, xdata[0], ydata[0], fitted, perr[0] 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Levenberg-Marquardt non-linear least-squares fitting in Python

2019-03-28 Thread William Ray Wing via Python-list


> On Mar 28, 2019, at 7:54 AM, Madhavan Bomidi  wrote:
> 
> Hi,
> 
> I have x and y variables data arrays. These two variables are assumed to be 
> related as y = A * exp(x/B). Now, I wanted to use Levenberg-Marquardt 
> non-linear least-squares fitting to find A and B for the best fit of the 
> data. Can anyone suggest me how I can proceed with the same. My intention is 
> to obtain A and B for best fit.
> 

Have you looked at the non-linear least-squares solutions in scicpy?
Specifically, a system I’ve had to solve several times in the past uses it and 
it works quite well.

from scipy.optimize import curve_fit

def func2fit(x,a,b,c):
return a - b * np.exp(-c * x)

Bill

> Look forward to your suggestions and sample code as an example.
> 
> Thanks and regards,
> Madhavan
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: the python name

2019-01-04 Thread William Ray Wing via Python-list

> On Jan 4, 2019, at 11:34 AM, Avi Gross  wrote:
> 
> 

[BYTE]

> As I joked in an earlier message, I remember using a version of FORTRAN 
> called WATFOR. Yes, there was a WATFIV. 
> 
> 

Yah - WATFOR was Waterloo FORTRAN, an interpreted FORTRAN that was used a lot 
in intro classes.  No matter what the student did (negative indexes in early 
FORTRAN would get you down into the OS), under WATFOR the mainframe (yup) 
wouldn’t crash.

Bill

PS:  I, for one will drop this now as it is getting further off topic.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: the python name

2019-01-04 Thread William Ray Wing via Python-list
On 3/01/19 2:03 PM, Avi Gross wrote:
> Challenge: Can we name any computer language whose name really would suggest 
> it was a computer language?
> I think the name is the least important aspect of a computer language.

I’d like to propose that classic FORTRAN (FORmulaTRANslator) came/comes close.

Bill
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating Win .exe file from *.py on Linux

2018-10-02 Thread William Ray Wing via Python-list


> On Oct 2, 2018, at 3:03 PM, John Doe  wrote:
> 
> Hello World
> 
> Is it possible to create on Linux win .exe file from *.py file?
> -- 
> https://mail.python.org/mailman/listinfo/python-list

As was pointed out here a day or so ago, the answer is yes, but it is a two 
step process.  First step is to use Cython to compile the python file to C 
source, then compile that to a binary executable.  The link given was:


https://medium.com/@xpl/protecting-python-sources-using-cython-dcd940bb188e 

Where the focus is keeping the python source away from prying eyes, but it 
generates exactly what you want.

Bill
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to change '\\' to '\'

2018-10-01 Thread William Ray Wing via Python-list


> On Oct 1, 2018, at 10:17 PM, Jach Fong  wrote:
> 
> Thanks for your info about how Windows supports the forward slash.
> 
> I don't quit sure what is the meaning of "top posting" in your mail.
> If its meaning (forgive me if I was wrong) is where the reply was put
> in mail, I have reason of standing on the opposite side.
> 

Yes, exactly correct 

> It was supposed that most discussant want to see the reply message
> instantly when they open the mail. They already know what is going on
> and no need to pass through all those previous message. "top posting"
> seems more reasonable to me:-)
> 

The problem is that it is comparatively rare for there to be a singleton Q and 
immediate A.  Even seemingly simple questions frequently trigger fairly long 
discussions, which assume familiarity with the earlier discussion. AND this 
list is pretty much the place of record for people researching python IFAQs 
(infrequently asked questions). So, six months from now a Google search that 
turns up a relevant thread will make sense only if it can be read as in-lined 
comments like this. 

> --Jach
> 
> mm0fmf at 2018/10/2 AM 05:05 wrote:
>>> On 01/10/2018 10:19, Jach Fong wrote:
>>> Hmmm...strange, I didn't see Rick's mail:-(
>>> 
>>> Sure the forward slash is better, not to cause this confusion.
>>> But I am curious, since when, I mean, since which version
>>> Windows start to accept forward slash?
>>> 
>> First, stop top posting.
>> Second, ISTR that all Windows NT versions and versions derived from the NT 
>> codebase support forward slash in pathnames given to functions. It may go 
>> back further, but anything derived from NT works.  I can't remember which 
>> Windows command shells support it, probably PowerShell does.
> 
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Matplotlib 3D limitations, please recommend alternative

2018-07-04 Thread William Ray Wing via Python-list

> On Jul 4, 2018, at 5:53 PM, John Ladasky  wrote:
> 
> I'm a regular Matplotlib user.  Normally, I graph functions.  I just 
> attempted to graph an icosahedral surface using the plot_trisurf() methods of 
> Matplotlib's Axes3D. I have discovered that Matplotlib is basically 
> hard-wired for graphing functions, and therefore will not work for 
> general-purpose 3D rendering.
> 
> If I have repeated X and Y values in my arrays, it doesn't matter that the Z 
> values might be different.  Matplotlib raises a ValueError, with the message 
> "x and y arrays must consist of at least 3 unique points."  If I break down 
> my polyhedron into individual triangles, I can get 16 of the 20 faces to 
> render, but not all of them.  Here's some minimal example code, which also 
> catches and prints the cause of the ValueError.
> 
> 

[big byte]


> # 
> 
> I explored Python OpenGL bindings about three years ago, and quickly got 
> bogged down.  Even with Python to assist, dealing with OpenGL was like trying 
> to program Java.  Of course, OpenGL can do EVERYTHING.  Far more than I need.
> 

The Python Open GL bindings have apparently changed fairly dramatically.  I’m 
no expert, I’m working my way through the on-line book here:

http://www.labri.fr/perso/nrougier/python-opengl/

But the author DOES lay things out in a nice step by step fashion - and with 
particular emphasis on scientific 3D plotting (which is what
I’m after).


> I would like to render polyhedra, preferably with uniformly colored faces (I 
> understand that color is a property that is associated with vertices in 
> OpenGL).  I would appreciate a simple interface.  The rendering doesn't have 
> to be especially fast or high quality.  The Matplotlib visualization is 
> acceptable, except of course for the missing faces.
> 
> There are many 3D graphics packages on PyPI.  Some appear to be quite 
> specialized.  I would appreciate your recommendations.  Thanks!
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list