Quantcast
Channel: 编程学习 –月与灯依旧
Browsing index pages (20 articles)

Image may be NSFW.
Clik here to view.

Set up self-hosted runners for Github Actions

Add and Install a new runner on our host Highly recommand run self-hosted runner as a systemd service # Save settings ./config.cmd --url https://github.com/XXX/MyApp --token XXXXXXXXX # Lets's deploy...

View Article


Javascript Array

Handle element in an Array const hobbies = ["sports", "cooking", "reading"]; console.log(hobbies[0]); # Get single element hobbies.push("surfing"); # Add new element to the end...

View Article


python字符串对齐

对于基本的字符串对齐操作,可以使用字符串的 ljust() , rjust() 和 center() 方法。比如: >>> text = 'Hello World' >>> text.ljust(20) 'Hello World ' >>> text.rjust(20) ' Hello World' >>>...

View Article

Image may be NSFW.
Clik here to view.

HTML栅格化示例

如果需要将一个DIV平均分割成几个小方格, 栅格化是比较好的解决方案, 本文演示一下 CSS代码: <style> .features .feat_list{ width: 60%; margin: 20px auto; outline: 1px solid blue; } .features .feat_list::before, .features...

View Article

交叉编译golang程序

本文演示了在ubuntu16.04上交叉编译golang程序的过程 配置本地golang环境 $ wget https://dl.google.com/go/go1.10.2.linux-amd64.tar.gz $ tar zxvf go1.10.2.linux-amd64.tar.gz $ sudo mv go /usr/local/ $ echo 'export...

View Article


Django parse a json/dictionary reminder on template

如果想在一个Django template里引入json, 正确的template写法为 python的views.py的写法 # -*- coding: utf-8 -*- from django.shortcuts import render from django.http import Http404, HttpResponse def get_product(request):...

View Article

一些初级python面试题

一些初级python面试题,这里简单罗列一下 # 反转字符串, 这个是最常见的 # 比如给一个字符串hello,将其反转为olleh def reverse(str): alist = list(str) alist.reverse() new_str = ''.join(alist) return new_str # 写一个方法打印如下内容,每一行打印5个 # server1, server2,...

View Article

Python读取配置文件模块ConfigParser

1,ConfigParser模块简介 假设有如下配置文件,需要在Pyhton程序中读取 $ cat config.ini [db] db_port = 3306 db_user = root db_host = 127.0.0.1 db_pass = xgmtest [SectionOne] Status: Single Name: Derek Value: Yes Age: 30 Single:...

View Article


使用pytest进行批量测试

Pytest是python的一个测试模块,可以编写一些简单的测试用例,也可以用来进行一些批量测试,下面简单介绍一下。 1,安装 $ pip install -U pytest or $ easy_install -U pytest $ py.test --version 2,基础语法 #!/usr/bin/python import pytest def func(x): return x + 1...

View Article


Python tips –轻松转换列表与字符串

There are a few useful tips to convert a Python list (or any other iterable such as a tuple) to a string for display. First, if it is a list of strings, you may simply use join this way: >>>...

View Article

python遍历文件脚本实例

自己写的一个Python遍历文件脚本,对查到的文件进行特定的处理。没啥技术含量,但是也记录一下吧。 #!/usr/bin/python # -*- coding: utf-8 -*- import sys import os import shutil dir = "/mnt/Packages" class Packages: def __init__(self,srcdir,desdir):...

View Article

Python re正则匹配中文

Python re正则匹配中文,其实非常简单,把中文的unicode字符串转换成utf-8格式就可以了,然后可以在re中随意调用将输入的utf-8中文解密为unicode,然后交由python处理(2014.10.09感谢QQ85897930纠正)。 unicode中中文的编码为/u4e00-/u9fa5,因此正则表达式u”[\u4e00-\u9fa5]+”可以表示一个或者多个中文字符...

View Article

安装Pyhton MySQLdb

安装很简单,几步就好 wget -q http://peak.telecommunity.com/dist/ez_setup.py python ./ez_setup.py wget http://downloads.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz tar -zxvf...

View Article


python中文件的复制

文件的复制 file类中没有提供专门的文件复制函数,因此只能通过使用文件的读写函数来实现文件的复制。这里仅仅给出范例: src = file("myfile.txt", "w+") temp = ["hello world! \n"] src.writelines(temp) src.close() src = file("myfile.txt", "r+") des =...

View Article

python备份远程FTP脚本

自己写的一个Linux上使用python备份远程FTP脚本,编写此脚本的初衷是为了方便一些使用虚拟主机的朋友,因为许多虚拟主机商不提供备份服务,导致文件丢失的情况时有发生,因此就有了这个脚本。 系统需要安装fuse-curlftpfs、zlib、zlib-devel三个软件包,其中fuse-curlftpfs包不好安装,得先安装个第三方的yum源,才可以通过yum的方式安装之。...

View Article


python读取系统信息

python读取系统信息的一些方法 最主要是的platform模块: >>> import platform >>> platform.version() '#1 SMP Fri Feb 22 00:31:26 UTC 2013' >>> platform.platform()...

View Article

python基础知识3:字典

字典使用大括号{ }来表示 字典中的“键”和“值”存在对应的映射关系,“键” 是唯一的,“值”并不唯一 1,字典的创建 >>> c={ } #第1种创建方法 >>> c['name']='zhang3' >>> c['age']=25 >>> items=[('name','zhang3'),('age',25)]...

View Article


python基础知识2:列表与元组

列表用大括号[]表示,元组用圆括号()表示 列表可以修改,字符串与元组不可修改 元组的分片还是元组,列表的分片还是列表 列表方法: name=["zhang3","li4","wang5"] name.append("gou6") #添加项 name.remove("gou6") #移除第一个匹配项,也可用del name[3]来移除 name.insert(3,"gou6") #插入项...

View Article

python基础知识1:字符串与分片

常见的算术运算: 幂运算(x的y次幂) pow(x,y) 取绝对值 abs(number) 平方根 math.sqrt(number) 浮点数取整 math.floor(32.9) 结果为32.0 获取输入值: 获取数字 x=input("input x:") 获取字符串 name=raw_input("what's your name?") print "Hello," + name +...

View Article

使用python备份VPS上的网站文件及数据库 1.0

学python有一段时间了,花了两天时间写了个备份的脚本。可以将Linux vps上的网站目录及数据库全部导出一份到远程FTP服务器上,再配置crontab实现每天的自动备份。功能上跟imcat的这个备份脚本是一样的,但程序比imcat的健壮多了,加入了N多自动判断,不会导致程序轻易出错。 代码仅适于python2,不适用于python3。因为调用了压缩模块,还需要yum install zlib...

View Article
Browsing index pages (20 articles)


Latest Images