Python Forum
can't read my file!!! - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: can't read my file!!! (/thread-4192.html)



can't read my file!!! - baronmontesqieu - Jul-28-2017

Hello. I'm trying to read a file after aligning and converting parts of the file, but python is not opening it.

Can someone help me?

thank you!

this is the code.



with open('C:/Users/hrithikjha/Desktop/samplesam.txt', 'r') as fh:
reader = csv.reader(fh, delimiter="\t")
d = list(reader)
file_writer = open('C:/Users/hrithikjha/Desktop/samplesam.txt','w')
for data in d:
if ( data[0].find('@') == -1 ):
file_writer.write('Alignment Code : ' + data[0] + ' FLAG Value : ' + data[1] + ' Binary Equivalant : ' + (bin(int(data[1]))[2:]))+'\n'
else:
print (data[0])
file_writer.write(data[0]+'\n')


RE: can't read my file!!! - ichabod801 - Jul-28-2017

Please put your code in Python tags so we can see the indentation. See the BBCode link in my signature for instructions. Also, please tell us exactly what is happening. Are you getting an error? What is the full text of the error?


RE: can't read my file!!! - baronmontesqieu - Jul-28-2017

I am not getting any error. It simply does not output anything.

I am new to the forums and I don't really know how to indent my code, but I will try my best here.
import csv
with open('C:/Users/hrithikjha/Desktop/samplesam.txt', 'r') as fh:
reader = csv.reader(fh, delimiter="\t")
d = list(reader)
file_writer = open('C:/Users/hrithikjha/Desktop/samplesam.txt','w')
for data in d:
if ( data[0].find('@') == -1 ):
file_writer.write('Alignment Code : ' + data[0] + ' FLAG Value : ' + data[1] + ' Binary Equivalant : ' + (bin(int(data[1]))[2:]))+'\n'
else:
print (data[0])
file_writer.write(data[0]+'\n')


RE: can't read my file!!! - ichabod801 - Jul-28-2017

Did you check out the instructions in the BBCode link in my signature like I said?

Also, try to print d before the loop, to make sure there is something in there.


RE: can't read my file!!! - baronmontesqieu - Jul-30-2017

Thank you so much! I really appreciate it.