小编Luc*_*asS的帖子

使用Python从Excel(.xlsx)中提取超链接

我一直在寻找用于Excel文件操作的xlrd和openpyxl库.但是,xlrd目前不支持formatting_info=True.xlsx文件,因此我无法使用xlrd hyperlink_map函数.所以我转向openpyxl,但也没有运气从excel文件中提取超链接.测试代码如下(测试文件包含一个简单的超链接,谷歌的超链接文本设置为"测试"):

import openpyxl

wb = openpyxl.load_workbook('testFile.xlsx')

ws = wb.get_sheet_by_name('Sheet1')

r = 0
c = 0

print ws.cell(row = r, column = c). value
print ws.cell(row = r, column = c). hyperlink
print ws.cell(row = r, column = c). hyperlink_rel_id
Run Code Online (Sandbox Code Playgroud)

输出:

test

None
Run Code Online (Sandbox Code Playgroud)

我想openpyxl目前还不支持完全格式化吗?是否有一些其他库可用于从Excel(.xlsx)文件中提取超链接信息?

python xlrd hyperlink openpyxl

9
推荐指数
2
解决办法
9602
查看次数

HTTP帖子使用httplib2错误

我正在尝试使用Google 在此处描述的刷新令牌来获取新的访问令牌.Google说我需要发出HTTP请求.我不知道怎么做,所以我从这里查看了如何做到这一点.但是,我必须正确地发布帖子,因为我收到invalid_request错误.

以下是我的相关代码:

h = Http()
post_data = {'POST': '/o/oauth2/token HTTP/1.1', 
             'HOST:': 'accounts.google.com', 
             'Content-Type:': 'application/x-www-form-urlencoded',
             'client_id':ClientID,
             'client_secret':ClientSecret,
             'refresh_token':SavedRefreshToken,
             'grant_type':'refresh_token'}
resp, content = h.request("https://accounts.google.com/o/oauth2/token", 
                          "POST", 
                          urlencode(post_data))
Run Code Online (Sandbox Code Playgroud)

我得到的回应是:

{
  "error" : "invalid_request"
}
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么?

python http-post httplib2 google-drive-api

3
推荐指数
1
解决办法
4519
查看次数

C++中的向量和结构

我正在尝试创建一个包含多种数据类型和向量的数据树.到目前为止我所拥有的内容如下所示:

struct VertStruct{
    double X, Y, Z;
};
struct FaceStruct{
    int F1, F2, F3, F4;
};
struct FaceNormalStruct{
    double X, Y, Z;
};
struct LODStruct{
    std::vector<VertStruct> Verts;
    std::vector<FaceStruct> Faces;
    std::vector<FaceNormalStruct> FaceNormals;
};
struct ChunkStruct{
    std::vector<LODStruct> LOD;
};

int main(){

    std::vector<ChunkStruct> Chunk;
    Chunk.resize(100);

    for(int i = 0; i < 100; i++)
    {
        Chunk[i].LOD.resize(5);

        for(int j = 0; j < 5; j++)
        {
            Chunk[i].LOD[j].Verts.resize(36);
            Chunk[i].LOD[j].Faces.resize(25);
            Chunk[i].LOD[j].FaceNormals.resize(25);
        }
    }
return 1;
}
Run Code Online (Sandbox Code Playgroud)

现在这个编译很好,正是我想要的,但是,如果我尝试将值设置为:

int Number = 42;
Chunk[5].LOD[4].Verts[3] = Number;
Run Code Online (Sandbox Code Playgroud)

然后我收到以下错误:

 main.cpp|126|error: no …
Run Code Online (Sandbox Code Playgroud)

c++ arrays struct vector

2
推荐指数
1
解决办法
1105
查看次数

与GLSL相关的OpenGL应用程序代码

我很难理解我的OpenGL应用程序和我的GLSL文件(.ver​​t和.frag)之间的联系.我知道如何创建顶点或片段着色器,网上有很多例子,但我在我的应用程序中实际使用着色器时遇到了困难,特别是将(绑定?)纹理链接到我的着色器.我的问题是,我错过了哪些代码使用我使用着色器上传到我的应用程序中的纹理?

我当前的应用程序创建一个窗口,加载4个纹理(岩石,草,石头和混合图,因为我想用它来进行纹理喷溅),然后在主循环中绘制一个四边形.我的整个应用程序代码如下:

#include <windows.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <SFML/Graphics.hpp>
#include <glew.h>
#include <gl/gl.h>
#include <gl/glu.h>

#include "textfile.h"
#include "textfile.cpp"

using namespace std;

class Scene {
public:
    void resize( int w, int h ) {
        // OpenGL Reshape
        glViewport( 0, 0, w, h );
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        gluPerspective( 120.0, (GLdouble)w/(GLdouble)h, 0.5, 500.0 );
        glMatrixMode( GL_MODELVIEW );
    }
};

///Shader
GLuint p, f, v;
void setShader() {

    char *vs,*fs;

    v = glCreateShader(GL_VERTEX_SHADER);
    f = glCreateShader(GL_FRAGMENT_SHADER);

    vs = textFileRead("shader.vert"); …
Run Code Online (Sandbox Code Playgroud)

c++ opengl

2
推荐指数
1
解决办法
702
查看次数

OpenGL VBO法线/照明问题

我无法使用VBO正常渲染法线.下面是我正在使用的代码,顶点是一个包含顶点的数组,而法线是一个包含法线的数组:

//Create the buffers and such
GLuint VBOID;
glGenBuffersARB(1, &VBOID);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBOID);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(vertices) + sizeof(normals), 0, GL_STATIC_DRAW_ARB);
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sizeof(vertices), vertices);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);

///Start loop
cout << "Starting" << endl;
while( window.isOpen() ) {
    sf::Event event;
    while( window.pollEvent( event ) ) {
        if( event.type == sf::Event::Closed )
            window.close();
    }
    fps = FPS.getElapsedTime().asSeconds();
    fps = 1 / fps;
    FPS.restart();
    if(ShowFPS.getElapsedTime().asSeconds() > 1)
    {
        cout << "FPS: " << fps << "\t FrameTime: " << 1000 / fps << endl;
        ShowFPS.restart(); …
Run Code Online (Sandbox Code Playgroud)

c++ opengl vbo

2
推荐指数
1
解决办法
820
查看次数

OpenGL显示列表优化

我目前正在为我的应用程序运行一些速度测试,我正在尝试找到更多方法来优化我的程序,特别是我的显示列表.目前我得到:

12 FPS,882,000个顶点

40 FPS,234,000个顶点

95 FPS,72,000个顶点

我知道我需要尽量减少拨打电话的数量,所以不要:

for(int i = 0; i < Number; i++) {
   glBegin(GL_QUADS);
   ...normal and vertex declarations here
   glEnd();
}
Run Code Online (Sandbox Code Playgroud)

更好的方法是这样做:

glBegin(GL_QUADS);
for(int i = 0; i < Number; i++) {
   ...normal and vertex declarations here
}
glEnd();
Run Code Online (Sandbox Code Playgroud)

这确实有助于将我的FPS提高到上面列出的结果,但是,还有其他方法可以优化我的显示列表吗?也许通过使用嵌套顶点数组以外的东西来存储我的模型数据?

c++ opengl optimization

0
推荐指数
1
解决办法
636
查看次数

使用 Python 从 Google API 获取文件元数据

我目前正在尝试研究如何使用 python 从谷歌驱动器下载文件元数据。我几乎只是从谷歌提供的文档中复制/粘贴,到目前为止一切都很好。当我尝试打电话时:

drive_file = drive_service.files().get(id=file_id).execute()
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

drive_file = drive_service.files().get(id=file_id).execute()
File "build\bdist.win-amd64\egg\apiclient\discovery.py", line 452, in method
TypeError: Got an unexpected keyword argument "id"
Run Code Online (Sandbox Code Playgroud)

然而,在谷歌文档中有一个例子(在Python选项卡),它显示了与我几乎完全相同的东西。我的代码无法运行是因为我缺乏 Python 经验还是其他原因?完整程序如下所示:

import httplib2

from apiclient.discovery import build
from oauth2client.client import OAuth2WebServerFlow

def getDriveService():
    ClientID = <MY_CLIENT_ID>
    ClientSecret = <MY_CLIENT_SECRET>
    OAUTH_SCOPE = 'https://www.googleapis.com/auth/drive'
    REDIRECT_URI = <MY_REDIRECT_URI>

    flow = OAuth2WebServerFlow(ClientID, ClientSecret, OAUTH_SCOPE, REDIRECT_URI)
    flow.redirect_uri = REDIRECT_URI
    authorize_url = flow.step1_get_authorize_url()
    print authorize_url
    code = raw_input('Enter verification code: ').strip()

    credentials = flow.step2_exchange(code)          
    http = httplib2.Http()
    http = …
Run Code Online (Sandbox Code Playgroud)

python google-api google-drive-api

0
推荐指数
1
解决办法
2190
查看次数