Python program to automatically read text file | applied electronics engineering

# Python program to automatically read text file

By Applied Electronics - Tuesday, May 24, 2016 No Comments
Below is a Python program that reads a text file automatically. This means that users do not have to type all the usual code such as open and read etc to read the text. At the start of the program, the user is asked to enter the name of the text file to be read. The program then reads the lines of the text file iteratively using while loop. The readline method is used to get one line of the text at a time. These text lines are then printed on the display. Finally we close the file to flush the buffer

txt = input('Enter the name of file: ')

f = open(txt)

while line:
print(line, end='')

f.close

Here is an example of using this program.

>>> import myprog
Enter the name of file:  mytext.txt
This is a AM circuit design tutorial using Proteus Professional v8. In this tutorial a simple AM circuit will be designed and simulated. The output is a 600KHz range AM signal.
The AM circuit that will be designed is shown below. 1. Start Proteus and create a new project, give it some name and save it to some folder of your choice. Select Schematic and PCB with no firmware option during the project creation if asked.
2. Turn on the component mode icon and then click the "P" icon to open the Pick Device window which allows you to search component in the proteus library. We will first add the two transistors 2N3904. Type 2N3904 into the search bar as shown and you will be shown the transistor. Now double click the transistor and it will added to the working library.
3. Add the resistor by typing "res" into the search field,  and double click on the item shown in the result window as shown. 4. Add the inductors by typing inductor and select the "B82432C1564K000" inductor or just type "B82432C1564K000" into the search field.
5. Add capacitors by typing cap in the search field and selecting capacitor from the category list and then selecting Generic from the sub-category list. Select two types of capacitors- one  CAP-ELEC which is a generic electrolytic capacitor and the other- CAP-POL which is the Polarized capacitor.
This is shown below-
6. Draw the schematic as shown in the Fig 1. The input port, the output port, the ground and the power part in the schematic can be found by clicking the "Terminal Mode". To name the input port and output port, simple double click on them and give them some name. For example here, input port is given "Modulating" and ouput port is given the name "AM_Signal". Also double click on the power supply and enter "+9V" in the input field. This is the 9V battery. This is shown below-
Near the input port we put a sine signal generator with 1V amplitude and frequency of 1KHz. This will act as our audio signal. This is done by clicking on the Generator Mode icon. This brings up an option for number of different signal generator, select the SINE option and put it on the input port wire as shown below-
7. Now to perform simulation and to see graph of the output, click the Graph Mode icon and select the Analogue type. Now near the output port right click, drag and release to get the graph displayed near the output port. Then select the probe icon on the wire and drag it into the graph.
8. To set the simulation time, right click on the top of the graph as shown and select edit properties. There set the start time to 0 and end time to 100m. To start simulation, press the "Space" key on the keyboard. This will start the simulation.