Archive for April, 2015


Use Python to detect your computer system and name

I work on several computers, sometimes Widows, sometimes Linux, so I got a problem after I pull my project file from Git. That is the file path.

To cope with this problem, I have to find out which computer I am working on at moment. With Python, you have sevral ways to do that:

  • >>>import platform
    >>>platform.node() => you will get the name of the computer
    [Out]: codehamster-home
  • >>>import socket
    >>>socket.gethostname() => get also the name of the computer
    [Out]: codehamster-work
  • >>>import platform
    >>>platfrom.uname() => you will get the detail information about your computer
  • >>>import sys
    >>>sys.platform => you will the type of the system
    [Out]: win32

Here is my function, which adjust the path according your computer:


Read an Image with python

  • If you want to read an image, you will need the ‘image’ package:
    • import Image
  • read the image:
  • convert the Image to grey scale:
  • convert the image to array:
    • numpy.asarray('L'))


  • Here is a introduction to “Image” package
  • opencv, pillow are the python image library