Python Forum
Adding string after every 3rd charater [SOLVED]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding string after every 3rd charater [SOLVED]
#1
Hello everybody,

I want to get the filesize of a folder and store it as a variable. So far I've manged to do so:

import os

def get_size(start_path = '.'):
    total_size = 0
    for dirpath, dirnames, filenames in os.walk(start_path):
        for f in filenames:
            fp = os.path.join(dirpath, f)
            if not os.path.islink(fp):
                total_size += os.path.getsize(fp)
    return total_size

line = get_size()
print(line)
Now I want to expand on that so that, going from the end to beginning, after every 3 digits it adds a point.
For example, instead of 1515124421 I want it to look like 1.515.124.421

How can I do so?
Reply


Messages In This Thread
Adding string after every 3rd charater [SOLVED] - by AlphaInc - Jul-10-2022, 01:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] [BeautifulSoup] Why does it turn inserted string's brackets into </>? Winfried 0 1,542 Sep-03-2022, 11:21 PM
Last Post: Winfried
  [SOLVED] [BeautifulSoup] Turn select() into comma-separated string? Winfried 0 1,129 Aug-19-2022, 08:07 PM
Last Post: Winfried
Question [SOLVED] Delete specific characters from string lines EnfantNicolas 4 2,254 Oct-21-2021, 11:28 AM
Last Post: EnfantNicolas
  Replace String in multiple text-files [SOLVED] AlphaInc 5 8,196 Aug-08-2021, 04:59 PM
Last Post: Axel_Erfurt
  Replace String with increasing numer [SOLVED] AlphaInc 13 5,096 Aug-07-2021, 08:16 AM
Last Post: perfringo
Thumbs Up Parsing a YAML file without changing the string content..?, Flask - solved. SpongeB0B 2 2,292 Aug-05-2021, 08:02 AM
Last Post: SpongeB0B
  Adding an ascending number [SOLVED] AlphaInc 3 2,261 Jul-11-2021, 10:13 AM
Last Post: perfringo
  reading lines from a string [Solved] ebolisa 14 6,439 Mar-28-2021, 08:16 PM
Last Post: perfringo
  Adding markers to Folium map only adding last element. tantony 0 2,138 Oct-16-2019, 03:28 PM
Last Post: tantony
  adding a string and an int ninjarunner2005 3 2,349 Dec-10-2018, 04:54 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020