Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Deleting the first 2 lines of a string

Tags:

I've searched many threads here on removing the first two lines of a string but I can't seem to get it to work with every solution I've tried.

Here is what my string looks like:

version 1.00 6992 [-4.32063, -9.1198, -106.59][0.00064, 0.99993, -0.01210][etc...] 

I want to remove the first two lines of this Roblox mesh file for a script I am using. How can I do that?

like image 888
GShocked Avatar asked Jun 14 '15 19:06

GShocked


People also ask

How do you remove multiple lines from a string in Python?

Use the strip() Function to Remove a Newline Character From the String in Python. The strip() function is used to remove both trailing and leading newlines from the string that it is being operated on. It also removes the whitespaces on both sides of the string.

How do you remove the last two lines in Python?

The . rsplit method is the correct tool when operating from the end (i.e. the right side of the string). Assuming the last line is newline terminated, 3 splits are necessary. We can tell the (r)split not to do more, so no join is needed to put the split pieces together.

How do I remove something from the beginning of a string in Python?

Use the . strip() method to remove whitespace and characters from the beginning and the end of a string. Use the . lstrip() method to remove whitespace and characters only from the beginning of a string.


2 Answers

I don't know what your end character is, but what about something like

postString = inputString.split("\n",2)[2] 

The end character might need to be escaped, but that is what I would start with.

like image 190
dstudeba Avatar answered Nov 03 '22 22:11

dstudeba


x="""version 1.00 6992 [-4.32063, -9.1198, -106.59][0.00064, 0.99993, -0.01210][etc...] abc asdda""" print "\n".join(x.split("\n")[2:]) 

You can simply do this.

like image 22
vks Avatar answered Nov 04 '22 00:11

vks