Jump to content

Python: adding code from another file into a library


Recommended Posts

Hey everyone,

I’m pretty new to python, but have done a lot of coding with php and JavaScript.

 

here is what I am hoping to do.

i want to write a script that will do the following:

1. scan sub directory make an array with the names of each of the files

2. iterate through the files using the array, and make either a object, or a function using the file name (without the extension) as the name, and the contents for the code

3. Run the function/create object that were just created, and with known variables


I’m pretty sure I can figure out step one and three. It’s step two that’s giving me problems. I tried using the open() function, and eval(), but it’s giving me some problems, and that feels like a ‘janky’ way to do it.

this is for a raspberry Pi project I’m using to control the equipment on my fish tank. The idea is I can write code for each sensor individually, and the program will automatically be able to incorporate it. I’d just have to drop it into the folder 

 

any suggestions?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.