Skip to content

Instantly share code, notes, and snippets.

@Kyonru
Last active October 11, 2017 17:40
Show Gist options
  • Save Kyonru/28cf92e48ee617f7eb186d0d9229d377 to your computer and use it in GitHub Desktop.
Save Kyonru/28cf92e48ee617f7eb186d0d9229d377 to your computer and use it in GitHub Desktop.
Find the line where the n-th character is
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 11 12:21:18 2017
Good way to find where the error is after a bad resolved merge conflict.
@author: kyonru
"""
with open ("name_of_the_file.extension", "r") as myfile:
data=myfile.readlines()
columnWanted=int(input("Write a column: "))
cnt = 0;
for i in range(len(data)):
cnt += len(data[i])
if(cnt >= columnWanted):
print("The line you want is aprox: "
+ str(i) + "\nLine:\n"+ data[i])
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment