book on modern Python

2019-07-25 Thread beliavsky--- via Python-list
I did some basic programming in Python 2 and now use Python 3. All I know about 
Python 3 is that print is a function requiring parentheses.

What is a good book on modern Python that covers topics such as type 
annotations? I know of

Fluent Python: Clear, Concise, and Effective Programming
by Luciano Ramalho (2015)

Introducing Python: Modern Computing in Simple Packages
by Bill Lubanovic (2014)

but wonder if the language has evolved significantly since they were published. 
I see that a 2nd edition of "Introducing Python" is due this year.
-- 
https://mail.python.org/mailman/listinfo/python-list


Python Humble Bundle from Packt

2019-01-01 Thread beliavsky--- via Python-list
For about the next two weeks, Humble Bundle 
https://www.humblebundle.com/books/python-packt-2019-books offers the following 
18 books and 7 videos on Python for $15.

BOOKS:

Python Interviews

OpenCV 3 Computer Vision with Python Cookbook

Mastering Flask Web Development

Python Automation Cookbook

Python Machine Learning By Example

Qt5 Python GUI Programming Cookbook.

Python Microservices Development

Hands-On Data Structures and Algorithms with Python

Python High Performance

Hands-On Software Engineering with Python

Django 2 by Example

Python Deep Learning Projects

Mastering Python Networking

Clean Code in Python

Modern Python Cookbook

Python 3 Object-Oriented Programming.

Raspberry Pi 3 Cookbook for Python Programmers

Django 2 Web Development Cookbook


VIDEOS:

Learn Python 3 from Scratch

Data Visualization with Python: The Complete Guide
 
REST APIs with Flask and Python
 
Data Analysis with Pandas and Python
 
Learn Python by Building a Blockchain and Cryptocurrency
 
Python for Finance: Investment Fundamentals and Data Analytics
 
Python For Offensive PenTest: A Complete Practical Course
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python library to break text into words

2018-05-31 Thread beliavsky--- via Python-list
On Thursday, May 31, 2018 at 5:31:48 PM UTC-4, Dietmar Schwertberger wrote:
> On 5/31/2018 10:26 PM, beliavsky--- via Python-list wrote:
> > Is there a Python library that uses intelligent guesses to break sequences 
> > of characters into words? The general strategy would be to break strings 
> > into the longest words possible. The library would need to "know" a sizable 
> > subset of words in English.
> 
> No need to re-invent the wheel:
> 
> import webbrowswer
> webbrowser.open( 
> "https://www.google.com/search?q=%s"%"atomicaccidents.pdf"+"+amazon";, new=0)
> 
> 
> Copy the title from the browser window and paste it into your script's 
> window which will read it with input() and rename the file.
> 
> Regards,
> 
> Dietmar

Thanks to both of you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Python library to break text into words

2018-05-31 Thread beliavsky--- via Python-list
I bought some e-books in a Humble Bundle. The file names are shown below. I 
would like to hyphenate words within the file names, so that the first three 
titles are

a_devils_chaplain.pdf
atomic_accidents.pdf
chaos_making_a_new_science.pdf

Is there a Python library that uses intelligent guesses to break sequences of 
characters into words? The general strategy would be to break strings into the 
longest words possible. The library would need to "know" a sizable subset of 
words in English.

adevilschaplain.pdf
atomicaccidents.pdf
chaos_makinganewscience.pdf
dinosaurswithoutbones.pdf
essaysinscience.pdf
genius_thelifeandscienceofrichardfeynman.pdf
louisagassiz_creatorofamericanscience.pdf
martiansummer.pdf
mind_aunifiedtheoryoflifeandintelligence.pdf
noturningback.pdf
onshakyground.pdf
scienceandphilosophy.pdf
sevenelementsthatchangedtheworld.pdf
strangeangel.pdf
theboywhoplayedwithfusion.pdf
thecanon.pdf
theedgeofphysics.pdf
thegenome.pdf
thegoldilocksenigma.pdf
thesphinxatdawn.pdf
unnaturalselection.pdf
water_thefateofourmostpreciousresource.pdf
x-15diary.pdf
-- 
https://mail.python.org/mailman/listinfo/python-list


Humble Book Bundle: Python by Packt

2018-01-01 Thread beliavsky--- via Python-list
One can purchase the following Python books and videos published by Packt for 
$15 at https://www.humblebundle.com/books/python-by-packt-book-bundle for about 
the next two weeks.

Python Data Analysis Cookbook
Mastering Python, Second Edition
Learning Robotics using Python
Python Programming with Raspberry Pi
Web Development with Django Cookbook
Expert Python Programming, Second Edition
Learning Python Web Penetration Testing (Video)
Python Data Science Essentials, Second Edition
Learning Concurrency in Python
Python Data Structures and Algorithms
Beginning Python (Video)
Building RESTful Python Web Services
Mastering Python Networking
Artificial Intelligence with Python
Deep Learning with Python (Video)
Python Machine Learning Projects (Video)
Python Machine Learning
Python Microservices Development
Python Design Patterns (Video)
Software Architecture with Python
Modern Python Cookbook
Python High Performance, Second Edition
Python GUI Programming Cookbook, Second Edition
Mastering Python (Video)
-- 
https://mail.python.org/mailman/listinfo/python-list


Refactoring tool to create Python functions

2017-05-08 Thread beliavsky--- via Python-list
Googling "refactoring python code to create functions" I came to
https://wingware.com/doc/intro/tutorial-refactoring where the "Extract 
Function/Method" does what I want. Is there a free Python tool that does this?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Intel Distribution for Python

2016-06-09 Thread beliavsky--- via Python-list
Intel has released Beta Update 1 of its Python distribution:

"What's New!
Jupyter* notebook interface
Neural network APIs support for pyDAAL
Optimized random number generation features for numpy.random package"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Intel Distribution for Python

2016-05-11 Thread beliavsky--- via Python-list
On Tuesday, May 10, 2016 at 11:17:33 PM UTC-4, Arshpreet Singh wrote:
> Thanks for the information, I just applied for program but I got one mail 
> about license and expiration. 
> 
> 
> This software license expires on October 29, 2016.
> 
> 
> I am not able to understand that can anyone put some light on that how 
> license can be expired?

I assume that the Intel python.exe executable will stop running on that date. 
When I had a trial license for the Intel Fortran compiler, ifort.exe stopped 
working after one month.
-- 
https://mail.python.org/mailman/listinfo/python-list


Intel Distribution for Python

2016-05-10 Thread beliavsky--- via Python-list
The Intel Distribution for Python 2017 Beta 
https://software.intel.com/en-us/python-distribution is available for Windows, 
Linux, and Mac OS for Python 2.7 and 3.5.

"The Beta product adds new Python packages like scikit-learn, mpi4py, numba, 
conda, tbb (Python interfaces to Intel® Threading Building Blocks) and pyDAAL 
(Python interfaces to Intel® Data Analytics Acceleration Library). The Beta 
also delivers performance improvements for NumPy/SciPy through linking with 
performance libraries like Intel® MKL, Intel® Message Passing Interface (Intel® 
MPI), Intel® TBB and Intel® DAAL."

I just installed Intel Python today. Has anyone tried it? Does it run your 
programs faster than the usual CPython?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python is an Equal Opportunity Programming Language

2016-05-08 Thread beliavsky--- via Python-list
On Saturday, May 7, 2016 at 4:02:32 AM UTC-4, Stephen Hansen wrote:
> On Fri, May 6, 2016, at 11:43 PM, Gregory Ewing wrote:
> > Steven D'Aprano wrote:
> > > Who is setting and enforcing this quota, and given that only about 1 in 20
> > > Python programmers is a woman, do you think men are seriously missing out
> > > on any opportunities?
> > 
> > Suppose there are 100 people wanting to ask questions, and
> > there is only time to answer 10 questions. If the 1 in 20
> > ratio holds, then 5 of those people are women and the other
> > 95 are men.
> > 
> > Alternating between men and women means that all of the
> > women get their questions answered, and only 5/95 of the
> > men. So in this example, if you're a woman you have a 100%
> > chance of getting answered, and if you're a man you only
> > have a 5.26% chance.
> > 
> > Whether you think this is a good strategy or not,
> > beliavsky is right that it's not "equal".
> 
> This is a pedantically and nonsensical definition of "equal", that
> ignores the many, many reasons why there are 1 in 20 women in that
> conference. Its looking at the end effect and ignoring everything that
> leads up to it, and deciding its instead special rights -- this is the
> great argument against minorities getting a voice, that their requests
> for equal *opportunity* are instead *special rights* that diminish the
> established majority's entrenched power. 
> 
> Those women are dealing with suppression, discrimination and dismissal
> on multiple levels that leave them in a disenfranchised position. 

The sex disparity in Python and in tech in general could be due in part to 
discrimination, but it could also be due to different male and female interests 
and (gasp) aptitudes on average. Are Asian-Americans over-represented in tech 
because whites have been suppressed? There are far more female than male 
teachers. I don't attribute it to anti-male suppression but to greater female 
interest in working with children.

In our public middle school (grades 6-8, ages 11-13) there is a programming 
club that is open to girls. My son is shut out because of his sex. That is just 
as wrong as excluding him because of his skin color. I oppose such 
discrimination.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python is an Equal Opportunity Programming Language

2016-05-06 Thread beliavsky--- via Python-list
On Friday, May 6, 2016 at 5:07:28 PM UTC-4, Ethan Furman wrote:
> On 05/06/2016 01:35 PM, beliavsky--- via Python-list wrote:
> 
> > Most of [Guido's] keynote at that conference was answering questions from
>  > the people who had attended. And he actually said, "Let's alternate 
> between
>  > men and women asking questions."On the second day of the conference, 
> he was
>  > wearing a shirt from PyLadies, another nonprofit like Django Girls 
> that helps
>  > women learn how to program on Python.
> >
> > *
> >
> > This not "equal opportunity". It is a quota system.
> 
> It's a corrective action, a way of getting men accustomed to listening 
> to women and hearing good ideas and questions from them, and a way to 
> accustom women to speaking in (currently) male dominated groups.

It's silly to say that just because a group is over-represented that it 
"dominates". If a conference has more Asians than whites does that necessarily 
make it Asian-dominated?
 
> And it is far more equal opportunity than having 25 males ask questions 
> and only one or two females.

Not if there are 25 males with questions and only one or two females with 
questions. Among the people who have questions, you could choose randomly. You 
and Terry Reedy misuse the term "equal opportunity".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python is an Equal Opportunity Programming Language

2016-05-06 Thread beliavsky--- via Python-list
On Thursday, May 5, 2016 at 3:00:01 PM UTC-4, Terry Reedy wrote:
> https://motherboard.vice.com/blog/python-is-an-equal-opportunity-programming-language
> 
> from an 'Intel(R) Software Evangelist'
> -- 
> Terry Jan Reedy

>From the link:

MB: What is it about Python that makes it friendly to women? Is it something 
about the actual language itself? Or is it more of a subcultural thing within 
the community?

DS: One thing that I think causes this is the founder of the Python project, a 
guy named Guido van Rossum. He's referred to as the "BDFL"--the Benevolent 
Dictator for Life. The way to think of him is like Linus Torvalds of Linux.

Most of his keynote at that conference was answering questions from the people 
who had attended. And he actually said, "Let's alternate between men and women 
asking questions."On the second day of the conference, he was wearing a shirt 
from PyLadies, another nonprofit like Django Girls that helps women learn how 
to program on Python.

*

This not "equal opportunity". It is a quota system. It's my 
impression that in the U.S., Asians are over-represented among programmers
relative to their share of the population and that whites and especially blacks 
are under-represented. Should we impose racial quotas on questions
at conferences and call that "equal opportunity" as well?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: repeat items in a list

2016-03-26 Thread beliavsky--- via Python-list
On Saturday, March 26, 2016 at 7:30:14 PM UTC-4, Mark Lawrence wrote:
> On 26/03/2016 22:12, beliavsky--- via Python-list wrote:
> > I can create a list that has repeated elements of another list as follows:
> >
> > xx = ["a","b"]
> > nrep = 3
> > print xx
> > yy = []
> > for aa in xx:
> >  for i in range(nrep):
> >  yy.append(aa)
> > print yy
> >
> > output:
> > ['a', 'b']
> > ['a', 'a', 'a', 'b', 'b', 'b']
> >
> > Is there a one-liner to create a list with repeated elements?
> >
> 
> yy = [aa for aa in xx for _ in range(nrep)]
> 
> I suggest that you try this sort of the thing at an interactive prompt, 
> it's a great way to learn.
> 
> You might also want to take a look at the itertools module 
> https://docs.python.org/3/library/itertools.html.  This is often used in 
> building structures like the ones you've been asking about today.  To me 
> it is the Swiss Army Knife of the stdlib.

Thanks for the one-liner, which I prefer to the one I made up using itertools:

yy = list(chain.from_iterable([list(repeat(aa,nrep)) for aa in xx]))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: repeat items in a list

2016-03-26 Thread beliavsky--- via Python-list
On Saturday, March 26, 2016 at 7:24:10 PM UTC-4, Erik wrote:
> Hi,
> 
> On 26/03/16 22:12, beliavsky--- via Python-list wrote:
> > I can create a list that has repeated elements of another list as follows:
> >
> > xx = ["a","b"]
> > nrep = 3
> > print xx
> > yy = []
> > for aa in xx:
> >  for i in range(nrep):
> >  yy.append(aa)
> > print yy
> >
> > output:
> > ['a', 'b']
> > ['a', 'a', 'a', 'b', 'b', 'b']
> >
> > Is there a one-liner to create a list with repeated elements?
> 
> yy = reduce(lambda a, b: a + b, ([i] * nrep for i in xx), [])
> 
> Or, if you want to "import operator" first, you can use 'operator.add' 
> instead of the lambda (but you _did_ ask for a one-liner ;)).
> 
> Out of interest, why the fascination with one-liners?

Thanks for your reply. Sometimes when I program in Python I think I am not 
using the full capabilities of the language, so I want to know if there are
more concise ways of doing things.
-- 
https://mail.python.org/mailman/listinfo/python-list


repeat items in a list

2016-03-26 Thread beliavsky--- via Python-list
I can create a list that has repeated elements of another list as follows:

xx = ["a","b"]
nrep = 3
print xx
yy = []
for aa in xx:
for i in range(nrep):
yy.append(aa)
print yy

output:
['a', 'b']
['a', 'a', 'a', 'b', 'b', 'b']

Is there a one-liner to create a list with repeated elements?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Exclude every nth element from list?

2016-03-26 Thread beliavsky--- via Python-list
On Saturday, March 26, 2016 at 1:02:06 PM UTC-4, Gary Herron wrote:
> On 03/26/2016 09:49 AM, beliavsky--- via Python-list wrote:
> > I can use x[::n] to select every nth element of a list. Is there a 
> > one-liner to get a list that excludes every nth element?
> 
> Yes:
> 
>  >>> L=list(range(20))
>  >>> [x   for i,x in enumerate(L)   if i%3 != 0]
> [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19]
> 
> 
> Gary Herron
> 
> 
> -- 
> Dr. Gary Herron
> Department of Computer Science
> DigiPen Institute of Technology
> (425) 895-4418

Thanks to you and others who replied. I see that enumerate is a useful function.
-- 
https://mail.python.org/mailman/listinfo/python-list


Exclude every nth element from list?

2016-03-26 Thread beliavsky--- via Python-list
I can use x[::n] to select every nth element of a list. Is there a one-liner to 
get a list that excludes every nth element? 
-- 
https://mail.python.org/mailman/listinfo/python-list


discussion group for Python in finance?

2016-03-18 Thread beliavsky--- via Python-list
Is there an active online group discussing the use of Python in finance?

Here are some resources for Python in finance I know of. Numpy, scipy, pandas, 
and matplotlib are useful packages discussed in the books "Python for Finance" 
by Hilpisch and "Python for Data Analysis" by McKinney. Quandl is a good 
packages for importing financial and economic data. Quantopian is a site that 
lets you backtest strategies coded in Python. IBpy is a package for trading at 
Interactive Brokers using Python. Quantstart has e-books and a blog about 
Python in finance. Robert Carver wrote a book "Systmatic Trading" that has 
Python code, and he has a blog "Investment Idiocy". Python is often discussed 
in the "programming and software" forum of wilmott.com .
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 2 vs Python 3 for teaching

2015-11-02 Thread beliavsky--- via Python-list
I think Python 2.x is still used more than Python 3.x in scientific computing. 
The Python books I have in this area, such as "Python for Finance: Analyze Big 
Financial Data" and "Python for Data Analysis", still use Python 2.x . An 
aspiring computational scientist, data scientist, or financial quant may still 
be better off learning Python 2.x but using print(x) rather than print x and 
doing other things to future-proof his code.
-- 
https://mail.python.org/mailman/listinfo/python-list


Planet Scipy blog

2015-10-08 Thread beliavsky--- via Python-list
There used to be a blog about SciPy at https://planet.scipy.org/ , discussing 
the applications of Python to scientific computing. Now there is a static page 
about "MPI for Python". What happened?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python speed

2015-08-07 Thread beliavsky--- via Python-list
On Friday, August 7, 2015 at 10:08:37 AM UTC-4, roge...@gmail.com wrote:
> Can anyone compare PyNum calculation speed to Fortran?
> 
> This is for a number crunching program working with large files.
> 
> Roger

Did you mean NumPy? It depends on the program. Here are two posts that compared 
speeds.

Comparing Python, NumPy, Matlab, Fortran, etc. (2009) 
https://modelingguru.nasa.gov/docs/DOC-1762

Optimizing Python in the Real World: NumPy, Numba, and the NUFFT (2015)
https://jakevdp.github.io/blog/2015/02/24/optimizing-python-with-numpy-and-numba/

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


Re: The EuroPython 2015 Keynotes

2015-07-10 Thread beliavsky--- via Python-list
On Friday, July 10, 2015 at 2:58:18 PM UTC-4, Chris Angelico wrote:
> On Fri, Jul 10, 2015 at 10:01 PM, beliavsky--- via Python-list
>  wrote:
> > On Friday, July 10, 2015 at 7:21:14 AM UTC-4, M.-A. Lemburg wrote:
> >> With Mandy Waite we have announced all keynotes for EuroPython 2015:
> >> 5 keynotes, 6 speakers, 4 women and 2 men.
> >
> > Your mentioning these numbers makes me wonder if the organizing committee 
> > is using gender preferences in its selection of keynote speakers. I hope 
> > not. It is better to choose the speakers who will give the most interesting 
> > talks and let the demographic chips fall where they may.
> >
> 
> I think that's more a matter of having the statistically-curious
> brain. In my father's family, there are 5 sons and 2 daughters - does
> that indicate gender preference in my reporting, or just an
> acknowledgement of a fact?

If 80% of Python programmers and potential speakers at a Python conference are 
male, the chance of 4 out 6 speakers being female is fairly low if gender is 
ignored. Some people think gender diversity in tech is so important that there 
should be gender preferences -- see for example this post by a Python blogger 
http://ilovesymposia.com/2015/04/03/calling-out-scipy-on-diversity/ . It is 
plausible that the organizers preferred female keynote speakers. Can the OP 
comment on this?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The EuroPython 2015 Keynotes

2015-07-10 Thread beliavsky--- via Python-list
On Friday, July 10, 2015 at 7:21:14 AM UTC-4, M.-A. Lemburg wrote:
> With Mandy Waite we have announced all keynotes for EuroPython 2015:
> 5 keynotes, 6 speakers, 4 women and 2 men.

Your mentioning these numbers makes me wonder if the organizing committee is 
using gender preferences in its selection of keynote speakers. I hope not. It 
is better to choose the speakers who will give the most interesting talks and 
let the demographic chips fall where they may.
-- 
https://mail.python.org/mailman/listinfo/python-list


Python programming classes for children

2015-07-01 Thread beliavsky--- via Python-list
My 11yo son is taking the online class "Intermediate Programming with Python" 
http://www.artofproblemsolving.com/school/course/catalog/python2 offered by the 
Art of Problem Solving company (AoPS). Classes meet for 1.5 hours a week for 12 
weeks. During the classes the instructor "lectures" (types into a console -- 
there is no sound) and students type answers to questions. There are weekly 
programming assignments. AoPS is a U.S. company whose focus is preparing 
students for math competitions.

Are there other groups offering Python courses for pre-college students?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Instead of deciding between Python or Lisp for a programming intro course...What about an intro course that uses *BOTH*? Good idea?

2015-05-11 Thread beliavsky--- via Python-list
On Sunday, May 10, 2015 at 9:38:38 PM UTC-4, Ian wrote:
> On Sun, May 10, 2015 at 3:16 PM, Marko Rauhamaa  wrote:
> > Scheme is my favorite language. I think, however, it is a pretty
> > advanced language and requires a pretty solid basis in programming and
> > computer science.
> >
> > Python, in contrast, is a great introductory programming language. Sure,
> > you *can* get quite advanced with it, too, but you can get quite a bit
> > of fun stuff done with just the basics.
> 
> MIT famously used Scheme in their introductory course for more than
> two decades. Although they switched to Python a few years ago, I don't
> think they did so because there was anything wrong with Scheme.
> Wikipedia informs me that Yale and Grinnell are still using Scheme for
> their introductory courses.

Yale has taken the unusual step of outsourcing its introductory CS class to 
Harvard, which uses C as the main language in its CS50 class.

http://yaledailynews.com/blog/2014/11/07/faculty-approve-cs50-for-yale/
Faculty approve CS50 for Yale

"Just under a month after announcing that Yale's computer science department 
was considering importing Harvard's most popular course, faculty voted to bring 
CS50 to Yale.

Following what Yale College Dean Jonathan Holloway described as a "long, 
healthy discussion," faculty at Thursday's monthly meeting voted overwhelmingly 
to approve CS50 as a class to be taught at Yale. Computer science department 
chair Joan Feigenbaum said that the next step for CS50 will be for Harvard to 
approve the sharing of CS50 with Yale. If the course earns approval, she noted, 
Yale will formally introduce the class in Fall 2015."

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


Re: EuroPython 2015: Django Girls Workshop

2015-04-17 Thread beliavsky
On Friday, April 17, 2015 at 1:25:51 PM UTC-4, M.-A. Lemburg wrote:
> We are happy to announce that we will be hosting a Django Girls Workshop
> during the EuroPython 2015. It will take place on 20th of July, the
> first day of the conference.
> 
> We believe in the work that this group is doing to bring more women
> into technology, and we will work towards making EuroPython 2015
> enjoyable and welcoming for these beginner programmers.

If your target audience is women, I think you should have termed it the Django 
Womens Workshop rather than the Django Girls Workshop. Referring to adults as 
children can be seen as condescending.

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


Re: [OT] fortran lib which provide python like data type

2015-02-02 Thread beliavsky
On Friday, January 30, 2015 at 5:51:38 PM UTC-5, Gregory Ewing wrote:
> Michael Torrie wrote:
> > On 01/30/2015 10:31 AM, Rustom Mody wrote:
> > 
> >>And what about the grey area between lightweight and heavyweight?
> > 
> > That's what the smart pointers are for.
> 
> I'd say it's what higher-level languages are for. :-)
> 
> I'm completely convinced nowadays that there is
> *no* use case for C++. If you need to program the
> bare metal, use C. For anything more complicated,
> use a language that has proper memory-management
> abstractions built in.

Lots of people are using C++ to build packages for statistical programming 
language R, using the package Rcpp. It has been possible to build such packages 
for R and S using Fortran and C since the beginning, and many have done so, but 
the wide usage of Rcpp suggests that there are advantages to using C++. C++ is 
still the primary language used by financial derivatives quants.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] fortran lib which provide python like data type

2015-01-29 Thread beliavsky
On Thursday, January 29, 2015 at 10:01:00 AM UTC-5, Liu Zhenhai wrote:
> Hi,
> I am not sure here is the right place to ask this question, but I want to 
> give it a shot:)
> are there fortran libs providing python like data type, such as set, dict, 
> list?
> Thanks,
> Yours liuzhenhai

The "Fortran library" http://bigdft.org/Wiki/index.php?title=Fortran_library 
appears to have some of what you want. I have not tried the code.

"The flib library provides an object called dictionary which is -- strictly 
speaking -- more than just a dictionary. It is polymorphic and can be a list or 
a dictionary, as in the python language. The other difference is that it keeps 
the order of the elements, which is very useful if we want to dump its contents 
to the yaml output. It represents indeed a tree of data, and for these reasons 
it will most likely change name into f_tree in a future release of the module.

These dictionaries are also used in the other parts of the flib library and are 
thus essential for its proper use. There are many examples in the file 
dicts.f90."
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 is killing Python

2014-08-06 Thread beliavsky
On Wednesday, May 28, 2014 6:38:22 PM UTC-4, Ben Finney wrote:
> Larry Martell  writes:
> 
> 
> 
> > No company that I work for is using python 3 - they just have too much
> 
> > of an investment in a python 2 code base to switch.
> 
> 
> 
> There are many large companies still using FORTRAN and COBOL because of
> 
> a large investment in those languages, which are far more outdated than
> 
> Python 2. What's your point?

Fortran compiler vendors such as Intel, IBM, Oracle/SUN and open source 
projects such as gfortran are updating their compilers to the Fortran 2003 and 
2008 standards while also keeping the ability to compile all the old Fortran 
code. FORTRAN 77 programmers and programs will not be forced to move to modern 
Fortran, but I'm not sure that Python 2.x users can be as confident that Python 
2.x will be supported on future operating systems.
-- 
https://mail.python.org/mailman/listinfo/python-list


lists vs. NumPy arrays for sets of dates and strings

2014-06-09 Thread beliavsky
I am going to read a multivariate time series from a CSV file that looks like

Date,A,B
2014-01-01,10.0,20.0
2014-01-02,10.1,19.9
...

The numerical data I will store in a NumPy array, since they are more 
convenient to work with than lists of lists. What are the advantages and 
disadvantages of storing the symbols [A,B] and dates [2014-01-01,2014-01-02] as 
lists vs. NumPy arrays?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python(x,y) interferes with earlier Numpy installation

2014-02-13 Thread beliavsky
I fixed the problem by reinstalling Numpy.
-- 
https://mail.python.org/mailman/listinfo/python-list


Python(x,y) interferes with earlier Numpy installation

2014-02-13 Thread beliavsky
I am running Python 2.7.5 on Windows 7 and installed Numpy, which worked.
Then I installed Python(x,y) from a file Python(x,y)-2.7.5.2.exe, and now 
running
the script

from numpy import array, size, shape, min, max, sum
a = array([1, 2, 3])
print shape(a)

gives the error messages

Traceback (most recent call last):
  File "x.py", line 1, in 
from numpy import array, size, shape, min, max, sum
  File "c:\python27\lib\site-packages\numpy\__init__.py", line 153, in 
from . import add_newdocs
  File "c:\python27\lib\site-packages\numpy\add_newdocs.py", line 13, in 

from numpy.lib import add_newdoc
  File "c:\python27\lib\site-packages\numpy\lib\__init__.py", line 18, in 

from .polynomial import *
  File "c:\python27\lib\site-packages\numpy\lib\polynomial.py", line 19, in 

from numpy.linalg import eigvals, lstsq, inv
  File "c:\python27\lib\site-packages\numpy\linalg\__init__.py", line 50, in 

from .linalg import *
  File "c:\python27\lib\site-packages\numpy\linalg\linalg.py", line 29, in 

from numpy.linalg import lapack_lite, _umath_linalg
ImportError: DLL load failed: The specified path is invalid.

How can I get Numpy working again? Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.x adoption

2014-01-18 Thread beliavsky
On Friday, January 17, 2014 6:03:45 PM UTC-5, Terry Reedy wrote:
> On 1/17/2014 5:16 PM, beliav...@aol.com wrote:
 
>  > Python 2 and 3 are incompatible in ways that do not apply to Fortran 
> 
>  > standards pre- and post- F77.
> 
> 
> 
> As stated above, I disagree with respect to pre-F77 and F77. Did you 
> 
> actually program in both, as I did?
> 
> 
> 
> -- 
> 
> Terry Jan Reedy

I should have written "F77 and post F77". I have programmed in Fortran 77, 90, 
and 95.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.x adoption

2014-01-17 Thread beliavsky
On Tuesday, January 14, 2014 2:38:29 PM UTC-5, Skip Montanaro wrote:
> > What's the problem with Python 3.x? It was first released in 2008, but
> 
> > web hosting companies still seem to offer Python 2.x rather.
> 
> >
> 
> > For example, Google App Engine only offers Python 2.7.
> 
> >
> 
> > What's wrong?...
> 
> 
> 
> What makes you think anything's wrong? Major changes to any
> 
> established piece of software takes a fairly long while to infiltrate.
> 
> Lots of COBOL and Fortran 77 still running out there.

I don't think the Fortran analogy is valid.

The Fortran standards after F77 are almost complete supersets of F77, and 
Fortran compiler vendors handle even the deleted parts of F77, knowing their 
customer base. Therefore you do not need to rewrite old Fortran code to use it 
with Fortran 95 or 2003 compilers, and you can easily mix old-style and modern 
Fortran. Later Fortran standards did not invalidate basic syntax such as print 
statements, as Python 3 did. Python 2 and 3 are incompatible in ways that do 
not apply to Fortran standards pre- and post- F77.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Best Python book(s) for a pre-teen?

2013-08-01 Thread beliavsky
On Tuesday, February 18, 2003 2:27:58 PM UTC-5, Mike Silva wrote:
> Hi all,
> 
> My son is 11 and wants to try programming, partly because it's what I
> do for a living.  Even though I don't (yet?) use or even know Python,
> through some unexplainable thought process I've decided it would be a
> good language to start him off with.

The Art of Problem Solving site, geared toward the best U.S. junior high and 
high school math students, offers a 10-week "Introduction to Programming" class 
http://www.artofproblemsolving.com/School/classlist.php that uses Python. There 
are weekly lectures in an online classroom and graded homework assignments. My 
10yo boy is taking the class. But he tells me JavaScript is his favorite 
language :).

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


Why did Quora choose Python for its development?

2011-05-20 Thread Beliavsky
I thought this essay on why one startup chose Python was interesting.

http://www.quora.com/Why-did-Quora-choose-Python-for-its-development

PHP was out of the question. Facebook is stuck on that for legacy
reasons, not because it's the best choice right now.[1] Our main
takeaway from that experience is that programming language choice is
very important and is extremely costly to change.

Python was a language that Charlie and I both knew reasonably well
(though I know it a lot better now than I did when we started). We
also briefly considered C#, Java, and Scala. The biggest issues with
Python are speed and the lack of typechecking.

C# seemed pretty promising. As a programming language, it's great,
but:

•We didn't want to be on the Microsoft stack. We were up for learning
something new, and MS SQL Server actually seemed pretty good, but we
knew we'd need to integrate with lots of open source code that has
only second-class support for .NET, if it supports it at all. Also,
most of the best engineers these days are used to open source stuff.
•We didn't want to take the risk of being on Mono (an open source
implementation of C#/.NET). It's not clear how long funding will be
around for that project, and I'd heard of various performance
problems. Plus, it seemed like everything else in the C# ecosystem
would assume we were on the Microsoft stack.

For a lot of little reasons, Java programs end up being longer and
more painful to write than the equivalent Python programs. It's also
harder to interoperate with non-Java stuff. Scala had a lot of the
downsides of Java and the JVM, although it wasn't quite as bad. The
language seemed a little too new and like it would bring some
unnecessary risk (for example, who knows how good will support be in
10 years).

Two other languages we very briefly thought about were OCaml and
Haskell (neither had big enough ecosystems or good enough standard
libraries, and both were potentially too hard for some designers/data
analysts/non-engineers who might need to write code).

We decided that Python was fast enough for most of what we need to do
(since we push our performance-critical code to backend servers
written in C++ whenever possible). As far as typechecking, we ended up
writing very thorough unit tests which are worth writing anyway, and
achieve most of the same goals. We also had a lot of confidence that
Python would continue to evolve in a direction that would be good for
the life of our codebase, having watched it evolve over the last 5
years.

So far, we've been pretty happy with the choice. There's a small
selection bias, but all of the employees who'd been working with other
languages in the past have been happy to transition to Python,
especially those coming from PHP. Since starting the following things
have happened:


•Python 2.6 got to the point where enough of the libraries we used
were compatible with it, and we made a very easy transition to it.
•Tornado (web framework) was released as open source, and we moved our
live updating web service to that.
•PyPy got to the point where it looks like it will eventually be
usable and will give us a significant speedup.

All together, these give us confidence that the language and ecosystem
is moving in a good direction.

[1] What are the horrors of PHP? and Do Facebook engineers enjoy
programming in PHP? and Why hasn't Facebook migrated away from PHP?
and What are some of the advantages of PHP over other programming
languages? for more on that.
Via Nizameddin Haşim Ordulu and JR Ignacio.
-- 
http://mail.python.org/mailman/listinfo/python-list


XEmacs output from Python

2011-02-01 Thread Beliavsky
The script

name = raw_input("What is your name? ")
print "Hello, ",name

runs fine from the Windows prompt (cmd.exe), but when I run it in a
shell buffer under XEmacs, I only see the text "What is your name? "
AFTER I enter some text, so a run looks like this:

H:\python>python xinput.py
x
What is your name? Hello,  x

Is there a workaround? Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


scipy code runs in empty directory, not another

2010-11-13 Thread Beliavsky
After installing numpy, scipy, and matplotlib for python 2.6 and
running the code from http://www.scipy.org/Cookbook/OptimizationDemo1
(stored as xoptimize.py) in a directory with other python codes, I got
the error messages

C:\python\code\mycode>python xoptimize.py
Traceback (most recent call last):
  File "xoptimize.py", line 3, in 
from pylab import *
  File "c:\python26\lib\site-packages\pylab.py", line 1, in 
from matplotlib.pylab import *
  File "c:\python26\lib\site-packages\matplotlib\__init__.py", line
133, in 
import sys, os, tempfile
  File "c:\python26\lib\tempfile.py", line 34, in 
from random import Random as _Random
  File "C:\python\code\mycode\random.py", line 1, in 
from RandomArray import standard_normal
  File "C:\python\code\mycode\RandomArray.py", line 1, in 
import ranlib
ImportError: No module named ranlib

When I create a new directory, copy xoptimize.py there, and run, the
program works. Can someone explain why other files are "interfering"
in the first case? Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


processing email with Python on Windows?

2008-10-03 Thread Beliavsky
I work for a financial company where we run Windows XP and read email
using Microsoft Outlook 2003. I get daily files that come as email
attachments from various counterparties. I save them as h:\firm_name
\mmdd.csv . Would Python be a good tool to automate the process of
saving reports, or would it be more convenient to use a Microsoft
proprietary language such as VB or C#? Of course one factor is one's
relative competence with the various languages.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Books to begin learning Python

2008-08-07 Thread Beliavsky
On Aug 6, 4:08 pm, Mike Driscoll <[EMAIL PROTECTED]> wrote:
> On Aug 6, 2:56 pm, Edward Cormier <[EMAIL PROTECTED]> wrote:
>
> > Which computer books are the best to begin learning Python 2.5 with?
> > I've heard that Learning Python 3rd Edition is a good choice - can
> > anyone give any more advice on this?
>
> > Thanks.
>
> There's lots of good books to read, including a few online ones. A lot
> of people like "Dive Into Python" (http://diveintopython.org/). If you
> want LOTS of information and some good code examples, Lutz's
> "Programming Python 3rd Ed" is great.

I have the 2nd edition. Has the 3rd edition been rewritten so that all
of its code will be valid in Python 3? I'd prefer not to buy Python
books that will become obsolete.

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


Re: Python Book Recommendations

2007-08-15 Thread Beliavsky
On Aug 15, 10:47 am, "Shawn Milochik" <[EMAIL PROTECTED]> wrote:
> If I could have only one book, I would buy "Core Python, Second
> Edition," by Wesley Chun.

I have bought about half a dozen Python books but will purchase only
Python 3 books in the future, when they become available. I wonder
when that will be and if most of the current books will be revised to
conform to Python 3.

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


Re: Where do they tech Python officialy ?

2007-07-24 Thread Beliavsky
On Jul 23, 1:27 pm, [EMAIL PROTECTED] (Cameron Laird) wrote:

> Autodidacticism is an alternative; feel free to regard 
> http://wiki.python.org/moin/PythonTraining> as a member of
> that class.  
>
> If you, for example, were to teach yourself Python, then
> volunteer with prominent extensions or even the core (there's
> plenty to do in regard to documentation and testing), you'd
> soon have accumulated quite a bit of experience that enlightened
> employers recognize is as professional as any other.

I'd guess that it's a lot harder to create/extend Python than to use
it, so I suggest that the OP first focus on becoming good Python
programmers. An important aspect of a course in Python programming
would be instructor comments on one's code. I wonder if any trainers
do code reviews by email.



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


Re: Pass by reference or by value?

2007-07-16 Thread Beliavsky
On Jul 13, 11:58 pm, sturlamolden <[EMAIL PROTECTED]> wrote:



> In Fortran you can only pass references.
>
> integer(4) :: a
> a = 1
> call bar(a)
>
> subroutine bar(a)
> integer(4) :: a
> a = 0 ! side-effect
> end subroutine
>
> That means, when a variable is used to call a function, the function
> receives a pointer to the actual argument, not a local copy. That is
> very different from C's copy-passing behaviour.

In Fortran, if a procedure argument is modified within the procedure,
that change is propagated to the value of the argument in the caller.
The standard does NOT mandate how this is accomplished, and one could
in theory write a compiler that makes a local copy of all procedure
arguments, as long as the variables passed as arguments were updated
in the caller. Early implementations of Fortran 90 often made copies
of array arguments, hurting performance. Current compilers do this
less often.

It is common to pass constants and expressions to Fortran procedures,
which does not fit the pass-by-reference paradigm.

Fortran 2003 has the VALUE attribute to give the C pass-by-value
behavior when desired.

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


compressing consecutive spaces

2007-07-09 Thread Beliavsky
How can I replace multiple consecutive spaces in a file with a single
character (usually a space, but maybe a comma if converting to a CSV
file)? Ideally, the Python program would not compress consecutive
spaces inside single or double quotes. An inelegant method is to
repeatedly replace two consecutive spaces with one.

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


Re: Python compared to other language

2007-05-18 Thread Beliavsky
On May 18, 3:04 pm, scott <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I have been looking at the various programming languages available.  I
> have programed in Basic since I was a teenager and I also have a basic
> understanding of C, but I want something better.
>
> Can anybody tell me the benefits and weaknesses of using Python?

That question has been asked hundreds of times here -- read the
archives of this group and language comparisons on the web, for
example the one by Eric Raymond at 
http://www.faqs.org/docs/artu/languageschapter.html
.

Even better, try the language and draw your own conclusions.

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


Re: List Moderator

2007-05-18 Thread Beliavsky
On May 18, 9:22 am, [EMAIL PROTECTED] wrote:



> You're probably right, but this week has been pretty bad. Every few
> posts there's another porn or boob related link. Sheesh!
>
> Mike

I wish Google Groups were enhanced to let users block messages
according to

(1) "keywords"
(2) average ranking of the message on Google groups.
(3) sender name

There are Python experts who work at Google ...

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


Re: Python-URL! - weekly Python news and links (May 16)

2007-05-17 Thread Beliavsky
On May 16, 2:45 pm, "Cameron Laird" <[EMAIL PROTECTED]> wrote:
> QOTW:  "Sometimes you just have to take the path of least distaste". - Grant
> Edwards
>
> "I want to choose my words carefully here, so I'm not misunderstood.  



I think Cameron Laird does a good job with the Python digest but
blundered here. Why did he highlight a foul comment having nothing to
do with Python?

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


Re: Trying to choose between python and java

2007-05-15 Thread Beliavsky
On May 15, 1:30 am, Anthony Irwin <[EMAIL PROTECTED]> wrote:



> #5 someone said that they used to use python but stopped because the
> language changed or made stuff depreciated (I can fully remember
> which) and old code stopped working. Is code written today likely to
> still work in 5+ years or do they depreciate stuff and you have to update?

Because Python 3 will change the syntax of print to disallow

print "Hello, world."

a substantial fraction of Python programs in existence, including all
of my programs, will be broken. Draw your own conclusions.

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


Re: Single precision floating point calcs?

2007-05-10 Thread Beliavsky
Off-topic, but maybe as practical as "[making] your own Python build
from altered source." ---

Fortran 95 (and earlier versions) has single and double precision
floats. One could write a Fortran code with variables declared REAL,
and compilers will by default treat the REALs as single precision, but
most compilers have an option to promote single precision variables to
double. In Fortran 90+ one can specify the KIND of a REAL, so if
variables as

REAL (kind=rp) :: x,y,z

throughout the code with rp being a global parameter, and one can
switch from single to double by changing rp from 4 to 8. G95 is a
good, free compiler. F95 has most but not all of the array operations
of NumPy.

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


Re: Numbers and truth values

2007-04-29 Thread Beliavsky
On Apr 28, 4:05 pm, [EMAIL PROTECTED] (Alex Martelli) wrote:
> John Nagle <[EMAIL PROTECTED]> wrote:
>
> >  I'd have to consider that a bug.
>
> >  Some very early FORTRAN compilers allowed you to redefine
> > integer constants:
>
> >   CALL SET(25,99)
> >   WRITE (6,100) 25
> >  100 FORMAT(I6)
>
> >   SUBROUTINE SET(IVAR, INEWVAL)
> >   IVAR = INEWVAL
>
> > would print
>
> >  99
>
> >  It was generally agreed by 1970 or so that this was a bad idea,
> > and was taken out of the language.
>
> It was still perfectly legal in the Fortran 1977 standard for a compiler
> to cause this effect, because the Fortran source you quote has
> *undefined behavior* -- the compiler doesn't have to diagnose this error
> and can cause any effects as a consequence.
>
> The point of Fortran is to let the compiler generate the fastest code it
> can, NOT to "tenderly hold your hand" lest scary bugs disturb your
> blessed and dreamy innocence.

The point of Fortran has been to make scientific programmers more
productive, and catching errors and producing fast programs are BOTH
ways of doing that. Compilers are judged on BOTH criteria:
speed: http://www.polyhedron.com/pb05/linux/f90bench_p4.html
diagnostics: http://www.polyhedron.com/pb05/linux/diagnose.html

If there is a compiler with great compile- and run-time debugging
capability with the right options turned on, and if the compiler also
produces optimally fast code with another set of options (or if
another compiler does this), isn't that the best of both worlds?

> If this has changed in the Fortran 1990 standard or later, then I can
> only say I'm happy I stopped using Fortran heavily before such standards
> became widespread in commonly available compilers -- by the late '90s,
> when I was still using _some_Fortran, it was Fortran '77, as that was
> the version that was widely available and well optimized.

I don't think the official status of such has changed -- it's still
illegal to change a constant and the compiler is still not required to
catch the error -- but compilers may be more likely to reject
such code as before, helping programmers spot errors. IMO that's a
good thing.

When is no longer using a language, one has the luxury of thinking
about it in an ideological rather than practical manner.

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


Re: Portable SciPy v0.1 released

2007-04-27 Thread Beliavsky
On Apr 27, 6:17 pm, Stef Mientki <[EMAIL PROTECTED]>
wrote:
> Portable SciPy, is an easy installer of SciPy for M$ windows users.

If you have an announcement for Windows users, I suggest that you not
needlessly turn them off by abbreviating Microsoft as M$ . You don't
like Windows, but many of us Windows users don't like the anti-Windows
snobs. There is nothing wrong with making money by selling software.

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


Re: Generalized range

2007-04-27 Thread Beliavsky
On Apr 27, 1:32 am, [EMAIL PROTECTED] (Alex Martelli) wrote:
> Michael Hoffman <[EMAIL PROTECTED]> wrote:
> > [EMAIL PROTECTED] wrote:
> > > Thanks - you have covered a fair bit of gorund here - I will modify
> > > myRange taking your suggestions into account. The one suggestion that
> > > I'm going to have to think through is repeatedly incrementing res.
>
> > > I deliberately did not use this as repeated addition can cause
> > > rounding errors to accumulate, making the loop run a little longer or
> > > shorter than necessary. I thought I would be far less likely to run
> > > into rounding issues with a multiplicative construct - hence my use of
> > > epsilon, and my question about an appropriate value for it
>
> > You are right about rounding issues--with a sufficiently small step, the
> > way I have done it, it could become an infinite loop. But you can still
> > do it with multiplication, without using an epsilon constant. How about
> > something like this:
>
> > index = 0
> > while res < maximum:
> >  yield minimum + (step * index)
> >  index += 1
>
> Absolutely (with your later correction of actually assigning res), MUCH
> better than the misguided attempts based on repeatedly adding 'step'.
>
> I've taught "numerical computing" in university, and I would have had to
> fail anybody who'd misunderstood floating-point computations badly
> enough to try that "+=step" idea (including, sigh, the coders of several 
> Fortran compilers who were popular at that time).

You may be referring to the Fortran DO loop with a REAL loop variable,
for example

do x=1.5,3.5,0.5
   print*,x
end do

This was part of standard Fortran 77, so one should blame the
standards committee, not the compiler writers. Very few features of
F77 were deleted in Fortran 95, but this was one of them. In practice,
nothing gets deleted from commercial Fortran compilers.

At the SciPy site http://www.scipy.org/Cookbook/OptimizationAndFitDemo1
there is some code

   1 from enthought.chaco.wx import plt
   2 from scipy import arange, optimize, special
   3
   4 plt.figure()
   5 plt.hold()
   6 w = []
   7 z = []
   8 x = arange(0,10,.01)
   9
  10 for k in arange(1,5,.5):
  11y = special.jv(k,x)
  12plt.plot(x,y)
  13f = lambda x: -special.jv(k,x)
  14x_max = optimize.fminbound(f,0,6)
  15w.append(x_max)
  16z.append(special.jv(k,x_max))
  17
  18 plt.plot(w,z, 'ro')
  19 from scipy import interpolate
  20 t = interpolate.splrep(w, z, k=3)
  21 s_fit3 = interpolate.splev(x,t)
  22 plt.plot(x,s_fit3, 'g-')
  23 t5 = interpolate.splrep(w, z, k=5)
  24 s_fit5 = interpolate.splev(x,t5)
  25 plt.plot(x,s_fit5, 'y-')

I think the use of arange with a non-integer increment is poor style,
for reasons discussed in this thread.

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


Re: Python Feature Request: Explicit variable declarations

2007-04-20 Thread Beliavsky
On Apr 14, 6:21 am, [EMAIL PROTECTED] wrote:
> Hello. Please tell me whether this feature request is sane (and not
> done before) for python so it can be posted to the python-dev mailing
> list. I should say first that I am not a professional programmer with
> too much technical knowledge.
>
> I would like to have something like the "option explicit" statement in
> Visual Basic which turns on C-like checking for declaration of
> variables.

The thoughts of the inventor of Python on "Adding Optional Static
Typing to Python" are at http://www.artima.com/weblogs/viewpost.jsp?thread=86641
. I wonder if the idea will be implemented in Python 3.0.

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


Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-15 Thread Beliavsky
On Apr 14, 10:12 pm, "Paddy" <[EMAIL PROTECTED]> wrote:



> So the running count is:
>   Ayes to the left:   VB compatibility.
>   Nays to the right:  QuadIO, Perl, Dijkstra paper.
>
> The nays have it!

One-based indexing would also Python more compatible with Fortran,
Matlab/Octave/Scilab, and S (the language of S-Plus and R). It appears
that engineers, scientists, and statisticians, as opposed to
professional programmers, like 1-based indexing. An obvious argument
for 1-based indexing in the FORmula TRANslation programming language
is that formulas involving arrays in textbooks almost always use 1-
based indexing.

Since Python has always had 0-based indexing and since a user-defined
base can cause problems, as has been discussed, I think Python and
extensions such as NumPy should be left as is.

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


Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-15 Thread Beliavsky
On Apr 14, 10:55 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:



> The FORTRAN family had started as 1-based (F95, and Ada, now allow
> for each array to have its own "base" => x : array (-10..10) of float).

Fortran has allowed a user-specified base since at least the 1977
standard -- see for example 
http://www.umiacs.umd.edu/~jhu/DOCS/SP/docs/essl/essl159.html
.

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


Re: Fortran vs Python - Newbie Question

2007-03-27 Thread Beliavsky
On Mar 27, 6:32 am, [EMAIL PROTECTED] (Cameron Laird) wrote:
> In article <[EMAIL PROTECTED]>,Beliavsky <[EMAIL PROTECTED]> wrote:
>
> .
> .
> .
>
>
>
> >Your experience with Fortran is dated -- see below.
>
> >> I'll be more clear:  Fortran itself is a distinguished
> >> language with many meritorious implementations.  It can be
> >> costly, though, finding the implementation you want/need
> >> for any specific environment.
>
> >Gfortran, which supports Fortran 95 and a little of Fortran 2003, is
> >part of GCC and is thus widely available. Binaries for g95, also based
> >on GCC, are available for more than a dozen platforms, including
> >Windows, Mac OS X, and Linux. I use both and consider only g95 mature,
> >but gfortran does produce faster programs. Intel's Fortran compilers
> >cost about $500 on Windows and Mac OS and $700 on Linux. It's not
> >free, but I would not call it costly for professional developers.
>
> >Speaking of money, gfortran and g95 have free manuals, the latter
> >available in six languages
> >http://ftp.g95.org/. Final drafts of Fortran standards, identical to
> >the official ISO standards, are freely available. The manual for Numpy
> >costs $40 per copy.
>
> My experience with Fortran is indeed dated.  However,
> I still work with university groups that balk at $500
> for valuable software--sometimes because of admini-
> strative conflicts with licensing (example:  the group
> needs an educational license that fits its team
> perfectly, but educational license have to be approved
> by a campus-wide office that involves the group in
> expenses uncovered by its grants, and ... complications
> ensue).  Intel's compiler, for example, is a great deal,
> and recognized as a trivial expense sometimes--but
> judged utterly impossible by a research group down a
> different corridor.
>
> My summary:  practical success depends on specific
> details, and specific details in the Fortran and Python
> worlds differ.
>
> Also, Beliavsky, thanks for your report on the pertinent
> Fortran compilers.  There *are* other proprietary Fortan
> compilers extant; do you expect them to fade away,
> leaving only g* and Intel, or are you simply remarking
> on those two as the (intellectual) market leaders?

My point was that a few years ago an advantage of Python+Numeric or
Octave or R over Fortran is that the former let one work at a much
higher level, if one restricted oneself to using only free tools. The
creation of g95 and gfortran has changed that somewhat, and the
existence of commercial compilers is a plus, since they can surpass
the free compilers in performance (Intel), functionality (creating
Windows GUI programs entirely in Fortran, for example) or diagnosing
errors (NAG, Lahey/Fujitsu and Salford/Silverfrost). A research group
could purchase a single license of a commercial compiler to use in
nightly builds but use the free compilers for development.

Which commercial compilers will fade away? Decent free compilers will
hurt the market for mediocre commercial ones, which may explain the
demise of the compiler from NA Software. The Fortran 2003 standard
adds many new features to Fortran 95, thus making big demands on
vendors, and I have heard that Lahey and Salford will not be upgrading
their compilers to the new standard. The active vendors appear to be
Absoft, IBM, Intel, Pathscale, Portland, and Sun.

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Beliavsky
On Mar 26, 10:16 am, [EMAIL PROTECTED] (Cameron Laird) wrote:
> In article <[EMAIL PROTECTED]>,[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> >Is there a mac version??
> >Thanks
> >Chris
>
> Yes.
>
> Several, in fact--all available at no charge.  The Python
> world is different from what experience with Fortran might
> lead you to expect.

Your experience with Fortran is dated -- see below.

>
> I'll be more clear:  Fortran itself is a distinguished
> language with many meritorious implementations.  It can be
> costly, though, finding the implementation you want/need
> for any specific environment.

Gfortran, which supports Fortran 95 and a little of Fortran 2003, is
part of GCC and is thus widely available. Binaries for g95, also based
on GCC, are available for more than a dozen platforms, including
Windows, Mac OS X, and Linux. I use both and consider only g95 mature,
but gfortran does produce faster programs. Intel's Fortran compilers
cost about $500 on Windows and Mac OS and $700 on Linux. It's not
free, but I would not call it costly for professional developers.

Speaking of money, gfortran and g95 have free manuals, the latter
available in six languages
http://ftp.g95.org/ . Final drafts of Fortran standards, identical to
the official ISO standards, are freely available. The manual for Numpy
costs $40 per copy.

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Beliavsky
On Mar 26, 10:31 am, "Carl Banks" <[EMAIL PROTECTED]> wrote:



> > You can write programs in Python that do usefully complicated things,
> > and you can get them to work in a reasonable time. Fortran can't do
> > this, for anything more than the trivial. "Classic" Fortran tasks of
> > the past are now seen as trivial. OK, so they did it to a lot of data,
> > but they really didn't do anything very complex to it.
>
> You couldn't be more incorrect.  I have run some very old (pre-Fortran
> 77) programs that are very far from trivial.
>
> > You can also write Python that other people can read and maintain. You
> > can't do this in Fortran, without a truly insane amount of trouble.
>
> This is a lie.  I've seen some Fortran code that was hellspawned, and
> some that was clear as glass.  The latter came about without a "truly
> insane amount of trouble".

I quite agree with you. People have written big, mission-critical
programs to run nuclear reactors and design planes in Fortran 66 and
77, although I hoped that they ran static analysis programs such as
FTNCHEK to verify them. Fortran 90 and later versions has modules,
whose use allows the compiler to check types in procedure calls. I
used Fortran 77 in my physics PhD program and find that I am much more
productive in Fortran 95 now, making fewer errors not caught at
compile time. The operations on arrays and array sections in Fortran
90+
help one to write number-crunching code that is "clear as glass".

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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Beliavsky
On Mar 26, 9:06 am, stef <[EMAIL PROTECTED]> wrote:

> As said by others, "Portability, scalability & RAD" as an advantage of
> Python are probably far more important.

All of those claimed advantages can be debated, although they may
exist for some tasks.

(1) Portability. Fortran has been run on hundreds if not thousands of
platforms since 1957. People who value portability often want
assurance that their code will be supported by compilers/interpreters
produced in the future. Standard-conforming Fortran 95 code is
conforming Fortran 2003 code, and the standards committee has decided
not to remove features in future versions. Python 3 is still somewhat
up in the air, and it will NOT be backward compatible with Python 2.x,
although migration tools will be provided.

(2) Scalability. If talking about parallel computing, the widely used
OpenMP Application Program Interface (API) supports multi-platform
shared-memory parallel programming only in C/C++ and Fortran. In
general, high performance computing is done in C, C++, and Fortran.

(3) RAD. Scripting programs WILL be faster to write in Python, because
of duck typing, the many built-in data structures, and other features.
For larger programs, a Fortran (or C++ or Java) compiler will catch
some errors at compile time that are caught only at run time in
Python, perhaps after considerable time has elapsed. Furthermore, the
higher speed of Fortran may mean that the time between program runs is
1 minute vs. 10 minutes in the corresponding Python program. This can
speed the development cycle.


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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Beliavsky
On Mar 26, 8:42 am, Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:



> You can get the speed of fortran in Python by using libraries like
> Numeric without losing the readability of Python.

Numeric and Numpy will faster than raw Python for array operations,
but I don't think they will match well-written C or Fortran, because
compilers can better optimize code in those "less dynamic" languages.

Someone recently mentioned here ("Quantum term project code- for
interest and for help") an example where Numeric was 180 times faster
in Fortran 95 using gfortran, asking for advice on how to speed up the
Python code -- see
https://wiki.asu.edu/phy416/index.php/A_Simple_Bose-Einstein_Condensate_Simulation
. No one replied.


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


Re: Fortran vs Python - Newbie Question

2007-03-26 Thread Beliavsky
On Mar 26, 8:40 am, [EMAIL PROTECTED] wrote:
> On Mar 26, 8:20 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> > OK...
> > I've been told that Both Fortran and Python are easy to read, and are
> > quite useful in creating scientific apps for the number crunching, but
> > then Python is a tad slower than Fortran because of its a high level
> > language nature, so what are the advantages of using Python for
> > creating number crunching apps over Fortran??
> > Thanks
> > Chris
>
> While I have never personally dealt withFortran, I looked it up here:
>
> http://en.wikipedia.org/wiki/Fortran_code_examples
>
> The code examples speak for themselves. I recommend you look those
> over and then look over similar simple program written in Python.

Code written using the features of modern Fortran (90 or later),
including free source form, looks better than code written in Fortran
66 or 77. Except that Fortran uses keywords to terminate blocks rather
than indentation as in Python, properly indented Fortran does not look
much different from Python. Neither language requires curly braces or
semicolons to terminate blocks and lines.

It does not make sense to argue against programming in Fortran 95 now
because of limitations that were removed long ago.

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


check if files are the same on Windows

2007-03-19 Thread Beliavsky
A crude way to check if two files are the same on Windows is to look
at the output of the "fc" function of cmd.exe, for example

def files_same(f1,f2):
cmnd= "fc " + f1 + " " + f2
return ("no differences" in popen(cmnd).read())

This is needlessly slow, because one can stop comparing two files
after the first difference is detected. How should one check that
files are the same in Python? The files are plain text.

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


Re: Python stock market analysis tools?

2007-03-05 Thread Beliavsky
On Mar 5, 12:41 am, "Raymond Hettinger" <[EMAIL PROTECTED]> wrote:
> On Mar 4, 7:52 pm, "Mudcat" <[EMAIL PROTECTED]> wrote:
>
> > I have done a bit of searching and can't seem to find a stock market
> > tool written in Python that is active. Anybody know of any? I'm trying
> > not to re-create the wheel here.
>
> What kind of tool do you want?  Getting quotes is the easy part:
>
> import urllib
> symbols = 'ibm jpm msft nok'.split()
> quotes = urllib.urlopen( 'http://finance.yahoo.com/d/quotes.csv?s='+
>  '+'.join(symbols) + '&f=l1&e=.csv').read().split()
> print dict(zip(symbols, quotes))
>
> The hard part is raising capital and deciding what to buy, sell, or
> hold.

Yes, and a discussion of investment approaches would be off-topic.
Unfortunately, newsgroups such as misc.invest.stocks are dominated by
spam -- the moderated newsgroup misc.invest.financial-plan is better.

Some research says that "mean variance portfolio optimization" can
give good results. I discussed this in a message

http://groups.google.com/group/misc.invest.financial-plan/msg/3b9d13f3d399050c?dmode=source
Newsgroups: misc.invest.financial-plan
From: [EMAIL PROTECTED]
Date: Mon, 26 Feb 2007 12:47:25 -0600
Local: Mon, Feb 26 2007 1:47 pm
Subject: Re: Portfolio Optimization Software?

To implement this approach, a needed input is the covariance matrix of
returns, which requires historical stock prices, which one can obtain
using "Python quote grabber" http://www.openvest.org/Databases/ovpyq .

For expected returns -- hmmm. One of the papers I cited found that
assuming equal expected returns of all stocks can give reasonable
results.

Then one needs a "quadratic programming" solver, which appears to be
handled by the CVXOPT Python package.

If someone implements the approach in Python, I'd be happy to hear
about it.

There is a "backtest" package in R (open source stats package callable
from Python) http://cran.r-project.org/src/contrib/Descriptions/backtest.html
"for exploring portfolio-based hypotheses about financial instruments
(stocks, bonds, swaps, options, et cetera)."

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


Re: f2py and Fortran90 gfortran_filename error

2007-02-28 Thread Beliavsky
On Feb 28, 12:40 am, Robert Kern <[EMAIL PROTECTED]> wrote:
> Tyler wrote:
> > Hello All:
>
> > Since my last post I have attempted to use the f2py program which
> > comes with numpy.
>
> It's better to ask these questions on numpy-discussion, instead. There are 
> more
> f2py users per capita there.
>
>  http://www.scipy.org/Mailing_Lists

I wish the Google Groups interface to the list 
http://groups.google.com/group/Numpy-discussion
worked. When I use it to post my messages bounce, but messages from
the list do show up on Google Groups. The "bounces" say

"This mailing list is now defunct. Please use
numpy-discussion@scipy.org to discuss NumPy, Numeric, and numarray.

http://projects.scipy.org/mailman/listinfo/numpy-discussion";

Yes, I know I could follow these instructions, but I prefer to use
Google Groups.

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


Re: Pep 3105: the end of print?

2007-02-20 Thread Beliavsky
On Feb 16, 10:17 am, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Fri, 16 Feb 2007 09:49:03 -0500, Jean-Paul Calderone wrote:
> > On Sat, 17 Feb 2007 01:32:21 +1100, Steven D'Aprano
> >> [snip]
>
> >>I don't think that follows at all. print is only a problem if you expect
> >>your code to work under both Python 2.x and 3.x. I wouldn't imagine
> >>that many people are going to expect that: I know I don't.
>
> > I think some people are confused that the language "Python 3.x" has "Python"
> > in its name, since there is already a language with "Python" in its name,
> > with which it is not compatible.
>
> There is no language "Python 3" -- yet. We're still all guessing just
> how compatible it will be with Python 2.
>
> To be precise, there is an experimental Python 3, but the specifications
> of the language are not fixed yet.
>
> As for the name... big deal. C and C++ and Objective C are completely
> different languages.Fortran 77 and Fortran 90 aren't exactly the same;
> nobody expects the same code to run unmodified on Forth 77 and FigForth,
> or any of another three dozen varieties of Forth.

The attitudes towards backwards compatibility of the Fortran standards
committee and the Python BDFL is very different.

Fortran 90 was a superset of Fortran 77, so standard-conforming
Fortran 77 programs have the same meaning when compiled with an F90
compiler. The committee does not consider changing things like the
meaning of 1/2. Even though WRITE provides a superset of the
functionality of PRINT, the committee would not dream of breaking so
much code by removing PRINT. No feature is deleted without being
declared obsolescent in a previous standard, which makes it easier to
plan ahead. In practice Fortran 95 compilers accept deleted features,
but they are required to a have a switch that identifies non-standard
code.

I think the C and C++ committees also take backwards compatibility
seriously, in part because they know
that working programmers will ignore them if they break too much old
code.

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


Re: Reading Fortran Data

2007-01-21 Thread Beliavsky

Carl Banks wrote:



> > A Fortran
> > list-directed write can print results in an almost arbitrary format,
> > depending on the compiler. Many compilers will separate integers by
> > several spaces, not just one, and they could use commas instead of
> > spaces if they wanted.
>
> 1. Hardly any compiler will produce a line of two integers, or reals,
> that another compiler couldn't read back.

Yes, but for more than three numbers, the statement is wrong. Intel
Fortran prints four double precision random n
as

  0.555891433847495   0.591161642339424   0.888434673900224

  0.487293557925127

but g95 prints them on a single line. I advise against using
list-directed Fortran writes to create files that other programs will
read, and I think most experienced Fortran programmers would agree.

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


Re: Reading Fortran Data

2007-01-21 Thread Beliavsky

Carl Banks wrote:



> >   WRITE(90,*) nfault,npoint
>
> Fortran writes this as two arbitrary integers separated by a space.

I wrote a paragraph in my reply explaining why this is wrong. A Fortran
list-directed write can print results in an almost arbitrary format,
depending on the compiler. Many compilers will separate integers by
several spaces, not just one, and they could use commas instead of
spaces if they wanted. The number of items printed before a new line is
started is also compiler-dependent. For more control, one uses a
formatted write, for example

write (90,"(2(1x,i0))") nfault,npoint



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


Re: Reading Fortran Data

2007-01-21 Thread Beliavsky
Tyler wrote:
> Hello All:
>
> After trying to find an open source alternative to Matlab (or IDL), I
> am currently getting acquainted with Python and, in particular SciPy,
> NumPy, and Matplotlib. While I await the delivery of Travis Oliphant's
> NumPy manual, I have a quick question (hopefully) regarding how to read
> in Fortran written data.
>
> The data files are not binary, but ASCII text files with no formatting
> and mixed data types (strings, integers, floats). For example, I have
> the following write statements in my Fortran code:

In plain Python, you can read each line in to a string, break the
string into "words" using split, and then convert the words into
variables of the desired types. If you are new to Python, this is an
important idiom to learn. I don't know if NumPy has  facilities to do
this more easily.

> I write the files as such:
>   WRITE(90,'(A30)') fgeo_name
>   WRITE(90,'(A30)') fmed_name

Let me comment on the Fortran code. For the following lines using
list-directed output, the compiler has considerable freedom in how it
writes the output. I guess you expect the integers nfault and npoint to
be written on one line and the vectors xpt and ypt to each be written
on separate lines. The compiler could print each number on a separate
line and be standard-conforming. This does not matter if you are going
to use a Fortran list-directed read to read the file, but it will
matter if you are using other languages. I suggest that you use format
strings to get more control over the ouptput format before you think
about reading the output files in Python. Otherwise you will be trying
to hit a moving target.



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


Re: Dividing integers...Convert to float first?

2007-01-05 Thread Beliavsky

Thomas Ploch wrote:
> Jonathan Smith schrieb:
> > Thomas Ploch wrote:
> >> [EMAIL PROTECTED] schrieb:
> >>> I'm still pretty new to Python. I'm writing a function that accepts
> >>> thre integers as arguments. I need to divide the first integer by te
> >>> second integer, and get a float as a result. I don't want the caller of
> >>> the function to have to pass floats instead of integers. How do I
> >>> convert the arguments passed to the function into floats before I do
> >>> the division? Is this necessary, or is their a better way?
> >>>
> >>> Thanks,
> >>>
> >>> Scott Huey
> >>>
> >>
> >> Yes, it is necessary. If you divide two integers, the result will be an
> >> integer.
> >>
> >>  >>> 1/2
> >>  0
> >>
> >> You need the function float() -> float because a division between
> >> integers and floats will have floats as their results
> >>
> >>  >>> float(1)/2
> >>  0.5
> >
> >
>  from __future__ import division
>  1/2
> > 0.5
> >
> > -smithj
> >
>
> aahh, I have been tought so many things about python that are actually
> so old, that I am starting to feel embarrassed.
>
> That brings me to the point, that learning a language X at university
> always brings you to a point where you know (almost) everything, but in
> reality know nothing because course material is too old...

If you learned C or Fortran 10 years ago, the constructs you learned
still have the same meaning, even though new features have been added
in C99 or Fortran 95. Mr. van Rossum  appears to value backwards
compatibility less than the C or Fortran standards committees do,
although I am sure he is introducing incompatibilities only after
serious consideration. If the C or Fortran committees tried to change
the meaning of int/int, they would be shot.

If you want to be confident that your code will run, unchanged, 10
years from now on the hardware and OS that will then be common, Python
2.x is not the language to use, unfortunately. From what I have read,
Python 3 will break things more fundamental than int/int.

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


Re: Writing more efficient code

2007-01-01 Thread Beliavsky
If in the newsgroup comp.lang.x somone asks how to do y, and you
suggest using language z, without answering their question, which was
how to do it in x, you will likely just annoy people and perhaps make
it even less likely that they will try z.

I have my own favorite language z and have not always heeded the above
advice, but I think the principle is still correct.

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


Re: Wow, Python much faster than MatLab

2006-12-29 Thread Beliavsky

Stef Mientki wrote:
> hi All,
>
> instead of questions,
> my first success story:
>
> I converted my first MatLab algorithm into Python (using SciPy),
> and it not only works perfectly,
> but also runs much faster:
>
> MatLab: 14 msec
> Python:  2 msec

For times this small, I wonder if timing comparisons are valid. I do
NOT think SciPy is in general an order of magnitude faster than Matlab
for the task typically performed with Matlab.

>
> After taking the first difficult steps into Python,
> all kind of small problems as you already know,
> it nows seems a piece of cake to convert from MatLab to Python.
> (the final programs of MatLab and Python can almost only be
> distinguished by the comment character ;-)
>
> Especially I like:
> - more relaxed behavior of exceeded the upper limit of a (1-dimensional)
>   array

Could you explain what this means? In general, I don't want a
programming language to be "relaxed" about exceeding array bounds.

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


Re: first and last index as in matlab

2006-12-17 Thread Beliavsky

Evan wrote:
> In matlab I can do the following:
>
> >> ind = [3,5,7,2,4,7,8,24]
> ind = 3 5 7 2 4 7 824
> >> ind(1)  ans = 3
> >> ind(end) ans =24
> >> ind([1 end])  ans =  324
>
> but I can't get the last line in python:
>
> In [690]: ind = [3,5,7,2,4,7,8,24]
> In [691]: ind[0]Out[691]: 3
> In [692]: ind[-1:]  Out[692]: [24]
> In [693]:  ??
>
> How do I pull out multiple indices as in matlab?

If you want functionality similar to Matlab in Python, you should use
Numpy, which has the "take" function to do what you want.

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


Re: automatically grading small programming assignments

2006-12-14 Thread Beliavsky
Brian Blais wrote:
> Hello,
>
> I have a couple of classes where I teach introductory programming using 
> Python.  What
> I would love to have is for the students to go through a lot of very small 
> programs,
> to learn the basic programming structure.  Things like, return the maximum in 
> a list,
> making lists with certain patterns, very simple string parsing, etc.  
> Unfortunately,
> it takes a lot of time to grade such things by hand, so I would like to 
> automate it
> as much as possible.
>
> I envision a number of possible solutions.  In one solution, I provide a 
> function
> template with a docstring, and they have to fill it in to past a doctest.  Is 
> there a
> good (and safe) way to do that online?  Something like having a student post 
> code,
> and the doctest returns.  I'd love to allow them to submit until they get it, 
> logging
> each attempt.

On a different matter, coding style, you could run something such as
Pylint on submitted codes and penalize them based on the number of
warnings emitted.
Maybe some adjustments would be necessary -- my experience with picky
compilers is that most but not ALL warnings indicate problems.

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


Re: About alternatives to Matlab

2006-12-11 Thread Beliavsky
I came across SAGE "Software for Algebra and Geometry Experimentation"
http://sage.math.washington.edu/sage/ , which includes Python and
Numeric and consists of

Group theory and combinatorics -- GAP
Symbolic computation and Calculus -- Maxima
Commutative algebra -- Singular
Number theory  -- PARI, MWRANK, NTL
Graphics -- Matplotlib
Numerical methods -- GSL and Numeric
Mainstream programming language -- Python
Interactive shell -- IPython
Graphical User Interface -- The SAGE Notebook
Versioned Source Tracking -- Mercurial HG

Maybe people who has tried this could give their impressions.

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


Re: Automatic debugging of copy by reference errors?

2006-12-11 Thread Beliavsky

Carl Banks wrote:
> Niels L Ellegaard wrote:
> > Marc 'BlackJack' Rintsch wrote:
> > > In <[EMAIL PROTECTED]>, Niels L
> > > Ellegaard wrote:
> > > > I have been using scipy for some time now, but in the beginning I made
> > > > a few mistakes with copying by reference.
> > > But "copying by reference" is the way Python works.  Python never copies
> > > objects unless you explicitly ask for it.  So what you want is a warning
> > > for *every* assignment.
> >
> > Maybe I am on the wrong track here, but just to clarify myself:
> >
> > I wanted  a each object to know whether or not it was being referred to
> > by a living object, and I wanted to warn the user whenever he tried to
> > change an object that was being refered to by a living object.
>
> This really wouldn't work, trust us.  Objects do not know who
> references them, and are not notified when bound to a symbol or added
> to a container.  However, I do think you're right about one thing: it
> would be nice to have a tool that can catch errors of this sort, even
> if it's imperfect (as it must be).
>
> ISTM the big catch for Fortran programmers is when a mutable container
> is referenced from multiple places; thus a change via one reference
> will confusingly show up via the other one.

As a Fortranner, I agree. Is there an explanation online of why Python
treats lists the way it does? I did not see this question in the Python
FAQs at http://www.python.org/doc/faq/ .

Here is a short Python code and a Fortran 95 equivalent.

a= [1]
c= a[:]
b= a
b[0] = 10
print a,b,c

output: [10] [10] [1]

program xalias
implicit none
integer, target  :: a(1)
integer:: c(1)
integer, pointer :: b(:)
a =  [1]
c =   a
b =>  a
b(1) = 10
print*,a,b,c
end program xalias

output: 10 10 1

It is possible to get similar behavior when assigning an array (list)
in Fortran as in Python, but one must explicitly use a pointer and "=>"
instead of "=". This works well IMO, causing fewer surprises, and I
have never heard Fortranners complain about it.

Another way of writing the Fortran code so that "a" and "b" occupy the
same memory is to use EQUIVALENCE.

program xequivalence
implicit none
integer :: a(1),b(1)
integer :: c(1)
equivalence (a,b)
a=  [1]
c=   a
b=   a
b(1) = 10
print*,a,b,c
end program xequivalence

output: 10 10 1

EQUIVALENCE is considered a "harmful" feature of early FORTRAN
http://www.ibiblio.org/pub/languages/fortran/ch1-5.html .

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


Re: feed-forward neural network for python

2006-12-07 Thread Beliavsky

mwojc wrote:
> Hi!
> I released feed-forward neural network for python (ffnet) project at
> sourceforge. Implementation is extremelly fast (code written mostly in
> fortran with thin python interface, scipy optimizers involved) and very
> easy to use.
> I'm announcing it here because you, folks, are potential users/testers.
>
> If anyone is interested please visit http://ffnet.sourceforge.net (and
> then post comments if any...)

Thanks for making available your code. The Fortran code compiles with
both g95 and gfortran. I looked at the code briefly, and it is
well-documented and clear, but I do wonder why you are writing new code
in Fortran 77. Using free source form instead of fixed source form
would make the code more readable, and using the array operations of
Fortran 90 would make it more concise. Gfortran is a Fortran 95
compiler and is part of gcc, so using Fortran 95 features should not
inhibit portability.

I think using the single letter "o" as a variable name is a bad idea --
it looks too much like "0".

I would like to see a Fortran driver (main program) for the code, so I
could see an example of its use independent from Python and f2py.

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


Re: len() and PEP 3000

2006-12-06 Thread Beliavsky
Thomas Guettler wrote:
> Hi,
>
> The function len() is not mentioned in the Python 3000 PEPs.
>
> I suggest that at least lists, tupples, sets, dictionaries and strings
> get a len() method. I think the len function can stay, removing it
> would break to much code. But adding the method, would bu usefull.
>
> Yes, I know, that I can call .__len__() but that is ugly.

I agree with you -- a.__len__() is ugly compared to len(a) . I am
surprised that such common idioms as len(a) may be going away. It is a
virtue of Python that it supports OOP without forcing OOP syntax upon
the user. How can one be confident that Python code one writes now has
a future?

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


Re: How do I print a numpy array?

2006-12-01 Thread Beliavsky

Robert Kern wrote:
> Grant Edwards wrote:
> > How do you print a numpy array?
> >
> > I tried the obvious print a, print `a`, and print str(a), but
> > none of them work on anything other than trivially small
> > arrays.  Most of my real data is elided and replaced with
> > ellipses.
>
> You might want to ask numpy questions on the numpy list:
>
>   http://www.scipy.org/Mailing_Lists
>
> Use numpy.set_printoptions(threshold=sys.maxint) to disable all summarization.

When I print an array in any language, I (and I think most programmers)
expect by default to have all elements displayed. Matlab, R, and
Fortran 95 have somewhat similar arrays to numpy, and that is what they
do. I don't remember Numeric summarizing arrays by default. R has a
"summary" function as well as a "print" function.

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


Re: Remarkable results with psyco and sieve of Eratosthenes

2006-11-29 Thread Beliavsky
Will McGugan wrote:
> Steve Bergman wrote:
> > Just wanted to report a delightful little surprise while experimenting
> > with psyco.
> > The program below performs astonoshingly well with psyco.
> >
> > It finds all the prime numbers < 10,000,000
>
> Actualy, it doesn't. You forgot 1 and 2.

The number 1 is not generally considered to be a prime number -- see
http://mathworld.wolfram.com/PrimeNumber.html .

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


Re: Quadratic Optimization Problem

2006-11-22 Thread Beliavsky
Stefan Behnel wrote:
> [EMAIL PROTECTED] wrote:
> > I need to do a quadratic optimization problem in python where the
> > constraints are quadratic and objective function is linear.
> >
> > What are the possible choices to do this.
>
> Too bad these homework assignments get trickier every time, isn't it?

I think this sarcasm is unjustified. It is not obvious to me that this
is a homework assignment.

The problem where constraints are linear and the objective function is
linear (quadratic) is known as linear (quadratic) programming, and
there are specialized codes for these problems. I don't know of
software in any language for the particular problem of a linear
objective function with quadratic constraints, so I would use a general
algorithm for nonlinearly constrained optimization. Maybe CVXOPT
http://www.ee.ucla.edu/~vandenbe/cvxopt/ will work for the OP -- I have
not tried it.

The site http://www.solver.com/probconic.htm calls the problem "conic
optimization".

A good newsgroup to ask about optimization algorithms is
sci.math.num-analysis.

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


Re: Finding skilled pythonistas for micro-jobs?

2006-11-18 Thread Beliavsky
I have gotten some Python tasks done at http://www.rentacoder.com.
Progammers are cheaper outside the U.S. and Western Europe, and you can
get a lot done for even $100.

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


Re: accessing fortran modules from python

2006-11-16 Thread Beliavsky

sam wrote:
> hello all,
>
> i am currently in the process of planning a piece of software to model
> polymerisation kinetics, and intend to use python for all the
> high-level stuff. the number-crunching is something i would prefer to
> do in fortran (which i have never used, but will learn), but i have no
> experience of accessing non-python code from python.

I strongly recommend learning Fortran 95, rather than Fortran 77

> i am also fairly new to programming period, and am therefore tackling a 
> fairly serious
> issue reletive to my experience.
>
> how easy is it to get fortran modules running from python?

G95 is a good, free Fortran 95 compiler -- I use it heavily, on
Windows. A discussion of "How to interface with Python programs" using
numpy is at http://www.g95.org/howto.html#python .

There is a numpy group http://groups.google.com/group/Numpy-discussion
with a recent thread "accessing FORTRAN from Python". There is also a
g95 group http://groups.google.com/group/gg95 .

> if c is easier to use in this respect, i could go in that direction instead.

easier to interface with Python, but not easier for writing numerical
code IMO, especially if you need multidimensional arrays.



> PS if numpy is adequate for this, i would be quite happy to use it. i
> got the impression it was more for matrix algebra. i will be
> programming a monte carlo simulation, which will need to perform a lot
> (a lot!) of simple operations over and over...

Fortran 95 has some of the advantages of numpy -- you perform
operations on whole arrays and array sections. It would probably be
considerably faster for code with loops.

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


Re: Programmatically finding "significant" data points

2006-11-14 Thread Beliavsky

erikcw wrote:
> Hi all,
>
> I have a collection of ordered numerical data in a list.

Called a "time series" in statistics.

> The numbers
> when plotted on a line chart make a low-high-low-high-high-low (random)
> pattern.  I need an algorithm to extract the "significant" high and low
> points from this data.
>
> Here is some sample data:
> data = [0.10, 0.50, 0.60, 0.40, 0.39, 0.50, 1.00, 0.80, 0.60, 1.20,
> 1.10, 1.30, 1.40, 1.50, 1.05, 1.20, 0.90, 0.70, 0.80, 0.40, 0.45, 0.35,
> 0.10]
>
> In this data, some of the significant points include:
> data[0]
> data[2]
> data[4]
> data[6]
> data[8]
> data[9]
> data[13]
> data[14]
> 
>
> How do I sort through this data and pull out these points of
> significance?

The best place to ask about an algorithm for this is not
comp.lang.python -- maybe sci.stat.math would be better. Once you have
an algorithm, coding it in Python should not be difficult. I'd suggest
using the NumPy array rather than the native Python list, which is not
designed for crunching numbers.

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


article on Python 2.5 features

2006-11-12 Thread Beliavsky
A Parade of New Features Debuts in Python 2.5
by Gigi Sayfan
"Python 2.5 still has the smell of fresh paint but it's the perfect
time to drill down on the most important new features in this
comprehensive release. Read on for detailed explanations and examples
of exception handling, resource management, conditional expressions,
and more."

The full article is at
http://www.devx.com/webdev/Article/33005/0/page/1 .

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


profanity on comp.lang.python (was Re: Pyro stability)

2006-11-08 Thread Beliavsky

Cliff Wells wrote:
> On Mon, 2006-11-06 at 18:20 -0800, Beliavsky wrote:
> > Carl J. Van Arsdall wrote:
> >
> > 
> >
> > > Pyro is fucking amazing and has been a great help to a couple of our 
> > > projects.
> >
> > You should watch your language in a forum with thousands of readers.
>
> The LA Times had a story that claimed that 64% of U.S. citizens use the
> word "fuck" and that 74% of us have heard it in public (I'll assume the
> remainder are your fellow AOL users).  I expect extrapolating these
> results worldwide wouldn't be far off the mark (the Brits were quite
> successful at spreading this versatile word).

If this is supposed to justify using bad language in a public forum, it
is poorly reasoned. Having heard "f***" does not mean they were not
annoyed. 100% of people have seen trash on the street, but that does
not justify littering. If a group of people don't mind profanity, there
is no harm in their swearing to each other. But Usenet is read by a
wide range of people, and needlessly offending some of them is wrong.
The OP used "f**" just for emphasis. English is a rich language,
and there are better ways of doing that.

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


Re: PSF Infrastructure has chosen Roundup as the issue tracker for Python development

2006-10-21 Thread beliavsky
BJörn Lindqvist wrote:
> On 10/20/06, Brett Cannon <[EMAIL PROTECTED]> wrote:
> > At the beginning of the month the PSF Infrastructure committee announced
> > that we had reached the decision that JIRA was our recommendation for the
> > next issue tracker for Python development.

I wonder if the committee has really decided on a PROBLEM or BUG
tracker, not an "issue" tracker. For some silly reason, "issue" has
become a euphemism for "problem" nowadays. It is worth keeping in mind
the difference. Questions about the future direction of Python, such as
(for example) whether there should be optional static typing, are
"issues". Python crashing for some reason would be a "problem".

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


Re: EXCITING OPPORTUNITY FOR EXPERIENCED APPLICATION DEVELOPERS (PYTHON)

2006-10-16 Thread beliavsky
If the company is so good, why does it hire recruiters like you?

It is rude to SHOUT your subject in all caps.

Your subject conveys nothing more than "Python job offered".

You should have mentioned in the subject that the job is in Hyderabad,
because even most readers of this group looking for jobs are probably
unwilling to relocate there, and thus they could skip the rest of the
message.

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


Re: OT: productivity and long computing delays

2006-09-27 Thread beliavsky
Paul Rubin wrote:
> I'm doing something where I frequently but unpredictably (i.e. I can't
> plan for it in advance) hit a snag that requires me to rebuild a large
> project.  The rebuild takes a couple hours.  During that time, I'm
> twiddling my thumbs and/or posting here, i.e. not getting anything
> useful done.  But the delay is not long enough that I can really
> switch to another project for a while.

Two hours is a long time! Maybe it takes a programmer 10 minutes to get
his mind focused on a new project, but that still leaves 110 productive
minutes. I think many programmers in corporate environments would
regard 2-hour blocks as luxuries. I have wondered the same thing as you
(how to be productive during "gaps"), but in situations where I am
often waiting a minute for a program to compile or run, not hours. I
suggest immersing yourself in the second project during 2-hour gaps.

>From reading your posts here I think you are a more experienced
programmer than I. I am a "quant" who programs, not a "programmer". But
those are my thoughts.

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


why a main() function?

2006-09-18 Thread beliavsky
I think I read a suggestion somewhere to wrap the code where a Python
script starts in a main() function, so one has

def main():
print "hi"

main()

instead of

print "hi"

What are the advantages of doing this?

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


How to make an announcement (was Re: ANN: GMPY binaries for Windows 2.5)

2006-09-01 Thread beliavsky
[EMAIL PROTECTED] wrote:
> GMPY binaries for Python 2.5 are available at
> http://home.comcast.net/~casevh/

"The General Multiprecision PYthon project (GMPY) focuses on
Python-usable modules providing multiprecision arithmetic functionality
to Python programmers."

A sign of Python's health is that there are so many open-source
projects that it is difficult to keep track of all of them. I think
announcements should contain at least one sentence describing what the
project is about. One can Google this, of course, but it saves the
reader time if this information is provided in the message.

>
> Notes
> 
> They have not been extensively tested.
>
> This is based on the CVS version of gmpy and includes a patch (not yet
> in CVS) from Alex Martelli that resolves a bug with divm(). Please
> consider this an "unofficial" release. The patch and the source code
> snapshot I used are also available on the website.
>
> GMP 4.2.1 is used.
>
> There are three versions available: one that should work on any
> processor, one compiled for Pentium 4 processor, and one compiled for
> AMD Athlon (32-bit).
>
> If there is demand, I'll create updated binaries for earlier version of
> Python.
> 
> Enjoy,
> 
> casevh

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


Re: where can i get older version of python?

2006-08-17 Thread beliavsky

[EMAIL PROTECTED] wrote:
> does any one know where can I get older version of python for windows?
>
> I am looking for versions between 2.0 and 2.2.

http://www.python.org/download/releases/

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


programming with Python 3000 in mind

2006-08-15 Thread beliavsky
At http://www-03.ibm.com/developerworks/blogs/page/davidmertz David
Mertz writes

"Presumably with 2.7 (and later 2.x versions), there will be a means of
warning developers of constructs that are likely to cause porting
issues [to Python 3000]. In the simplest case, this will include
deprecated functions and syntax constructs. But presumably the warnings
may cover "potential problems" like the above example."

The current beta version of Python is 2.5 . How can a Python programmer
minimize the number of changes that will be needed to run his code in
Python 3000? In general, he should know what is being removed from
Python 3000 and if possible use the "modern" analogs in Python. A
manager of Python programmers might want external evidence of
portability, though (such as an absence of interpreter warnings).

Some basic syntax such as

print "hello world"

is going away to make print look like a function. IMO, fixing what is
not broken because of the aesthetic tastes of the BDFL is a bad idea.
His reasoning is at
http://mail.python.org/pipermail/python-dev/2005-September/056154.html
.

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


Re: Python Projects Continuous Integration

2006-07-28 Thread beliavsky

Harry George wrote:
> "Dave Potts" <[EMAIL PROTECTED]> writes:
>
> > Hi,
> >
> > I'm just starting a development project in Python having spent time in
> > the Java world.  I was wondering what tool advice you could give me
> > about setting up a continuous integration environment for the python
> > code: get the latest source, run all the tests, package up, produce the
> > docs, tag the code repository.  I'm used to things like Maven and
> > CruiseControl in the Java world.
> >
> > Cheers,
> >
> > Dave.
> >
>
> First, sorry to hear you have had to use Java. You should recover
> after a few months in Python.  Second, welcome to Python.

If you are serious about welcoming someone to Python, don't start by
making snide comments about their primary computer language. There are
trade-offs between Python and language X, for almost all X's.

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


Re: Making a time series analysis package in python - advice or assistance sought

2006-07-07 Thread beliavsky
Ray Tomes wrote:
> Hi Folks
>
> I am an old codger who has much experience with computers
> in the distant past before all this object oriented stuff.
> Also I have loads of software in such languages as FORTRAN
> and BASIC, QBASIC etc that is very useful except that it
> really doesn't like to run on modern operating systems and
> has hopeless graphics resolution and lack of ease of use in
> some ways.

The Fortran code, which I assume is Fortran 77 or earlier, should run
fine on "modern operating systems" using free (g77, g95, or gfortran)
or commercial compilers.

> My desire is to get all the facilities available in my
> old programs working in a modern platform with flexible
> and high-res graphics and easy to use. Ideally I might
> find some good coders that are interested in the subject
> who would assist me, alternatively some help in getting
> started because there is so much info and so many resources
> and libraries etc that I don't know where to start.
>
> My package will have the following capabilities:
> 1. Able to read time series data in a variety of formats.
> 2. Able to create, manipulate and save time series files.
> 3. Able to do vector arithmetic on time series, including
> dozens of functions.

Fortran 90 and later versions have array operations, as does NumPy. You
could convert parts of the FORTRAN code to F90

> 4. Loop and macro facilities to simplify repetitive stuff.
> 5. Flexible high-resolution graphic presentation.
> 6. Built in functions to include:
> FFT / fourier analysis, MESA / maximum entropy spectral analysis,
> multiple regression, canonical correlation etc etc etc.
> I have code for all these mostly in FORTRAN, some QBASIC.
>
> The applications of the package include:
> 1. Analysis of time series data from many branches of science.
> 2. Economic / business models including forecasting.
> 3. Markets, stocks, commodities forecasting.
> 4. Interdisciplinary causal analysis.
> 5. Many more

There exist public domain codes for many of the topics you mention, and
I think several are part of NumPy. Many statistical algorithms are in
R, for which the underlying C and Fortran code is available. I suggest
that you identify which of your algorithms are not publicly available
and focus on those, making an R package of them. I am interested in
MESA. Then you can exploit the R graphics and language (called S) and
have your work easily accessible to many users.

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


source reduction using Python

2006-06-21 Thread beliavsky
Intel has introduced something called CESR, written in Python, to aid
C, C++, and Fortran programmers in reducing the sizes of programs
included in bug reports. Here is a brief description from
http://cache-www.intel.com/cd/00/00/21/93/219320_relnotes_10.pdf :

"Compiler Error Source Reducer (CESR) is a set of utilities which are
useful individually
or collectively in gathering, reducing, pinpointing, protecting,
documenting, and
bundling test cases comprised of C/C++ or Fortran source code. It can
be helpful if
you have a large application for which you want to extract a small test
case for
submission to Intel® Premier Support. CESR can be downloaded from
Intel® Premier
Support File Downloads - search for text CESR in the file description.
CESR is
unsupported and should be considered experimental, but we welcome your
feedback
on it through Intel® Premier Support. CESR requires prior installation
of Python 2.2 or
newer."

I think one needs to qualify for "Intel Premier Support" to get CESR. I
wonder if a similar open-source Python program exists.

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


Re: Econometrics in Panel data?

2006-05-10 Thread beliavsky
Cameron Laird wrote:
> In article <[EMAIL PROTECTED]>, I counseled:
> >In article <[EMAIL PROTECTED]>,
> >DeepBlue  <[EMAIL PROTECTED]> wrote:
> >>so are you saying that Python is not an appropriate language for doing
> >>econometrics stuff?
> >>
> >>
> >>Dennis Lee Bieber wrote:
> >>> On Tue, 09 May 2006 05:58:10 +0800, DeepBlue <[EMAIL PROTECTED]> 
> >>> declaimed the
> >>> following in comp.lang.python:
> >>>
>  Hi all,
> 
>  I am new to Python. Just wondering can Python able to do econometric
>  regression in either Time-series or pooled (panel) data? As well as test
>  for hetero, autocorrelation, or endogeneity?
>   .
>   .
>   .
> >There is not, however, a readily-accessible library targeted
> >for this sort of work.  If I had the opportunity to work in
> >econometrics now, I'd think seriously about R, Lisp, and
> >Mathematica, and see what's available among the functional
> >languages, along with Python.
>
> Smalltalk, too; I'd throw it in the mix.  Much serious econometrics
> has been done with Fortran, but I have no enthusiasm for pursuing
> that direction, mostly because I think too much of the computing
> world is going in a different one.

There are many statistics packages and programming languages used in
econometrics and in general, so most of the computing world is going in
a different
"direction", no matter which package or language you choose.

Enough programmers still use Fortran that major hardware vendors such
as Intel, IBM, and Sun are actively maintaining their Fortran 95
compilers and adding features from Fortran 2003. G95 is free, available
almost everywhere that gcc is, and good enough for production use IMO.

The recent book
http://methcenter.psu.edu/newbooks/fortranbook/thebook.html
Developing Statistical Software in Fortran 95
by David R. Lemmon and Joseph L. Schafer
Spriger (2005)

discusses how to build statistical software components in Fortran that
can be used in statistical packages.

The IMSL and NAG software libraries have extensive statistical
functionality and are available in Fortran, among other languages.

It is important for a programming language used for econometrics to
conveniently handle multidimensional arrays, and here Fortran outshines
C, C++, and Java (NumPy is good, though).

I am a quantitative financial analyst who implements econometrics
algorithms. Data sets are getting bigger -- use of intraday data is now
common -- and the CPU time for many algorithms scales as the N^2 or
N^3, where N is the number of observations. Speed still matters.

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


Re: Econometrics in Panel data?

2006-05-08 Thread beliavsky

DeepBlue wrote:
> Hi all,
>
> I am new to Python. Just wondering can Python able to do econometric
> regression in either Time-series or pooled (panel) data? As well as test
> for hetero, autocorrelation, or endogeneity?
> Thank you!

NumPy can do linear regression, and one can certainly program any
statistical algorithm in it. For the fairly advanced statistical
methods you are interested in, however, it may be easiest to call R
from Python using the methods described at
http://www.omegahat.org/RSPython/index.html .

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


connect file object to standard output?

2006-05-08 Thread beliavsky
I want to write a function that writes to an output file if specified
and otherwise to standard output. How can I connect a file object to
standard output in the code below? I could use an if statement to
choose between print and print>>fp throughout the function, but this
seems awkward. I think there is a way to connect standard output to a
file, but I'd prefer not to do that, since I want to use plain print
statements to warn about errors in the function and have their output
appear on the screen. Thanks.

def write_data(data,out_file=""):
if (out_file != ""):
fp = open(out_file,"w")
else
fp = # how to connect standard output to fp?
print>>fp,data
# more print>>fp statements follow

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


Re: search file for tabs

2006-05-02 Thread beliavsky

Fredrik Lundh wrote:
> [EMAIL PROTECTED] wrote:
>
> > The following code to search a file for tabs does not work, at least on
> > Windows XP. Could someone please tell me what's wrong? Thanks.
> >
> > xfile = "file_with_tabs.txt"
> > for text in open(xfile,"r"):
> > text = text.strip()
> > if ("\t" in text):
> > print text
>
> since you're stripping away all leading and trailing whitespace from each
> line, you'll only find lines that have tabs "in the middle".
>
> (your code is only five lines long.  don't you think you could have double-
> checked each line a couple of times, asking yourself "what exactly is this
> line doing", in less time than it took you to compose the mail ?)

Both your specific and general suggestions are correct. Thanks.

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


search file for tabs

2006-05-02 Thread beliavsky
The following code to search a file for tabs does not work, at least on
Windows XP. Could someone please tell me what's wrong? Thanks.

xfile = "file_with_tabs.txt"
for text in open(xfile,"r"):
text = text.strip()
if ("\t" in text):
print text

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


  1   2   3   >