美文网首页
python 代码碎片

python 代码碎片

作者: 蓝天白云bubble | 来源:发表于2020-07-29 09:02 被阅读0次

一、将Oracle中的某张表导出到csv文件

import cx_Oracle
import pandas as pd

conn = cx_Oracle.connect('username', 'password', '127.0.0.1:1521/TESTDB')
sql = 'SELECT * FROM student'
df = pd.read_sql(sql, conn)
df.to_csv('student.csv')
print(df.head())

二、获得自身进程号并杀掉自身进程

import os
import time

# 获得当前进程号
pid = os.getpid()
print('pid:', pid)

for i in range(100):
    print(i)
    time.sleep(0.5)
    if i == 11:
        # 结束当前进程
        os.system('kill -9 {}'.format(pid))

相关文章

网友评论

      本文标题:python 代码碎片

      本文链接:https://www.haomeiwen.com/subject/lwjyectx.html