How do you print multiple tabs in python?

I'm trying to print a certain string each time on a new line and each line adding a new tab.

For example:

String
      String
           String

The code I used:

print(string + "\n\t" + string "\n\t" + string)

Which gives the output:

String
      String
      String

Can someone explain me why is it happening, and what are the ways to work around it?

How do you print multiple tabs in python?

asked Nov 23, 2018 at 18:38

How do you print multiple tabs in python?

2

You can create a for loop and add a tab in each cycle:

number = 3
string = "String"
for i in range(number):
    print('\t' * i + string + '\n', end="")

Output:

String
    String
        String

You can use it for any positive value of variable number. You can also create a function that does the above:

def printTabbed(number,string):
    for i in range(number):
        print('\t' * i + string + '\n', end="")

And then call it:

printTabbed(3,"String")

answered Nov 23, 2018 at 18:44

How do you print multiple tabs in python?

Vasilis G.Vasilis G.

7,3334 gold badges20 silver badges28 bronze badges

Use

print(string + "\n\t" + string "\n\t\t" + string)

In your code, the third line only contains one tab indent (indents don't "carry over" to the next lines, so you have to indent every line from the start).

answered Nov 23, 2018 at 18:39

andersourceandersource

7893 silver badges9 bronze badges

2

Considering you want to do this multiple times it is best to use a loop such as this:

n = 10 // amount of times you want to print
for x in range(n):
    tabs = "\t"*x
    print(tabs+"String"+"\n")

answered Nov 23, 2018 at 18:44

Tobias WilfertTobias Wilfert

9143 gold badges16 silver badges26 bronze badges

I have opened several webpages of my interest into the tabs of chrome browser using a python program. Now I like to save these pages as pdf files using the printer function of the browser. PDF is my default printer, so I wanted to know if there are any modules that I can use to invoke the printer driver and save the open tabs of the default browser. I will be very thankful for any suggestion or direction to move forward.

You can use pdfkit (with wkhtmltopdf) for converting a HTML file to PDF...

How do you print multiple tabs in python?

Maybe you could use Python Selenium to take screenshots of the page. That's my only idea.

How do you print multiple tabs in python?

Excel gives you a lot of options when you’re trying to print your work. You can choose to print the entire worksheet, a specific area in the worksheet, print multiple sheets, or all sheets at one go.

In this tutorial, I will show you how you can print multiple sheets in Excel at one go. These could be some selected sheets or all the sheets in the workbook.

And in case you want to print a specific area in multiple/all sheets, you can do that too with a little bit of VBA magic.

So let’s get started!

  • Print All Sheets at One Go
  • Print Multiple Sheets (Selected Ones) at One Go
  • Print Multiple Sheets With a Specific Print Area
    • Setting the Print Area manually
    • Setting the Print Area using VBA

Excel has an inbuilt feature that allows you to specify to print all the sheets at one go.

Below are the steps to print all the sheets in the workbook:

  1. Click the File tab
    How do you print multiple tabs in python?
  2. Click on the Print option
    How do you print multiple tabs in python?
  3. In the Print page, click on the Print setting drop-down
    How do you print multiple tabs in python?
  4. Click on Print Entire Workbook
    How do you print multiple tabs in python?
  5. Click on Print
    How do you print multiple tabs in python?

The above steps would print all the sheets in the workbook. In case you have a print area set in some of the sheets, then only that print area will be printed.

You can also see what will be printed in the Print preview on the right. You can also change page numbers and see what will be printed on each page.

Easy enough!

Now, what if you only want to print only some specific sheets and not the entire workbook.

Read on!

This is again quite easy to achieve.

All you need to do is selected those specific sheets that you want to print and then print it!

Below are the steps to print some specific sheets in a workbook in Excel:

  1. Select all the sheets that you want to print. To do this, hold the Control key and select sheets one by one. In this example, I am selecting Sheet 1, 4 and 5
    How do you print multiple tabs in python?
  2. Click the File tab
  3. Click on the Print option
  4. In the Print page, click on the Print setting drop-down
  5. Click on Print Active Sheets (in most cases, it’s already the default option, but in case it isn’t you can choose that from the drop-down)
    How do you print multiple tabs in python?
  6. Click on Print

When you select multiple sheets, these all act as active sheets while printing.

You can also see what will be printed in the Print preview on the right. You can also change page numbers and see what will be printed on each page.

This one is a little more complex than the previous two.

Suppose you have a workbook with multiple sheets, and you want to print a specific area from each sheet.

Maybe there is summary data in each sheet and you only want to print this data and not the entire worksheet.

This can be done by setting a print area in all the sheets and then printing these (as shown in the above two methods).

Now when it comes to setting the print area:

  • You need to do it manually for each sheet (especially if the print area is different for each sheet)
  • Or you can use a simple VBA code to set the same print area in all the sheets at one go.

Once you have set the print area, you can then use any of the above methods to print the sheets.

So let me quickly show you how to set the Print area manually and using VBA.

Setting the Print Area manually

Below are the steps to do this:

  1. Select the cells that you want to be covered in the print area
  2. Click the ‘Page Layout’ tab
    How do you print multiple tabs in python?
  3. In the Page Setup group, click on ‘Print Area’
    How do you print multiple tabs in python?
  4. Click on ‘Set Print Area’
    How do you print multiple tabs in python?

That’s it!

This would set the print area to the selected cells and when you print this sheet, only the print area will be printed.

You need to do this manually for each sheet. So if you want to print specific areas in Sheet1, Sheet4, and Sheet5, you will have to do it for each sheet separately.

Setting the Print Area using VBA

In case you have a lot of worksheets, setting the print area manually can be time-consuming.

In that case, you can also use VBA to quickly set the print area in one sheet, and then run the code to replicate it to all the other sheets.

Note: This method works well when you have the same range of cells that you want to use while setting the Print Area.

Below is the VBA macro code that will do this:

Sub SetPrintAreas1()
    Dim PrntArea As String
    Dim ws As Worksheet
    PrntArea = ActiveSheet.PageSetup.PrintArea
    For Each ws In Worksheets
        ws.PageSetup.PrintArea = PrntArea
    Next
    Set wks = Nothing
End Sub

The above code uses the print area from the active sheets, goes to all the sheets in the workbook and sets the same print area in each of these sheets.

It uses a loop to go through each worksheet and then set the same area in each worksheet as the print area. In case you want this to be different for each sheet, I believe doing it manually would be faster.

Once you have this set, you can now print all the sheets (or some selected sheets), and only the print area will be printed.

You can put this VBA macro code in a regular module and run it from there.

So these are some scenarios where you can print multiple sheets in Excel in one go.

Hope you found this tutorial useful!

You may also like the following Excel tutorials:

  • How to Print Comments in Excel
  • How to Print Excel Sheet on One Page
  • How to Insert Page Numbers in Excel Worksheets
  • How to Compare Two Excel Sheets (for differences)
  • How to Unhide Sheets in Excel (All In One Go)
  • How to Print the Top Row on Every Page in Excel

How do you use multiple tabs in Python?

Ways to open multiple tabs using Selenium:.
After specifying either Firefox/Chrome driver for selenium, first, we need to open a webpage..
We need to call “execute_script” method which in turn executes window. ... .
Then we need to switch to that tab and for that tab can give any valid URL..

How do you print tabs in Python?

How do you print a tab character in Python? The easiest way to print a tab character in Python is to use the short-hand abbreviation '\t' . To see the tab spaced character in the REPL wrap any variable containing a tab character in the built-in print() function.

How do I make multiple tab spaces in Python?

The expandtabs() character replaces the '\t' with whitespace until the next tab stop. The position of '\t' is 3 and the first tab stop is 8. Hence, the number of spaces after 'xyz' is 5. The next tab stops are the multiples of tabsize .

How do you split a tab in Python?

split() method to split a string by tab, e.g. my_list = re. split(r'\t+', my_str) . The re. split() method will split the string on each occurrence of a tab and return a list containing the results.