Paolo Amoroso's Journal

Python

If you lived through the personal computer revolution of the 1980s, you may have read some books that got you hooked with programming. These works led the reader through the intellectual adventure of using computing to explore interesting problem domains.

Two recent Python books bring back this fascination and excitement with programming, Impractical Python Projects: Playful Programming Activities to Make You Smarter and the sequel Real-World Python: A Hacker's Guide to Solving Problems with Code, both by Lee Vaughan and published by No Starch Press.

They are not Python tutorials or guides. Instead, they present stimulating coding projects for non-programmers who want to use Python for doing experiments, test theories, or simulate natural phenomena. This includes professionals who are not software developers but use programming to solve problems in science and engineering. And, of course, hobbyists.

Exploring and understanding the problem domain is an integral part of the books' projects along with coding. This is unlike typical programming books where the examples are often trivial, have little or no domain depth, and are stripped of everything but the essentials.

The science and engineering Vaughan's books cover include some great projects that match my interest in astronomy and space. For example, Impractical Python Projects has chapters on estimating alien civilizations, simulating a volcano on Jupiter’s moon Io, simulating orbital maneuvers, and stacking planetary images. Real-World Python discusses re-discovering Pluto, plotting the Apollo 8 lunar trajectory, selecting martian landing sites, and detecting exoplanets.

The sample code is straightforward, clear, and hints at how much can be done with little code. Since the books are not language tutorials, they focus on prototyping and exploration rather than building large and maintainable systems.

#Python #books

Discuss... | Reply by email...

First reading about Flet made me jump over my chair as it's what I was long looking for, a solution to my web and Android development needs. Flet is an opinionated, Flutter-based GUI framework for creating multi-user web, desktop, and mobile applications.

What I was looking for is an easy way of creating simple web and Android apps in Python. Web frameworks such as Django are overkill and too low level for me, and in most cases require JavaScript or other non-Python frontend code.

As for mobile, although there are Python frameworks for Android development like Kiwi and BeeWare, they come with the ballast of a heavy Java and Android SDK toolchain.

Flet overcomes these issues. It enables creating web apps that hide a web framework under the hood. And, without touching Java, Flet can make also PWAs that run on Android and other mobile platforms. All from the same fully Python code base. Plus, deploying Flet web apps to my favorite Python environment, Replit, is well supported and straightforward.

I'm closely following the development of Flet and will experiment with the framework.

#Android #Python

Discuss... | Reply by email...

I decided what to work on next on Suite8080, the suite of Intel 8080 Assembly cross-development tools I'm writing in Python. I'll add two features, the ability for the assembler to trim trailing uninitialized data and a macro assembler script.

Trimming uninitialized data

Consider this 8080 Assembly code, which declares a 1024 bytes uninitialized data area at the end of the program:

# . . .

data:        ds    1024
             end

For this ds directive, the Suite8080 assembler asm80 emits a sequence of 1024 null bytes at the end of the binary program. The executable file is thus longer and may be slower to load on the host system, typically CP/M.

The Digital Research CP/M assemblers, ASM.COM and MAC.COM, strip such trailing uninitialized data from binaries. After asking for feedback to r/asm, I decided to do the same with asm80. I should be able to implement this optimization by adding just one line of Python, so the feature is a low-hanging fruit.

Macro assembler

asm80 can accept source files from standard input, which makes it possible to combine the assembler with an external macro preprocessor to get a macro assembler. Thanks to its ubiquity, M4 is the clear choice for a preprocessor.

Assuming prog.asm is an 8080 Assembly source file containing M4 macros, this shell pipe can assemble it with asm80:

$ cat prog.asm | m4 | asm80 - -o prog.com

The - option accepts input from standard input and -o sets the file name of the output binary program.

The other Suite8080 feature I'm going to implement is a mac80 helper script in Python to wrap such a shell pipe and make assembling macro files more convenient. In other words, syntactic sugar wrapping asm80 and M4.

The script will use the Python subprocess module to set up the pipe, feed the proprocessed source to the assembler, and not much else.

#Suite8080 #Python

Discuss... | Reply by email...

The Python feed of my old blog Moonshots Beyond the Cloud has long been aggregated by Planet Python. But I'm no longer going to update that blog, so I removed the old feed from Planet Python and submitted the Python feed of my new blog, Paolo Amoroso's Journal.

#Python #blogging

Discuss... | Reply by email...

It all started when I added a new Intel 8080 Assembly demo to Suite8080. Pushing the commit to the GitHub repo triggered a rebuild of the project documentation hosted on Read The Docs, which failed.

I maintain the Suite8080 documentation with Jupyter Book and publish it to Read The Docs with Sphinx as the backend.

Over the previous months, while my work on Suite8080 was on hold, some backward incompatible Jupyter Book update broke the Suite8080 documentation configuration. I had no idea what to do, so I opened a Read The Docs issue. After some troubleshooting with the help of Manuel Kaufmann, Benjamin Balder Bach contributed a Suite8080 pull request that fixed the issue.

Benjamin's patch has an additional advantage. I no longer have to manually edit conf.py to let sphinx.ext.autodoc discover the project's Python packages.

#Suite8080 #Python

Discuss... | Reply by email...

The GitHub repo of my Free Python Books project is about to get 3.5K stars. As I write this it has 3,499 stars, 448 forks, and 149 watches.

This milestone is mind blowing, humbling, and unexpected.

The project is a categorized list of Python books that are free to read or download. Despite the simplicity, something in the resource resonates with many Python developers and enthusiasts.

It all started as a personal list of books I discovered while learning Python, which I wanted to read later or reference. I shared the early list on Reddit and it snowballed from there.

I'm happy also because this success hints there are many learners who, in the age of video, still seek books and text resources.

#Python #books

Discuss... | Reply by email...

What I anticipated and planned for is happening.

After the great momentum of the initial work on Suite8080, I set it aside for a couple of months. Now I'm about to resume work on the project and wonder how hard it'll be to dive back into the Python code and continue development.

I tried to prepare for this by documenting the system and commenting the code. I also took many notes on to-do items, features I'd like to add, and ways to implement them. At a few thousand lines, the code base is small and I hope it won't be too difficult to understand and change.

Still, I'm a Python beginner and my code is tightly coupled, fragile, not modular, and hard to extend.

Suite8080 is a suite of Intel 8080 Assembly cross-development tools I'm writing in Python.

#Python #Suite8080

Discuss... | Reply by email...

I released version 0.5.0 of Suite8080, a suite of Intel 8080 Assembly cross-development tools I'm writing in Python. Although still in an early stage, this version makes Suite8080 gain enough functionality to be useful in a variety of Assembly applications.

In my next steps I'm going to focus on two areas of improvement.

First, I'll write more 8080 programs to process with the Suite8080 assembler and run on emulated CP/M systems or actual hardware. After all, this is the fun part I began the project for.

The Suite8080 Python sources are still a tangled mess of tightly-coupled, unencapsulated, beginner code with global state that makes it difficult to add new features or change existing ones. Therefore, the other area of improvement I'll work on is a major redesign. This should make the code easier to work with and extend.

#Python #Suite8080

Discuss... | Reply by email...

I extended the Suite8080 assembler to allow the ds directive to take a label as an operand. The label, which must be defined before use, may be in uppercase. I also broke into subsections the section of the documentation about the assembler limitations, as well as mentioning the limitations of org and ds.

This hopefully concludes the work to make the assembler accept uppercase identifiers such as instruction mnemonics, labels, and constants.

Suite8080 is a suite of Intel 8080 Assembly cross-development tools I'm writing in Python.

#Suite8080 #Python

Discuss... | Reply by email...

Once I fixed the Suite8080 assembler to let db accept uppercase symbols, I was ready to work on a similar fix for dw.

But I got dw uppercase support for free as a side effect of canonicalizing symbols to lowercase when adding 16-bit words to the symbol table, as dw already converted symbols to lowercase before checking for inclusion in the table. This unlocked uppercase symbol support, again for free, for most other 8080 instructions that take an address operand such as lhld, shld, lda, sta, jmp, and more.

#Suite8080 #Python

Discuss... | Reply by email...