#🔒 question abt python files

44 messages · Page 1 of 1 (latest)

fallow grotto
#

when looking through other people's projects on Github, I noticed that there are multiple python files in one project why is this

humble urchinBOT
#

@fallow grotto

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

fallow grotto
#

im new so can u explain this like im 5 years old

zenith tendon
#

It's either configuration files or like

#

It's hard to explain specifically

#

In pynput, you will get errors when you use pyautogui to click right after pynput detects a click, it'll cause lag problems

#

To fix this, we will use statements and different files to stop the lag issue

#

That's my assumptions

autumn moon
#

I'm not sure what import is talking about, but the reason to have multiple python files in a project is more or less the same as the reason to have multiple c++ or java or c# files - easier to understand and maintain code, and modularity.
Modularity especially so, in Python.

#

Unlike java or c# that don't have top-level procedural code (everything is wrapped in a class or method), python modules are executed upon import

zenith tendon
fallow grotto
#

what does pynput and pyautogui have to do

zenith tendon
zenith tendon
autumn moon
#

For a more advanced example:

What's elegant in python is that you can swap module imports to achieve different functionality, like for example you could import database_mssql instead of database_mysql, assuming both implement a get_db function that your api endpoints depend on, and you will have swapped the database implementation, achieving the same level of modularity that you would achieve by implementing a repository pattern in something like c#, but in a more pythonic way.

#

Where the database_mssql and database_mysql modules include all the top-level code you need to build a connection string, engine, and whatever else you might need to connect to the database.
Then both modules contain the same function that just returns an instance of a database session / connection.

#

But yeah, maybe a too complex / convoluted example for your question - refer to my first answer.

#

If you're doing data science you can build pipelines from multiple modules in order to make your data flow easier to understand and reproduce.

#

You could of course technically do all this using one massive python file with thousands of lines, but why would you?

twilit iron
#

You guys aren't following the "explain like i'm 5 years old" prompt lol.

twilit iron
#

My version is "there's too much code. It could all be in one file, but it's better to group related code together in separate files"

fallow grotto
#

Explain for a Galactic Emperor of Intergalactic Cyber Warfare and Quantum Encryption

#

with 2 bazillion years of experience

twilit iron
#

tbf 5 years old is quite young to even know what code is, so YMMV

fallow grotto
#

😂

twilit iron
#

As a dad of a 5 year old...yeah not even scratch

fallow grotto
#

Damn🤣

twilit iron
#

I mean he's just learning to read so...

fallow grotto
#

better teach him asm when he turns 7 then

#

it will be to late then

twilit iron
#

Yeah, start from the ground up haha

fallow grotto
#

🤣 🤣 🤣

twilit iron
#

we'll build a CPU on a breadboard first though

#

then move up to machine instructions

#

@fallow grotto any more questions? Sorry going off on a tangent here...

fallow grotto
#

chat gpt explains modularity for a 5 yr old: Oh boy, are you ready for a fun explanation?

Imagine you have a bunch of LEGO blocks in different shapes and colors. Each block can do a special thing, like one block can make a car move, another block can make a house appear, and another block can make a robot talk.

Modularity is like building with these LEGO blocks. Instead of trying to make one huge, complicated block that does everything, we break it down into smaller, simpler blocks that do one thing really well.

This way, when we want to build something new, like a castle, we can just take the blocks we need, like the house block and the car block, and connect them together to make something amazing!

And the best part? If we want to change something, like make the car block go faster, we can just take that one block out and replace it with a new one, without affecting the whole castle.

So, modularity is like building with LEGO blocks, where each block is a special piece that can be connected and used to make something new and amazing, and it makes it easy to change and improve things without making a big mess!

autumn moon
twilit iron
#

Yeah...that's perfect.

humble urchinBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.