this post was submitted on 25 Jun 2024
25 points (90.3% liked)
Python
6408 readers
2 users here now
Welcome to the Python community on the programming.dev Lemmy instance!
π Events
Past
November 2023
- PyCon Ireland 2023, 11-12th
- PyData Tel Aviv 2023 14th
October 2023
- PyConES Canarias 2023, 6-8th
- DjangoCon US 2023, 16-20th (!django π¬)
July 2023
- PyDelhi Meetup, 2nd
- PyCon Israel, 4-5th
- DFW Pythoneers, 6th
- Django Girls Abraka, 6-7th
- SciPy 2023 10-16th, Austin
- IndyPy, 11th
- Leipzig Python User Group, 11th
- Austin Python, 12th
- EuroPython 2023, 17-23rd
- Austin Python: Evening of Coding, 18th
- PyHEP.dev 2023 - "Python in HEP" Developer's Workshop, 25th
August 2023
- PyLadies Dublin, 15th
- EuroSciPy 2023, 14-18th
September 2023
- PyData Amsterdam, 14-16th
- PyCon UK, 22nd - 25th
π Python project:
- Python
- Documentation
- News & Blog
- Python Planet blog aggregator
π Python Community:
- #python IRC for general questions
- #python-dev IRC for CPython developers
- PySlackers Slack channel
- Python Discord server
- Python Weekly newsletters
- Mailing lists
- Forum
β¨ Python Ecosystem:
π Fediverse
Communities
- #python on Mastodon
- c/django on programming.dev
- c/pythorhead on lemmy.dbzer0.com
Projects
- PythΓΆrhead: a Python library for interacting with Lemmy
- Plemmy: a Python package for accessing the Lemmy API
- pylemmy pylemmy enables simple access to Lemmy's API with Python
- mastodon.py, a Python wrapper for the Mastodon API
Feeds
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
There's not much here to go on. Are you asking how to write a module that you can import?
Are these the same set of DB files every time? Are the columns and other configurations the same? Are you writing new python code every month?
Are you using some ETL process to spit out a bunch of files that you'd like to have imported and available easily? Are the formats the same but the filenames differ?
I think it's the first thing you're after. There are a bunch of tutorials knocking around about this, eg, https://www.digitalocean.com/community/tutorials/how-to-write-modules-in-python-3
You might also be asking: if I write a module, how do I make it available for all my new python projects to use? You could just copy your whatever-my-module-is-called.py file around to your new projects (this might be simplest) but if you're also expecting to be updating it and would like all of your projects to use the updated code, there are alternatives. One is to add the directory containing it to your PYTHONPATH. Another is to install it (in edit mode) in your python environment.
[I get the impression you're a data person rather than a programmer - perhaps you have a colleague who's more of the latter you can tap up for this? It doesn't have to be difficult, but there's typically a little bit of ceremony involved in setting up a shared module however you choose to do it.]
Yes, kinda.
They get updated by the accounting team each month. Some of them are csv, other come from an access database file, other from the sql server.
Some of the code need to be run each month with the updated databases, but there's a lot of ad hoc statistical studies that my boss ask for that use the same databases.
I guess yes. And not, the accountants keep the same filenames but change the directory lmao.
Thanks, im checking it out.
import sys sys.path.append('my\\modules\\directory) import my_module
You're right, I'm an actuarie. I wanted to do computer science instead of actuarial sciences, but I tough that it would be better getting an actuarial degree and then doing a masters on CS (still in planning, maybe 2026). I'm the only guy on the company who uses python and people here thinks I'm a genius because I have automated some boring things from excel.
If things are changing a bit each month, then in your module rather than a plain variable assignment
you might want a function that you can pass in parameters to represent the things that can change:
Then you can call it like this:
... gope that makes some sense.
If it is the first thing, just put the db setup code you're using in one file, call it "database.py"
database.py
From a second file in the same directory, write: main_program.py
then run it with
python main_program.py
The main thing to realise here is that there are two names involved. One's the module, the other is the variable (or function name) you set inside that module that you want to get access to.