There are countless reasons for parsing data, and the same is true of the tools and techniques involved. However, when you need to do something new with this data, even the "right" tool may not be enough. This concern also exists for the integration of heterogeneous data sources. The right tool for the job should be a programming language sooner or later.
Oracle provides a number of very powerful utilities to load, process, and unload data. Sql*loader, Data Pump, external tables, Oracle Text, and regular expressions all provide these capabilities. However, people often need to do something out of the database (or, to be more trivial, you may not have access to the necessary database permissions).
Python can be used to perform high-level, effective data parsing. With a large number of standard libraries and many modules available free on the Internet, you can handle data logic without having to parse the bytes manually.
Just sent a small hacker in the address bar can unblock the page, recently learned Python, wrote a fairly simple thing, can also do this thing
- #-*-Coding:utf-8-*-
- "" "Author:hujinpu" ""
- "" "Http://docs.python.org/lib/module-urllib.html" ""
- Import Urllib
- URLs = {' blocked Web address ':' downloadtomycomputer.htm '}
- For URL in URLs:
- FileName = URLs[url]
- Urllib. Urlretrieve(url,filename)
- F = open(filename,' R ')
- Content = f. Read()
- F. Close()
- NewFileName = "New_" + filename
- F = open(newfilename,' W ')
- F. Write( content + "<script>document.onselectstart = Document.oncontextmenu = Document.onmousedown = Document.onkeydown = function () {return true;}; </script> ");
- F. Close()
Where URLs are a dictionary that can write a lot of URLs you want to conquer
Python's interaction
In many cases, you will want your program to interact with the user (possibly yourself). You'll get input from the user and print some results. We can use raw_input and input statements separately to accomplish these functions. For output, you can also use a variety of str (string) classes. For example, you can use the Rjust method to get a string that is right-aligned at a certain width. Use Help (str) for more details.
Another common input/output type is processing files. The ability to create, read, and write files is required by many programs
File:
You can open a file by creating an object of the file class, using the read, ReadLine, or write method of the file class to read and write files appropriately. The ability to read and write to a file depends on the pattern you specify when you open the file. Finally, when you are done with the file, you call the Close method to tell Python that we have finished using the file.
#!/usr/bin/python
#Tue Jan 8 21:25:42 CST 2013
Poem= ' \ \
Programming is fun
When the work was done
If you wanna make your work also fun:
Use python!
‘‘‘
F=file (' Poem.txt ', ' W ')
F.write (poem)
F.close ()
F=file (' Poem.txt ')
While True:
Line=f.readline ()
If Len (line) = = 0:
Break
Print line,
F.close ()
The mode of opening the file can be read (' R '), write (' W '), or append (' a ').
Write can only write strings.
Storage device
Python provides a standard module, called Pickle. With it you can store any Python object in a file, and then you can take it out completely, which is known as a persistent storage object.
There is also a module cpickle, its function and the Pickle module is identical, but writes in C language so faster than pickle.
#!/usr/bin/python
#Wed Jan 9 17:40:54 CST 2013
Import Cpickle as P
Shoplistfile= ' Shoplist.data '
shoplist=[' apple ', ' egg ', ' banana '
F=file (Shoplistfile, ' W ')
P.dump (SHOPLIST,F)
F.close
F=file (Shoplistfile)
Storedlist=p.load (f)
Print Storedlist
Use import: As syntax. So that we can use the module name with the segment.
Python also has exception handling. With try. Except for exception handling. We put the usual statements in the try block, and we put our error-handling statements in the except block.
We put all the statements that could throw errors in the try block, and then handle all the errors and exceptions in the EXCEPT clause/block. Except clauses can be specialized in handling a single error or exception, or a set of errors/exceptions that are included in parentheses. If the name of the error or exception is not given, it handles all errors and exceptions. For each try clause, there is at least one associated except clause.
Try: Finally
What if you were reading a file and wanted to close the file regardless of whether it happened or not? This can be done using the finally block. Note that under a try block, you can use both the EXCEPT clause and the finally block. If you want to use them at the same time, you need to embed one in the other.
Run Time.sleep (2) in the program to rest the program. Need to be added to the time module.
The Python standard library is installed with Python and contains a large number of machine-useful modules.
How to use Python to mask some basic features in HTML