Category Archives: Python

[Python] Produces a circular image of 001-100

import matplotlib.pyplot as plt import numpy as np def draw_circle_with_number(number, filename): fig, ax = plt.subplots(figsize=(5, 5)) ax.set_xlim(0, 1) ax.set_ylim(0, 1) # draw circular circle = plt.Circle((0.5, 0.5), 0.4, color=’blue’, fill=False, linewidth=4) ax.add_artist(circle) # add text ax.text(0.5, 0.5, f'{number:03}’, color=’black’, fontsize=90, … Continue reading

Posted in Python | Comments Off on [Python] Produces a circular image of 001-100

[Python] fix error while loading shared libraries: libpython2.7.so.1.0

error log: /opt/rh/python27/root/usr/bin/python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory check libpython2.7.so.1.0 exist? find . -name ‘libpython2.7.so.1.0’ if the file was exist: edit the ldconfig config echo “/opt/rh/python27/root/usr/lib64” > /etc/ld.so.conf.d/python27.conf ldconfig … Continue reading

Posted in CentOS, Python | Leave a comment

[Gitbook] 使用 Windows 視窗編輯器

試著使用 Windows 的視窗編輯器來撰寫 Gitbook 目前測試了 Miu 跟 MarkdownPad 這兩個編輯器 不過前者 Miu 因為 Liveview 並不支援 HTML 語法,所以被我拋棄了 等他有支援再回去用看看 PS. Mac 上大家推的都是 Mou 而用 Windows 寫 Gitbook 就不像在 Linux 上有 gitbook init 可以產生相對映的 md 檔案 就改之前寫的 parse.py 來產生吧 (這邊使用的 python 版本是 3.0) … Continue reading

Posted in Python | Leave a comment

[Python] SyntaxError: Missing parentheses in call to ‘print’

因為在 Ubuntu 上目前安裝的 Python 版本還是 2.7 而之前在 Windows 安裝的版本為 3.0 導至把 Ubuntu 上寫好的 code 拿至 Windows 上編譯時會發生下列錯誤… SyntaxError: Missing parentheses in call to ‘print’ 這時候參考stackoverflow: What does “SyntaxError: Missing parentheses in call to ‘print’” mean in Python? 得知要把 print 語法修正一下 … Continue reading

Posted in Python | Leave a comment

Gitbook 超過兩層目錄無法創建檔案/目錄的解套

因為gitbook作者認為一本書的章節目錄不應該過於複雜 所以原本預設只有兩層目錄 在去年一堆相關討論串結束後雖然已讓目錄可以超過兩層 但是gitbook (github源)卻無法建立相對應的目錄及檔案 在爬了許多code後 (/usr/lib/node_modules/gitbook)決定還是自己寫一個parse code來處理 這邊在讀完SUMMARY.md後會自動偵測檔案目錄是否不存在 不存在就直接創建 預設只抓三層檔案目錄的結構 # !/usr/bin/python # -*- coding: utf-8 -*- import re import os for line in open(“SUMMARY.md”): try: src1 = re.search(‘((.+?))’, line) src = src1.group(1) except: print line else: cnt = … Continue reading

Posted in Gitbook, Python | Leave a comment

[Wisemapping] find user by email in Python

#! /usr/bin/python # coding:utf-8 # curl “http://localhost:8080/wisemapping/service/admin/users/email/{使用者帳號信箱}.json” –get –basic -u “admin@wisemapping.org:admin” import sys import urllib2 import base64 import yaml import datetime username = ‘admin@wisemapping.org’ password = ‘admin’ if len(sys.argv) == 2: request = urllib2.Request(“http://localhost:8080/wisemapping/service/admin/users/email/%s.json” % sys.argv[1]) base64string = base64.encodestring(‘%s:%s’ % … Continue reading

Posted in Python, Wisemapping | Leave a comment

Eclipse 安裝 Python 模組

下載 Python 進行安裝 Python 下載連結 安裝過程中記得勾選加入環境變數 開啟 Eclipse => Help => Eclipse Marketplace 搜尋 Python => Go 安裝 PyDev – Python IDE for Eclipse 勾選 PyDev for Eclipse、Pydev Mylyn Integration => Next I accept the terms of the license agreements … Continue reading

Posted in Eclipse, Python | Leave a comment

Python 註解

# 這是註解~~~ “”” 這也是註解 “””

Posted in Python | Leave a comment