Search
- Filter Results
- Location
- Classification
- Include attachments
- https://eng.libretexts.org/Courses/Delta_College/Introduction_to_Programming_Concepts_-_Python/14%3A_Object-Oriented_Programming/14.08%3A_Many_InstancesThe constructor has both a self parameter that points to the object instance and then additional parameters that are passed into the constructor as the object is being constructed: Copies the paramete...The constructor has both a self parameter that points to the object instance and then additional parameters that are passed into the constructor as the object is being constructed: Copies the parameter that is passed in (nam) into the name attribute within the object instance. The output of the program shows that each of the objects (s and j) contain their own independent copies of x and nam:
- https://eng.libretexts.org/Courses/Delta_College/Introduction_to_Programming_Concepts_-_Python/12%3A_Networked_Programs/12.07%3A_Parsing_HTML_using_BeautifulSoupThe program prompts for a web address, then opens the web page, reads the data and passes the data to the BeautifulSoup parser, and then retrieves all of the anchor tags and prints out the href attrib...The program prompts for a web address, then opens the web page, reads the data and passes the data to the BeautifulSoup parser, and then retrieves all of the anchor tags and prints out the href attribute for each tag. # Retrieve all of the anchor tags tags = soup('a') for tag in tags: # Look at the parts of a tag print('TAG:', tag) print('URL:', tag.get('href', None)) print('Contents:', tag.contents[0]) print('Attrs:', tag.attrs)
- https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Python_for_Everybody_(Severance)/13%3A_Python_and_Web_Services/13.02%3A_Looping_through_NodesOften the XML has multiple nodes and we need to write a loop to process all of the nodes. In the following program, we loop through all of the user nodes:
- https://eng.libretexts.org/Courses/Delta_College/Introduction_to_Programming_Concepts_-_Python/12%3A_Networked_Programs/12.04%3A_Retrieving_web_pages_with_urllibWhile we can manually send and receive data over HTTP using the socket library, there is a much simpler way to perform this common task in Python by using the urllib library. But soft what light throu...While we can manually send and receive data over HTTP using the socket library, there is a much simpler way to perform this common task in Python by using the urllib library. But soft what light through yonder window breaks It is the east and Juliet is the sun Arise fair sun and kill the envious moon Who is already sick and pale with grief As an example, we can write a program to retrieve the data for romeo.txt and compute the frequency of each word in the file as follows:
- https://eng.libretexts.org/Courses/Delta_College/Introduction_to_Programming_Concepts_-_Python/04%3A_Functions/4.07%3A_Definitions_and_UsesAs you might expect, you have to create a function before you can execute it. In other words, the function definition has to be executed before the first time it is called.
- https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Python_for_Everybody_(Severance)/06%3A_Strings/6.12%3A_DebuggingFor example, look at the program which we used to demonstrate the while loop in the chapter on iteration: There are two solutions to this to make line three "safe" even if the line is empty. One possi...For example, look at the program which we used to demonstrate the while loop in the chapter on iteration: There are two solutions to this to make line three "safe" even if the line is empty. One possibility is to simply use the startswith method which returns False if the string is empty. Another way is to safely write the if statement using the guardian pattern and make sure the second logical expression is evaluated only where there is at least one character in the string.:
- https://eng.libretexts.org/Courses/Delta_College/Introduction_to_Programming_Concepts_-_Python/04%3A_Functions/4.04%3A_Random_NumbersGiven the same inputs, most computer programs generate the same outputs every time, so they are said to be deterministic. Determinism is usually a good thing, since we expect the same calculation to y...Given the same inputs, most computer programs generate the same outputs every time, so they are said to be deterministic. Determinism is usually a good thing, since we expect the same calculation to yield the same result. For some applications, though, we want the computer to be unpredictable. Games are an obvious example, but there are more.
- https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Python_for_Everybody_(Severance)/13%3A_Python_and_Web_Services/13.06%3A_Google_geocoding_web_serviceGoogle has an excellent web service that allows us to make use of their large database of geographic information. We can submit a geographical search string like "Ann Arbor, MI" to their geocoding API...Google has an excellent web service that allows us to make use of their large database of geographic information. We can submit a geographical search string like "Ann Arbor, MI" to their geocoding API and have Google return its best guess as to where on a map we might find our search string and tell us about the landmarks nearby.
- https://eng.libretexts.org/Bookshelves/Computer_Science/Programming_Languages/Python_for_Everybody_(Severance)/12%3A_Networked_Programs/12.02%3A_The_World's_Simplest_Web_BrowserPerhaps the easiest way to show how the HTTP protocol works is to write a very simple Python program that makes a connection to a web server and follows the rules of the HTTP protocol to request a doc...Perhaps the easiest way to show how the HTTP protocol works is to write a very simple Python program that makes a connection to a web server and follows the rules of the HTTP protocol to request a document and display what the server sends back. However, since the protocol that we use most commonly is the HTTP web protocol, Python has a special library specifically designed to support the HTTP protocol for the retrieval of documents and data over the web.
- https://eng.libretexts.org/Courses/Delta_College/Introduction_to_Programming_Concepts_-_Python/13%3A_Python_and_Web_Services/13.6%3A_Google_geocoding_web_serviceGoogle has an excellent web service that allows us to make use of their large database of geographic information. We can submit a geographical search string like "Ann Arbor, MI" to their geocoding API...Google has an excellent web service that allows us to make use of their large database of geographic information. We can submit a geographical search string like "Ann Arbor, MI" to their geocoding API and have Google return its best guess as to where on a map we might find our search string and tell us about the landmarks nearby.
- https://eng.libretexts.org/Courses/Delta_College/Introduction_to_Programming_Concepts_-_Python/14%3A_Object-Oriented_Programming/14.07%3A_Classes_as_TypesWe can use type and dir with the classes that we create. an = PartyAnimal() print (\"Type\", type(an)) print (\"Dir \", dir(an)) print (\"Type\", type(an.x)) print (\"Type\", type(an.party)) Type <cla...We can use type and dir with the classes that we create. an = PartyAnimal() print (\"Type\", type(an)) print (\"Dir \", dir(an)) print (\"Type\", type(an.x)) print (\"Type\", type(an.party)) Type <class '__main__.PartyAnimal'> Dir ['__class__', '__delattr__', ... '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'party', 'x'] Type <class 'int'> Type <class 'method'> From the dir output, you can see both the x integer attribute and the party method are available in the object.