Considering migrating to Python from Visual Basic 6 for engineering applications

Steven D'Aprano steve at pearwood.info
Sat Feb 20 02:54:05 EST 2016


On Fri, 19 Feb 2016 10:53 pm, wrong.address.1 at gmail.com wrote:

>> See http://nedbatchelder.com/text/python-parsers.html for a list of
>> parsers that can do all sorts for you.  Or the stdlib re module
> 
> I am an engineer, and do not understand most of the terminology used
> there. 

Google, or the search engine of your choice, is your friend.

https://duckduckgo.com/html/

https://startpage.com/eng/?


Wikipedia even more so: Wikipedia has lots of good, useful articles on
computing concepts.

https://en.wikipedia.org/wiki/Category:Computing

And use the search box visible at the top of every page.

Or ask here.



> And do I need something fancy to read a line of numbers? Should it 
> not be built into the language?

In your own words:

"I will have to read data given to me by people, which may not come in nice
formats like CSV"

I trust that you don't expect the language to come with pre-written
functions to read numbers in every imaginable format. If you do, you will
be disappointed -- no language could possible do this.

To answer your question "Do I need something fancy...?", no, of course not,
reading a line of numbers from a text file is easy.

with open("numbers.txt", "r") as f:
    for line in f:
        numbers = [int(s) for s in split(line)]


will read and convert integer-valued numbers separated by whitespace like:

    123 654 9374 1 -45 3625


one line at a time. You can then collate them for later use, or process them
as you go. If they're floating point numbers, change the call to int() to a
call to float().






-- 
Steven




More information about the Python-list mailing list