一名结构工程师学习Python的心路历程A Structural Engineer’s Journey Learning Python

上一文“ Python从YJK数据库读取荷载工况信息 ”主要是试试付费阅读的功能,后续可能会有一些付费的作品。在此感谢付费阅读的朋友们,希望读完的朋友能以一推三实现自己期望的数据库读取功能。感谢崔博士等好朋友帮忙分享转发。我写文比较随心,也无意广泛传播,更不想自诩为公知。13年毕业到15年左右那会还有很多“技术情怀”,15年后更注重提升自身技术能力,虽然情怀还在,但更多是内在的自我激励。我们知道,无论这个社会如何浮躁,但永远无法改变“胜者为王的社会”的这种残酷现实,各行各业都是如此,当我们欢闹嬉戏时候,总有一些优秀的人却还在努力锻造自身实力。我一直在向那些努力拼搏的人(小勇哥、崔博、陈博、吴博及我司各位大佬等)学习,今天来说说自己的编程学习之路。

从13年毕业至今,做了不少超限项目,除了去年做了20多个(主要是负责、指导和校对工作),其他几年基本都是每年十个左右(主要是广东地区按国标后,有一些原本按广高规不需做超限的现在要做了)。回头再看做这些项目的工作流程,只怪自己学Python太晚,到17年左右才真正掌握一些Python基本的读取功能,没学会编程之前自己就是纯手工操作,数据导入excel,然后用excel筛选数据,排序,然后用excel手动画图,调整曲线图的格式(我们公司有自己的模板,并严格执行公司的格式风格,对内容和格式都有严格的要求是显得公司更专业更有素养的表现之一)。如果有项目比较着急要,经常要搞得通宵达旦,如果项目有交叉,时间就更紧张了,连续好几天熬夜也是常有的事情,最终做出来的报告质量也是纰漏较多,校对修改的工作量比较大。这是我17年前的生活写照。后来学了VBA和Python以及C++,才真正实现“数据处理的自由和享受”。

其实我开始学Python的时间,是在研究生一年级(2011年那会)学ABAQUS的Python脚本开发,初步了解了一些Python的基本知识,当时的参考书是曹金凤《Python语言在Abaqus中的应用》第一版。现在出了第2版,多了不少新内容。

Anaconda Package Manager
图1:《Python语言在Abaqus中的应用》第二版目录

当时我课题是高层框筒结构减震,需要做实际减震项目的弹塑性时程分析。最初导师建议我用ABAQUS建模算弹塑性时程,但是由于没有现成的ABAQUS接口程序,所以当时虽然学了一点Python,因为没有怎么用就给放弃了,自己没什么编程基础以及时间,当时也没能力写PK转Aba接口(当时还没有yjk这个软件)。当时好电脑还是很贵,实验室也没很好的电脑跑ABAQUS,所以放弃了ABA,我最终选择用Perform3D。现在想来,如果没有当初放弃ABA,也不会有后来翻译p3d文档出书(上帝关上了一扇门,往往会打开另一扇窗。虽然最后回头看也不是很满意,但那段时光专注一件事投入所有时间和精力去做也是一件快乐的事情)。

当时Python还没像现在这么火热,我也没认识到它那么强大的第三方包。Python是开源语言,Python有很多开源的第三方包。我现在用的anaconda3,可以在清华镜像免费下载。

Anaconda Package Manager
图2:清华镜像网站

为什么用anaconda?因为它已经把各种包给配置好了,当然也有一些人觉得它包非常大,所以自己在python官网下载,然后自己用pip配置各种包,这也是一种方法,但是很容易会导致各种包不兼容的情况。原谅我在某些事情上不爱折腾。 anaconda默认的包是这样的。

Anaconda Package Manager
图3:Anaconda 包管理器

installed可以选择看到默认安装的包,虽然大部分都用不上,但是减少了自己配置的时间,还有人搭配pycharm一起用,也是挺好。最新版本的anaconda已经兼容了pycharm。但是我用spyder已经用习惯了。

Anaconda Package Manager
图4:Anaconda 可选编译器

spyder集成了常用了一些数据处理库,够用了。 写界面可以用PyQt,如果不想敲代码写界面,可以在anconda的安装路径下Anaconda3\Library\bin下找到designer.exe,利用designer拖拽绘制自己的界面,然后用命令行转换为代码,搞清楚pyqt的基本用法就行,这个部分要学习一些基础的东西,但是没有想象中那么难。

Anaconda Package Manager
图5:qt designer写UI界面

后来在网上找一些例子,学习了pyqt,也看了一些电子书,没有专门系统地学习PyQt,真的只需要搞懂一些基本的就好,甚至拿网上的例子改改就行。

这样下来,结构工程师达到的基本编程技能差不多是: (1)文本读写–我最初是vba来写,学习了一些vba的基本知识。后来Python很容易实现, (2)写出excel绘制图表–这部分我最开始是用VBA在excel里直接写的,vba是通过录制宏,实现一些excel的绘图和数据汇总功能。python需要调用xlsxwriter包。xlsxwriter包有非常详细的官方文档https://xlsxwriter.readthedocs.io/ ,可以根据所需要的格式来查具体的细节。 (3)读写数据库–这部分我主要是针对etabs的mdb数据库,要了解SQL数据库语言。 (4)写界面–如果自己用无所谓界面,可以忽略。 (5)客户端程序–这部分主要是针对有研发需求的工程师。考虑到运行效率,我现在改用c++来实现之前python实现的功能,实现的原理也基本是一样的,你会发现所有语言都是相通的,主要是实现功能的想法和思路,有时候我会先用Python写局部功能或测试想法。 (6)混合编程–这个是最近才学会的,最近写C++调用python脚本读取二进制的模块。

所有这些都是自学,不断提问,不断在google搜索答案,虽然也不一定能找到,但是自己也在不断思考积累,慢慢地可以写一些大程序(虽然没有系统架构,但是能顺畅跑起来应该没问题)。我现在依然还是会遇到不少bug和问题,但我现在跟之前有最大的不同就是不再害怕这些bug,克服了内心对代码和bug的恐惧了。我有时候也会因为一两个bug和功能实现卡一两天的时候,但是最终还是能解决,这样挺好,可以专注一件事是一件很好的事情。下面的视频号是演示的是我用C++编写的超限平台部分功能。

希望以上内容对你有所启发。 欢迎点赞转发,也欢迎不同的声音和意见,欢迎拍砖和留言。不知道下一期会是什么时候写了,如果有好的想法也欢迎提问,这篇先这样吧。最后祝各位阅读此文的朋友新春愉快,阖家幸福。

This article “Extracting Load Case Information from YJK Database Using Python” was primarily an experiment with paid reading functionality. Future paid content may follow. I sincerely appreciate those who supported the paid reading initiative. For readers who completed the article, I hope you can apply the techniques to develop your own database reading capabilities. Special thanks to Dr. Cui and other friends for sharing and promoting my work. My writing style remains personal and informal – I never aim for viral distribution or public intellectualism.

From 2013-2015, I still maintained strong “technical passion”. After 2015, my focus shifted toward technical skill development while retaining that passion as internal motivation. We must acknowledge: no matter how chaotic society becomes, the fundamental truth of “survival of the fittest” remains unchanged across industries. While we’re distracted by daily life, exceptional individuals continue forging their capabilities. I constantly learn from hardworking peers (Xiaoyong Ge, Dr. Cui, Dr. Chen, Dr. Wu, and senior colleagues) – let me share my programming journey.

Technical Evolution (2013-Present)

Since graduation, I’ve worked on numerous out-of-code projects:

  • 20+ projects in 2023 (primarily responsible for leadership, guidance, and verification)
  • ~10 projects/year historically (especially since Guangdong’s national code adoption created new requirements for previously non-out-of-code high-rise buildings)

Looking back at pre-Python workflows:

  • Manual data import to Excel
  • Laborious filtering/sorting
  • Tedious chart creation/adjustment per strict company templates
  • Frequent all-nighters during project overlaps
  • High error rates requiring extensive revisions

This changed after mastering VBA, Python, and C++ – finally achieving “data processing freedom”.

Early Programming Exposure

My first encounter with Python was during graduate studies (2011) through曹金凤’s Python Applications in Abaqus (now in its 2nd edition with expanded content). My thesis involved seismic reduction analysis for high-rise frame-core structures using ABAQUS. Though advised to use ABAQUS for elasto-plastic time-history analysis, I abandoned it due to:

  • Lack of existing ABAQUS interface programs
  • Insufficient programming foundation/time
  • No YJK software availability at the time

Hardware limitations also played a role – ABAQUS required expensive workstations. I eventually chose Perform3D instead. While not perfect, this “detour” led to translating P3D documentation into a published book. As they say: “When life closes a door, it opens a window.”

Python Ecosystem Development

Back then Python wasn’t as dominant as today. I now use Anaconda3 (freely available via Tsinghua Mirror) for its pre-configured package ecosystem:

  • Anaconda Package Manager
  • While some criticize its size, I prefer avoiding dependency hell through manual pip installations
  • Spyder became my IDE of choice despite PyCharm integration
  • Spyder IDE

For GUI development:

  • PyQt offers powerful capabilities
  • Use Anaconda’s built-in designer.exe for drag-and-drop interface creation
  • PyQt Designer
  • Learning curve isn’t as steep as imagined – modifying online examples works well

Structural Engineer’s Programming Roadmap

Through self-study, I developed essential skills:

  1. Text Processing: Initially with VBA, now Python
  2. Excel Chart Generation:
    • Formerly Excel VBA macros
    • Currently using xlsxwriter XlsxWriter Example
  3. Database Operations:
    • Focused on ETABS MDB databases
    • Requires SQL proficiency
  4. GUI Development: Optional for personal tools
  5. Client Applications:
    • Transitioned from Python to C++ for performance
    • Core logic principles remain consistent across languages
  6. Hybrid Programming:
    • Recently implemented C++ calling Python scripts for binary file reading

Learning Philosophy

All skills were self-taught through:

  • Persistent questioning
  • Google searches (success not guaranteed)
  • Gradual accumulation of knowledge

While I still encounter bugs, my mindset has changed:

  • No longer fear coding challenges
  • Comfortable spending days resolving complex issues
  • Enjoy focused problem-solving

The following video demonstrates my C++-developed out-of-code platform:

Final Thoughts

I hope this inspires fellow engineers. Comments, criticisms, and suggestions are always welcome. Wishing all readers a happy New Year and prosperous family!

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注