python中使用postgres

python中使用postgres

本文不详细介绍如何用python连接并操作postgres数据库,只介绍如何在Python下安装postgres数据库接口,以及在安装过程中遇到的一些问题。

我其中博客介绍了利用easy_install来安装mysql数据库接口。如果没有安装easy_install的童鞋,请参考博文: Ubuntu下安装easy_install 和 mysql-python

和Mysql一样,用Python连接postgres数据库也需要对应的连接库。我采用的是psycopg2 ,如果有童鞋不想用easy_install安装,上面已经给出了psycopg2的官方网址,里面也介绍了其他的安装方法以及详细的使用文档。下面开始介绍利用easy_install安装psycopg2的过程:

注:以下过程是在64位Ubuntu12.04机器上实验的,32位系统应该也适用,系统未安装postgres数据库,默认已经安装了easy_install。

sudo easy_install psycopg2

在没有安装postgres开发环境的机器上很可能出现下面的错误

复制代码
Error: pg_config executable not found.

Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:

    python setup.py build_ext --pg-config /path/to/pg_config build ...

or with the pg_config option in 'setup.cfg'.
error: Setup script exited with 1
复制代码

提示说,pg_config executable没有找到,google一下,发现需要另外安装一个postgres的开发库(我是这么理解的~)

sudo apt-get install libpq-dev

安装完成后,再次安装 psycopg2,postgres for python的开发环境就已经配置好了,在开发中如果想连接postgres数据库,直接import psycopg2即可,关于psycopg2的详细使用方法可访问我上面提供的网址

本文来自博客园,如果查看原文请点击 http://www.cnblogs.com/meibenjin/archive/2013/05/05/3061147.html

 

中大阿里巴巴校招笔试个人分享

ps.看着一堆师兄、大三的还有研究生的、突然觉得自己好年轻。

 

 上次web群里一直在讨论网申投简历实习,不小心顺手也投了一篇、简历都没提交,就留了联系方式而已...大二的人怎么去实习...纯属玩玩而已.....可能中大报名的人都能去。 

 

 直接讲题了、不讲故事了。

 

总共六道题、 题目可能记不清了,记不清的就讲大意吧

1、这题就是让你根据一个表格、他把写出来涉及到了,table  tbody thead/th   rowspan  colspan那些  我蛋疼的加了一个tfoot..其实是有的、不知道有没有用错 

 但是要注意一点的就是,有一列用了rowspan的话 下面的tr中要少一个td...

 

2、这题的考点就是css代码的简化

  

复制代码
 2 
 3  /* 原题题意大概如此...考点都在这了、重复的我就删掉了 */
 4 
 5  div.container {
 6       width:  500px;
 7       background-image:  url(/img/sprite.png);
 8       background-repeat:  no-repeat;
 9       background-position:  4px 10px;    /* 数字记不清了 */
10   }
11   
12   div.container #news-list, div.container #news-list li {
13       background-image:  url(/img/sprite.png);
14       background-repeat:  no-repeat;
15       background-position:  4px 10px;    /* 数字记不清了 */
16   }
17   
18   a {
19       font-size:  14px;
20       color:  #00000000;
21       line-height:  150%;
22       font-weight:  bold;
23 }
24 

 

复制代码

这个大概就这样做吧、 

  

复制代码
 2  div.container {
 3       width:  500px;
 4       background:  url(/img/sprite.png) no-repeat 4px 10px;
 5   }
 6   
 7  #news-list, #news-list li {
 8       background:  url(/img/sprite.png) no-repeat 4px 10px;
 9   }
10   
11   a {
12       font:  #000000 bold 14px/150%;
13 }
14 
复制代码

 

 

3.这题有两个小题、给你一个登录框的图片 (a) 符合web语义的html代码  (b) 用css实现图片效果(form的边框是圆角加透明)

 这边应该是仅支持现代浏览器、border-radius.我透明用的是border:thick solid rgba(0,0,0,0.5)  。语义化id设得人一眼看出那个id是干嘛的就好

那个x按钮图片要右float...细节蛮多的、目测很悬 。

 

4、这题让你找出页面中 class 为test的节点

 

我写了三种(这数字太虚幻了、其实就一种)

  1、jquery 中的$(".test")

  2、仅支持部分浏览器的 getElementsByClassName的DOM操作

  3、这个可以叫做无环数的深搜么?贴代码先...可惜我最后忘记写调用的、然后DOM中压根没有hasChildNodes()这方法、把那个判断去掉应该就对了吧?...提交交卷的坏处 0 0

   

复制代码
var myNode = [],
    body = document.body;    /* 忘记写了- -调用,给跪了,就只写了一个函数 */

function getNode(a) {
    // if (a.hasChildNodes()){
        var child = a.childNodes,
           len = child.length;

        for ( var i = 0; i < len; i++){
           getNode(child[i]);
       }
   //  } else {
        if (a.className == "test"){
          myNode.push(a);
       }
    // }
}

getNode(body);
复制代码

 

5、这一题就是给你一个有重复数的数组、然后让写一个函数 返回值为去掉重复数字后的数组、这个用一个hash-table就可以了

  

复制代码
 2  var arr = [1, 2, 2, 3, 4, 5, 6, 6];
 3 
 4  function getArray(a) {
 5      var hash = {},
 6         len = a.length,
 7         result = [];
 8     
 9      for ( var i = 0; i < len; i++){
10          if (!hash[a[i]]){
11             hash[a[i]] =  true;
12             result.push(a[i]);
13         } 
14     }
15      return result;
16 }
17 
18 getArray(arr);  //  输出[1, 2, 3, 4, 5, 6]
19 
复制代码

 

6、聊一聊你对前端工程师的看法...这个看你多能吹水了...前端不仅仅是前端...

 

 

噗...全部就是这些、感觉蛮好玩的、原来中大写前端的还有美女师姐~~坐在我后面的后面的后面的后面...哈哈、这次笔试纯属体验生活、蛮好玩的感觉、那个监考官一定是东北妹子、这么霸气的~祝大家好运 @会长 @范师兄 @其它师兄师姐

 

 

Li Zhugang(李珠刚) School of Software Sun Yat-sen University(中山大学) Email: [email protected] Weibo: http://weibo.com/u/2541756412
 
分类:  技术学习研究
标签:  javascript笔试
 
 
分类:  PythonUbuntu

你可能感兴趣的:(JavaScript,笔试)