Title: ord function execution in loop
Tags: python;zipper
Question: I have two folders, and each folde contains 196 files, they all are in (```'\xae\xae\xb4\x9e\x8f\x9f\xba\xc1\xd5\xbd\xcd\xa1\xb7\'```) format. I am trying to read this data convert it into human readable form. I want to combine the data of both the files of the 2 folder.

I tried this using ```ord()``` function but while trying to retrive a single file with expected output, I am getting wrong values. I tries to extract first element of the read but output I am getting is forst value of all the files.
here is my code:

```for file_name, files in izip(list_of_files, list_of_filesO):
     fi = open(file_name,"r").read()
     fo = open(files,"r").read()
     f =  [open("/home/vidula/Desktop/project/ori_tri/input_%i.data" %i,'w')for i in range(len(list_of_files))]
     read = [ord(i) for i in fi]
     reado = [ord(i) for i in fo]
     zipped = zip (read,reado)
     print read[0]
```

Expected output:

```125,25
36,54
98,36
78,56
```

Thank you in anticipation.

Comment: "they all are in ('\xae\xae\xb4\x9e\x8f\x9f\xba\xc1\xd5\xbd\xcd\xa1\xb7\') format." I have absolutely no idea what you mean by this. If I opened your file in Notepad, would I see the quotes and backslashes? Would it all be one long string?

Comment: it is a hex file, cannot be read in notepad.


Here is another answer: ```[ord(i) for i in fi]
```

Iterating over a file iterates over lines of the file. It sounds like you want to iterate a character at a time. For that, you could try explicitly ```read```ing each file as a single chunk, and then iterating over the resulting strings.

If you do not want the whole file contents in memory, you could try making a custom iterator, like:

```def each_char_of(a_file):
    while True:
        x = a_file.read(1)
        if not x: return
        yield x
```

Comment for this answer: I am sorry sir, I am newbie in programming, I am not getting what should I do? I have 2 directory containing 196 files each, In each files 121 values in hex format, I am trying to convert hex to int using ord().and write it into new output file. Each output file should have 121 values of 2 input files(like 123,456 56,23 89,56) and 196 files in new directory.but I am getting 196 values in each file of new directory.  Can you please suggest me what shall be done? Thakyou

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:12/07/12', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><zipper>', 'Title': 'ord function execution in loop', 'ViewCount': 1088, 'id': 13758250, 'user_AboutMe': '', 'user_AccountId': 2121134.0, 'user_DisplayName': 'shreya', 'user_Reputation': 297.0, 'user_Views': 138.0, 'user_id': 1884345.0}}