0

Good night guys , i have a question, im trying to concatenate strings into an array i have a .txt, that is divided in 3 gruoups ".I 1" ".I 2" ".I 3" my code generates an array of the total number of ".I n" in this case an array of 3, and my objective is to store all the lines after ".I x" in the x position of the array example.... ".I 1" in array[1] , ".I 2" in array[2] etc.

my code is just saving the last line before the next ".I" instead of saving all the lines, i knew that this was going to happend but the problem is that i dont know how to concatenate or push or append the lines in to the same position of the array

TXT DOCUMENT cran.all.txt

.I 1
.T
experimental investigation of the aerodynamics of a
wing in a slipstream .
.A
brenckman,m.
.B
j. ae. scs. 25, 1958, 324.
.W
experimental investigation of the aerodynamics of a
wing in a slipstream .
  an experimental study of a wing in a propeller slipstream was
made in order to determine the spanwise distribution of the lift
increase due to slipstream at different angles of attack of the wing
and at different free stream to slipstream velocity ratios .  the
results were intended in part as an evaluation basis for different
theoretical treatments of this problem .
  the comparative span loading curves, together with
supporting evidence, showed that a substantial part of the lift increment
produced by the slipstream was due to a /destalling/ or
boundary-layer-control effect .  the integrated remaining lift
increment, after subtracting this destalling lift, was found to agree
well with a potential flow theory .
  an empirical evaluation of the destalling effects was made for
the specific configuration of the experiment .


.I 2
.T
simple shear flow past a flat plate in an incompressible fluid of small
viscosity .
.A
ting-yili
.B
department of aeronautical engineering, rensselaer polytechnic
institute
troy, n.y.
.W
simple shear flow past a flat plate in an incompressible fluid of small
viscosity .
in the study of high-speed viscous flow past a two-dimensional body it
is usually necessary to consider a curved shock wave emitting from the
nose or leading edge of the body .  consequently, there exists an
inviscid rotational flow region between the shock wave and the boundary
layer .  such a situation arises, for instance, in the study of the
hypersonic viscous flow past a flat plate .  the situation is somewhat
different from prandtl's classical boundary-layer problem . in prandtl's
original problem the inviscid free stream outside the boundary layer is
irrotational while in a hypersonic boundary-layer problem the inviscid
free stream must be considered as rotational .  the possible effects of
vorticity have been recently discussed by ferri and libby .  in the
present paper, the simple shear flow past a flat plate in a fluid of small
viscosity is investigated .  it can be shown that this problem can again
be treated by the boundary-layer approximation, the only novel feature
being that the free stream has a constant vorticity .  the discussion
here is restricted to two-dimensional incompressible steady flow .


.I 3
.T
the boundary layer in simple shear flow past a flat plate .
.A
m. b. glauert
.B
department of mathematics, university of manchester, manchester,
england
.W
the boundary layer in simple shear flow past a flat plate .
the boundary-layer equations are presented for steady
incompressible flow with no pressure gradient .

PYTHON CODE

import re
import numpy as np

def total_archivos() :
    hand = open("cran.all.txt")
    total= 0
    for line in hand:
        line = line.strip()
        if ".I" in line:
            total=total+1
    return total

def escribir() :
    hand = open("cran.all.txt")
    total= 0
    for line in hand:
        line = line.strip()
        if ".I" in line:
            total=total+1
        else:
            textos[total-1]=np.array(line)



cuenta=total_archivos()
textos = np.array(range(cuenta), dtype='|S1000')
escribir()
print cuenta
print textos[0]
print textos[1]
print textos[2]

THE RESULT

1400
the specific configuration of the experiment .
here is restricted to two-dimensional incompressible steady flow .
incompressible flow with no pressure gradient .

Note that this is only the last line from each "I. x" i want to store all the lines in the same array position.

in advanced thanks a lot for your help.

2 Answers 2

1

I suggest use line.startswith("special_chr") and line.endswith("special_chr") for handle end and start of your lines ! then you have a more pythonic code and less error !

Sign up to request clarification or add additional context in comments.

1 Comment

Thx a lot , but i have a few questions, how would you use it? it is returning me booleans , do you have any idea for its implementation?
0

i Found an easier solution , instead of worrying for concatenations in the array , i created simple temporal variable called "doc" i use this variable to concatenate the lines and then when they are all concatenated i just save the variable in the array position that i want, and then i clean the variable this is how my code ended

import re
import numpy as np



def total_archivos() :
    hand = open("cran.all.txt")
    total= 0
    for line in hand:
        line = line.strip()
        if ".I" in line:
            total=total+1
    return total

def escribir(doc) :
    hand = open("cran.all.txt")
    total= 0
    for line in hand:
        line = line.strip()
        if ".I" in line:
            doc = ""
            total=total+1
        else:
            doc = doc + line
            textos[total-1]=doc



doc = ""
cuenta=total_archivos()
textos = np.array(range(cuenta), dtype='|S2000')
np.array(textos).tolist()
escribir(doc)
print cuenta
print textos[1330]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.