# File Reading

**URL:** <https://www.ruby-forum.com/t/file-reading/242253>\
**Category:** GNU Radio\
**Created:** [June 9, 2015, 3:17pm UTC](https://www.ruby-forum.com/t/file-reading/242253 "2015-06-09T15:17:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [June 9, 2015, 3:17pm UTC](https://www.ruby-forum.com/t/file-reading/242253/1 "2015-06-09T15:17:05Z")

</div>

I am having trouble reading a file and putting it as a variable or some  
way  
so that the USRP Source block will read it and evaluate each item. I’m  
using a file source and i tried connecting to a message sink, but I’m  
stuck  
there because the output of the sink does not match the input of the  
USRP  
Source. Is there a way to have a txt file read and put into a array of  
some  
sort to be evaluated?

---

<div class="post-metadata">

**Author:** ![Ashraf\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@Ashraf\_Y](https://www.ruby-forum.com/u/Ashraf_Y)\
**Post date:** [June 9, 2015, 3:24pm UTC](https://www.ruby-forum.com/t/file-reading/242253/2 "2015-06-09T15:24:41Z")

</div>

On Tue, Jun 9, 2015 at 8:31 AM, Ashraf Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I am having trouble reading a file and putting it as a variable or some  
> way so that the USRP Source block will read it and evaluate each item. I’m  
> using a file source and i tried connecting to a message sink, but I’m stuck  
> there because the output of the sink does not match the input of the USRP  
> Source. Is there a way to have a txt file read and put into a array of some  
> sort to be evaluated?

The file source block reads binary data that it converts to stream of  
samples.

What you want sounds like you could write a simple Python function to  
accomplish.

Tom

---

<div class="post-metadata">

**Author:** ![Ashraf\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@Ashraf\_Y](https://www.ruby-forum.com/u/Ashraf_Y)\
**Post date:** [June 10, 2015, 9:16am UTC](https://www.ruby-forum.com/t/file-reading/242253/3 "2015-06-10T09:16:40Z")

</div>

On Tue, Jun 9, 2015 at 9:17 AM, Ashraf Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Thank you for responding. I’m still new to GRC, so I don’t know how to go  
> about doing that. Would I have to write a .py file? Then how would I import  
> it to GRC?

Please keep replies on the list.

So I was about to reply something along the lines of “It’s just Python,  
you  
can figure it out,” but then I realized that we provide a good mechanism  
for handling this; it’s just not well exposed. So I wrote a tutorial on  
it  
this morning:

[http://gnuradio.org/redmine/projects/gnuradio/wiki/TutorialPythonFunctions](http://gnuradio.org/redmine/projects/gnuradio/wiki/TutorialPythonFunctions)

Hope this helps.

Tom

---

<div class="post-metadata">

**Author:** ![Ashraf\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e19adc/32.png) [@Ashraf\_Y](https://www.ruby-forum.com/u/Ashraf_Y)\
**Post date:** [June 10, 2015, 9:45am UTC](https://www.ruby-forum.com/t/file-reading/242253/4 "2015-06-10T09:45:53Z")

</div>

This helps a lot. Thank you. I hope I’m adding this reply to the list  
correctly.
