I got this error while trying to
pip3 install tensorflow. I tried
python3 -m pip install tensorflow as well — it didn't work.
ERROR: Could not find a version that satisfies the requirement tensorflow ERROR: No matching distribution found for tensorflow
As was my case, the reason for this error might be that you are using
pip from a Python version not yet supported by any version of TensorFlow. I was running Python 3.9 and TensorFlow only had compatibility up to Python 3.8. By creating a new environment with Python 3.8 (or reverting the current environment to use 3.8) I could
pip3 install tensorflow successfully.
There's a problem to solve, ideas to implement, and the result is often a usable artifact.
What has always put me off architecture is its slow nature. It might take years for big projects to go from ideation to design to construction to use. Yet tiny interventions (think small retrofits and interior designs) can be swift.
That's the joy of coding; you can formalize an idea into a usable prototype in a matter of minutes. Write code, run your program, then visualize and interact with your changes. When programming simple and interactive systems, you can see and use a functioning prototype from the early development stages.
Of course, I don't mean that it takes minutes to create complex programs, but that coding is a dynamic process that provides feedback as you make changes. Whereas large software projects might resemble architecture projects' slowness, small-scale architectural interventions might be as fun as prototyping with code.
About six months ago, Microsoft launched Pylance, a "fast and feature-rich language support for Python," available in the Visual Studio Code marketplace.
Pylance depends on our core Python extension and builds upon that experience, for those of you who have already installed it.
Among its main features are type information, auto-imports, multi-root workspace support, and type checking diagnostics.
The name Pylance serves as a nod to Monty Python’s Lancelot, who is the first knight to answer the bridgekeeper’s questions in the Holy Grail.
- User phone numbers
- Other people’s phone numbers stored in address books
- Profile names
- Profile pictures and
- Status message including when a user was last online
- Diagnostic data collected from app logs
Here are the 'Key Updates' that all users will need to accept before they take effect, on February 8, 2021, to continue using WhatsApp.
Last modified: January 04, 2021
- Better Communication With Businesses. Many businesses rely on WhatsApp to communicate with their customers and clients. We work with businesses that use Facebook or third parties to help store and better manage their communications with you on WhatsApp.
- Making It Easier To Connect. As part of the Facebook Companies, WhatsApp partners with Facebook to offer experiences and integrations across Facebook’s family of apps and products.
As I mentioned last week, I published 52 stories and sketches in 2020.
Here are the ten with the most views (in descending order).
What stories did you enjoy the most?
In 2020, billions of people wore a face mask to walk outside for the first time.
We've had to comply with full lockdowns, limited gatherings, and ever-changing curfews. We've reduced our travels and kept our trips as local as they can be. Christmas hasn't been our traditional holiday—a sense of fear and anxiety accompanies our gatherings with friends and family—and local restrictions forced many to spend salient dates apart from each other.
This publication is the last of the year, and I wanted to shift my focus from the bad to the positive, highlighting some of the good things I take from 2020.
At the turn of 2019, I published Twelve Grapes—a short reflection on temporal landmarks and New Year's resolutions. A few months later, I shared A Year of Transformation—a podcast about what I learned and changed in 2019.
I miss traveling and meeting with people face to face without the fear of being infected or infecting others.
As we enter 2021, companies and individuals will benefit from improved skills to work virtually1, yet I can only wish for things to get back to "normal."
Happy New Year!
Right before the turn of the year, I bring you a brand new episode that opens up the ALGO series—conversations between Jose Luis Garcia del Castillo y López and myself on topics such as teaching, coding, machine learning, and creativity.
It's been three years since I last interviewed Jose Luis, and I enjoyed learning how his life changed when he became a Doctor of Design, began teaching at Harvard, and started live-streaming his lectures online.
We also discuss the guilt of postponing things, the difficulties of delegating tasks and micro-management, the fear of shipping creative work, and lessons learned after forty podcast episodes.
Six hundred days ago, I began a quest to practice sketching, writing, and meditation—activities I enjoy doing that I want to cultivate. Even if only for a few minutes per day, I would engage in deliberate practice. Let me share some keys that might help you develop a practice to improve your skills.
Malcolm Gladwell repeatedly mentions the 10,000-hour rule in Outliers, a time that signifies how much practice you need to become proficient at a given skill. Of course, Gladwell didn't mean the time you practice is independent of talent or how you practice.1
As Cal Newport explains in Deep Work, two core components help identify deliberate practice: "(1) your attention is focused tightly on a specific skill you're trying to improve or an idea you're trying to master; (2) you receive feedback so you can correct your approach to keep your attention exactly where it's most productive."2 If you're not familiar with the term, Anders Ericsson coined it in the 1990s.2
The type of work experts do is as important as the time spent; you need to work through the right challenges to sharpen your skills.
In 2019, I interviewed Scott H. Young, author of Ultralearning, who shed some light on the issue. "There's a huge amount of research that shows that transferring skills from one domain to another is a lot more difficult than people think. Directness is, essentially, that when you are learning to do something, you want to tie your learning activities to the context in which you want to apply this skill later. If you are learning a language and you want to have conversations, you need to have conversations; if you are learning public speaking because you want to stand on stage and give speeches, you [have to] stand on stage and give speeches."3
In sketching, I won't get much better at drawing portraits if I spend the bulk of my time drawing buildings and objects; these are two distinct tasks. I'll acquire individual skills while I practice sketching buildings that might transfer and be useful when drawing portraits—say, noticing where lights and shadows are—but others won't—perspective drawings have nothing to do with drawing eyes and lips and ears. In Young's words, "you have to think about what you're trying to accomplish and how you're going to use it."4 That is the gist of directness, practicing the exact skills you want to get better at.
After almost two years of deliberate practice—which doesn't mean I wasn't practicing before but that I'm diligently practicing every day now—, some of my improvement is visible. I'm more comfortable writing; I'm more confident and less nervous interviewing guests on my podcast; and I find it easier to capture shapes, lights, and shadows when sketching. Paradoxically, these skills come more naturally the more I practice.
It's helpful to define your weaknesses and gather feedback from others from my experience, as they will inform the skills you need to practice. What are you trying to accomplish, and how are you going to use [your skill]? Young's question highlights the importance of knowing why you're practicing in the first place.
For me, it's all about improving my craft and inspiring others. My current commitments include writing two hundred words, meditating for ten minutes, and sketching something from reality every day. I use a habit tracker to track my progress, which helps me not "break the chain." I want to make sure I'm showing up and not missing one day. Regarding content publication, I aim to release a podcast episode per month, a sketch and story per week, and a live stream per week.
"When it's time to write, there will be days that you don't feel like typing. But stepping up when it's annoying or painful or draining to do so, that's what makes the difference between a professional and an amateur."5 In Atomic Habits, James Clear denotes the difference between the pro and the amateur. "Professionals stick to the schedule; amateurs let life get in the way."5 Jocelyn K. Glei also defines that professionalism in Manage Your Day-To-Day: "A professional is someone who can keep working at a high level of effort and ethics, no matter what is going on—for good or ill—around him or inside him. A professional shows up every day."6
For better or worse, I decided to formalize—or professionalize—my dearest hobbies. Publishing my work online makes it real, and I tend to take it more seriously this way. Even when I don't feel like practicing, I know that building the habit is more important than what I might write, sketch, or record on a given day. Days come from time to time, in which I can spend more time and focus. When I can't find the time to concentrate fully, for instance, I might meditate while I shower or walk, while other days I can sit for more than twenty minutes completely idle, without distractions. I might sketch something in two or three minutes or write to comply with my 200-word minimum during busy days but then spend hours drawing or writing when I can make time for it. Yet this only happens when you show up every day.
If you've read this far, you might be asking how you can incorporate these principles into your practice.
As I learned from my coach, it's best to define where you'd like to be one, two, or five years from now, and list the skills you need to develop to get there. That goal will determine the type of work and challenges you need to practice.
Show up every day, nurture your continued practice, focus on the tiny daily improvements, and enjoy. Ten thousand hours of training might take you far, but what matters are the hours you practice deliberately applying your skills as you want to use them in the future.
Newport, Cal. Deep Work: Rules for Focused Success in a Distracted World. 1st ed., Kindle version, Grand Central Publishing, 2016. ↩ ↩
Martínez–Alonso, Nono. "Getting Simple." Scott Young: Ultralearning, How to Master Hard Skills, Outsmart the Competition, and Accelerate Your Career, 6 August, 2019. ↩
Young, Scott, and James Clear. Ultralearning: Master Hard Skills, Outsmart the Competition, and Accelerate Your Career. Illustrated, Kindle version, Harper Business, 2019. ↩
Clear, James. Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones. Illustrated, Kindle version, Avery, 2018. ↩ ↩
99U, and Jocelyn Glei. Manage Your Day-to-Day: Build Your Routine, Find Your Focus, and Sharpen Your Creative Mind (99U). Kindle version, Amazon Publishing, 2013. ↩
We humans are social beings; we need to be around others, share our time and stories and gossip, the warmth of physical contact, and the display and feeling of love. It's in our nature. Since the internet's appearance, we've tried to fulfill this need with virtual calls, meetings, and gatherings—which render extremely useful in professional settings but don't suffice in our personal lives. We communicate in shallow ways via social media and instant messaging and connect more deeply through audio and video calls. Yet, all of this is insufficient for our well-being, and we often get a false sense of connection.
The big tech companies are working on immersive virtual and augmented realities to shorten the gap between the experience of in-person meetings and their virtual equivalents. Facebook Horizon lets you 'explore and create' collaboratively with virtual avatars. Apple—reportedly engineering a pair of augmented reality glasses, a headset along the lines of Google Glass and Microsoft HoloLens—is preparing to release augmented reality from the limitations of smartphones and tablets. In these environments, astonishing visuals would make participants believe they're in the same room, haptic feedback would fool their bodies into thinking they're touching objects, and brain waves could help them hallucinate the rest, ala Black Mirror.
If it were to reduce the risk of infecting ourselves and our loved ones during this (and future) pandemics while meeting our psychological and social needs, this scenario doesn't sound bad at all.
For now, nothing beats sitting together and holding each others' hands, even if wearing a face mask. But, of course, this isn't always a possibility.
As these immersive technologies improve, we'll rely on them more and more, replacing long-distance travel, hazardous physical interactions, and face masks with virtual gatherings and wearables.
Meanwhile, here's a reminder to myself: Protect what you have by being mindful and patient; better times lie ahead.
For the last episode of Getting Simple, I answered a question submitted by a listener: During your commute, do you listen to music or podcasts?
I'd love to hear from you. Ask a question.
You've probably seen this sign before. It means we're taking a break—a pause.
A straight "Closed for vacation" sign that keeps you off work during the holiday season.
On these dates, OPEN signs keep on-location workers away from their loved ones, and remote workers distracted, never fully present, always alert to potential notifications.
In the internet era, you have the option to do your homework, schedule your publications, switch off notifications, and be present.
That's the peace of mind of planning and automation.
I fixed a bug that sporadically made Spotify remove my show, the Getting Simple podcast, from its platform without any logical explanation and, more worrisome, without warnings or notifications.
Some time ago, I noticed the podcast's RSS feed displayed episode release dates localized in Chinese and other languages. Something that, to my eyes, seemed random. Yesterday, I finally identified the issue.
The XML feed is cached for thirty minutes at a time — a duration I set to avoid overloading the server by re-generating the feed on every request.
But this feed re-generation used the requesting party's "locale." This code corresponds to the language and region configured in the system that performs a web request. For instance, the
en-US locale represents a visitor or bot configured to use the English language and the United States region. A localized site — that can adjust its content to different locales — would display a date as
Wed, 02 Dec 2020 for
en-US visitors and as
Mié., 02 Dic. 2020 for
date('D, d M Y H:i:s O'); // returns "Wed, 02 Dec 2020 05:19:14 -0500"
date('D, d M Y H:i:s O') PHP method uses the operating system's language and region to determine what to display, but a localized website can adjust to the visitor's locale or even comply with explicit requirements.
App::setLocale('en-US'); // force locale to en-US Item::formatDate(Date::now(), 'D, d M Y H:i:s O') // returns "Wed, 02 Dec 2020 05:22:55 -0500" App::setLocale('es-ES'); // force locate to es-ES Item::formatDate(Date::now(), 'D, d M Y H:i:s O') // returns "Mié., 02 Dic. 2020 05:22:55 -0500"
The issue was that the re-generation of the podcast feed was dependent on the requesting agent's locale when the cache expired, which could be any user or bot. Spotify was pinging the podcast and could load a feed generated by an agent that used a locale other than English in the past thirty minutes.
App::setLocale('en-US'); // Generate episode timestamps here
When Spotify found dates were not in English, it removed the show altogether—something that Apple Podcasts and other networks didn't do—and then added the podcast back hours later, when episode dates were in English again.
Spotify took its time to reload all existing episodes after forcing the localization of episode timestamps to use the
en-US locale and re-generating the feed. Now all episodes and their stats are back. Hopefully, the show won't disappear again, and users won't hit this ugly, erroring embedded player.
I'm writing more than ever, but I still find it hard to hit my Tuesday posts' deadline.
I guess I'm lazy.
To me, the draft is playful and fun, but polishing for publication can be hard work.
I think I'm good at generating new ideas, consistently adding new post drafts to my to-do list.
Ever postponing the editing work, I would often publish new pieces—written from scratch—instead of editing existing drafts.
But there's no way out: it makes little to no sense to publish drafts, and I try to come back to the posts I've already started (which tend to become some of my best stories).
The important thing is to move forward; To practice daily, ship a new story every Tuesday, and enjoy how writing and publishing get easier, week by week.
In future posts, I'll share the tools and techniques that help me write more and better and the planning methods I'm experimenting with to consistently writing and publishing my weekly story.
In DigitalOcean, running the
do-release-upgrade command was returning the following message.
Checking for a new Ubuntu release Please install all available updates for your release before upgrading.
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade
shutdown -r now
You could stop here if all you want is to install available updates. Read the warning below to make sure you don't break your live applications and whether this is the best approach you can take.
WARNING: Please read this article by DigitalOcean on the potential pitfalls of upgrading an existing installation with your applications running on it. Instead of upgrading in-place, the recommended approach is to migrate your applications by creating a new, fresh instance with Ubuntu 20.04 LTS instead of upgrading an existing one. (Run at your own risk!)
Last month, I asked you for questions.
Among other questions, a listener from South Africa asked whether, during my commute, I listen to music or podcasts, and why. It's interesting as I've been working from home for the past two years and barely had to commute.
I chose this as the first podcast question and enjoyed answering it live. The episode will come out soon.
What's your take? Do you prefer to listen to music or podcasts?
If you want, you can reply to this email, send a voice note, or ask a question at gettingsimple.com/voice.
I'd love to hear from you.
For the last episode of Getting Simple, Roberto Molinos highlights the benefits of being patient and embracing uncertainty and shares a series of techniques, theories, and books that can help you rethink your company, market your products, and have a 4-day workweek.
Toggl Track is on. Every second counts toward the active task. But I'm frozen. The time block I allocated to this piece of work has ended, and I can't decide whether to continue or move onto the next item. Tasks often take longer than I initially thought.
What should I do? Time is ticking.
Andy Warhol's artworks have sold for millions of dollars. His most famous works—think of Campbell's Soup Cans (1962) and Marylin Diptych (1962)—are limited edition paintings. Campbell's Soup Cans' piece consists of 32 images produced over five months1, and Marilyn Monroe's artwork consists of 50 portraits.2
After hand-painting thirty-two soup cans by hand, Warhol moved to photo-silkscreen, a printmaking technique originally invented for commercial use that allowed Warhol and other artists to create reproductions of the same artwork using a silkscreen.3
Warhol painted the soup cans with acrylic paint. Each canvas corresponded to a soup variety sold by Campbell's back in the 1960s.
Screen printing speeds up the reproduction of an artwork. Once the silkscreen is ready, colors are applied, one by one, using a squeegee to push the ink through the mesh screen4, either by hand or automatically with a machine, a process being used at the time to mass-produce advertisements.3
"I don't think art should be only for the select few," Warhol claimed, "I think it should be for the mass of the American people."
Nowadays, we could argue this vision is a reality. Large corporations and artisans deploy a wide range of mediums to automate what used to be done by hand, producing goods en masse, lessening their price and uniqueness while improving its quality and availability. You can buy a ready-to-hang print of Vang Goh's The Starry Night at IKEA for $49.99 while the Museum of Modern Art in Midtown Manhattan shields and exhibits the original painting.
Contrary to his statement, Warhol created artwork for the selected few that could pay for it. In 2007, a 1964 Large Campbell's Soup Can sold for $7.4 million, and Silver Car Crash sold for $105.4 million in 2013.
Aesthetics and taste aside, it's all about the story behind each piece.
Who made it, why, and in what context?
Campell's Soup Cans. (n.d.). In Wikipedia. Retrieved November 9, 2020.
Today, I bring you an episode that celebrates a year and a half of weekly sketches and stories. At the time I published this essay on my blog, I was at fifty-three publications. But as I write these lines, I'm at seventy-one posts. Happy Newsletter-versary!
The Amazon Web Services (AWS) command-line interface — the
awscli — lets you update the code of a Lambda function right from the cli. Here's how.
aws lambda update-function-code \ --function-name my-function-name \ --region us-west-2 \ --zip-file fileb://lambda.zip
Let's understand what you need to run this command.
aws lambda update-function-code- to execute this command you need the
awscliinstalled on your machine and your authentication information has to be configured to your account
--function-name- this is the name of an existing Lambda function in your AWS account
--region- the region in which your Lambda lives (in this case, it's Oregon, whose code is
us-west-2, you can see a list of regions and their codes here)
--zip-file- this is the path to your zipped Lambda code with the
fileb://prefix, in the example, there's a
lambda.zipfile in the current directory, alternatively you can use the
--s3-keyto use a zip file from an S3 bucket)
In a quest to spend more time writing and less time sharing online what I write, I developed an automated workflow to share my posts on social media with minimal effort.
What used to take me up to ninety minutes per week happens now automatically.
I can focus on sketching and writing while the machine takes care of formerly-manual labor.
I sketch and write daily, pairing up my sketches and essays as little stories. I have to manually scan and edit my drawings, as well as polish my writing drafts and translate them into Spanish. I then upload the sketch and story to my website and schedule them for publication.
On the publication date, a series of automated events take place.
Let's see what those are.
First, the story shows up on my RSS feed — a standardized system to distribute content online so users and applications can receive updates1 — which contains all my publications. The story also appears on the main page of my website, at Nono.MA, and on my sketches page, Sketch.Nono.MA.
In the early morning of the scheduled date, a Mailchimp newsletter campaign reads my RSS feed and sends the Spanish version via email to Spanish subscribers. Later that day, early morning in the United States, another newsletter campaign emails the original English story. (The one you're reading now.)
The same feed is read by Zapier, an online service I've configured to share my weekly sketch and story on multiple social media accounts, including Facebook, Twitter, Tumblr, LinkedIn, and Instagram.
The post is shared on two Facebook pages, two Twitter accounts, two Instagram accounts, one Tumblr account, and my personal LinkedIn profile, and scheduled to be re-shared on Twitter on Friday, two weeks later, using Buffer. An image-processing and optimization service called Imgix resizes my sketch's canvas to be shared as a square image on Instagram.
Two optional manual steps make this process feel a bit more human: sharing on Hacker News, something I might not want to do every week, and sharing on my Facebook timeline. (Neither Hacker News nor Facebook's API let you automate this step.)
Sharing each story used to steal ten to ninety minutes of my time.
Now my job is to supervise the pipeline works and make little adjustments here and there.
I can focus on sketching and writing.
I've recently started answering reader and listener questions on my podcast.
I encourage you to ask me anything related to the topics I write about on this newsletter and talk about on the Getting Simple podcast.
Go to gettingsimple.com/question and hit record.
I'd love to hear from you.
For the last episode of Getting Simple, I had the chance to talk to Microsoft's Adam Menges, former employee at Apple and founder at Lobe.ai, a company that helps people build intelligence into their apps by making it simple and understandable.
Tune in to discover Adam's unconventional education and career, why he strives to have death present in his day-to-day, and his life hacks and daily routines, including custom-made clothing, note-taking and file-management workflows, meditation, and much more.
The compact disc—the CD—was co-developed by Philips and Sony back in the 1980s.1 This format was initially developed to store and play music but was then adapted to what we know as the CD-ROM to store data as well, and other formats followed that allowed us to read and write different kinds of data.
In 1995, Microsoft shipped Windows 95 as a CD-ROM and also as a pack of 13 or 26 floppy disks for compatibility with older computers that didn't have a compact disc reader. The entire Windows 95 operating system was only around 22 to 24 megabytes. (More than four times smaller than Instagram for iPhone!)
Priced at dozens or hundreds of dollars, software used to come packed in a huge box. The lucky software, the one that could afford the development costs, would update every couple of years. Windows 95, for instance, released a few updates and patches in 1996 and 1997, while Windows 98 was cooking.
The transaction happened at a physical store where we were buying something tangible: a program packed in a box.
The Office Suite—Microsoft Word, Excel, and PowerPoint—was bought in a box and installed in your machine with a CD. Every time you formatted your computer or bought a new one, you would come back to those CDs and re-install the software. Office 2003. 2009. 2013. These updates demarcated the appearance of file formats and new functionality that wouldn't work in older versions.
Today you buy a phone with a set of preinstalled apps and, right at your fingertips, you have an app store. With a payment method, you can make a transaction with a finger tap, your fingerprint, or a scan of your face. The app starts installing right away. Maybe free, maybe a couple of dollars. This world is cheaper but gets more and more expensive as we transition into a subscription model. And stores are not only on your phone but on your tablet, laptop, browser, and even on your photo camera or game console.
We get notified of new versions of the apps we use daily. And there's a culture of constant improvement in which applications like Dropbox, Spotify, or Uber release a new version weekly or bi-weekly to keep up-to-date.
At any stage, software bugs can be introduced, existing ones fixed, and new functionality added. We used to have a program that would continue to work the same way for years. But we now have what's called liquid software. Ever-changing code and hundreds of version numbers. (Dropbox is up to version 107.4.443 as I write these lines!)
We're in an era of constant updates, and there's no way back. If there's a bug today, we expect a fix tomorrow. A patch, an update. The problem comes when we can't say no and need to keep programs up-to-date to run on the latest operating systems that would otherwise stop functioning.
In the mobile world, there's a chance that you never upgrade and use a fixed set of functionality. But the web is different. When you load a website, it might have been re-deployed. A new version, updated seconds ago, runs in your browser. The red button you used yesterday to send an email might have changed its place, color, or shape overnight. A piece of functionality you liked (or the annoying bug you had yesterday) might suddenly go away.
An alternative might be to use custom systems or systems with slower update cycles in which backward compatibility is a priority.
Yet it's unlikely we'll ever go back to the once-a-year update, the diskette, or the CD.
With automations in place, the need to spend time on manual tasks disappears; you can do more in less time and your duties are delegated to the machine, which completes them in the background while you do other things. You're free to move onto new endeavors. As John Maeda says, "Savings in time feel like simplicity."
I guess you'd agree with me that, while the job of scribes was fundamental for spreading knowledge back when printers didn't exist, there's no point in copying documents by hand today.
Automation shifts our perception of what we do and augments our production capacity, often devaluing the human labor involved.
When the technology allows for it, we relegate essential tasks to automated systems which don't require any human input, while other tasks—less important but harder to automate—end up filling the bulk of our time with manual labor.
Effortless automated processes are easy to underestimate. One click and you've got access to millions of online publications, books, and other content. One more click and the book is sent to your Kindle, printed at home, or shipped to your house.
If it can be automated, it will.
However, it's important to remember that the amount of labor involved to complete a task—or the lack thereof—doesn't determine its importance, and that the time and effort required to perform a task heavily depends on skill.
Even when we assign excessive value to processes that involve manual labor, the importance and necessity of a task should be defined with independence of the amount of hours required to complete it and its complexity.
Still, difficulty and expertise highly determine how much you'll get paid for work and, as more and more processes are automated, we'll have a harder time finding jobs that pay well.
This trend to delegate processes to the machine contributes to the undervaluation of manual work, except when the human factor provides something different that makes it unique.
To write text to a file using Python, you can either append text or overwrite all existing contents with new text.
To append text, open the file in
append mode, write to it to add lines of text, and close it.
file = open('/path/to/file.txt', 'a') # 'a' is append-to-end-of-file mode file.write('Adding text to this document.') file.close()
You can also write the entire contents of the files, overwriting any existing content using the
w mode instead of
file = open('/path/to/file.txt', 'w') # 'w' is overwrite mode file.write('This will override any existing content in the text to this document.') file.close()
You can use
\n and other codes to add line breaks to your document.
file = open('/path/to/file.txt', 'w') # 'w' is overwrite mode file.write('First line.\nSecond line.\nThird line.\n\nNono.MA') file.close()
# file.txt First line. Second line. Third line. Nono.MA
To determine whether a file or directory exists using Python you can use either the
os.path or the
os library offers three methods:
import os # Returns True if file or dir exists os.path.exists('/path/to/file/or/dir') # Returns True if exists and is a file os.path.isfile('/path/to/file/or/dir') # Returns True if exists and is a directory os.path.isdir()
pathlib library has many methods (not covered here) but the
pathlib.Path('/path/to/file').exists() also does the job.
import pathlib file = pathlib.Path('/path/to/file') # Returns True if file or dir exists file.exists()
Before the invention of printing, professional scribes copied manuscripts by hand. Woodblock printing, movable type, etching, and other inventions preceded the printing press, in our efforts to automate such a labor-intensive task as the duplication and production of text documents.
It would be hard to make a living rewriting books with pen nowadays. Printers and the internet make it easy and cheap to reproduce text documents or ship books to your house.
If we were to travel back in time and gifted a professional copyist a printer, they'd probably lit it on fire. I wonder how their life would change if, instead of burning the printer, they decided to use it.
When manipulating semantic segmentation datasets, I found myself having to downsize segmentation masks without adding extra colors. If the image is cleanly encoded as a PNG, only the colors representing each of the classes contained in the label map will be present, and no antialias intermediate colors will exist in the image.
When resizing, though, antialias might add artifacts to your images to soften the edges, adding new colors that don't belong to any class in the label map. We can overcome this problem loading (or decoding) input images with TensorFlow as PNG and resizing our images with TensorFlow's
NEAREST_NEIGHBOR resizing method.
import tensorflow as tf # Read image file img = tf.io.read_file('/path/to/input/image.png') # Decode as PNG img = tf.io.decode_png( img, channels=3, dtype=tf.uint8 ) # Resize using nearest neighbor to avoid adding new colors # For that purpose, antialias is ignored with this resize method img = tf.image.resize( img, (128, 128), # (width, height) antialias=False, # Ignored when using NEAREST_NEIGHBOR method=tf.image.ResizeMethod.NEAREST_NEIGHBOR ) # Save the resize image back to PNG tf.keras.preprocessing.image.save_img( '/path/to/output/image.png', img )
..they'd probably be surprised by how you do certain things.
Things they never thought of doing that way and assumed everyone else did differently.
What would you surprise us with?