[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[python #HSE-220221]: read_colortable



Hello, and thanks for the follow-up!

A "file-like object" refers to anything in Python that you can interact with 
that "looks like" a file. For example my actual file on disk, or my in-memory 
thing that looks like a file, or my object visible remotely on some server 
somewhere; I can interact with these using methods like `.read()` and 
`.write()`. In this case, that does *not* include strings/Paths (though many 
packages out there do take strings, paths, or file-like objects for a variety 
of functions.)

So in this case, if your colortable follows the format Ryan specified before, 
you could read it in as follows:

  with open('mycolortable.tbl') as fobj:
      ctable = metpy.plots.read_colortable(fobj)

where you create a file-like object by `open()`ing our text file. I hope this 
helps! Don't hesitate to follow-up if you have any other questions.


All the best,

Drew


> So what exactly is a 'file-like object'?  Is it a string with a path to a
> filename, like './mycolortable.tbl' ?
> Let's say I've got a color table saved in a text file called
> 'mycolortable.tbl'.  What would the syntax look like to read this color
> table?
> 


Ticket Details
===================
Ticket ID: HSE-220221
Department: Support Python
Priority: Low
Status: Closed
===================
NOTE: All email exchanges with Unidata User Support are recorded in the Unidata 
inquiry tracking system and then made publicly available through the web.  If 
you do not want to have your interactions made available in this way, you must 
let us know in each email you send to us.