logo
down
shadow

How to print a long string in multiple lines in Python3


How to print a long string in multiple lines in Python3

By : chincho
Date : November 21 2020, 04:01 AM
Does that help I recently came across python f-string. Let, there is a long line of string like , This is what you use textwrap for:
code :
import textwrap
string = 'L4qrGFHK8eDA9Vy05gNH7inxfaVpPZH3i9pRdWScalA0pIGHKGqUEXejplKiYaCNizbiKH72LoQaoz1pQH9caDfAX5xtfQAZEri7QGkvxMAJWXsjPEPLQhTtTvvhDR1tMM9zX8Dd0l15bBW1Q3VQReOsbP5AQmMOK9GV0WYPZ015sg7tg8JKOs7hFJfD8bdpUQgWbGrxSdS95PnBTf4P2nTWWLrWzo3DQNyXHs29R6MZ92qqfPLGL8SSQNchWyo4V9NoHdAHDo5TdPf6VmNQaQAl9HKLVawTTg379plHr81YYEoojzstCSPh3jAy9W4dmjTLrBUxzA9tK5UlHKMGx7IYieNGfXBKTaCegdJOUubZPajkp0KY8OcpHxlaVFVdIPi58n6VH7evAomB'
# print("{string}:<40")
print(textwrap.fill(string, 40))

L4qrGFHK8eDA9Vy05gNH7inxfaVpPZH3i9pRdWSc
alA0pIGHKGqUEXejplKiYaCNizbiKH72LoQaoz1p
QH9caDfAX5xtfQAZEri7QGkvxMAJWXsjPEPLQhTt
TvvhDR1tMM9zX8Dd0l15bBW1Q3VQReOsbP5AQmMO
K9GV0WYPZ015sg7tg8JKOs7hFJfD8bdpUQgWbGrx
SdS95PnBTf4P2nTWWLrWzo3DQNyXHs29R6MZ92qq
fPLGL8SSQNchWyo4V9NoHdAHDo5TdPf6VmNQaQAl
9HKLVawTTg379plHr81YYEoojzstCSPh3jAy9W4d
mjTLrBUxzA9tK5UlHKMGx7IYieNGfXBKTaCegdJO
UubZPajkp0KY8OcpHxlaVFVdIPi58n6VH7evAomB


Share : facebook icon twitter icon
Android: How to split a very long String with items that are multiple lines long?

Android: How to split a very long String with items that are multiple lines long?


By : user2135491
Date : March 29 2020, 07:55 AM
seems to work fine I think that the problem comes from the fact that you are using readLine to read your file. By using this function the buffer is read until a line feed "\n" or carriage return "\r" is found. However, What you want is to split the string each time the occurrence ',' is found.
Try to use read instead to read through Due_Today. This is only a pseudo-code:
code :
int value   = 0;
int counter = 0;
String str  = "";
StringBuilder strb = new StringBuilder();

// Read until the end of the file
while((value = reader.read()) != -1)
{
    // Convert int to a character
    char c = (char)value;
    strb.append(c);

    // If the separator is found
    if (c == ','){

        str = strb.toString().replaceAll("^\"|\"$", "");
        switch (counter) {

            /* Do things according to the value of counter:
            Read description, data, title.. according to the data structure of what you are trying to parse 

            Example:
            case 1:  Description = str;
            break;
            case 2:  Band = str;
            break;
            */

        }

        // Prepare to read a new string and initialize the string builder
        strb.setLength(0);
        counter ++;
    }
}
while((value = reader.read()) != -1)
{
     // Convert int to a character
     char c = (char)value;


      // Searching for the separator
      if (c == ','){
           if (state == 1) {
                state = 2;
           } else {
                state = 0;
                strb.append(c);
            }
       }
       else if (c == '"'){
            if (state == 2){
                 // The separator if found, read the string
                 processElement(strb, counter); 

                  // Prepare to read a new string
                  state = 0;
                  counter ++;

             } else {
                  state = 1;
                  strb.append(c);
             }
       } else {
             strb.append(c);
       }
}

// Process the last element
processElement(strb, counter);


public void processElement(StringBuilder strb, int counter){
    String str = strb.toString().replaceAll("^\"|\"$", "");
    System.out.println("String to process= " + str);

    /*
         Do something with it here..

    switch (counter) {
        case 1:  Description = str;
        break;

        case 2:  Band = str;
        break;

        ...
    }
    */

    // Initialize the string builder
    strb.setLength(0);
}
while((value = reader.read()) != -1)
{
     // Convert int to a character
     char c = (char)value;
     strb.append(c);
}
String str = strb.toString();
How to print a textbox long text in C# print document (print multiple lines)

How to print a textbox long text in C# print document (print multiple lines)


By : JohnDJasper
Date : March 29 2020, 07:55 AM
it should still fix some issue I tried with this link its a good article and answer is working. https://msdn.microsoft.com/en-us/library/system.drawing.graphics.measurecharacterranges(v=vs.90).aspx
In Biopython: Can you ‘print’ so a long output will be formatted as multiple lines each with a max char length, as often

In Biopython: Can you ‘print’ so a long output will be formatted as multiple lines each with a max char length, as often


By : mbajrach
Date : March 29 2020, 07:55 AM
around this issue You could write a custom print function which gets as input a string and splits the string into parts of 60 char and then prints those parts.
code :
def custom_print(string):
    counter=0
    res=""
    for char in string:
        if counter==60:
            print res
            counter=0
            res=""
            continue
        res+=char
        counter+=1
Python3.7: RegEx for string between strings on multiple lines?

Python3.7: RegEx for string between strings on multiple lines?


By : user1889291
Date : March 29 2020, 07:55 AM
I hope this helps . I would like to find 30,850 in: , You also can search text by bs4
code :
from bs4 import BeautifulSoup

tx = """
  <div class='user-information__achievements-heading' data-test-points-title>
    Points
    </div>
    <div class='user-information__achievements-data' data-test-points-count>
    30,850
    </div>
    </div>
"""

bs = BeautifulSoup(tx,"lxml")
result = bs.find("div",{"class":"user-information__achievements-data"}).text
print(result.strip()) # 30,850
Python3: Use Dateutil to make multiple vars from a long string

Python3: Use Dateutil to make multiple vars from a long string


By : ichirurgie
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further assuming you want to pull one line at random from the string you can use choice from the random module.
code :
from random import choice
data = "This is the day\nOf the expanding man\nThat shape is my shade\nThere where I used to stand\nIt seems like only yesterday\nI gazed through the glass\n..."
my_lines = data.splitlines()
my_line = choice(my_lines)
print(my_line)
That shape is my shade
shadow
Privacy Policy - Terms - Contact Us © bighow.org