正在尝试python中的以下正则表达式,但它返回一个错误
import re
...
#read a line from a file to variable line
# loking for the pattern 'WORD' in the line ...
m=re.search('(?<=[WORD])\w+',str(line))
m.group(0)
我得到以下错误:
AttributeError:'NoneType‘对象没有属性'group'
%%writefile testcipher.py
import argparse
def parse_command_line():
parser=argparse.ArgumentParser()
parser.add_argument("infile",type=argparse.FileType('r'),help="show this help message and exit")
args=parser.parse_args()
def read_file(file_path):
with open(
# Load the Pandas libraries with alias 'pd'
import pandas as pd
# Read data from file 'filename.csv'
# (in the same directory that your python process is based)
# Control delimiters, rows, column names with read_csv (see later)
data = pd.read_csv("C:/Python Scripts/TextFile
s="ABC"
for k in ["isalnum()", "isalpha()", "isdigit()", "islower()", "isupper()"]:
for c in s:
print(c.k)
在执行上面的代码时得到这个错误"AttributeError:'str‘对象没有属性'k’“。对于这个错误,我参考了其他类似的问题,但与我的问题无关,我对python非常陌生。
类似的问题还有很多。这里有两个: Python Error: AttributeError: 'NoneType' object has no attribute 'to_excel' AttributeError: 'Object has no attribute' 我想在excel文件的列标题中用空格替换下划线,然后保存它。代码如下: import pandas as pd
ws = r'c:/users/jpilbeam/Reverse911_1a_English_.xlsx'
# data frame from ex
我有一个25 of的文本文件。所以我把它压缩成tar.gz,它变成了450 MB。现在,我想从python中读取该文件,并处理文本data.for,这是我所提到的。但在我的案例中代码不起作用。守则如下:
import tarfile
import numpy as np
tar = tarfile.open("filename.tar.gz", "r:gz")
for member in tar.getmembers():
f=tar.extractfile(member)
content = f.read()
Data = n
每当我尝试使用这个循环功能时,它都会给我一个错误,它的行比我的代码末尾更远。一般来说,我对python和编码是相当陌生的,但我认为这是我下载的存储库的一部分。错误代码如下所示 Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/player.py", line 603, in run
self._do_run()
File "/opt/virtualenvs/python3/lib/python3.8/
我在Python上做“猜测单词”,但我找不到这个错误。
AttributeError: 'int' object has no attribute 'index' (python)
它在letterIndex=word.index(guess)行上给了我一个错误。
def checkLetter(word):
blanks = '_' * len(str(word))
print('Word: ', blanks)
if str(guess) == str(letters):
letter
我正在尝试从中读取一个XML文件。到目前为止,我尝试了以下几种方法:
from xml.dom.minidom import parse
#Start Get Employees
xml = urllib.request.urlopen('https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.stocks%20where%20symbol%3D%22wfc%22&diagnostics=true&env=store%3A%2F%2Fdatatable
首先,我使用pd.read_sql()函数创建了一个数据集。据我所知,所有导入的列都是字符串。
然后创建一个新的空变量并定义一个函数,如下所示(tinyurl.com/tnr9b83):
df['status_update'] = ""
def f(row):
if (row['priority'] in ("1","2")) and (row['failed'] == "Y"):
val = "F"
elif (row['pr
我试图在pysphere中使用VIProperty,但我得到的是'str‘对象没有属性'typecode'。
代码:
for h, mor in server.get_hosts().items():
if mor == 'xxx.com':
prop = VIProperty(server, mor)
错误:
Traceback (most recent call last):
File "teardown.py", line 29, in <module>
prop = VIProper
我得到了一个.csv文件,这是一个来自气象站的数据文件,其中包括日期、时间、温度、露点、湿度等。这是迄今为止我在Python文件中所拥有的:
import math
import pandas as pd
import math
import numpy
openfile=pd.read_csv('KOAK.csv','r',delimiter=',',skiprows=8,header=None)
f1=openfile.read()
openfile.close()
我跳过了前8行,因为它们包含标题信息。如何修复此Python代码以读取整个数
我现在尝试运行Python代码,如下所示: def from_file(filename, sep='\n'):
"Parse a file into a list of strings, separated by sep."
return (filename).read().strip().split(sep) 我得到了错误,如: AttributeError:'str‘对象没有'read’属性 有什么想法吗?
我不明白为什么mypy在我的方法中抱怨错误的类型:
def check_earliest(self, symbol: str) -> Optional[datetime]:
"""Return earliest date of available data for a given symbol."""
try:
return self.read(symbol).index.min()
except (KeyError, AttributeError):
我正在尝试使用python中的poll()轮询一个进程。
我不明白,我为它提供了一个整数值来进行轮询。例如:值为14870
14870
Traceback (most recent call last):
File "test.py", line 29, in <module>
parse_file(input_csv[0])
File "test.py", line 24, in parse_file
ret = pid[r].poll()
AttributeError: 'int' object has n