- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何使 OpenGL 中的镜面照明发挥作用?我使用 python,我一直在尝试学习它是如何工作的,我已经能够使纹理工作、深度、创建基本的游戏玩法,但现在我试图让镜面照明像手电筒一样工作,所以我不断将它的位置更改为与玩家相同的位置以及玩家正在看的方向,但它不起作用!
import pyglet, math
from pyglet.gl import *
tela = pyglet.window.Window(height=500, width=500, caption="Halloween")
glEnable(GL_DEPTH_TEST)
glEnable(GL_TEXTURE_2D)
glEnable(GL_LIGHTING)
glLightfv(GL_LIGHT0, GL_AMBIENT, (GLfloat*4)(0,0,0,1))
glLightfv(GL_LIGHT0, GL_DIFFUSE, (GLfloat*4)(0,0,0,1))
glEnable(GL_LIGHT0)
tela.set_mouse_visible(False)
pos = [0,0,0]
rotX = rotY = pre = 0
comando = {"a":0,"d":0,"w":0,"s":0}
Dparede = pyglet.image.load("inf/Parede_Branca.png").get_image_data().get_data('RGBA', 225*4)
parede = pyglet.resource.image("inf/Parede_Branca.png").get_texture()
Dchao = pyglet.image.load("inf/Madeira.png").get_image_data().get_data('RGBA', 225*4)
chao = pyglet.resource.image("inf/Madeira.png").get_texture()
@tela.event
def on_draw():
global pos, comando, rotX, rotY, parede, chao, Dchao, Dparede
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
if comando["w"] == 1:
pos[2] += math.cos(math.pi*rotX/180)
pos[0] += math.sin(math.pi*rotX/180)
if comando["s"] == 1:
pos[2] -= math.cos(math.pi*rotX/180)
pos[0] -= math.sin(math.pi*rotX/180)
if comando["d"] == 1:
pos[2] += math.sin(math.pi*rotX/180)
pos[0] -= math.cos(math.pi*rotX/180)
if comando["a"] == 1:
pos[2] -= math.sin(math.pi*rotX/180)
pos[0] += math.cos(math.pi*rotX/180)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45, 1, 0.1, 1000)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
if pos[0] < -188:
pos[0] = -188
if pos[2] < -188:
pos[2] = -188
if pos[0] > 188:
pos[0] = 188
if pos[2] > 188:
pos[2] = 188
glLightfv(GL_LIGHT0, GL_SPECULAR, (GLfloat*4)(1,1,1,1))
glLightfv(GL_LIGHT0, GL_POSITION, (GLfloat*4)(pos[0],pos[1]-1,pos[2],1))
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, (GLfloat*3)(pos[0]+1000*(math.sin(math.pi*rotX/180)),pos[1]+1000*(math.cos(math.pi*rotY/180)), pos[2]+1000*(math.cos(math.pi*rotX/180))))
glLightfv(GL_LIGHT0, GL_SPOT_CUTOFF, (GLfloat*1)(45))
gluLookAt(pos[0], pos[1], pos[2], pos[0]+math.sin(math.pi*rotX/180), pos[1]+math.cos(math.pi*rotY/180), pos[2]+math.cos(math.pi*rotX/180), 0, 10, 0)
glBindTexture(GL_TEXTURE_2D, chao.id)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 225, 225, 0, GL_RGBA, GL_UNSIGNED_BYTE, Dchao)
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (GLfloat*4)(1,1,1,1))
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, (GLfloat*1)(100))
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, (GLfloat*4)(0,0,0,1))
# chão
glBegin(GL_POLYGON)
glTexCoord2f(0,0)
glVertex3f(-200,-20,200)
glTexCoord2f(0,10)
glVertex3f(-200,-20,-200)
glTexCoord2f(10,10)
glVertex3f(200,-20,-200)
glTexCoord2f(10,0)
glVertex3f(200,-20,200)
glEnd()
glBindTexture(GL_TEXTURE_2D, parede.id)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 225, 225, 0, GL_RGBA, GL_UNSIGNED_BYTE, Dparede)
# teto
glBegin(GL_POLYGON)
glTexCoord2f(0,0)
glVertex3f(-200,20,200)
glTexCoord2f(0,50)
glVertex3f(-200,20,-200)
glTexCoord2f(50,50)
glVertex3f(200,20,-200)
glTexCoord2f(50,0)
glVertex3f(200,20,200)
glEnd()
# parede
glBegin(GL_POLYGON)
glTexCoord2f(0,0)
glVertex3f(-200,20,200)
glTexCoord2f(0,50)
glVertex3f(-200,20,-200)
glTexCoord2f(10,50)
glVertex3f(-200,-20,-200)
glTexCoord2f(10,0)
glVertex3f(-200,-20,200)
glEnd()
# parede
glBegin(GL_POLYGON)
glTexCoord2f(0,0)
glVertex3f(-200,-20,-200)
glTexCoord2f(0,50)
glVertex3f(200,-20,-200)
glTexCoord2f(10,50)
glVertex3f(200,20,-200)
glTexCoord2f(10,0)
glVertex3f(-200,20,-200)
glEnd()
# parede
glBegin(GL_POLYGON)
glTexCoord2f(0,0)
glVertex3f(200,-20,-200)
glTexCoord2f(0,50)
glVertex3f(200,-20,200)
glTexCoord2f(10,50)
glVertex3f(200,20,200)
glTexCoord2f(10,0)
glVertex3f(200,20,-200)
glEnd()
# parede
glBegin(GL_POLYGON)
glTexCoord2f(0,0)
glVertex3f(-200,-20,200)
glTexCoord2f(0,50)
glVertex3f(200,-20,200)
glTexCoord2f(10,50)
glVertex3f(200,20,200)
glTexCoord2f(10,0)
glVertex3f(-200,20,200)
glEnd()
@tela.event
def on_key_press(k,m):
global comando
if k == pyglet.window.key.A:
comando["a"] = 1
if k == pyglet.window.key.D:
comando["d"] = 1
if k == pyglet.window.key.W:
comando["w"] = 1
if k == pyglet.window.key.S:
comando["s"] = 1
if k == pyglet.window.key.Q:
tela.close()
@tela.event
def on_key_release(k,m):
global comando
if k == pyglet.window.key.A:
comando["a"] = 0
if k == pyglet.window.key.D:
comando["d"] = 0
if k == pyglet.window.key.W:
comando["w"] = 0
if k == pyglet.window.key.S:
comando["s"] = 0
@tela.event
def on_mouse_motion(x, y, dx, dy):
global rotX, rotY, pre
if pre == 0:
rotX-=dx/2
if rotY >= 0:
rotY = -1
if rotY <= -180:
rotY = -179
rotY+=dy
if x > 400 or x < 100 or y > 400 or y < 100:
tela.set_mouse_position(250,250)
pre = 1
else:
pre = 0
def SRO(dt):
on_draw()
pyglet.clock.schedule_interval(SRO, 1/120)
pyglet.app.run()
我已经尝试更改 glMaterial,或更改照明中的不同内容,但没有任何效果,我只想让照明像手电筒一样工作,请用代码给出答案
最佳答案
由于 gouraud shading,您想做的事是不可能的固定功能灯模型。另见 OpenGL Lighting on texture plane is not working ,这是一个关于类似问题的问题。您必须将表面(墙壁和地板)分割为更小的瓷砖,因为灯光仅针对顶点坐标进行计算并在表面上进行插值。表面中间的镜面高光不会出现。
我知道这不会让你满意。但请注意,glBegin
/glEnd
绘制的那幅画sequences,固定函数矩阵堆栈和固定函数,per vertex light model,几十年来一直被弃用。参见 Fixed Function Pipeline和 Legacy OpenGL .了解 Vertex Specification和 Shader最先进的渲染方式。
如果你想“看到”任何东西,你必须跳过聚光灯,因为它不适用于你的几何体:
glLightfv(GL_LIGHT0, GL_SPOT_CUTOFF, (GLfloat*1)(45))
但激活环境漫射光:
glEnable(GL_LIGHTING)
glLightfv(GL_LIGHT0, GL_AMBIENT, (GLfloat*4)(1,1,1,1))
glLightfv(GL_LIGHT0, GL_DIFFUSE, (GLfloat*4)(1,1,1,1))
glEnable(GL_LIGHT0)
对于光的计算,需要表面的法向量。
激活灯模型 GL_LIGHT_MODEL_TWO_SIDE
边:
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE)
通过 glNormal3f
设置法向量:
# chão
glBegin(GL_POLYGON)
glNormal3f(0, -1, 0)
glTexCoord2f(0,0)
glVertex3f(-200,-20,200)
glTexCoord2f(0,10)
glVertex3f(-200,-20,-200)
glTexCoord2f(10,10)
glVertex3f(200,-20,-200)
glTexCoord2f(10,0)
glVertex3f(200,-20,200)
glEnd()
glBindTexture(GL_TEXTURE_2D, parede.id)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, Dparede)
# teto
glBegin(GL_POLYGON)
glNormal3f(0, -1, 0)
glTexCoord2f(0,0)
glVertex3f(-200,20,200)
glTexCoord2f(0,50)
glVertex3f(-200,20,-200)
glTexCoord2f(50,50)
glVertex3f(200,20,-200)
glTexCoord2f(50,0)
glVertex3f(200,20,200)
glEnd()
# parede
glBegin(GL_POLYGON)
glNormal3f(-1, 0, 0)
glTexCoord2f(0,0)
glVertex3f(-200,20,200)
glTexCoord2f(0,50)
glVertex3f(-200,20,-200)
glTexCoord2f(10,50)
glVertex3f(-200,-20,-200)
glTexCoord2f(10,0)
glVertex3f(-200,-20,200)
glEnd()
# parede
glBegin(GL_POLYGON)
glNormal3f(0, 0, 1)
glTexCoord2f(0,0)
glVertex3f(-200,-20,-200)
glTexCoord2f(0,50)
glVertex3f(200,-20,-200)
glTexCoord2f(10,50)
glVertex3f(200,20,-200)
glTexCoord2f(10,0)
glVertex3f(-200,20,-200)
glEnd()
# parede
glBegin(GL_POLYGON)
glNormal3f(-1, 0, 0)
glTexCoord2f(0,0)
glVertex3f(200,-20,-200)
glTexCoord2f(0,50)
glVertex3f(200,-20,200)
glTexCoord2f(10,50)
glVertex3f(200,20,200)
glTexCoord2f(10,0)
glVertex3f(200,20,-200)
glEnd()
# parede
glBegin(GL_POLYGON)
glNormal3f(0, 0, 1)
glTexCoord2f(0,0)
glVertex3f(-200,-20,200)
glTexCoord2f(0,50)
glVertex3f(200,-20,200)
glTexCoord2f(10,50)
glVertex3f(200,20,200)
glTexCoord2f(10,0)
glVertex3f(-200,20,200)
glEnd()
当灯光位置由 glLightfv(GL_LIGHT0, GL_POSITION, pos)
设置时,然后位置乘以当前模型 View 矩阵。
这意味着如果在设置 View 矩阵 (gluLookAt
) 之前设置位置,则灯光位置是相对于相机( View 空间位置)的。
如果在设置 View 矩阵之后设置,那么光源位置必须在世界坐标中,因为它是由 View 矩阵转换的。
如果您希望光源是相机位置,则必须将光源设置到位置 (0, 0, 0),在 View 矩阵由 gluLookAt
。
glLightfv(GL_LIGHT0, GL_POSITION, (GLfloat*4)(0,0,0,1))
gluLookAt(pos[0], pos[1], pos[2], pos[0]+math.sin(math.pi*rotX/180), pos[1]+math.cos(math.pi*rotY/180), pos[2]+math.cos(math.pi*rotX/180), 0, 10, 0)
如果你想让聚光灯(或多或少)起作用,那么唯一的可能就是使用非常小的 GL_SHININESS
。参数(例如1):
glLightfv(GL_LIGHT0, GL_POSITION, (GLfloat*4)(0,0,0,1))
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, (GLfloat*3)(0, 0, -1))
glLightfv(GL_LIGHT0, GL_SPOT_CUTOFF, (GLfloat*1)(45))
gluLookAt(pos[0], pos[1], pos[2], pos[0]+math.sin(math.pi*rotX/180), pos[1]+math.cos(math.pi*rotY/180), pos[2]+math.cos(math.pi*rotX/180), 0, 10, 0)
glLightfv(GL_LIGHT0, GL_AMBIENT, (GLfloat*4)(0,0,0,1))
glLightfv(GL_LIGHT0, GL_DIFFUSE, (GLfloat*4)(0,0,0,1))
glLightfv(GL_LIGHT0, GL_SPECULAR, (GLfloat*4)(1,1,1,1))
# [...]
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, (GLfloat*1)(1))
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (GLfloat*4)(1,1,1,1))
另一种可能性是实现一个简单的 Per Fragment Lighting着色器程序:
创建着色器程序源代码:
vert_code = b"""
varying vec3 N;
varying vec3 v;
varying vec2 uv;
void main(void)
{
uv = gl_MultiTexCoord0.xy;
v = vec3(gl_ModelViewMatrix * gl_Vertex);
N = normalize(gl_NormalMatrix * gl_Normal);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
"""
frag_code = b"""
varying vec3 N;
varying vec3 v;
varying vec2 uv;
uniform sampler2D u_texture;
void main (void)
{
vec3 L = normalize(gl_LightSource[0].position.xyz - v);
vec3 E = normalize(-v); // we are in Eye Coordinates, so EyePos is (0,0,0)
vec3 R = normalize(-reflect(L,N));
//calculate Ambient Term:
vec4 Iamb = gl_FrontLightProduct[0].ambient;
float spotCos = dot(gl_LightSource[0].spotDirection, -E);
float sotCutOff = step(gl_LightSource[0].spotCosCutoff, spotCos);
//calculate Diffuse Term:
vec4 Idiff = gl_FrontLightProduct[0].diffuse * max(dot(N,L), 0.0);
Idiff = clamp(Idiff, 0.0, 1.0) * sotCutOff;
// calculate Specular Term:
vec4 Ispec = gl_FrontLightProduct[0].specular
* pow(max(dot(R,E),0.0),0.3*gl_FrontMaterial.shininess);
Ispec = clamp(Ispec, 0.0, 1.0) * sotCutOff;
vec4 texColor = texture2D(u_texture, uv);
gl_FragColor = vec4(texColor.rgb * (Iamb + Idiff + Ispec), texColor.a);
}
"""
编译链接程序:
from ctypes import *
sh_code_list = [(GL_VERTEX_SHADER, vert_code), (GL_FRAGMENT_SHADER, frag_code)]
sh_objs = []
for sh_code in sh_code_list:
sh_obj = glCreateShader(sh_code[0])
src_buffer = create_string_buffer(sh_code[1])
buf_pointer = cast(pointer(pointer(src_buffer)), POINTER(POINTER(c_char)))
glShaderSource(sh_obj, 1, buf_pointer, None)
glCompileShader(sh_obj)
temp = c_int(0)
glGetShaderiv(sh_obj, GL_COMPILE_STATUS, byref(temp))
if not temp:
glGetShaderiv(sh_obj, GL_INFO_LOG_LENGTH, byref(temp))
buffer = create_string_buffer(temp.value)
glGetShaderInfoLog(sh_obj, temp, None, buffer)
print( 'compile error:' )
print(buffer.value)
sh_objs.append(sh_obj)
program = glCreateProgram()
for shObj in sh_objs:
glAttachShader(program, shObj)
glLinkProgram(program)
temp = c_int(0)
glGetProgramiv(program, GL_LINK_STATUS, byref(temp))
if not temp:
glGetProgramiv(program, GL_INFO_LOG_LENGTH, byref(temp))
buffer = create_string_buffer(temp.value)
glGetProgramInfoLog(program, temp, None, buffer)
print( 'link error:' )
print(buffer.value)
在程序的主循环之前加载纹理:
glBindTexture(GL_TEXTURE_2D, chao.id)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, Dchao)
glBindTexture(GL_TEXTURE_2D, parede.id)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1024, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE, Dparede)
绘制场景时使用程序:
@tela.event
def on_draw():
global pos, comando, rotX, rotY, parede, chao, Dchao, Dparede
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
if comando["w"] == 1:
pos[2] += math.cos(math.pi*rotX/180)
pos[0] += math.sin(math.pi*rotX/180)
if comando["s"] == 1:
pos[2] -= math.cos(math.pi*rotX/180)
pos[0] -= math.sin(math.pi*rotX/180)
if comando["d"] == 1:
pos[2] += math.sin(math.pi*rotX/180)
pos[0] -= math.cos(math.pi*rotX/180)
if comando["a"] == 1:
pos[2] -= math.sin(math.pi*rotX/180)
pos[0] += math.cos(math.pi*rotX/180)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45, 1, 0.1, 1000)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
if pos[0] < -188:
pos[0] = -188
if pos[2] < -188:
pos[2] = -188
if pos[0] > 188:
pos[0] = 188
if pos[2] > 188:
pos[2] = 188
glLightfv(GL_LIGHT0, GL_POSITION, (GLfloat*4)(0,0,0,1))
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, (GLfloat*3)(0, 0, -1))
glLightfv(GL_LIGHT0, GL_SPOT_CUTOFF, (GLfloat*1)(45))
gluLookAt(pos[0], pos[1], pos[2], pos[0]+math.sin(math.pi*rotX/180), pos[1]+math.cos(math.pi*rotY/180), pos[2]+math.cos(math.pi*rotX/180), 0, 10, 0)
glLightfv(GL_LIGHT0, GL_AMBIENT, (GLfloat*4)(0.2,0.2,0.2,1))
glLightfv(GL_LIGHT0, GL_DIFFUSE, (GLfloat*4)(0.8,0.8,0.8,1))
glLightfv(GL_LIGHT0, GL_SPECULAR, (GLfloat*4)(1,1,1,1))
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, (GLfloat*1)(100))
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (GLfloat*4)(1,1,1,1))
glBindTexture(GL_TEXTURE_2D, chao.id)
glUseProgram(program)
# chão
glBegin(GL_POLYGON)
glNormal3f(0, 1, 0)
glTexCoord2f(0,0)
glVertex3f(-200,-20,200)
glTexCoord2f(0,10)
glVertex3f(-200,-20,-200)
glTexCoord2f(10,10)
glVertex3f(200,-20,-200)
glTexCoord2f(10,0)
glVertex3f(200,-20,200)
glEnd()
glBindTexture(GL_TEXTURE_2D, parede.id)
# teto
glBegin(GL_POLYGON)
glNormal3f(0, -1, 0)
glTexCoord2f(0,0)
glVertex3f(-200,20,200)
glTexCoord2f(0,10)
glVertex3f(-200,20,-200)
glTexCoord2f(10,10)
glVertex3f(200,20,-200)
glTexCoord2f(10,0)
glVertex3f(200,20,200)
glEnd()
# parede
glBegin(GL_POLYGON)
glNormal3f(-1, 0, 0)
glTexCoord2f(0,0)
glVertex3f(-200,20,200)
glTexCoord2f(10,0)
glVertex3f(-200,20,-200)
glTexCoord2f(10,1)
glVertex3f(-200,-20,-200)
glTexCoord2f(0,1)
glVertex3f(-200,-20,200)
glEnd()
# parede
glBegin(GL_POLYGON)
glNormal3f(0, 0, 1)
glTexCoord2f(0,0)
glVertex3f(-200,-20,-200)
glTexCoord2f(10,0)
glVertex3f(200,-20,-200)
glTexCoord2f(10,1)
glVertex3f(200,20,-200)
glTexCoord2f(0,1)
glVertex3f(-200,20,-200)
glEnd()
# parede
glBegin(GL_POLYGON)
glNormal3f(-1, 0, 0)
glTexCoord2f(0,0)
glVertex3f(200,-20,-200)
glTexCoord2f(10,0)
glVertex3f(200,-20,200)
glTexCoord2f(10,1)
glVertex3f(200,20,200)
glTexCoord2f(0,1)
glVertex3f(200,20,-200)
glEnd()
# parede
glBegin(GL_POLYGON)
glNormal3f(0, 0, 1)
glTexCoord2f(0,0)
glVertex3f(-200,-20,200)
glTexCoord2f(10,0)
glVertex3f(200,-20,200)
glTexCoord2f(10,1)
glVertex3f(200,20,200)
glTexCoord2f(0,1)
glVertex3f(-200,20,200)
glEnd()
关于python - 我如何使 OpenGL 镜面光工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55338066/
我正在处理一组标记为 160 个组的 173k 点。我想通过合并最接近的(到 9 或 10 个组)来减少组/集群的数量。我搜索过 sklearn 或类似的库,但没有成功。 我猜它只是通过 knn 聚类
我有一个扁平数字列表,这些数字逻辑上以 3 为一组,其中每个三元组是 (number, __ignored, flag[0 or 1]),例如: [7,56,1, 8,0,0, 2,0,0, 6,1,
我正在使用 pipenv 来管理我的包。我想编写一个 python 脚本来调用另一个使用不同虚拟环境(VE)的 python 脚本。 如何运行使用 VE1 的 python 脚本 1 并调用另一个 p
假设我有一个文件 script.py 位于 path = "foo/bar/script.py"。我正在寻找一种在 Python 中通过函数 execute_script() 从我的主要 Python
这听起来像是谜语或笑话,但实际上我还没有找到这个问题的答案。 问题到底是什么? 我想运行 2 个脚本。在第一个脚本中,我调用另一个脚本,但我希望它们继续并行,而不是在两个单独的线程中。主要是我不希望第
我有一个带有 python 2.5.5 的软件。我想发送一个命令,该命令将在 python 2.7.5 中启动一个脚本,然后继续执行该脚本。 我试过用 #!python2.7.5 和http://re
我在 python 命令行(使用 python 2.7)中,并尝试运行 Python 脚本。我的操作系统是 Windows 7。我已将我的目录设置为包含我所有脚本的文件夹,使用: os.chdir("
剧透:部分解决(见最后)。 以下是使用 Python 嵌入的代码示例: #include int main(int argc, char** argv) { Py_SetPythonHome
假设我有以下列表,对应于及时的股票价格: prices = [1, 3, 7, 10, 9, 8, 5, 3, 6, 8, 12, 9, 6, 10, 13, 8, 4, 11] 我想确定以下总体上最
所以我试图在选择某个单选按钮时更改此框架的背景。 我的框架位于一个类中,并且单选按钮的功能位于该类之外。 (这样我就可以在所有其他框架上调用它们。) 问题是每当我选择单选按钮时都会出现以下错误: co
我正在尝试将字符串与 python 中的正则表达式进行比较,如下所示, #!/usr/bin/env python3 import re str1 = "Expecting property name
考虑以下原型(prototype) Boost.Python 模块,该模块从单独的 C++ 头文件中引入类“D”。 /* file: a/b.cpp */ BOOST_PYTHON_MODULE(c)
如何编写一个程序来“识别函数调用的行号?” python 检查模块提供了定位行号的选项,但是, def di(): return inspect.currentframe().f_back.f_l
我已经使用 macports 安装了 Python 2.7,并且由于我的 $PATH 变量,这就是我输入 $ python 时得到的变量。然而,virtualenv 默认使用 Python 2.6,除
我只想问如何加快 python 上的 re.search 速度。 我有一个很长的字符串行,长度为 176861(即带有一些符号的字母数字字符),我使用此函数测试了该行以进行研究: def getExe
list1= [u'%app%%General%%Council%', u'%people%', u'%people%%Regional%%Council%%Mandate%', u'%ppp%%Ge
这个问题在这里已经有了答案: Is it Pythonic to use list comprehensions for just side effects? (7 个答案) 关闭 4 个月前。 告
我想用 Python 将两个列表组合成一个列表,方法如下: a = [1,1,1,2,2,2,3,3,3,3] b= ["Sun", "is", "bright", "June","and" ,"Ju
我正在运行带有最新 Boost 发行版 (1.55.0) 的 Mac OS X 10.8.4 (Darwin 12.4.0)。我正在按照说明 here构建包含在我的发行版中的教程 Boost-Pyth
学习 Python,我正在尝试制作一个没有任何第 3 方库的网络抓取工具,这样过程对我来说并没有简化,而且我知道我在做什么。我浏览了一些在线资源,但所有这些都让我对某些事情感到困惑。 html 看起来
我是一名优秀的程序员,十分优秀!