Bus Simulator 21 Coming to the Xbox Family in 2021
Hey everyone!
Today I’m extremely thrilled to reveal the newest addition to the popular Bus Simulator franchise: Bus Simulator 21. Discover new officially licensed bus brands, fresh features as well as a brand-new open world set in the United States! Get ready for the richest game of the series to date with numerous officially licensed buses by world-famous brands such as Alexander Dennis. More brands and buses will be revealed at a later point in time. The most modern vehicle fleet awaits you featuring the introduction of a double decker and electric buses for the very first time.
Discover Angel Shores, inspired by the sunny San Francisco Bay Area, and drive the American Dream in this fresh setting. Explore the industrial district, the peripheral areas, downtown or Chinatown in an even larger open world, and live your best life as a bus driver. In case you are feeling homesick, you can still revisit Seaside Valley from the current Bus Simulator containing also the new districts provided with the Official Map Extension.
Create and evaluate your own route network in the cooperative multiplayer and build up your transport empire together with your friends. Experience even more freedom with the game’s refined management systems, numerous new and expanded features, and the option of setting up detailed timetables for your own bus fleet for the first time ever. If you do not feel like taking care of your company’s micromanagement and prefer to only drive, just like a true bus enthusiast, you can have the reliable AI handle all the planning tasks.
WithBus Simulator 21you can look forward to the fullest bus driving experience we have ever built. We are eagerly awaiting the release in 2021 to embrace you on the streets of Angel Shores. For more information, please visit our official website: https://bus21.bussimulator-game.com
Ex-Riot devs launch multiplayer game studio Odyssey Interactive in Canada
A team of game makers who used to work at Riot Games have raised roughly $6 million in seed funding to open Odyssey Interactive, a new Canadian game studio that aims to build competitive multiplayer games.
Notably, the company says its looking to hire folks interested in building those sorts of experiences for mobile devices as it spins up operations in the Kitchener-Waterloo area of Ontario.
Odyssey’s founding members all have prior experience working at Riot on League of Legends and Teamfight Tactics. Now that they’ve raised $6 million from investors like Andreessen Horowitz and Golden Ventures they (according to a press release) plan to “get the studio off the ground, hire a team of rockstars, and take a few stabs at making some hopefully pretty awesome games.”
Don’t Miss: Beyond the HONK – an Untitled Goose Game Q& A
Everyone seems to be honking a bit more than usual with the recent release of House House’s brilliant Untitled Goose Game, a game where you take control of a horrible goose who terrorizes the unwitting members of a small town.
House House’s Nico Disseldorp, programmer on the game, recently answered our goose-related questions.
Gamasutra: Who are you, what is House House, and what is Untitled Goose Game?
Nico Disseldorp: House House is four people; Nico Disseldorp (me), Michael McMaster, Jake Strasser and Stuart Gillespie-Cook. While we each have specialties in terms of the day to day work we do (I’m the programmer) I would say the more important part of our job is the bit where talk everything through together. Everything is decided by consensus, so the four of us choose together how the game comes out.
The four of us were friends before we had ever made video games, and we started making our first game Push Me Pull You because it sounded like a good way to spend some time together. That game caught a few people’s attention and things very slowly snowballed and we eventually became a video game company.
This goose game is one where you play as a horrible goose who tries to ruin everyone’s day. The game started with that premise, and we just kept trying to think of funny things for a goose to do, and funny ways for people to react, until eventually a game started to solidify around the idea.
Untitled Goose Game was made by more than just the four of us. We also worked with Em Halberstadt, who was the sound designer, Kalonica Quigley, who did additional art and animation work, Dan Golding, who made the music and Cherie Davison, who programmed the rebindable controls.
Gamasutra: Untitled Goose Game first hit the scene nearly two years ago, in a memorable YouTube video that got passed around a number of sites. How useful has been social media in publicizing and promoting the game?
Disseldorp: That video was made by Jake, who is also one of the developers. He has a background in film and TV, so trailer work comes pretty naturally to him. The video itself was thrown together quite quickly with a bit of an assumption that not many people would see it. In hindsight I think “not overthinking it” probably helped the video in a few different ways.
After we posted the video online it was quite popular, and something strange happened where places were reposting it more like it was from the “funny video” category rather than the “game trailer” category. Maybe the fact that the game didn’t have a name helped? The video’s big success was a surprise to us and definitely changed our perception of the game we were making.
Our general social media strategy is to avoid thinking about social media as much as possible. We want to stay focused on making the game. But we know that Jake is good at making videos, so we generally try to ignore social media day to day, until we have something to say, like a platform or release date announcement, and then do a video about it.
Despite often feeling like we should tweet more, I think this has worked out pretty well for us. Once someone told me they really liked how “mysterious” our social media presence was, which seemed very generous. I would have said “inattentive.”
Gamasutra: The tone of the game is remarkable. No one speaks, but their mannerisms speak volumes about what they’re like. What inspired this little bubble of life? Were you worried about making a more low-key kind of humorous game? Was there any temptation to make it a bit broader?
Disseldorp: The whole idea for the game started with this realization that a person having to interact with a scary goose was this very normal, grounded conflict. Getting chased by a goose is absurd, but it really does happen to people all the time. So for us the mundaneness, or everydayness of the situation was very important.
Every now and then during development we’d come up with an idea for something bigger, like mucking up a wedding for example, but we’d always let those ideas go because we wanted to make sure that it felt like this was a very normal day in the character’s lives. Anything out of the ordinary is the result of the goose.
I guess this aversion to escalation also helps with the structure of the game we wanted. The human characters are able to tidy up most messes and put things back to normal again, giving the goose a chance to play the same tricks over and over. The mischief is a bit cyclical.
Gamasutra: Each character has the things they care about, and their way of reacting when those things are upset. How did you create and refine this emergent gameplay? How much iteration did you do upon it, and how did it change through development? And when did you realize that the game was really funny, and how did you isolate and refine the humor?
Disseldorp: We didn’t have too much of an up front plan about how all this stuff would work. In that sense it was very iterative. We started with the premise “you are a horrible goose” and some vague ideas like “the goose could steal stuff from people” that sounded like they might be funny, and then had to work backwards and add systems that could support the moments we wanted.
We did this by making a single AI character (the precursor of our groundskeeper) and just slowly adding behavior that felt like it could contribute to the situations we wanted. One of the first things we did was give them a few items that the goose could steal, and made it so they would chase after the goose to get them back. At this point we didn’t have any sense of the game’s wider game progression or if there would be any goals, we just kept trying to add things the would make stealing things feel better.
Eventually this led us to add idle loops where people would use their items, reaction animations for state transitions, vision cones, remembered positions, thought bubbles. In hindsight obviously lots of these things took inspiration from stealth games, but we picked them up one at a time just because they seemed right for the kind of small scale interactions we wanted.
Gamasutra: It’s not been remarked upon much so far, but those who pay attention will note it: the interactive musical accompaniment is amazing. It has what I think is the best procedural soundtrack I’ve ever heard…How [the soundtrack] adapts to the current situation; how it’ll delay beats in search of the perfect time to add a note of punctuation; how it’ll sometimes seem triumphant when the goose pulls off the heist of some knickknack; how the themes of different characters will start playing as you change areas; and so on. What else can it do, and how did you manage to accomplish all this? Is a soundtrack in the offing?
Disseldorp: The story of the game’s music started when early on we realized that we liked how the game felt alongside these old solo piano pieces from Debussy’s Preludes. They reminded us of silent films or “micky-mousing” in cartoons, but were a bit softer, and conveniently these compositions were in the public domain, so we were allowed to use them.
We decided to use Debussy as some trailer music, and asked Dan Golding (who did the music for Push Me Pull You as well) if he could make us a new recording for the trailer. That trailer turned out to be very popular, and one thing that people kept remarking on was how much they liked the “reactive” music. This was a misunderstanding and the music was not reactive (we had cut the trailer to the music and not the other way around) but there was something about the way that particular track jumped around with disjointed phrases that really let people believe the music was reactive.
Optimistically (and perhaps naively) this made us wonder if we could maybe just do what people thought we were doing, and play the different parts of the Debussy piece in a disjointed way, reacting to what the player was doing. We figured that if it worked correctly, it could feel like a piano player was accompanying your game session live.
It took us a few different attempts to find a solution that worked, but we ended up with something we are very happy with. The final system has two versions of each track; one that sounds like the original composition, and another “low energy” version that plays in a more subdued way. Dan has split each version into hundreds of different audio files that each represent about two beats of music. Depending on the action on screen, we can then have the music seamlessly move between playing the high or low energy versions, or to pause on silence for a while. At any given moment there are only two possible audio files that could play next, but because there’s lots of room to jump up to a higher energy or down to a lower energy or to silence it’s easy for the game to make a perfectly timed change in energy that feels very deliberate and specific.
There will be a soundtrack (soon hopefully) but there is still a bit to figure out about how it will work. Obviously in the game the music plays differently each time, whereas on a soundtrack there will be one version that’s the same every time. I think Dan has some good ideas about how to do it and I’m looking forward to the end results.
Gamasutra: Examining the old trailer from 2017 shows a few minor differences. One of them is that the game is, subtly, a bit fuller in terms of non-soundtrack music. The quiet “fwap” of the goose’s footsteps is new, and the goose’s voice is a lot more realistic (before it was kind of a rough quack). I’ve also noticed that the radios in the game have multiple stations. How important was it to you to get the sound right, and how much of the effort of making the game went into it?
Disseldorp: That old trailer uses placeholder sounds sourced by us from royalty-free online collections.
In 2018 Em Halberstadt come on board and replaced everything with the sounds you hear today. She was extremely thorough and really went overboard finding different places for unique sounds. As just one example, there are maybe 160 or so unique objects in the game, and all of them have unique sounds for being picked up, getting dropped, clanging on concrete, thudding on the grass, getting dragged around on different surfaces. It’s incredible to me. The end result is something very playful, where simply touching everything in the game is kind of a game in itself, just to see what kinds of sounds each object will make.
Gamasutra: Interactions between unexpected things helps keep players coming back a time or two for more after finishing the main course. Although I was a bit sad that you couldn’t get the old man to wear the groundskeeper’s hat (yes, I tried), I was pleased to find that hiding in the box in the Neat Neighbor’s yard resulted in getting thrown over the fence! Many of these things are highlighted with items on the game-end to-do list.
Were all of these things ultimately planned, or did a few interactions emerge from the properties of the items? Were you yourselves surprised by any interactions? Are there any special interactions you’d like to draw attention to?
Disseldorp: These types of things were a mix between systemic stuff that worked for everything once it was set up and lots of handcrafted solutions where we tried to anticipate what else people might try, or might believe would work. We’ve been happy to keep the boundaries between the two pretty vague, so it’s not always obvious to a player what’s “core behavior” and what is more handcrafted.
Filling in edge cases where something felt like it “should” work was important to keep people believing in things they wanted to try. Our whole game relies on people believing that their silly ideas might just work, so if we had a rule like “you can steal someone’s slippers when their feet are off the ground,” then we had to find other situations where the slippers were off the ground and make the slippers steal-able then as well.
I don’t think we added many things specifically for the post-credits to-do lists. Our approach to them was just to think of interesting things you could already do in the game and just write them down.
Now that people are playing the game at home, some things have definitely surprised us. We’ve watched a few videos or streams in the last week and said “I didn’t know you could do that” after someone breaks the broom by tug of warring with a different character or something.
At the same time, we knew we could never cover every possibility, some things players might want might not work for technical reasons, or we didn’t have the time to make them work in that way. So we had to signal to players that some stuff won’t work as well. For example, one of the first objects you come across in the game is a bright red lawn mower that looks like it could be turned on. We never ended up adding interactions for it, but left it in the level because we found that it was a nice way to calibrate expectations. In this game lots of stuff will work, but some stuff won’t and that’s okay.
Gamasutra: It seems, to me, that a lot of Untitled Goose Game‘s charm and fun comes from the unwieldiness of the goose itself…Yet the goose controls well; it’s the perfect mix of awkward and capable, and despite how flexible and adaptable its model is, it always looks and feels, not like a model, but like a natural, realistic goose, which makes a couple of the extra objectives, like “Score a goal,” a lot trickier. How did you model the goose’s appearance and control?
Disseldorp: Controlling the goose requires a bit more active attention to low-level things like reaching and moving than in lots of comparable games. I find this type of complexity does a lot to shift the scale of the interactions towards a smaller scale. Things that might be so trivial as to not be worth mentioning in some games, like “walk over there and pick up that item” are made slightly more physical and interesting. It’s enough that you could say someone did a good job or a bad job of it.
The extreme of this type of small scale movement focus is a game like QWOP, where movement is nearly impossible and to walk at all is a huge accomplishment. For the goose I think we try to use that same ingredient but just add the tiniest bit. It’s like 1 percent QWOP.
To make a bit of a broader claim, I think this is about avoiding artifice. In lots of games movement is assumed to be trivial, and the challenge comes from something more genre-based, like shooting or jumping or whatever. But those things can lead to a game where the character seems really natural most of the time but then has to kill a hundred people and jump over heaps of boxes for some reason. One way to avoid this is to make a game without that kind of challenge, like a walking simulator, and for us we tried to put the challenge into other places. So we have slightly more complex movement, more obtuse clues, that sort of thing.
Disney+ to offer ‘Mulan’ as $30 in-app purchase on iOS, Apple TV
Disney on Friday announced distribution plans for the hotly anticipated live action remake of “Mulan,” saying the VOD release will be available to Disney+ subscribers as an in-app purchase.
The entertainment giant earlier in August said the film would hit Disney+ as a paid exclusive on “premier platforms,” but failed to name partner providers, Deadline reports.
According to a Disney+ webpage, “Mulan” will be available from Sept. 4 as an in-app purchase on Apple, Roku and Google platforms. The film is also set to go up for purchase through Disney’s website.
Disney+ subscribers are slated to get access to the film following its September premiere, though a streaming date has not been announced.
The move comes amid controversy surrounding app store fees implemented by Apple and Google, each of which faces lawsuits from developers for taking a slice of in-app transactions. By making “Mulan” available as an in-app Disney+ “premium” purchase, Disney subjects its film to app store fees, which in Apple’s case is 30%.
“We thought we would give it a try, to try to recapture some of that investment that we’ve got,” said Bob Chapek, CEO of The Walt Disney Company. Chapek characterized the “one-off” strategy as a “a chance to learn,” Deadline reports.
Using Fedora and Linux to produce and play music is now easy. Not that long ago, it was a nightmare: configuration was a complicated task and you needed to compile some applications yourself. The compatibility with electronic devices was the real story. But, now we can see the end of the road. Playing music under Linux with Fedora is becoming user friendly.
Configuration
Fedora has long been usable to play music because of the CCRMA repository. Moreover, there also exists a Fedora Spin dedicated version: Fedora Jam. And today, you also have a COPR repository (which I manage) with a lot of stuff in it.
There are still some minimal steps to follow before being able to efficiently use a musical application. First, you will need to install the Jack audio connection kit and the qjackctl user interface:
dnf install jack-audio-connection-kit qjackctl
Then, as a root user, you will need to add yourself to the jackuser group:
sudo usermod -a -G jackuser <my_user_id>
To enable the changes made, you just have to logout of and log back in to your session or if you prefer reboot your machine.
Using basic applications
Now, you can add some applications to play with like LMMS or MuseScore.
All of these applications are available in the main Fedora repository:
dnf install lmms mscore audacity
Fedora and your instrument, in real time
Configuration
Editors note: A real time Kernel is necessary for audio recording on your PC, especially when doing multi track recording.
If you want to use your instrument (like an electric guitar) and use the sound of your instrument in some Fedora application, you will need to use Jack Audio Connection Kit with a real time kernel.
With the CCRMA repository, to install the real time kernel, use the following command as a root user:
dnf install kernel-rt
With the LinuxMAO Fedora COPR repository, use the following command:
dnf install kernel-rt-mao
The RT Kernel from CCRMA repository corresponds to a vanilla RT kernel with some Fedora patches applied whereas the one from the LinuxMAO repository is a pure vanilla one (a clean RT kernel without any patches).
Once this is done, we still need to perform some tuning on qjackctl to reduce the audio latency so it is negligible.
The main QJackCtl interface.
Click on the “Setup” button and set the following values:
Sample rate: 48000 or 44100 (this is the sampling frequency and these values are mostly supported on all commercially available sound cards)
Frames / period: 256
Periods / Buffer: 2
MIDI driver: seq (this value is required is you want to use a MIDI device)
With these parameters, you can easily achieve an audio latency of around 10 ms. While this value is the limit for the human ear and is hardly noticeable, you can reach lower latency with the penalty of increased CPU load.
Using Guitarix
To add some effects to your instrument, we will use a rack of effects: guitarix (edit: guitarix, the virtual guitar amplifier).
dnf install guitarix
Now, you have to connect your instrument to the audio card (the internal one or a USB adapter). Editors note: This normally requires an interface between the electric guitar and the audio line in of the audio card. There are also guitar to USB adapters. Once your instrument is connected, with qjackctl, we will connect:
the audio input to guitarix
the guitarix mono rack to the guitarix stereo rack
the guitarix stereo rack to the stereo audio output of your audio card
Connecting Guitarix using the QJackCtl graph window.
You do that by clicking on the Graph button of QJackCtl. Inside the Graph window, you just have to connect wires to the various elements . Each block represents an application. Guitarix is split into two blocks (preamp and rack). The preamp is where you select the amplifier characteristics, and the rack is where you apply mono and stereo effects. There are two other blocks with the system label for the audio input (the one on the left in the above figure) and the audio outputs (the one on the right).
Your instrument should be connected to the first audio input. You should test that your guitar is connected and that it’s able to be heard when played. Most of the time, we use the first two slots of audio output. But this will depend on your audio card.
Editors note: The actual configuration of inputs and outputs depends upon the type of hardware chosen. The stereo speakers of the PC were chosen as the output in the example shown.
If the MIDI interface of the sound card is chosen, there are also two red blocks which are dedicated to MIDI inputs / outputs. These would then be setup as the input from the instrument and the output from the rack.
Guitarix is an amp plus a rack of effects for you instrument. Mostly dedicated to guitar, but you can uses it with synthesizers too.
The Guitarix rack effects.
Adding some backing tracks
Better than just playing guitar on your own, you can play guitar with a group. To do this, we will install TuxGuitar.
dnf install tuxguitar
The TuxGuitar main interface.
TuxGuitar will play GuitarPro files. These files contains several instruments scores and can be played in real time. You just have to download a GuitarPro file from this website and open it with TuxGuitar.
Start TuxGuitar and click on Tools -> Plugins and check the fluidsynth plugin. Then, once fluidsynth is checked, click on Configure. Click on the Audio tab and select Jack as Audio Driver. In the Synthetizer tab, choose the same sampling frequency you chose for QjackCtl above (48000 or 44100 Hz).
In the soundfonts tab, you can add your own SF2 or SF3 file to improve the audio rendering. You can now close the Plugins window. Click on Tools -> Settings -> Sound. Here, you can select the king of audio used to render the score. If you have several SF2 / SF3 files, you will select the chosen one for the audio rendering here. Restart TuxGuitar after you’re satisfied with your selections. After restarting TuxGuitar, a new block will appear in the Graph window of QJackCtl.
QJackCtl with Guitarix and TuxGuitar.
You will just have to connect the block tagged ‘fluidsynth’ to the audio output like you have done with Guitarix.
Using MIDI devices
Using MIDI devices in real time is as easy as with audio. We will connect a virtual MIDI keyboard: vkeybd (but the same procedure applies with a real MIDI device) to a MIDI synthetizer: amsynth.
dnf install amsynth vkeybd
The main interface of AmSynth.
The virtual MIDI keyboard VKeyBD.
Once you have started amsynth and vkeybd, you will see new connections on the QJackCtl’s Graph window.
Amsynth and VKeyBD in QJackCtl’s graph window.
In this window, the red slots correspond to the Jack Audio MIDI connections whereas the purple ones correspond to the ALSA MIDI connections. Jack MIDI connections talk only to Jack MIDI connections. And the same for ALSA. If you want to connect a Jack MIDI connection to an ALSA MIDI connection, you will need to use a MIDI gateway: a2jmidid. You can read some more informations in the Ardour manual.
We have now covered some main topics of the audio under Fedora Linux. But there are a lot more things you can do.
Use some block connected language to perform many things: PureData
An audio / video block language: PureData
There is also a great audio looper available: SooperLooper.
SooperLooper, a great tool to build audio loops.
You can do live rehearsal through the internet: Jamulus.
Against the COVID side effects: Jamulus for live internet rehearsal.
Want to become the new famous DJ: have a look at Mixxx
Mixxx for DJing.
Webography
Some links now:
Here is a YouTube video where I play guitar through Guitarix and I use TuxGuitar to play the backing tracks in real time. Both TuxGuitar and Guitarix are sent through non-mixer which is a small mixing application. To be able to record the audio of the session “on the fly”, I also use timemachine. And to avoid reconnecting everything each time I want to play guitar, I use Ray Session to start every application and connect all the Jack Audio connections.
I also made a small demonstration of the use of Jamulus for a live rehearsal. On this YouTube video, I use Jamulus, QJackCtl, Guitarix mainly. The second guitarix is 30 km away. The latency was around 15 ms. It’s quite small and hardly noticable.
On this YouTube video, I tried to make some comparison between various SF2 / SF3 soundfont files. I used a GuitarPro file for the Opeth’s song “epilogue”.
On this YouTube video, I use MuseScore to play a GuitarPro file and I play along while my guitar sound is processed by Guitarix.
Here, it’s a live performance with a dancer. TuxGuitar + Non Session Manager + Non Mixer + Guitarix. I always used this kind of combination and Linux has never hanged … Finger crossed !
Some compositions made with LMMS on Fedora 25 to 32. Using some really nice plugins like Surge, NoiseMaker from DISTRHO package and others. All these compositions are libre music and are hosted on Jamendo.
If you need some help:
LinuxMusicians: a great place with skilled people willing to help
LinuxMAO: if you speak french, this is the place to be. A lot of resources related to various software.
LinuxAudio: another great website with various ressources to help.
Posted by: xSicKxBot - 08-22-2020, 09:44 AM - Forum: Lounge
- No Replies
The First Fall Guys Tournament Has A $5000 Top Prize
Fall Guys: Ultimate Knockout is a hugely competitive game, but not one, necessarily, built with esports in mind. Consequently, the first (unofficial) Fall Guys tournament, which is set for next week and will be an event hosted, should be interesting.
Esports player and speedrunner "GrandPooBear" has announced Fallmania, a "series" of events that will culminate in one streamer taking home a $5000 prize. Interested streamers are free to sign up if they want to be considered for the tournament.
Fallmania is set for August 27. Since there's no second place in Fall Guys, the competitions will be winner-takes-all.
Petite InvertMouse Bundle, Spellforce/Sacred Franchise Sale
Petite InvertMouse Bundle | 5 Steam Games + 4 DLC | 92% OFF
[www.indiegala.com] Get 9 steam keys filled with exciting, story rich anime-themed games & artwork
Unhack 2, Without Within 2, Cursed Sight, their artwork and more, 9 total Steam keys, all of them in one bundle at a mouse-sized price! Get it in the first 24 hours at ONLY 2.49 and SAVE 92% OFF!
Geoff Keighley Hypes Gamescom Opening Night Live, Show Starts Next Week
E3 might not have gone ahead this year, but in its place, there has been plenty of online events. We’ve had EA Play, Ubisoft Forward, a Nintendo Direct Mini, and many other broadcasts showcasing various upcoming games.
The next big event on the horizon is this year’s all-digital Gamescom show. As you might recall, it starts on 27th August (that’s next week) and will feature games from all sorts of publishers.
Geoff Keighley – the host of the opening ceremony – has now taken to Twitter to share the following video. He says the opening show will be a two-hour showcase, featuring over 20 games with brand new content – ranging from “next-gen stuff” to “indie stuff”, to the “biggest games in the world”. He’ll start revealing more about it tomorrow.
As already mentioned, there are more than 80 partners sharing announcements across three packed days.
Although Nintendo won’t be attending, some of the bigger partners that will be making an appearance include Activision Blizzard, Bandai Namco, Bethesda, Electronic Arts, Sega Europe, Ubisoft and team Xbox. Some other notable companies you can expect to see include Bossa Studios, Curve Digital, Dotemu, Merge Games and Strictly Limited Games.
To break one line into multiple lines in Python, use an opening parenthesis in the line you want to break. Now, Python expects the closing parenthesis in one of the next lines and the expression is evaluated across line boundaries. As an alternative, you can also use the backslash \ just in front of the line break to escape the newline character.
Problem: Given a long line of Python code. How to break it into multiple lines?
There are multiple ways of breaking this into multiple lines. Let’s get an overview first:
Exercise: Run the code. What’s the output? Modify Method 3 and write it as a one-liner again!
We now dive into each of those methods.
Method 1: Implicit Line Continuation — Use Parentheses to Avoid Line Break Backslashes
The PEP 8 – Style Guide argues that the best way to break long lines into multiple lines of code is to use implicit line continuation by using parentheses. An opening parenthesis signals to Python that the expression has not finished, yet. So, the Python interpreter keeps looking in the following line to close the currently open expression. This way, you can rewrite any Python one-liner to a multi-liner just by using one or more pairs of parentheses.
Here’s the original statement from the PEP 8 style guide (emphasis by me):
The preferred way of wrapping long lines is by using Python’s implied line continuation inside parentheses, brackets and braces. If necessary, you can add an extra pair of parentheses around an expression, but sometimes using a backslash looks better. Make sure to indent the continued line appropriately.
Do you need an example for implicit line continuation? Here it is:
# Long Line
a = list(zip(['Alice', 'Bob', 'Liz', 'Ann'], [18, 24, 19, 16])) # Implicit Line Continuation
b = list(zip(['Alice', 'Bob', 'Liz', 'Ann'], [18, 24, 19, 16])) print(a)
# [('Alice', 18), ('Bob', 24), ('Liz', 19), ('Ann', 16)] print(b)
# [('Alice', 18), ('Bob', 24), ('Liz', 19), ('Ann', 16)]
The long line a = list(zip(['Alice', 'Bob', 'Liz', 'Ann'], [18, 24, 19, 16]))zips together two lists to obtain the result [('Alice', 18), ('Bob', 24), ('Liz', 19), ('Ann', 16)]. You can rewrite this into multiple lines by using the existing parentheses. Note that it is good style to hierarchically align the lines in Python. In our example, the two lists are aligned when creating the multi-line statement to assign the variable b.
Remember: you can always break lines if an opened bracket, parenthesis, or bracelet has not been closed!
Method 2: Explicit Line Continuation — Use the Line Break Backslash \
However, what if you don’t want to introduce new parentheses into your expression? Can you still break up a one-liner into multiple lines?
The answer is: yes! Just use the line break backslash \ which you may call explicit line continuation. With the backslash, you can break at any position in your expression. Technically, the backslash character “escapes” the newline character that follows immediately afterwards. By escaping the newline character, it loses its meaning and Python simply ignores it. This way, you don’t have to introduce any new parentheses.
Here’s a minimal example that shows the flexibility with which you can break new lines this way:
To solve this readability problem, mathematicians and their publishers follow the opposite convention.
Donald Knuth explains the traditional rule in his Computers and Typesetting series: “Although formulas within a paragraph always break after binary operations and relations, displayed formulas always break before binary operations”[3].
You can do both in Python but you should prefer the latter to improve readability of your code!
Method 3: Break a String by Using a Multi-Line String with Triple Quotes
Example: Say, you have the following long string from Romeo and Juliet:
s = 'Mistress! what, mistress! Juliet! fast, I warrant her, she:\n Why, lamb! why, lady! fie, you slug-a-bed!\n Why, love, I say! madam! sweet-heart! why, bride!\n What, not a word? you take your pennyworths now;\n Sleep for a week; for the next night, I warrant'
Note the newline character in the string: it’s really a multip-line string! Can you rewrite this into multiple lines to improve readability?
You can restructure strings by using the triple quotes that allows you to define a multi-line string without the newline character '\n' in the string. This significantly improves readability of multi-line strings! Here’s an example:
s1 = 'Mistress! what, mistress! Juliet! fast, I warrant her, she:\n Why, lamb! why, lady! fie, you slug-a-bed!\n Why, love, I say! madam! sweet-heart! why, bride!\n What, not a word? you take your pennyworths now;\n Sleep for a week; for the next night, I warrant' # MULTI-LINE
s2 = '''Mistress! what, mistress! Juliet! fast, I warrant her, she: Why, lamb! why, lady! fie, you slug-a-bed! Why, love, I say! madam! sweet-heart! why, bride! What, not a word? you take your pennyworths now; Sleep for a week; for the next night, I warrant''' print(s1 == s2)
# True
These are two ways of defining the same string. If you compare them, the result is True. However, the second way is far more readable and should be preferred!
Where to Go From Here?
Enough theory, let’s get some practice!
To become successful in coding, you need to get out there and solve real problems for real people. That’s how you can become a six-figure earner easily. And that’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs?
Practice projects is how you sharpen your saw in coding!
Do you want to become a code master by focusing on practical code projects that actually earn you money and solve problems for people?
Then become a Python freelance developer! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner.