How to use read_py_file method in prospector

Best Python code snippet using prospector_python

argument.py

Source:argument.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3 The argument of hscode4"""5import os6DEFAULT_CHAPTER = '01'7DEFAULT_FILE_ROOT = os.path.join(os.environ['HOME'], 'hscode_file')8class Argument:9 """10 The argument set11 """12 def __init__(self):13 self.all_chapters = False14 self.chapter = DEFAULT_CHAPTER15 self.file_root = DEFAULT_FILE_ROOT16 self.outdated = False17 self.no_latest = False18 self.print_help = False19 self.quiet_mode = False20 self.url_proxy = None21def print_help():22 """23 Print the help info24 """25 print('参数列表:')26 print(' --help|-h 查看帮助信息')27 print(' --search|-s [chapter] 爬取具体章节(商品编码前两位)的内容,默认01')28 print(' --all|-a 爬取所有章节的内容。该开关开启时,--search 无效')29 print(' --file-root [dir] 保存文件的根路径')30 print(' 默认值[HOME]/hascode_file')31 print(' 文件名格式: ')32 print(' hscode_[chapter]_YYYYMMDD_HH:mm.txt')33 print(' hscode_[chapter]_latest.txt')34 print(' --no-latest 不生成(或覆盖原有的)latest文件')35 print(' --quiet|-q 静默模式,不打印日志信息')36 print(' --outdated 包含[过期]数据')37 print(' --proxy|-p [proxy-url] 请求代理')38 print(' --proxy https://www.baidu.com?s={url}')39 print(' {url} 是原始请求 url')40def parse_argv(sys_argv):41 """42 解析系统参数43 python hscode.py -s 8544 """45 length = len(sys_argv)46 result = Argument()47 # 是否已经读取 py 参数48 read_py_file = False49 for i in range(0, length):50 arg = sys_argv[i]51 if not read_py_file and arg.endswith('.py'):52 read_py_file = True53 continue54 # 搜索条件参数55 if arg in ['-s', '--search'] and length > i + 1 and not result.all_chapters:56 i += 157 result.chapter = sys_argv[i]58 # 文件根目录59 elif arg == '--file-root' and length > i + 1:60 i += 161 result.file_root = sys_argv[i]62 # 是否包含已过期数据63 elif arg == '--outdated':64 result.outdated = True65 # 不生成/覆盖 latest 文件66 elif arg == '--no-latest':67 result.no_latest = True68 # 爬取所有章节69 elif arg in ['--all', '-a']:70 result.all_chapters = True71 result.chapter = None72 # 打印帮助信息73 elif arg in ['--help', '-h']:74 result.print_help = True75 # 静默模式76 elif arg in ['--quiet', '-q']:77 result.quiet_mode = True78 # 代理79 elif (arg in ['--proxy', '-p']) and length > i + 1:80 i += 181 url_proxy = sys_argv[i]82 if '{url}' in url_proxy:83 result.url_proxy = url_proxy...

Full Screen

Full Screen

test_openpy.py

Source:test_openpy.py Github

copy

Full Screen

...9 enc, lines = openpy.detect_encoding(f.readline)10 nt.assert_equal(enc, 'iso-8859-5')11def test_read_file():12 read_specified_enc = io.open(nonascii_path, encoding='iso-8859-5').read()13 read_detected_enc = openpy.read_py_file(nonascii_path, skip_encoding_cookie=False)14 nt.assert_equal(read_detected_enc, read_specified_enc)15 assert u'coding: iso-8859-5' in read_detected_enc16 17 read_strip_enc_cookie = openpy.read_py_file(nonascii_path, skip_encoding_cookie=True)18 assert u'coding: iso-8859-5' not in read_strip_enc_cookie...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run prospector automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful