Best Python code snippet using prospector_python
pydiction.py
Source: pydiction.py
1#!/usr/bin/env python2# pydiction.py 0.5345""" pydiction creats a dictionary of Python module attributes for vim's completion feature.6 Usage: pydiction.py <module(s)> [-v]7 (Note: If you're getting import errors try importing the Package's main module below in this file)89 Example: The following will append all the time and math modules' attributes to the file "pydiction" with 10 and without the "time." and "math." prefix: 11 12 $python pydiction.py time math13 14 To print the output to stdout, supply the -v option (This won't append to the pydiction file):15 16 $python pydiction.py -v time math17"""18 192021__author__ = 'Ryan (gt3) Kulla <ambiod@sbcglobal.net>'22__version__ = '0.5'232425import os26import sys27import types282930def main_loop(write_to):31 sub_mods = []3233 for mod_name in sys.argv[1:]:34 sub_mods = mod_lookup(mod_name, sub_mods, write_to)3536 # process current mod_name's submodules37 for mod_name in sub_mods:38 sub_mods = mod_lookup(mod_name, sub_mods, write_to, False)394041def mod_lookup(mod_name, sub_mods, write_to, dig=True):42 prefix_on = {True:"%s.%s(", False:"%s.%s"}43 prefix_off = {True:"%s(", False:"%s"}4445 try:46 exec "import %s" % mod_name47 except ImportError, err_msg:48 if sub_mods != []: # sub_mod isn't an importable module49 sub_mods.remove(mod_name) 50 else: 51 sys.stderr.write("ImportError: %s\n" % err_msg)52 sys.exit()5354 mod_contents = dir(eval(mod_name))5556 write_to.write('\n-- %(x)s module with "%(x)s." prefix --\n' % {'x': mod_name})57 for attr in mod_contents:58 if callable(getattr(eval(mod_name), attr)):59 write_to.write(prefix_on[True] % (mod_name, attr) + '\n')60 else:61 write_to.write(prefix_on[False] % (mod_name, attr) + '\n')62 if dig is True: # dig for submodules63 if type(getattr(eval(mod_name), attr)) is types.ModuleType:64 sub_mods.append(mod_name + '.' + attr)6566 write_to.write('\n-- %(x)s module without "%(x)s." prefix --\n' % {'x': mod_name})67 for attr in mod_contents:68 if callable(getattr(eval(mod_name), attr)):69 write_to.write(prefix_off[True] % attr + '\n')70 else:71 write_to.write(prefix_off[False] % attr + '\n')7273 return sub_mods747576if __name__ == '__main__':77 if sys.version_info[0:2] < (2, 3):78 sys.stderr.write("Please upgrade to Python 2.3 or greater\n")79 sys.exit()8081 if len(sys.argv) <= 1:82 sys.stderr.write("%s requires at least one argument\n" % sys.argv[0])83 sys.exit()8485 if "-v" in sys.argv:86 write_to = sys.stdout87 sys.argv.remove("-v")88 else:89 if os.path.exists("pydiction"):90 print "Appending to pydiction file.."91 else:92 print "Creating and writing to pydiction file.."93 write_to = open("pydiction", "a")94
...
second-2.py
Source: second-2.py
1class RingBuffer:2 def __init__(self, capacity):3 self.capacity = capacity4 self.data = [None for i in range(capacity)] # junk values5 self.write_to = 06 self.read_from = 07 def _inc(self, inx):8 return (inx + 1) % self.capacity9 def write(self, data):10 if self.write_to == self.read_from and self.data[self.write_to] is not None: # value is overwritten11 self.read_from = self._inc(self.read_from)12 self.data[self.write_to] = data13 self.write_to = self._inc(self.write_to)14 # print(f"DEBUG: write_to {self.write_to}")15 def read(self):16 data = self.data[self.read_from]17 if data is None:18 raise Exception("Trying to read from an empty ring buffer")19 self.data[self.read_from] = None20 self.read_from = self._inc(self.read_from)21 # print(f"DEBUG: read_from {self.read_from}")22 return data23 def __str__(self):...
Check out the latest blogs from LambdaTest on this topic:
“Test frequently and early.” If you’ve been following my testing agenda, you’re probably sick of hearing me repeat that. However, it is making sense that if your tests detect an issue soon after it occurs, it will be easier to resolve. This is one of the guiding concepts that makes continuous integration such an effective method. I’ve encountered several teams who have a lot of automated tests but don’t use them as part of a continuous integration approach. There are frequently various reasons why the team believes these tests cannot be used with continuous integration. Perhaps the tests take too long to run, or they are not dependable enough to provide correct results on their own, necessitating human interpretation.
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
Have you ever visited a website that only has plain text and images? Most probably, no. It’s because such websites do not exist now. But there was a time when websites only had plain text and images with almost no styling. For the longest time, websites did not focus on user experience. For instance, this is how eBay’s homepage looked in 1999.
Recently, I was going through some of the design patterns in Java by reading the book Head First Design Patterns by Eric Freeman, Elisabeth Robson, Bert Bates, and Kathy Sierra.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!