我完全是个python新手。我一直在尝试从包含以下数据的文件中去掉前两个字符和一个句点:
12.This a line
13. This is a line too
14. 12 and 13 please stop fighting
我想去掉第一行中的12.1,还想去掉换行符。但是在第三行,在.后面有一个空格,我也需要去掉它。
到目前为止,这是我尝试过的:导入re
with open('linex.txt', 'r+') as lines:
for line in lines:
line = line[2:]
line
在使用string.strip()进行非常简单的字符串操作时,我得到了一些非常奇怪的结果。我想知道这是否是一个只影响我的问题(我的python安装有什么问题吗?)还是普通的窃听器?
窃听器是很有连线的,下面是:
>>> a = './omqbEXPT.pool'
>>> a.strip('./').strip('.pool')
'mqbEXPT' #the first 'o' is missing!!!
只有当“o”跟随“./”时才会发生这种情况!
>>> a
我需要帮助完成我当前的任务之一,我试图通过Python从查询中只选择表名。
因此,基本上假设查询如下所示
Create table a.dummy_table1
as
select a.dummycolumn1,a.dummycolumn2,a.dummycolumn3 from dual
Now i am passing this query into Python using STRINGIO and then reading only the strings where it starts with "a" and has "_" in it like
我如何修复这个程序,以便我可以计算字母的数量和我如何计算单词?
import collections as c
text = input('Enter text')
print(len(text))
a = len(text)
counts = c.Counter(a)
print(counts)
spaces = counts(' ')
print(specific)
print(a-spaces)
#I want to count the number of letters so I want the amount of characters - the a
例如,有一个文本块。
"Text blob1. Text blob2. Text blob3 45.6%. Text blob4."
我想用空间"."代替点,即" "。但与此同时,数字之间的圆点应该保留下来。例如,应该将前面的示例转换为:
"Text blob1 Text blob2 Text blob3 45.6% Text blob4"
如果我用:
p = re.compile('\.')
s = p.sub(' ', s)
它用空间代替所有的点。
对这里的模式或方法有什么建议吗?
使用Python和regex,您可以帮助转换 First sentence.Second sentence. Third 3.4 sentence3.Fourth sentence. Fifth5. Sixth. 至 First sentence. Second sentence. Third 3.4 sentence3. Fourth sentence. Fifth5. Sixth. 即,当空格位于两个字母表之间并且任一侧的字符都是字母表时,需要插入空格。如果句点两边都是数字,则不需要插入空格。请帮帮忙。 提前谢谢。
我需要在字符串中获取最后一个匹配0-9.*,如下所示
one 1.234 three
some text 1.2321 xyz 1 5 1.234 and more text
some other text
但也需要它周围的文本-即使在第三行中没有数字时也是如此
我想使用^(.*)([0-9\.]*+)(.*)$,但它正好与第一个(.*)匹配。
另一方面,^(.*?)([0-9\.]*+)(.*?)$只匹配最后一个(.*?)。
为什么会这样呢?我以为它会试着满足所有规则?
我知道我可以排除0-9。从上一个.*获得我想要的东西,但是我想知道为什么我使用了*+,但上面的方法不起作用