python:python
                Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| python:python [2014/04/18 13:58] – [TODO] dblume | python:python [2024/02/27 15:43] (current) – [Linux script that takes either stdin or files] dblume | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Python ====== | + | ====== | 
| Man, there' | Man, there' | ||
| Line 7: | Line 7: | ||
| * [[http:// | * [[http:// | ||
| * [[http:// | * [[http:// | ||
| - | * Of course, there' | + | * Of course, there' | 
| * There' | * There' | ||
| - | * Look into the microframework [[http:// | + | * Look into the microframework [[http:// | 
| * [[https:// | * [[https:// | ||
| * [[http:// | * [[http:// | ||
| * [[http:// | * [[http:// | ||
| - | * [[https:// | + | * [[https:// | 
| + | * A Power Point deck by Alex Martelli describing [[http:// | ||
| + | * [[http:// | ||
| + | * [[http:// | ||
| Would be nice to create a binary search in text files in Python. | Would be nice to create a binary search in text files in Python. | ||
| Line 20: | Line 23: | ||
| Would be good to experiment with [[http:// | Would be good to experiment with [[http:// | ||
| + | |||
| ===== Data Analysis ===== | ===== Data Analysis ===== | ||
| Line 76: | Line 80: | ||
| ===== Linux script that takes either stdin or files ===== | ===== Linux script that takes either stdin or files ===== | ||
| + | Newer way, **use [[https:// | ||
| <code python> | <code python> | ||
| if __name__==' | if __name__==' | ||
| Line 84: | Line 89: | ||
| if not line: | if not line: | ||
| break | break | ||
| - | my_process_line( line.rstrip() ) | + | my_process_line(line.rstrip()) | 
| else: | else: | ||
| # Process lines of the files specified. | # Process lines of the files specified. | ||
| for fname in sys.argv[1: | for fname in sys.argv[1: | ||
| - | if not os.path.exists( fname ): | + | if not os.path.exists(fname): | 
| - | treat_argument_as_literal( fname ) | + | treat_argument_as_literal(fname) | 
| continue | continue | ||
| - | with open( fname, ' | + | with open(fname, ' | 
| while 1: | while 1: | ||
| line = f.readline() | line = f.readline() | ||
| if not line: | if not line: | ||
| break | break | ||
| - | my_process_line( line.rstrip() ) | + | my_process_line(line.rstrip()) | 
| </ | </ | ||
| Line 145: | Line 150: | ||
|  |  | ||
| if __name__ == ' | if __name__ == ' | ||
| - | cProfile.run( " | + | cProfile.run(" | 
| </ | </ | ||
| Line 159: | Line 164: | ||
| # Split input data by row and then on spaces | # Split input data by row and then on spaces | ||
| - | rows = [ line.strip().split(' | + | rows = [line.strip().split(' | 
| # Reorganize data by columns | # Reorganize data by columns | ||
| Line 165: | Line 170: | ||
| # Compute column widths by taking maximum length of values per column | # Compute column widths by taking maximum length of values per column | ||
| - | col_widths = [ max(len(value) for value in col) for col in cols ] | + | col_widths = [max(len(value) for value in col) for col in cols] | 
| # Create a suitable format string | # Create a suitable format string | ||
| - | format = ' ' | + | format = ' ' | 
| # Print each row using the computed format | # Print each row using the computed format | ||
| Line 199: | Line 204: | ||
| self.__m_x = x | self.__m_x = x | ||
| - | x = property( getx, setx ) | + | x = property(getx, | 
| class B: | class B: | ||
| """ | """ | ||
| - | __slots__ = [ " | + | __slots__ = [" | 
| def __init__(self): | def __init__(self): | ||
| self.__m_x = 0 | self.__m_x = 0 | ||
| Line 214: | Line 219: | ||
| self.__m_x = x | self.__m_x = x | ||
| - | x = property( getx, setx ) | + | x = property(getx, | 
| class C(object): | class C(object): | ||
| - | """ | + | """ | 
| def __init__(self): | def __init__(self): | ||
| self.__x = 0 | self.__x = 0 | ||
| Line 228: | Line 233: | ||
| self.__x = x | self.__x = x | ||
| - | x = property( getx, setx ) | + | x = property(getx, | 
| </ | </ | ||
| Line 247: | Line 252: | ||
| fcntl.flock(f, | fcntl.flock(f, | ||
| </ | </ | ||
| + | |||
| + | ====== Various Approaches to threaded URL Requests ====== | ||
| + | |||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * Or, use the doc's [[https:// | ||
| + | * And, as mentioned in Parallelism in One Line, [[https:// | ||
| ====== Fibonacci Generator with Itertools ====== | ====== Fibonacci Generator with Itertools ====== | ||
| Line 268: | Line 281: | ||
| # for i in range( 5 ): | # for i in range( 5 ): | ||
| # print i, fib( i ) | # print i, fib( i ) | ||
| + | </ | ||
| + | |||
| + | ====== Parse C++ Code with nm and graphviz' | ||
| + | |||
| + | <code bash> | ||
| + | sudo apt-get install graphviz | ||
| + | </ | ||
| + | |||
| + | <code python> | ||
| + | # Read `nm` output | ||
| + | output = subprocess.check_output([' | ||
| + | for line in output.split(' | ||
| + | if ' | ||
| + | |||
| + | # Make a .dot file | ||
| + | with open(filename + ' | ||
| + | file.write(' | ||
| + | for f, destinations in self.graph.items(): | ||
| + | for d in destinations: | ||
| + | file.write(f' | ||
| + | |||
| + | |||
| + | def create_png_image(filename): | ||
| + | with open(filename + ' | ||
| + | p1 = subprocess.run([' | ||
| + | |||
| </ | </ | ||
python/python.1397854706.txt.gz · Last modified: 2023/04/12 20:44 (external edit)
                
                