我已经完成了几个关于Python的教程,我知道如何定义类,但我不知道如何使用它们.例如,我创建以下文件(car.py):
class Car(object):
condition = 'New'
def __init__(self,brand,model,color):
self.brand = brand
self.model = model
self.color = color
def drive(self):
self.condition = 'Used'
Run Code Online (Sandbox Code Playgroud)
然后我创建另一个文件(Mercedes.py),我想从类Car创建一个Mercedes对象:
Mercedes = Car('Mercedes', 'S Class', 'Red')
Run Code Online (Sandbox Code Playgroud)
,但是我收到一个错误:
NameError: name 'Car' is not defined
Run Code Online (Sandbox Code Playgroud)
如果我在创建它的同一个文件(car)中创建一个实例(对象),我没有问题:
class Car(object):
condition = 'New'
def __init__(self,brand,model,color):
self.brand = brand
self.model = model
self.color = color
def drive(self):
self.condition = 'Used'
Mercedes = Car('Mercedes', 'S Class', 'Red')
print (Mercedes.color)
Run Code Online (Sandbox Code Playgroud)
哪个印刷品:
Red
Run Code Online (Sandbox Code Playgroud)
所以问题是:如何从同一个包(文件夹)中不同文件的类创建一个对象?
地图格式OpenDrive提供(除其他外)道路的几何形状。道路的每一段都可以具有不同的几何形状(例如线、弧、螺旋、多项式)。提供的道路几何“螺旋”信息如下:
- s - relative position of the road segment in respect to the beginning
of the road (not used in here)
- x - the "x" position of the starting point of the road segment
- y - the "y" position of the starting point of the road segment
- hdg - the heading of the starting point of the road segment
- length - the length of the road segment
- curvStart - the curvature at …Run Code Online (Sandbox Code Playgroud) 我想为一个变量分配一个excel范围:
import xlrd
file = r"C:\Users\Lisa\Desktop\Frank\export.XLSX"
book = xlrd.open_workbook(file)
sheet = book.sheet_by_index(0)
data = [range("A3:D7")]
Run Code Online (Sandbox Code Playgroud)
,但我收到一个错误:
data = [range("A3:D7")]
TypeError: 'str' object cannot be interpreted as an integer
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我需要将字符串HTML从西里尔和拉丁符号的混合转换为UNICODE.
我尝试了以下方法:
Public HTML As String
Sub HTMLsearch()
GetHTML ("http://nfs.mobile.bg/pcgi/mobile.cgi?act=3&slink=6jkjov&f1=1")
MsgBox HTML
HTML = StrConv(HTML, vbUnicode)
MsgBox HTML
End Sub
Function GetHTML(URL As String) As String
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", URL, False
.Send
HTML = .ResponseText
End With
End Function
Run Code Online (Sandbox Code Playgroud)
您可以看到StrConv之前和之后的内容.如果您想在文件中获取html,可以使用以下代码:
Public HTML As String
Sub HTMLsearch()
GetHTML ("http://nfs.mobile.bg/pcgi/mobile.cgi?act=3&slink=6jkjov&f1=1")
Dim path As String
path = ThisWorkbook.path & "\html.txt"
Open path For Output As #1
Print #1, HTML
Close #1
HTML = StrConv(HTML, vbUnicode)
path = ThisWorkbook.path & "\htmlUNICODE.txt"
Open path …Run Code Online (Sandbox Code Playgroud) 我必须在bash中对扩展名为“.prot”的文件夹中的所有文件执行命令
该命令称为“bezogener_Spannungsgradient”,其名称如下:
bezogener_Spannungsgradient filename.prot
Run Code Online (Sandbox Code Playgroud)
谢谢!
我想将单元格的地址/名称作为字符串而不是列,行.
ws - a worksheet
ows - another worksheet
cell is a string = "G5"
i and c are respectivly row and columns
cell = ws.Cells(i, 1)
ows.Cells(cell).Value = ws.Cells(i, c)
Run Code Online (Sandbox Code Playgroud)
__ _ __ _ __ _ __ ||||||| _ __ _ __ _ __ _ _
该代码带来了错误.
干杯,维哈尔
我用2种不同的方法进行了计算.对于那些计算,我有两个参数:x和y
最后,我计算了两种方法之间的%ERROR,用于每种变化.现在我想根据结果创建一个3D表面图:
x -> on x axis
y -> on y axis
Error -> on z axis
Run Code Online (Sandbox Code Playgroud)
以下是数据示例:
A = [
-0.1111 1.267 9.45680081826912
-0.1111 2.6 212.361735695025
-0.25 1.533 40.5729362609655
-0.25 2.867 601.253624894196
-0.4286 1 0.12116749607863
-0.4286 3.4 79.6948438921078
-0.6667 2.067 33.3495544017519
-0.6667 3.667 141.774875517481
-1 2.6 -0.0399171449531781
0.09091 1.533 163.7083541414 ];
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试用冲浪功能绘制它时:
x = A(:,1);
y = A(:,2);
z = A(:,3);
surf(x,y,z)
Run Code Online (Sandbox Code Playgroud)
,我收到一个错误:
Error using surf (line 75)
Z must be a matrix, not a scalar or vector
Error …Run Code Online (Sandbox Code Playgroud) 我想垂直打印以下列表字典:
result = {'WeightedLevel': [388.850952, 716.718689, 1312.55957, 2405.087158, 4460.083984, 8543.792969, 18805.201172, 57438.140625, 1792.367554], 'Job': 'Desktop', 'LoadLevel': [0.212399, 0.393191, 0.727874, 1.347436, 2.494368, 4.617561, 8.548006, 15.824027, 1.0], 'Task': 'test', 'Failure': [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0], 'Blocks': [7255.151855, 231.589661, 9.365415, 0.55364, 0.0504, 0.006408, 0.001204, 0.000842, 2.060041]}
Run Code Online (Sandbox Code Playgroud)
所以看起来应该是这样的:
Job Task LoadLevel Blocks Failure WeightedLevel
Desktop test 4546543 4384284 0,46544564 0,1354385
474454 978456 2 9655
9655 55654 966 665
Run Code Online (Sandbox Code Playgroud)
等等...
我尝试过在网上找到的一些代码,但它们仍然会横向打印结果:
for k, d in result.items():
print(k + ":", d)
Run Code Online (Sandbox Code Playgroud)
和 …
我想对绘制的数据拟合衰减指数.我没有曲线拟合或优化工具箱.
x = [0 0.0036 0.0071 0.0107 0.0143 0.0178 0.0214 0.0250 0.0285 0.0321 0.0357 0.0392 0.0428 0.0464 0.0464];
y = [1.3985 1.3310 1.2741 1.2175 1.1694 1.1213 1.0804 1.0395 1.0043 0.9691 0.9385 0.9080 0.8809 0.7856 0.7856];
figure()
plot(x,y,'*')
Run Code Online (Sandbox Code Playgroud)
我怎样才能在MATLAB中实现这一目标?
如果同一行中的其他单元格符合预定义的条件,则需要对几列的值求和。仅3列的工作公式如下:
=SUM(SUMIFS(‘Sheet1'!W:W; ‘Sheet1'!$B:$B;"Sales";‘Sheet1'!$C:$C;">=4");SUMIFS(‘Sheet1'!X:X; ‘Sheet1'!$B:$B;"Sales";‘Sheet1'!$C:$C;">=4");SUMIFS(‘Sheet1'!Y:Y; ‘Sheet1'!$B:$B;"Sales";‘Sheet1'!$C:$C;">=4"))
Run Code Online (Sandbox Code Playgroud)
我将需要针对多个单元格使用该公式(每次总计10列以上),并且需要手动更改列,因此我需要通过以下方式使用相同的公式:
=SUMIFS(‘Sheet1'!W:Y; ‘Sheet1'!$B:$B;"Sales";‘Sheet1'!$C:$C;">=4")
Run Code Online (Sandbox Code Playgroud)
,但当前此公式导致“ #VALUE!” 错误。这样做的原因是(我假设)使用多个列“ W:Y ”您能建议一种解决方法吗?