top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to read file in python?

0 votes
How to read file in python?
posted May 31, 2018 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Using read() method we can read a file in python. 

file = open(“testfile.text”, “r”) 
answer Jun 30, 2018 by Maninder Bath
Similar Questions
+2 votes

Is there a better way to do that:

def Read_CSV_File(filename):
 file = open(filename, "r")
 reader = csv.DictReader(file)
 line = 1
 for row in reader:
 if line < 6:
# process the CSV
0 votes

How to read/load the cmake file in python and access its elements. I have a scenario, where i need to load the make file and access its elements. I have tried reading the make file as text file and parsing it,but its not the ideal solution. Please let me know how to load the .mk file and access its elements in python.

+1 vote

With Mozrepl addon in Firefox and Python I do:

> import telnetlib
> tn = telnetlib.Telnet(r'', 4242, 5)
> tn.read_eager()
'nWelcome to MozRepl.nn - If you get stuck at the "'
> tn.read_until("repl> ")
> tn.write(r'alert(window.content.location.href)'+"n")

and I get an alert box with the URL of the active tab.

But how do I read that URL into a python variable? Something like tn.write(r';var zz = window.content.location.href'+ "n") but that doesn't get it into python.

+1 vote

I want to read the combo box in excel by using "xlrd" but in the output it is showing empty message, its not reading the combo box can u guys help me how to read the combo box in excel by "xlrd"

code written like this

workbook = xlrd.open_workbook('path of the file')
worksheet = workbook.sheet_by_name('sheetname')
TargetSystem = worksheet.cell_value(4, 2)
+1 vote

I use scapy for MGCP. I started off with reading a .pcap file with MGCP packets.

For example:

from scapy.all import *
from scapy.utils import *
from scapy.layers.mgcp import *

mgcp_pkts = rdpcap("my-mgcp-capture.pcap")

However, rdpcap() is returning all MGCP packets as UDP packets. The output is something like:

All 262 UDP packets are actually MGCP packets. 

I would have thought rdpcap() will understand MGCP packet format.

Would appreciate help on how I can make scapy read MGCP packets from a .pcap file.