Home.Verilog.Digital Design.Digital Basics.Python.RF Basics.
Custom Search

Legal Disclaimer

Chip Designing for ASIC/ FPGA Design engineers and Students
Digital-logic Design...  Dream for many students… start learning front-end…

Legal Disclaimer

@TYH :- 4G LTE Long Term Evolution Tutorial, CloudComputing
Verilog Tutorial.
Get Noticed:- Submit your own content to be published on fullchipdesign.com

Send it to fullchip@gmail.com

Digital Basics Tutorial.
File read operations.

Class & global var.

File write op's.

Glob module.

Conditional stms.

String 2 hex.

UNIX in Python.

Diamond Pattern.

TypeError - arg.

TyprError - str.

TypeError - strconv.


Function call.

Read bin files.

Input TEST vectors ‘to_try_vectors.dat’

0.955511                  1.212213

-1.450977                 0.958842

RESULTS output file input_python_file_c.dat





import sys

import os

import string

import commands


### Author:- FullChipDesign ###

### Description :- Utility for running UNIX commands

and file operations ###


class file_op:



    def file_read(self, file):


             self.file_to_read = file

             self.filn = 0


             # UNIX command line operations


             commands.getoutput('rm -rf ./input_python_file_c.dat')


             # Read all lines in a text file and execute the following for loop for each line

             for self.filn in self.file_to_read.readlines():

                 self.rfile = self.filn.rstrip('\n\r\t')

                 # Calculate length of each line

                 self.ln = len(self.rfile)

                 # print self.rfile


                 # self.string_to_signed()  



             # Strip off white space on end

             self.rfile = string.strip(self.rfile)




# Function for data manuplation

# File write operations


    def filter_text (self):

             self.ci = 0

             self.idata = 0

             self.qdata = 0

             self.test =  0

             self.temp_write = open('input_python_file_c.dat' , 'a')


             for self.ci in range(0, 1, 1):

                 self.idata = self.rfile[self.ci:self.ci+8]

                 self.qdata = self.rfile[self.ci+9:self.ci+18]

                 # print self.idata

                 # print self.qdata



             self.idata = string.strip(self.idata)

             self.qdata = string.strip(self.qdata)


             # Write file

             self.temp_write.write("%s \n" % self.idata)

             self.temp_write.write("%s \n" % self.qdata)


             # Close file




# Command line operations for reading file from command line


if len(sys.argv) == 1:

    r1 = file_op()




    r1 = file_op()

    r1.file_read(open(sys.argv[1], 'r'))



Advanced Python code for running UNIX commands and File Operations

¨ Running UNIX shell commands from within the python code.

¨ Open and read file from command file

¨ Read all lines in text file and execute a set of functions for each line.

¨ Open and write file from the command line.

Python Program rw_test1.py

Following code can be re-used to do following: