#064 - How to Learn Python for Engineering
Effective Strategies for Learning and Applying Python in Your Engineering Workflow.
Hi everybody, welcome back! π
A Happy April Fools to everyone! My quest for understanding frequently results in outcomes best suited for this particular date. I feel right at home on April 1st.
Welcome to this guide on how to effectively learn Python for engineering purposes.
This article is designed to help you navigate the Python landscape and approach your learning journey in a structured and practical manner.
Rather than diving into the specifics of the Python language or getting bogged down with code snippets, we'll focus on broader strategies and methods to help you learn and progress efficiently.
The goal is to provide you with a clear roadmap that emphasizes hands-on engagement and practical application, helping you avoid some of the common pitfalls that many, including myself, have encountered along the way.
We will cover:
Getting Started with Python: Laying the foundations.
Building Practical Skills: Enhancing your proficiency through practical projects.
Advanced Techniques and Integration: Exploring more complex applications and integrating Python with other tools.
Real-World Applications and Long-Term Growth: Applying your skills to solve real-world problems and planning for continuous improvement.
There are many resources available for you to do all of these things. If these ideas resonate with you, I suggest you join the Flocode Beta Program and youβll be first to know when I drop the Python Essentials Course. Itβs coming, there has been a lot of rework and refinement of the curriculum based on excellent feedback from some early testing groups.
Section 1: Getting Started with Python
Learning Python for engineering purposes may seem like a tall order, especially if your schedule is already packed with professional and personal commitments.
I donβt know a single professional engineer who has available time to do anything. This is the single greatest hurdle to leap. Only you know how you can adjust your workflow/schedule to fit in skill acquisition.
The key lies not in passively consuming Python tutorial content but in active, hands-on engagement with the language. This may sound extremely obvious but Iβll walk you through some considerations that might help accelerate your progress and prevent your from falling into some of the rabbit holes that I ended up in.
Initial Learning Phase: Initially, you need to spend time learning the basics, whether through online courses, textbooks, or workshops. This phase is about getting the lay of the landβunderstanding the scope of Python and familiarizing yourself with key concepts and landmarks in the programming landscape. You will be creating a giant mental model of whatβs out there. Slowly over time, you can explore topics and build connections. This phase is fun, low stakes and extremely interesting. You will begin to understand how powerful Python is. Enjoy this part.
Avoid Passive Learning: One of the biggest pitfalls to avoid is spending excessive time watching tutorial videos without applying what you've learned. While tutorials can provide valuable insights, they often lack the depth required to build a solid foundation. Once you understand the basics, it's crucial to engage in repetitive, hands-on activities to reinforce your learning. Passively watching tutorials is like junk food for your brain, itβs similar to scrolling mindlessly through Instagram and creates the illusion of learning but youβre really just using up valuable thinking reserves!
"One must learn by doing the thing; for though you think you know it, you have no certainty until you try." - Sophocles
Set Up and Environments: Familiarize yourself with essential tools and practices such as project setup, virtual environments, and version control. These are fundamental aspects of project management in software engineering. Start by learning how to set up virtual environments using tools like uv,
poetry
,venv
orvirtualenv
, and understand how to use Git for version control.Check out this article on uv for a more detailed primer:
#044 - Python Environments, Again | uv: A Guide to Python Package Management
Β·"Everything should be made as simple as possible, but not simpler."
This knowledge will help you manage your code repositories effectively. Git knowledge runs deep so start with the complete basics and give yourself the space to absorb this information over time from project to project. It will take time (months/years) to understand its depth, but you donβt need to be an expert to make great progress and follow good practices early on.
Understand the Analytical Side: Beyond the technical setup, Python requires analytical thinking and problem-solving skills. You'll need to learn how to use different methods and tools within the language to solve problems logically. This involves a certain amount of heavy lifting, similar to building strength through lifting weights. Coding exercises your brain, and you need to actively think through problems and solutions. At the beginning this feels impossible, like youβre wasting your time but through a structured approach, where you regulate the complexity, you can make great progress.
Hands-On Practice: Progress in coding comes from doing, not just watching. Frame your problems and try to come up with multiple solutions, analyzing why certain approaches work and others donβt. This practice helps deepen your understanding and builds problem-solving skills. In a future post, if there is interest, I will share some problems and solutions. Let me know in the comments below if this is of interest.
"You donβt learn to walk by following rules. You learn by doing, and by falling over." - Richard Branson
Project Implementation: After gaining basic knowledge, the next step is to start implementing small projects. Start with simple tasks relevant to your field. For instance, if you frequently use Excel or other software for repetitive tasks, try to replicate a small part of that workflow in Python. Jupyter Notebooks are excellent for this purpose, especially the cloud versions available on platforms like Kaggle or Google Colab. The cloud tools are great but nothing beats setting up your own virtual environments and local workstation.
Good Project Management Practices: As you start coding, aim to develop good project management practices. Use Git for version control and set up repositories on platforms like GitHub or GitLab. Learn how to make pull requests, merge branches, and manage your code effectively. These habits will provide a significant boost to your progress and help you avoid common pitfalls that can slow you down. Donβt be intimidated by the scope of these tools, yes thereβs a lot to learn but it gets easier as you gain familiarity. Remember there was once a time when you had no idea how to use Microsoft Excel.
Incremental Learning: Learning Python is a gradual process. You must trust this process. You donβt need to master everything at once before starting to code. Begin with the basics, and as you work on projects, gradually incorporate more advanced practices and tools. Each project will teach you something new and help consolidate your knowledge. One of the best things about coding is that their are many paths to the same goal. You can solve problems in many different ways, some better than others but what is your goal? A solved problem or an optimally solved problem? An interesting discussion!
"Done is better than perfect." - Sheryl Sandberg
Developing Programmatic Thinking: Once you're comfortable with the basics, focus on developing your programmatic thinking skills. This involves understanding how to break down problems, write algorithms, and structure your code logically. Over time, you'll learn how to refactor your code to make it more efficient and maintainable. If you want to dig into these concepts, check out my previous article:
#026 - Programmatic Thinking: For Engineers
Β·As an engineer, you're trained to approach problems systematically and logically. Programming requires the same fundamental skills, breaking down complex problems into smaller steps and using logical operations to solve each part. Thinking programmatically means applying that same analytical engineering mindset to writing code.
"Programming is thinking, not typing.β - Casey Patton
Learning Python for engineering requires a mix of theoretical knowledge and practical application. Start with the basics, develop good project management habits, and gradually build your skills through actual tasks you need to do.
Section 2: Building Practical Skills
Once you have a foundational understanding of Python, it's time to build practical skills that will make you proficient in applying Python to engineering tasks. This section focuses on practical approaches and techniques that can enhance your learning and efficiency.
Start with Simple Projects: Begin with small, manageable projects that are directly relevant to your field. For example, if you frequently perform calculations in Excel, try automating these tasks with Python. Use simple scripts to read data from Excel files, perform calculations, and output the results. Libraries like Pandas and openpyxl can be extremely helpful for these tasks.
Some ideas for simple projects for common engineering tasks:
Automate Timesheet Entries: Use Python to read time entries from a CSV file and automatically input them into a web-based timesheet system using Selenium.
Simple Calculator for Engineering Formulas: Create a command-line tool or a Jupyter Notebook for basic Python functions for simple routine calculations.
Document Conversion: Automate the conversion of documents from one format to another (e.g., PDF to DOCX) using libraries like
pdf2docx
orpypandoc
.Monitor Email for Specific Keywords: Use the
imaplib
library to read emails and automatically flag or sort them based on specific keywords in the content.Batch Rename Files: Use the
os
library to automate the renaming of multiple files in a directory based on a specific pattern, I often do this for model results or photos from inspections.
Use Jupyter Notebooks: Jupyter Notebooks are a fantastic tool for learning and practicing Python. They allow you to write and execute code in small chunks, making it easier to experiment and see immediate results. This iterative process is ideal for learning, as it lets you test hypotheses and understand the behavior of your code in real-time. Platforms like Kaggle and Google Colab offer cloud-based Jupyter environments that are easy to set up and use. Most of my calculation files are developed in Jupyter so that you can document the design process as you proceed. It tracks my thought process throughout and I can include references, links, thoughts and related content. To read more about Jupter, check out:
#059 - Jupyter Notebooks vs. Scripts: Which? Why? When?
Β·There are typically two schools of thought when it comes to doing engineering work in Python. And like many things in todayβs society, these viewpoints can be extremely polarizing. So, let us continue this grand tradition of absolutism, plug our fingers firmly in our ears, and explore both extremes, if only to gain a broader view of the pros and cons of each.
Embrace Repetition: Repetition is key to mastering any skill, and programming is no exception. Regularly practice the workflow of setting up projects, managing virtual environments, and using version control (commits, branches, merges). These repetitive tasks will become second nature over time, freeing up mental space to focus on more complex problems. At the beginning, these aspects will likely drive you insane and you might find yourself screaming into a pillow. This is normal.
Understand Development Operations: Even for small projects, adopting good development operations (DevOps) practices is crucial. Learn the basics of continuous integration and continuous deployment (CI/CD). Tools like GitHub Actions and GitLab CI/CD can help automate testing and deployment processes, ensuring that your code is always in a deployable state. You donβt need to know everything about this, you just need to know it exists. As you gain experience, these aspects will click into place.
Collaborate and Seek Feedback: Join online communities and forums where you can share your projects and seek feedback from more experienced programmers. Platforms like GitHub, Stack Overflow, and Reddit are great places to ask questions, find solutions, and collaborate on projects. Engaging with the community can provide new perspectives and help you learn best practices. This is exactly what the Flocode Community is for.
Develop Problem-Solving Skills: Focus on developing your problem-solving skills by tackling a variety of challenges. Websites like LeetCode, HackerRank, and Codewars offer coding challenges that can help you practice and improve your problem-solving abilities. These platforms provide problems of varying difficulty levels, allowing you to gradually increase the complexity of the tasks you tackle. Make no mistake, the difficulty of the problems on Leetcode will make your head spin. I have definitely struggled a lot with these problems but I have also learned some very cool and efficient approaches to solving problems involving data structures and algorithms. There are not shortcuts here, you need to put in the reps.
Document Your Work: Good documentation is essential in engineering. Practice writing clear, concise documentation for your projects. Use Markdown to create README files that explain what your project does, how to set it up, and how to use it. Documenting your code helps others understand your work and can also reinforce your understanding of the concepts you're using. Most often, you will be writing for a future version of yourself. Never underestimate your ability to forget everything!
Learn Debugging Techniques: Debugging is an integral part of programming. It is frustrating, difficult, yet extremely rewarding. Learn how to use debugging tools effectively. Python's built-in debugger (
pdb
) and IDE features like those in Visual Studio Code can help you step through your code, inspect variables, and understand the flow of your program. Being proficient in debugging will save you time and frustration when things go wrong. Itβs an emotional rollercoaster.Apply Python to Real-World Problems: Look for opportunities to apply Python to real-world problems in your engineering work. Whether it's automating data analysis, creating simulations, or developing tools to streamline workflows, using Python in practical applications will reinforce your learning and demonstrate the language's power. Why stop at your engineering work, you may find interesting applications in your personal life. Me, being a dork, have used it for
Refactor and Improve Your Code: As you gain more experience, regularly revisit and refactor your code to improve its efficiency and readability. Refactoring helps you understand your code better and often reveals new ways to optimize and enhance your solutions.
By focusing on these practical skills and continuously challenging yourself with new projects and problems, you'll steadily improve your proficiency in Python. Remember, the goal is to integrate Python seamlessly into your engineering workflows, making your work more efficient and effective.
Section 3: Advanced Techniques and Integration
As you progress in your Python learning journey, it's essential to explore advanced techniques and integrate Python with other tools and systems you use in your engineering practice. This section delves into these advanced aspects and how they can enhance your efficiency and capabilities.
Explore Advanced Libraries and Frameworks: Beyond the basic libraries like NumPy and Pandas, many advanced libraries can significantly enhance your Python projects. For example:
SciPy: For advanced mathematical, scientific, and engineering calculations.
Matplotlib and Seaborn: For data visualization.
SymPy: For symbolic mathematics.
Pynite and Opensees: For structural analysis.
TensorFlow and PyTorch: For machine learning and AI applications.
Automate Repetitive Tasks: Automating repetitive tasks can save you significant time and effort. Python's scripting capabilities allow you to automate tasks like data entry, file manipulation, and report generation. Use libraries like
openpyxl
to work with Excel files,os
for file system operations, andrequests
for web scraping and API interactions.Integrate Python with Other Software: Many engineering tasks require integrating Python with other software tools. For instance:
CAD Software: Use libraries like freecad,
pyautocad
orezdxf
to interact with AutoCAD and manipulate DXF files.Finite Element Analysis (FEA) Software: Integrate Python with tools like ANSYS ,SAP2000, Strand7, Tekla using their respective Python APIs.
BIM Software: Automate and enhance workflows in software like Revit using the Revit Python Wrapper (RevitPythonShell) or Dynamo.
GIS Software: Use libraries like
geopandas
andshapely
to work with geospatial data and integrate with GIS software like QGIS.
Develop Custom Applications: Building custom applications can solve specific problems in your workflow that off-the-shelf software cannot address. Frameworks like Solara, Streamlit, Dash, and Flask make it easy to create web applications. For example, you can develop a custom app to visualize structural analysis results or to automate a series of engineering calculations.
Leverage Machine Learning: Machine learning can provide powerful solutions to complex engineering problems. Explore how machine learning can be applied to predictive maintenance, optimization problems, and data analysis. Start with supervised learning algorithms like linear regression and progress to more complex models like neural networks. This topic is much. more approachable than most people think. Read more about it here:
#062 - Machine Learning for Engineers | When and How Should We Use it?
Β·Machine learning (ML) is becoming more approachable and useful for engineers.
Collaborate and Share Your Work: Collaborate with colleagues and share your projects using platforms like GitHub. Version control systems like Git help manage changes and collaborate efficiently. Contributing to open-source projects or sharing your own can provide valuable experience and feedback.
Create Interactive Dashboards: Tools like Solara, Plotly Dash and Bokeh allow you to create interactive dashboards that can visualize data and results dynamically. These dashboards can be used to present analysis results to stakeholders in an intuitive and interactive manner.
Use Containerization and Virtualization: Containerization tools like Docker can help create consistent development environments and simplify the deployment of applications. Docker allows you to package your application with all its dependencies, ensuring it runs consistently across different environments.
Understand Database Management: Learn how to work with databases to manage and analyze large datasets efficiently. Libraries like SQLAlchemy for SQL databases or MongoDB for NoSQL databases can help you integrate database management into your Python projects.
Focus on Code Quality and Testing: As your projects become more complex, maintaining code quality becomes crucial. Use testing frameworks like
pytest
to write tests for your code, ensuring it behaves as expected.
Section 4: Real-World Applications and Long-Term Growth
The final stage of mastering Python for engineering involves applying your skills to real-world problems and planning for long-term growth in your programming abilities. This section provides insights into practical applications and strategies for continual improvement.
Identify Real-World Problems: Look for problems in your daily work that can be solved more efficiently with Python. This could involve automating data processing tasks, creating simulations, or developing custom analysis tools. The key is to find areas where Python can save time and improve accuracy.
Build a Portfolio: Document your projects and create a portfolio showcasing your Python skills. This can be a personal website, a GitHub repository, or a collection of Jupyter Notebooks. A well-organized portfolio demonstrates your abilities to potential employers and collaborators and provides a reference for your work.
Networking and Professional Development: Attend industry conferences, webinars, and meetups to connect with other professionals who use Python in engineering. Networking can lead to collaborations, job opportunities, and valuable insights into how others are applying Python in their work.
Stay Current and Experiment: Technology and industry practices evolve rapidly. Stay current by following industry news, subscribing to newsletters, participating in forums, and actively experimenting with new libraries, frameworks, and tools. Staying updated and curious ensures that your skills remain relevant and that you can leverage the latest advancements in your work.
Contribute to Open Source Projects: Contributing to open-source projects is an excellent way to improve your skills, learn from others, and give back to the community. It exposes you to larger codebases, collaborative workflows, and different coding standards. Contributing code, documentation, or bug fixes provides valuable experience. Look for projects that align with your interests and expertise, such as:
Explore Interdisciplinary Applications: Python's versatility allows you to apply it in various fields beyond traditional engineering. Explore interdisciplinary applications such as data science, machine learning, and artificial intelligence. These fields offer powerful tools and techniques that can enhance your engineering projects.
Reflect on Your Progress: Regularly reflect on your learning journey and assess your progress. Identify areas where you have improved and areas that need further development. Setting goals and tracking your progress can keep you motivated and focused on continual improvement.
Create Value for Your Organization: Demonstrate the value of your Python skills by applying them to create tangible benefits for your organization. This could involve improving efficiency, reducing costs, or developing new products or services. Showcasing the practical impact of your work can help secure support and resources for further projects.
Document and Share Your Knowledge: Create comprehensive documentation for your projects and share your knowledge with the community. Writing detailed guides, tutorials, and blog posts can help others learn from your experiences and contribute to the collective knowledge base.
Thereβs a lot to chew on here but sometimes it helps to survey the entire landscape before you choose where to start digging.
Stay tuned for more on Flocode. Itβs been an extremely fun journey so far, especially the podcast.
Thank you to all subscribers, from each of the 142 countries around the world. Your perspectives and your insights are greatly appreciated.
See you in the next one.
James π