Day 335: Python controlling the System (Subprocess) 🔧 Running Shell Commands from Python Sometimes Python isn't enough. Sometimes you need to run a git command, ping a server, or execute a C++ program from your Python script. The subprocess module is the bridge between Python and your Operating System. import subprocess # Running a simple echo command # capture_output=True lets us store the result in a variable result = subprocess.run(['echo', 'Hello from the shell!'], capture_output=True, text=True) print(f"Shell said: {result.stdout}") My Use Case: I recently used this to automate a git backup script that runs git add and git commit automatically at the end of the day. #Automation #SystemAdmin #Python #DevOps
Python Subprocess Module for Shell Commands
More Relevant Posts
-
Your Python script isn't "finished" until it's an executable. Let’s be real: your non-technical stakeholders aren't going to install Python, set up a virtual environment, and run pip install -r requirements.txt just to see your work. If you want your automation to actually get used, make it a .exe. How to do it in 10 seconds: pip install pyinstaller pyinstaller --onefile your_script.py Check your /dist folder, and you’re done. One file, one click, total impact. Pro Tip: If your terminal says "command not found," use python -m pyinstaller instead. It ensures you're using the right Python environment every time! #PythonProgramming #Efficiency #ProgrammingLife
To view or add a comment, sign in
-
I've been doing some Python/C API work lately for a client: writing a C layer, packaged as a Python wheel, that allows you to invoke that C code from Python. It's really fun and the Python/C API is very well documented. It teaches a lot about how Python works under the hood, for example the ref count system. It's really not so complex once you get familiar with it. The fun thing is that it opens the door to all kinds of things, for example you can call native code, or call code from C or C++ libraries. Perhaps I'll make a little demonstration, for example to show how to invoke a native voice-to-speech framework from Python. Or maybe invoke some JUCE code..? :D I wonder if you could create an audio plugin host from Python 🤔 Join my newsletter: https://lnkd.in/eUr7bAGC
To view or add a comment, sign in
-
Did you know you can specify data types in Python. Python may be dynamically typed, but you can still declare expected data types using type hints to make your code clearer and more professional. Example 👇 def my_func(age: int, name: str, is_active: bool) -> None: print(age, name, is_active) This does not enforce types at runtime, but it helps in many ways: ✅ Improves code readability ✅ Makes functions self-explanatory ✅ Helps IDEs catch mistakes early ✅ Essential for large and team-based projects Type hints are widely used in modern Python, especially in frameworks, APIs, and production-level code. Clean code isn’t just about making things work — it’s about making them understandable. #Python #TypeHints #CleanCode #Programming #SoftwareDevelopment #PythonTips
To view or add a comment, sign in
-
Ever wondered how Python packages are actually created? Or what happens behind the scenes when you run pip install? If you’ve ever thought about building your own Python package, publishing it, and installing it just like any other library — this article breaks it down step by step. From project structure to packaging, versioning, and distribution, the link below walks through the entire process in a practical, beginner-friendly way. If you’re serious about writing reusable, shareable Python code, this is a must-read. link below: https://lnkd.in/gVdZEqHc #Python #PythonPackaging #Pip #OpenSource #SoftwareEngineering #Developers #Programming #TechLearning
To view or add a comment, sign in
-
🔥 Day 76 of my #100DaysLogicChallenge C++ vs Python: Static Linking vs Dynamic Linking EXPLAINED! 🧠⚙️ Today I learned how programs actually link libraries and why C++ binaries behave very differently from Python programs. Understanding static vs dynamic linking explains: why C++ executables are fast, why Python apps are flexible, and why deployment works differently in both. 🧠 What I learned today • What linking really means • Difference between static & dynamic linking • Why C++ supports both • Why Python relies on dynamic linking • Impact on performance, size, and deployment 🔗 Static Linking (Mostly C++) Libraries are embedded inside the executable Bigger binary size Faster execution No external dependency at runtime Platform-specific binaries Used in: System software Embedded systems Performance-critical applications 🔗 Dynamic Linking (Python & Modern Apps) Libraries loaded at runtime Smaller executable Easier updates Slower startup Dependency required at runtime Used in: Python programs Web applications Rapid development environments 💡 Key Insight C++ trades flexibility for speed. Python trades speed for flexibility. #100DaysLogicChallenge #Day76 #Linking #Cpp #Python #SystemThinking #LearningInPublic #BuildInPublic 🚀
To view or add a comment, sign in
-
-
Forget the Tomfoolery... Agent "Grandmaster Python" built a Python Version Manager instead. Even got a slot for 4.0 to fill if that day ever comes. Versioning is a serious dilemma when building advanced ecosystems. Build in adaptability for long term capability.
To view or add a comment, sign in
-
💡Not a bug. Just Python being Python. Python “Bug” That Isn’t a Bug At first, this looks confusing. You create two variables with the same number, but Python treats them differently. What’s really happening? Python caches small integers (from -5 to 256) to improve performance. 256 reused from cache same memory object 257 created again different memory locations That’s why: a == b compares the value True a is b compares memory (identity) True / False This is one of those Python internals that: trips up beginners surprises experienced developers shows why understanding the language really matters Not magic. Not a bug. Just how Python works. #Python #Programming #SoftwareEnginering #Developer #Coding
To view or add a comment, sign in
-
-
The 4 Core JSON Functions in Python - When to Use What? If you work with JSON in Python, these four functions are all you need. But knowing when to use which is key: 📌 Common Scenarios: I have bytes from Pub/Sub → json.loads(message_bytes.decode("utf-8")) I have a JSON string → json.loads(json_string) I have a dict and want a string → json.dumps(my_dict) I have a dict and want bytes → json.dumps(my_dict).encode("utf-8") I want to parse from a file/stream → json.load(file) I want to write JSON to a file/stream → json.dump(obj, file) 💡 Pro Tip: load/dump → for files or streams loads/dumps → for strings in memory #Python
To view or add a comment, sign in
-
-
What I Learned Today in Python – API Development & Global Exposure 🌍 Today I learned how to convert a Python function into a real-world API and expose it to the internet. 🔹 Built APIs using FastAPI 🔹 Used Pydantic for request validation in POST APIs 🔹 Created both GET and POST endpoints 🔹 Tested APIs using Postman and Swagger UI 🔹 Ran the server with Uvicorn 🔹 Exposed local Python APIs to the world using Ngrok 💡 Key takeaway: With the right tools, a simple Python function can be transformed into a production-ready API and shared globally within minutes. This was a great hands-on experience in understanding how backend services actually work in real applications. Learning step by step. Building daily. 🚀 #Python #FastAPI #APIDevelopment #BackendDevelopment #Ngrok #Uvicorn #Pydantic #LearningByDoing #TechJourney
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development