In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I would like to talk to you about how to correctly understand the Python source files, many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
Using the Python source file at the bottom of the build script, you can define the compile target. The inner elements of the Python source file are the tasks executed during the compile run, especially the py-compile task, which is responsible for compiling all Python code starting from the src directory.
This task recursively traverses all subdirectories and compiles all Python modules. Instead of hardcoding the src directory to the place of the call, the script defines an attribute called src.dir in the build script. Then, when you need to use this directory name.
It can be referenced by ${src.dir}. To run the build script, open it from Eclipse. Eclipse has built-in Ant build script editing and browsing capabilities. The Outline view shows the structure of the build script. In the Navigator view.
Select the build script, right-click, and select "Run Ant...". Select the compile target and click "Run". The output during the execution of the build script should be displayed in the Console view, indicating that the run was successful. As can be seen from the analysis of the above pydoc goals.
Summary of Python programming skills
Full parsing of Python design language features
Brief Reading flexible Python programming language
About the hodgepodge of Python versions
How to master Python exception handling
Line 7 declares the target name and indicates that it depends on the init and compile targets. This means that before running the pydoc target, Ant must ensure that the init and compile targets are already running, and if not, run them first.
The pydoc target on which the init target depends is defined on lines 3 through 5. The init target simply creates a directory where the PyDoc API document files are stored. As mentioned earlier, you want to define a property called pydoc.dir for the location where the generated document is saved.
Line 8 begins with the py-doc task. As mentioned earlier, you pass in the PYTHONPATH used in generating the pydoc. The destdir attribute tells the py-doc task where to output the generated HTML document. Lines 9 through 11 define which Python source files should be processed during document generation. Filesets are a common structure in Ant scripts.
Can be used to define a set of files to operate on. This is a powerful feature that allows you to select the file you want to operate on through name patterns, Boolean logic, and file properties. A complete description of this is available in the Ant documentation. In this example, all files in the "src" directory are selected recursively.
There is a standard unit testing framework in the Python source file (starting with Python 2.3). This is only an optional module in Python 2.2), which is very similar to the Java jUnit framework. The test case is structured in the same way as jUnit. Each class and module to be tested usually has its own test class. The test class contains a test device (fixture).
They are initialized in the setUp function. Each test is written as a separate test function in the test class. The unittest framework cycles back and forth between test functions, calling setUp, then testing functions, and then tearDown test functions. See the example in listing 4.
Import unittest from pprint import pprint import feedparser class FeedparserTest (unittest.TestCase): "A test class for the feedparser module." Def setUp (self): "set up data used in the tests. SetUp is called before each test function execution." Self.developerWorksUrl = "testData/developerworks.rss" def testParse09Rss (self): "Test a successful run of the parse function for a 0.91 RSS feed." Print "FeedparserTest.testParse09RSS ()" result = feedparser.parse (self.developerWorksUrl) pprint (result) self.assertEqual (0 Result ['bozo']) self.assert_ (result is not None) channel = result [' channel'] self.assert_ (channel is not None) chanDesc = channel ['description'] self.assertEqual (u'The latest content from IBM developerWorks' ChanDesc) items = result ['items'] self.assert_ (items is not None) self.assert_ (len (items) > 3) firstItem = items [0] title = firstItem [' title'] self.assertEqual (u'Build installation packages with solution installation and deployment technologies' Title) def tearDown (self): "" tear down any data used in tests tearDown is called after each test function execution. " Pass if _ _ name__ = ='_ _ main__': unittest.main ()
The above listing is a test class that implements the basic testing functions of the feedparser module. For the complete test class, see src/feedparserTest/FeedparserTest.py under the feedParserTest project. The step function is responsible for preparing the test device to be used throughout the test, in this case only the directory of the RSS file used for the test.
The test function will parse it. TestParse09Rss is the real test function. Python source file this function calls the feedparser.parse function, passes the test RSS file, outputs the parsing results, and performs basic checks through the assert function of the TestCase class.
If any assert evaluates to something that is not true, or if any exception is thrown during execution, unittest reports a test failure or error. The two lines of * * are responsible for running the test inside the test class by running the module directly.
After reading the above, do you have any further understanding of how to correctly understand the Python source files? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.