如何在Python中找到String中的模式/组合?(How do you find patterns/combinations within a String in Python? [closed])
我想在Python中返回以下所有实例,但不确定如何。 如在,每次找到以下格式时,如何搜索字符串并打印:
<a href="[what I'm trying to return is here]" class="faux-block-link__overlay-link"
I'm looking to return all instances of the following in Python, but not sure how. As in, how can I search a String and print every time the following format is found:
<a href="[what I'm trying to return is here]" class="faux-block-link__overlay-link"
原文:https://stackoverflow.com/questions/37101336
最满意答案
显然,如果你可以将所有数据缓冲到内存中(如果主机系统可以支持一个工作集页面,这个页面足够大,可以让所有数据实际上保留在RAM中而不需要分页,那么这可能是最快的可能的方法。
但是,要非常小心地考虑由虚拟内存分页子系统引起的“隐藏磁盘I / O”! 如果请求的“内存中”数据实际上不是 “在内存中”,则会发生页面错误,并且您的进程将停止在其轨道中,直到检索到页面为止。 (如果发生“页面窃取”,那么,你就遇到了麻烦。你的“内存”策略刚刚变成了一个非常低效的(!)基于磁盘的策略。如果密钥是随机分配的,那么你的进程就有了一个巨大的工作集,它正在随机访问。如果所有的内存实际上都不在内存中, 并且会留在那里,那你就麻烦了。
如果要对大文件进行更新,请考虑在处理update-delta文件之前对其进行排序 ,以便所有相同的键都相邻。 您现在可以编写COBOL程序以利用此功能(当然,如果检测到
abend
记录,则会abend
!)。 如果“this”记录中的键与“previous”记录中的键相同,则无需重新读取记录。 (并且,在密钥确实发生变化之前,您实际上不需要编写旧记录。)由于索引文件访问方法带有一系列密钥,因此每个密钥可能“接近”先前的密钥 -请求,以便一些必要的索引树页面已经在内存中。 显然,您需要对此进行基准测试,但是对文件进行排序所花费的时间远远少于在索引查找中花费的时间。 (实际上可能相当大。)Obviously, if you can buffer all of the data into memory (and if the host system can support a working-set of pages which is big enough to allow all of it to actually remain in RAM without paging, then this would probably be the fastest possible approach.
But, be very careful to consider "hidden disk-I/O" caused by the virtual-memory paging subsystem! If the requested "in-memory" data is, in fact, not "in memory," a page-fault will occur and your process will stop in its tracks until the page has been retrieved. (And if "page stealing" occurs, well, you're in trouble. Your "in-memory" strategy just turned into a possibly very-inefficient(!) disk-based one. If keys are distributed randomly, then your process has a gigantic working-set that it is accessing randomly. If all of that memory is not actually in memory, and will stay there, you're in trouble.
If you are making updates to a large file, consider sorting the updates-delta file before processing it, so that all occurrences of the same key will be adjacent. You can now write your COBOL program to take advantage of this (and, of course, to
abend
if an out-of-sequence record is ever detected!). If the key in "this" record is identical to the key of the "previous" one, then you do not need to re-read the record. (And, you do not actually need to write the old record, until the key does change.) As the indexed-file access method is presented with the succession of keys, each key is likely to be "close to" the one previously-requested, such that some of the necessary index-tree pages will already be in-memory. Obviously, you will need to benchmark this, but the amount of time spent sorting the file can be far less than the amount of time spent in index-lookups. (Which actually can be considerable.)
相关问答
更多-
什么是COBOL用于?(What is COBOL used for? [closed])[2022-03-23]
由Grace Murray Hopper '发明'的COmmon Business Oriented Language(阅读她的故事,她是我们今天所知的计算发展中的关键人物之一)。 总体思路是产生一种基于英语的语言,而不是基于数学或在代码中表达的语言。 很简单,你会使用像 ADD YEARS TO AGE 而不是 age = age + years 要么 age += years 出现在二十世纪六十年代初期,它被大量采用在商业领域进行加工。 在COBOL中仍然有大量的应用程序仍在运行和维护,它仍然非常 ... -
对于第一个问题,你可以简单地使用像; 然后你可以通过给出分隔符将文件导入excel: 01 NEWFILE. 05 EMPID PIC 9(6). 05 FILLER PIC X VALUE ';'. 05 NAME PIC A(10). 05 FILLER PIC X VALUE ';'. 05 COMPANY PIC X ...
-
显然,如果你可以将所有数据缓冲到内存中(如果主机系统可以支持一个工作集页面,这个页面足够大,可以让所有数据实际上保留在RAM中而不需要分页,那么这可能是最快的可能的方法。 但是,要非常小心地考虑由虚拟内存分页子系统引起的“隐藏磁盘I / O”! 如果请求的“内存中”数据实际上不是 “在内存中”,则会发生页面错误,并且您的进程将停止在其轨道中,直到检索到页面为止。 (如果发生“页面窃取”,那么,你就遇到了麻烦。你的“内存”策略刚刚变成了一个非常低效的(!)基于磁盘的策略。如果密钥是随机分配的,那么你的进程就有 ...
-
那对你有用吗? // query for a given term ("search_term") $search_query = new WP_Query(); $search_posts = $search_query->query('s=search_term'); 资源 Does that work for you? // query for a given term ("search_term") $search_query = new WP_Query(); $search_posts = $ ...
-
DD声明通常是: - //ddname DD DSN=KC02477.NEWEMP.WORKASGN.KSDS,DISP=SHR 其中ddname将在程序中定义。 The DD statement would typically be :- //ddname DD DSN=KC02477.NEWEMP.WORKASGN.KSDS,DISP=SHR where ddname would be defined within the program.
-
几个问题 为什么在读取文件???时必须将值移动到表而不是执行测试。 赋值是否明确规定在进行任何测试之前必须将每条记录读入表中? 或者你只需要将所有相关记录存储在一个表中,如果其中一个有错误,则将它们全部打印出来。 最好尽可能少地存储在表格中。 如果你需要将整个文件存储在一个表中,基本上你可以 将文件读入表格 在工作存储中包含Copybooks 如果要测试表条目,请检查记录类型并将表条目移动到相应的副本。 01 File-Records. 03 filler occurs 285. ...
-
COBOL中的嵌套执行循环?(Nested Perform Loops in COBOL?)[2022-03-22]
DISPLAY INPUTC.后的那个令人讨厌的范围终止期DISPLAY INPUTC. 正在终止嵌套的PERFORM语句的范围。 摆脱期限,一切都应该正常工作。 在将程序编码为COBOL-85标准时,您应该在程序部门使用的唯一时间段是终止段落和段落标题以及终止当前段落,段落或程序所需的时段。 That nasty scope terminating period after DISPLAY INPUTC. is terminating the scope of the nested PERFORM sta ... -
COBOL的范围是什么?(What is the scope of COBOL)[2022-07-21]
Cobol对变量进行编译时绑定,有时称为静态范围。 在此范围内,Cobol支持程序中的多个范围: “外部”变量是Fortran或汇编程序常见部分的等价物,它们是真正的全局变量。 在工作存储中声明为全局的“全局程序范围”变量对于在该程序中包含的所有嵌套子程序中声明它们的整个程序是可见的。 在工作存储中声明的“程序范围”变量对于声明它们的整个程序是可见的。 在本地存储中声明的“程序范围”变量对于声明它们的整个程序是可见的,但在每次调用时都会被删除并重新初始化。 思考线程范围,sorta。 “嵌套程序范围”Cob ... -
jEdit具有COBOL模式,但它也不会以特殊方式处理前七个字符,除非它们后跟*或/。 然后整行被视为评论。 应该可以改变编辑模式来改变这种状况,不过我有点担心它的表现。 jEdit has a COBOL mode but it also doesn't treat the first seven characters in a special way, except when they are followed by * or /. Then the whole line is treated as a ...
-
COMP-3是二进制编码十进制(BCD)的实现。 一个字节中的每个半字节对应一个数字,最后一个半字节保持符号。 你有...的地方 00 20 0C 01 10 0C 01 00 0C ...我们可以将前三个字节映射到RECORD-X ,其值为+002.00。 具有值C,A,F或E的符号半字节在算术上被认为是正的; 值为B或D的符号半字节在算术上被认为是负数。 小数点未在数据中编码,您必须具有字段定义才能知道它的位置。 IBM Enterprise COBOL具有“首选符号”的概念,其中C表示正数,D表示负 ...