import inspect lines = inspect.getsource(magic_function) print(lines) … [Read more...] about How to get the Python source codelines?
NumPy is the fundamental package for scientific computing with Python. It contains among other things: a powerful N-dimensional array object; import numpy as np T = np.array([ [[1,2,3], [4,5,6], [7,8,9]], [[11,12,13], [14,15,16], [17,18,19]], [[21,22,23], [24,25,26], [27,28,29]], ]) print(T.shape) # (3,3,3) print(T.ndim) # 3 print(T.size) # 27 print(T) Each … [Read more...] about Tensor in NumPy and what may be useful to know about tensor shapes
This program is simple post and get request implementation. Since Python works almost anywhere this is a handy code to have. ''' This is a comment, If you see this, CGI is not working ''' import sys import urllib2 import urllib '''Pickling is the process converting object into a byte stream, and unpickling is the inverse operation.''' try: import cPickle as … [Read more...] about Post and Get requests in Python
Question is how to read HTML from some URL in Python. Here is the answer: try: r = urllib2.urlopen(url) except: print "Unexpected error, looks that URL isn't available or doesn't exist." sys.exit(0) html = r.read() Thanks … [Read more...] about Read HTML from URL
To extract frequent words from some text we can work with Dict in Python. If you need to disable some words add them to stopword string # prints 40 top keywords for the text def PrintTopKeywords(text): stopwords = 'I we he she a about an and are as at be by com for from how if in is it me more my myself of on or that the this to was what when where who will with you your' … [Read more...] about Extract frequent words from the text in Python