Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyPI package and files
#5
(Oct-23-2021, 04:44 PM)ChrisOfBristol Wrote: The answer was to type info python
This gives the syntax as python3 -m mymodules.myapp datafile.dat
Then the point of making a package is somewhat gone if do it like this.

So before talk about Entry Points to make if for command line,
if want to load file in a package there is importlib.resources(New in Python 3.7)
So eg in Packaging Python Projects if i add this.
from importlib import resources

def add_one(number):
    return number + 1

with resources.open_text('example_package', 'somefile.dat') as fp: # Just 42 in somefile.dat
    number = fp.read()
Then can now use number from the package.
>>> from example_package import example
>>>
>>> example.add_one(2)
3
>>> example.add_one(int(example.number))
43
>>>
Reply


Messages In This Thread
PyPI package and files - by ChrisOfBristol - Oct-22-2021, 07:58 PM
RE: PyPI package and files - by Axel_Erfurt - Oct-22-2021, 08:49 PM
RE: PyPI package and files - by snippsat - Oct-22-2021, 10:51 PM
RE: PyPI package and files - by ChrisOfBristol - Oct-23-2021, 04:44 PM
RE: PyPI package and files - by snippsat - Oct-23-2021, 09:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Including data files in a package ChrisOfBristol 4 2,580 Oct-27-2021, 04:14 PM
Last Post: ChrisOfBristol
  fileinput package appears to be zeroing files rexrf 0 1,491 Jul-01-2020, 06:05 PM
Last Post: rexrf
  Updating a package published on PyPI marqrdt 1 2,447 Jan-02-2018, 02:03 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020