@@ -1641,12 +1641,13 @@ def virtualfile_out(
1641
1641
1642
1642
Examples
1643
1643
--------
1644
+ >>> from pathlib import Path
1644
1645
>>> from pygmt.clib import Session
1645
1646
>>> from pygmt.datatypes import _GMT_DATASET
1646
1647
>>> from pygmt.helpers import GMTTempFile
1647
1648
>>>
1648
1649
>>> with GMTTempFile(suffix=".txt") as tmpfile:
1649
- ... with open (tmpfile.name, mode="w") as fp:
1650
+ ... with Path (tmpfile.name).open( mode="w") as fp:
1650
1651
... print("1.0 2.0 3.0 TEXT", file=fp)
1651
1652
...
1652
1653
... # Create a virtual file for storing the output table.
@@ -1661,8 +1662,7 @@ def virtualfile_out(
1661
1662
... with lib.virtualfile_out(fname=tmpfile.name) as vouttbl:
1662
1663
... assert vouttbl == tmpfile.name
1663
1664
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
1664
- ... with open(vouttbl, mode="r") as fp:
1665
- ... line = fp.readline()
1665
+ ... line = Path(vouttbl).read_text()
1666
1666
... assert line == "1\t2\t3\tTEXT\n"
1667
1667
"""
1668
1668
if fname is not None : # Yield the actual file name.
@@ -1692,13 +1692,14 @@ def read_virtualfile(
1692
1692
1693
1693
Examples
1694
1694
--------
1695
+ >>> from pathlib import Path
1695
1696
>>> from pygmt.clib import Session
1696
1697
>>> from pygmt.helpers import GMTTempFile
1697
1698
>>>
1698
1699
>>> # Read dataset from a virtual file
1699
1700
>>> with Session() as lib:
1700
1701
... with GMTTempFile(suffix=".txt") as tmpfile:
1701
- ... with open (tmpfile.name, mode="w") as fp:
1702
+ ... with Path (tmpfile.name).open( mode="w") as fp:
1702
1703
... print("1.0 2.0 3.0 TEXT", file=fp)
1703
1704
... with lib.virtualfile_out(kind="dataset") as vouttbl:
1704
1705
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
@@ -1779,7 +1780,7 @@ def virtualfile_to_dataset(
1779
1780
>>>
1780
1781
>>> with GMTTempFile(suffix=".txt") as tmpfile:
1781
1782
... # prepare the sample data file
1782
- ... with open (tmpfile.name, mode="w") as fp:
1783
+ ... with Path (tmpfile.name).open( mode="w") as fp:
1783
1784
... print(">", file=fp)
1784
1785
... print("1.0 2.0 3.0 TEXT1 TEXT23", file=fp)
1785
1786
... print("4.0 5.0 6.0 TEXT4 TEXT567", file=fp)
0 commit comments