Skip to content

Instantly share code, notes, and snippets.

@manichabba
manichabba / spam.py
Created July 23, 2016 21:29
Python exercise 7.2
spam = 0.0
Count = 0
fname = raw_input("Enter file name: ")
try:
fh = open(fname)
except:
print "File cannot be opened:",fname
exit ()
for line in fh:
fname = raw_input("Enter file name: ")
fh = open(fname)
lst = list()
for line in fh:
for word in line.split():
if word not in lst:
lst.append(word)
lst.sort()
print lst
name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
emails = list()
count = dict()
for line in handle:
if not line.startswith("From ") : continue
words = line.split()
emails.append (words[1])
fname = input("Enter file name:")
handler = open(fname,'r')
file = handler.read()
words = file.split()
req = input("Enter the word you want to find in the file:")
ans = words.count(req)
print (req," occurs ",ans, " times.")
name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)
hour = list()
count = dict()
for line in handle:
if not line.startswith("From ") : continue
time = line.split()[5]
hour.append(time.split(":")[0])
for key in hour:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#myPage">Mani Chabba</a>
</div>
@manichabba
manichabba / FindNumber.py
Created August 15, 2016 14:10
Finding Numbers in a Haystack In this assignment you will read through and parse a file with text and numbers. You will extract all the numbers in the file and compute the sum of the numbers.
import re #using regular expressions
print sum(map(int, re.findall('[0-9]+',open('RegexSum289081.txt').read())))
#Outline-read the file, look for integers using the re.findall(),converting the extracted strings to integers and summing up the integers.
@manichabba
manichabba / WritingWeb.py
Created August 15, 2016 14:42
Using sockets to read a URL and get information
import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('www.pythonlearn.com', 80))
mysock.send('GET http://www.pythonlearn.com/code/intro-short.txt HTTP/1.0\n\n')
while True:
data = mysock.recv(512)
if ( len(data) < 1 ) :
break
@manichabba
manichabba / NumScrap.py
Created August 15, 2016 17:34
Number scraping using beatiful soup from content of span tag
import urllib
from BeautifulSoup import *
url = raw_input("Enter the URL:")
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html)
tags=soup('span')
x = list()