我做了一个简单的程序,但是当我运行它时会显示以下错误:
line1 = []
line1.append("xyz ")
line1.append("abc")
line1.append("mno")
file = open("File.txt","w")
for i in range(3):
file.write(line1[i])
file.write("\n")
for line in file:
print(line)
file.close()
Run Code Online (Sandbox Code Playgroud)
它显示以下错误消息:
文件"C:/ Users/Sachin Patil/fourth,py.py",第18
行,输入文件中的行:UnsupportedOperation:不可读
检查sklearn模型是否已安装的最优雅方法是什么?即它是否fit()在实例化之后调用了它的函数.
我正在使用angular2验证我的模板,但同时它显示了这个错误:
Cannot read the property 'errors' of undefined.
Run Code Online (Sandbox Code Playgroud)
这是我的模板:
<h3 class = "head">{{title}}</h3>
<form [ngFormModel]="form" #f="ngForm">
<div class="row">
<div class="form-group">
<label class="formHeading">Facebook</label>
<input type="text" id="facebook" class="form-control col-xs-3" ngControl="facebook" #facebook="ngForm" >
</div>
<div *ngIf ="facebook.touched && facebok.errors">
<div class="form-row btn">
<button type="submit" class="btn btn-primary pull-right butspace" [disabled]="!f.valid">Save</button>
</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
我不知道为什么它会显示这个错误.任何人都可以解决它?
我对Python有点陌生,并且我一直在通过Anaconda使用Jupyter Notebook。我正在尝试导入一个csv文件来制作一个DataFrame,但是我无法导入该文件。
这是使用本地方法的尝试:
df = pd.read_csv('Workbook1')
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-11-a2deb4e316ab> in <module>()
----> 1 df = pd.read_csv('Workbook1')
Run Code Online (Sandbox Code Playgroud)
之后,我尝试使用路径(我将用户用作用户名)
df = pd.read_csv('Users/user/Desktop/Workbook1.csv')
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-13-3f2bedd6c4de> in <module>()
----> 1 df = pd.read_csv('Users/user/Desktop/Workbook1.csv')
Run Code Online (Sandbox Code Playgroud)
我正在使用Mac,这也是我的新手,我不确定100%是否正确导入了正确的路径。谁能提供一些见解或解决方案,让我打开此csv文件。
I want to say that Napp Granade
serves in the spirit of a town in our dis-
trict of Georgia called Andersonville.
Run Code Online (Sandbox Code Playgroud)
我有数千个包含上述数据的文本文件,并且单词已使用连字符和换行符进行包装。
我想要做的是删除连字符并将换行符放在单词的末尾。如果可能的话,我不想删除所有带连字符的单词,只删除那些位于行尾的单词。
with open(filename, encoding="utf8") as f:
file_str = f.read()
re.sub("\s*-\s*", "", file_str)
with open(filename, "w", encoding="utf8") as f:
f.write(file_str)
Run Code Online (Sandbox Code Playgroud)
上面的代码不起作用,我尝试了几种不同的方法。
我想浏览整个文本文件并删除所有表示换行符的连字符。如:
I want to say that Napp Granade
serves in the spirit of a town in our district
of Georgia called Andersonville.
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。
Traceback (most recent call last):
File "bs4.py", line 1, in <module>
import bs4
File "/home/mhadi/Desktop/bs4test/bs4.py", line 5, in <module>
soup = bs4.BeautifulSoup(site,'lxml')
AttributeError: module 'bs4' has no attribute 'BeautifulSoup'
Run Code Online (Sandbox Code Playgroud)
代码:
import bs4
import urllib.request
site = urllib.request.urlopen('http://127.0.0.1:8000').read()
soup = bs4.BeautifulSoup(site,'lxml')
#for i in site:
# print(site[i])
print(soup)
Run Code Online (Sandbox Code Playgroud) 我想知道是否有任何功能的构建或一个简单的方法来绘制一个元素的直方图2d array.
例如,如果A=rand(100,1),那么A是1D array,并且hist(A)可以做直方图.
但是,如果A=rand(100,100),我想对元素进行直方图A,就像将每个元素A作为一个元素处理一样1D array.有一个简单的方法吗?
我需要附加/格式化带有API调用的id列表的URL.
但是,当我将列表放在API的末尾时:
https://api.twitter.com/1.1/users/lookup.json?user_id=%s'%a
Run Code Online (Sandbox Code Playgroud)
我只是得到一个空字符串作为响应.
我尝试将列表转换为字符串并删除方括号,执行以下操作:
a = str(followers['ids'])[1:-1]
Run Code Online (Sandbox Code Playgroud)
但我仍然遇到同样的问题.我假设它是由一开始时的单引号引起的.
我试过从字符串中删除撇号:
a.replace("'", "")
Run Code Online (Sandbox Code Playgroud)
现在我的想法已经用完了.
我编写了这段代码来遍历目录并查找大于 300MB 的文件。
但是,我得到了很多重复值,并且文件之间的重复数量各不相同。任何人都可以解释这一点或为我改进代码吗?
import os
path = 'C:\\Users\\brentond\\Desktop\\Lower Thames Crossing'
for foldername, subfolders, filenames in os.walk(path):
for subfolder in subfolders:
for filename in filenames:
if os.path.getsize(os.path.join(foldername, filename))>300000000:
print(foldername + '\\' + filename)
Run Code Online (Sandbox Code Playgroud) 当我输入错误的输入但当我输入正确的输入时,我得到 None 。它没有出现。请帮我解决这个概念。
def order():
try:
count = int(input("How many order ? "))
return count
except Exception as e:
print("Kindly enter in numbers")
print("Example :- 1, 2, 3, 4, 5 etc..")
finally:
print("Thanks to choose our service.")
choice = order()
print(choice, " will be ordered soon!!")
Run Code Online (Sandbox Code Playgroud)
输出:
How many order ? asdd
Kindly enter in numbers
Example :- 1, 2, 3, 4, 5 etc..
Thanks to choose our service.
None will be ordered soon!!
Run Code Online (Sandbox Code Playgroud) python ×6
python-3.x ×3
angular ×1
api ×1
csv ×1
file ×1
for-loop ×1
histogram ×1
html ×1
if-statement ×1
matlab ×1
pandas ×1
regex ×1
scikit-learn ×1