Considering migrating to Python from Visual Basic 6 for engineering applications
wrong.address.1 at gmail.com
wrong.address.1 at gmail.com
Sat Feb 20 13:45:17 EST 2016
On Saturday, 20 February 2016 09:54:15 UTC+2, Steven D'Aprano wrote:
> 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)]
>
This looks good enough. This does not seem complicated (although I still understand almost nothing of what is written). I was simply not expressing myself in a way you people would understand.
>
> 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().
>
And I guess if the first three numbers are integers and the fourth is a float, then also there must be some equally straightforward way.
Thanks for this explanation, which changes my view about reading numbers in Python.
>
>
>
>
>
> --
> Steven
More information about the Python-list
mailing list