11.05.2015

Python 3超新手常犯的錯誤

##注意parameter的值是variable時,不會跟著variable的值來改變

t = 0

def p(a=t):
    print("a=%d"%a)

def main():
    global t
    t = 100
    p()
    print("t=%d"%t)

if __name__ == "__main__":
    main()

##############Output#############
a=0
t=100

10.20.2015

Python3 "from m import *" 超新手常犯的錯誤

#在python 3, 請注意s的值並不會共用
# a.py
from b import *

def main():
    global s
    print(s)
    add()
    print(s)
    s += 6
    print(s)
    add()
    print(s)

if __name__ == "__main__":
    main()

# b.py
s =10

def add():
    global s
    s += 1
    print("s=%d"%s)

###
# Execute a.py
###
10
s=11
10
16
s=12
16

#如果要s的值共用,可以如下修改:
# a.py
import b

def main():
    print(b.s)
    b.add()
    print(b.s)
    b.s += 6
    print(b.s)
    b.add()
    print(b.s)

if __name__ == "__main__":
    main()

# b.py (不變)
s =10

def add():
    global s
    s += 1
    print("s=%d"%s)

###
# Execute a.py
###
10
s=11
11
17
s=18
18

9.25.2015

Can't log in to ubuntu 12.04 (轉貼)

I can't log in to my ubuntu 12.04. Once I login I got returned back to the original screen after a trial to enable X11 Forwarding.
Can you help me with this.
shareimprove this question
   
Are you trying to login remotely? What did you do to try to enable X11 forwarding? –  izx May 19 '12 at 21:40
   
Does this only happen when trying to log in remotely? Or are you having this problem logging in locally as well? –  Eliah Kagan Mar 27 '13 at 1:07
   
Check your .xsession-errors in your home directory, I found an error over there, fixed it, then I can login from desktop. I did try to change the permission and ownership of .Xauthority but it doesn't help in my case. – user288195 Jun 3 '14 at 23:25

9 Answers

I haven't tried to enable X11Forwarding, but I used to have the same problem. You can fix this in a few steps:
  • When you get to the graphical login screen, hit Ctrl+Alt+F2, thus you get to a textual login.
  • Put in your name and password (password is not displayed when you type, neither as stars or bullets).
  • Type sudo apt-get install gdm and hit enter, give your password and wait to get a line ending with a dollar sign again.
  • Type sudo dpkg-reconfigure gdm.
  • Hit Enter at the first screen.
  • Select gdm in the list you get in the second screen with the arrow keys.
  • Hit the Tab button (above the caps lock one). Now you see the word Ok highlighted. Hit Enter.
  • Type sudo reboot and hit enter. You'll get another graphical login screen, but you'll be able to log in!
P.S.:
  1. If you are used to running some programs like ifconfig or others which are administrative ones from a terminal emulator (e.g. gnome-terminal) you'd better add a line like PATH="$PATH:/sbin:/usr/sbin" at the end of the .bashrc file in your home directory. You can do it with echo 'PATH="$PATH:/sbin:/usr/sbin"' >> ~/.bashrc.
  2. If you want to change back to the other graphical login screen from time to time and see if it was bug-fixed and it works again you can run sudo dpkg-reconfigure gdm and select lightdm and reboot (doesn't look like it works if you just run sudo pkill X).
shareimprove this answer

9.07.2015

5.19.2015

PTT標題前符號的意思 (轉貼)

【+】 還沒看過的文章,如果已看過 + 就會消失
【~】 就是這篇文章你已經看過,但只要是有新推文,或是原PO修了文,就會以此標記來提醒讀者說「此文章有新推文囉!」或是「此文章已被原PO修過囉!」

【M m】 這是被板主m起來的文章,也就是認為重要,不該系統清除,或者是不讓原PO刪除的標記此標記,差別只在於,大M是未讀,小m是已讀
【=】 就是m文內容有新變更,例如作者修改文章或是有人推文,看完就會變m
【!】 被版主標記起來,而此標記,為「鎖文」,通常是文章具爭議性,鎖起來,防止再戰下去也就是說,表示該篇文章不能推文、競標、回應

【S s】 被版主標記用,這標記通常是待處理、或已處理的文章,要看各板板主怎麼去使用也就是各板用途定義不同,大S是已讀,小s是未讀

 在我的最愛裡文章前的紅勾勾v是指你還沒有看過這個版上的最後一篇文章,如果看完就會消失,但有新文章就會出現