Blog Cover Image

Inspire you to have New thinking, Walk out your unique Road.

有的時候,你無意間遇到的一些故事,會激發你的靈感,改變你的想法,接下來你會用與之前全然不同的觀念去創造屬於你獨特的故事。

Sign @MinaYu.

[Develop]Python 桌機版開發遇到之問題(1)

Posted on

有鑒於自己最近剛接手一個做到一半的桌機開發程式

由於自己只用過Django and Python 寫過網頁

而對於桌機版的Python

根本一竅不通

可是….我又得… 接這個,因為這是我論文的程式QQQQQ

這是學弟留給我的春節功課,好好的春節除了中流感外

還不能休假,得加班,最慘的是!!!!

這個東西搞完後,還有一連串的大數據等著我去分析阿拉拉


廢話不多說,先來介紹一下程式在幹什麼

簡單來說它就是一個爬蟲的桌機程式,來爬蟲測驗者的資料(這邊牽扯到隱私我就不多說了XD)

然後將他們的資訊傳回虛擬機的資料庫裡

聽起來簡單,主要功能有3-4個

但為了讓自己作業簡單,我決定將一個比較困難,也比較難以掌控的功能先刪除

那個功能叫做「人臉辨識」


首先,小學弟用的是Python 2版,而我目前建的環境是Python 3.6版

開發IDE: Python 3.6 IDE

(對了,這個桌機是寫成exe給受試者用的,不過敝人的電腦程式只有Mac跟Ubuntu 嗚嗚)

要做的功能很簡單,就是一個有3個功能的爬蟲程式,將資料搜集好,最後結束上傳至資料庫裡

難就難在,小學弟沒有打包,然後用了很多奇奇怪怪的環境

我在開發的時候,得依照他的環境去弄

雖然小學弟也有問我需不需要將功能拆給我,這樣我方便整合

但約好的前一天本人中流感,我也來不及請教他,每個程式是在幹嘛QQ


從Python 2 轉去 Python 3 最先遇到的問題是

“inconsistent use of tabs and spaces in indentation”

Tab 得用4格取代

解法:

With IDLE editor you can use this

Edit –> Select All Format –> Untabify Region Assuming your editor has replaced 8 spaces with a tab, enter 8 into the input box. Hit select, and it fixes the entire document.

使用Python IDLE 編譯器,然後照著上面做

要注意的是將tab用8格取代

然後確定

這樣他就不會報錯了

Stackoverflow


再來會遇到的問題是Print 的問題

<code><del><span class="kwd">print</span> </del><span class="str"><del>"Hello world"</del>
</span></code>




<code><span class="kwd">print</span><span class="pun">(</span><span class="str">"Hello world"</span><span class="pun">)</span></code>

意思是換到Python 3版後,你應該要使用( ) 將想印的字包起來

Stackoverflow


用PyQt4來寫Python介面,可能會在打包程式的時候會有許多問題

小學弟表示用PyQt4這個來寫Python介面,可能會在打包程式的時候會有許多問題

因此,他建議我用這個“Tkinter”

而這也是目前遇到的問題,就是我沒有裝PyQt4這個環境


My junior student give me a BIG homework for my 2 weeks Chinese holiday.

He develop a Python Desktop Version Program for record tester’s data and return the results to database after finishing test.

I have to use that program to complete my paper’s research so I have to continue developing his program.

Here is some mistakes, I have to solve.

I use “Python 3.6 IDE” to develop this program

When you change environment from Python 2 to Python 3

“inconsistent use of tabs and spaces in indentation”

First, you may face this problem.

This is the solution:

With IDLE editor you can use this

Edit –> Select All Format –> Untabify Region Assuming your editor has replaced 8 spaces with a tab, enter 8 into the input box. Hit select, and it fixes the entire document.

Stackoverflow


Second, you may face the problem of “print”

“SyntaxError: Missing parentheses in call to ‘print’”

This is mean that you have to put ( ) after the words you want to print (or want to recall)

<code><del><span class="kwd">print</span> </del><span class="str"><del>"Hello world"</del>
</span></code>




<code><span class="kwd">print</span><span class="pun">(</span><span class="str">"Hello world"</span><span class="pun">)</span></code>

Stackoverflow


Third, my junior student make the UI by using PyQt4

Using PyQt4 could cause lots of BUGS.

If you don’t want to sell the program(the program shouldn’t looks beautiful), just make research, you can use “Tkinter” to develop UI.

He suggest that using Tkinter to develop UI can reduce the bugs in Binding Package.

(This is third mistake I am facing now. I am solving this and trying to replace PyQt4 by Tkinter)