Jumat, 29 November 2013

Disconnect and Map Network Drive on Windows with Python

I'm using Python version 3.3.2
  1. method using subprocess.Popen

  2. # Balon Coding, 29 November 2013
    # Map network drive using subprocess.Popen
    # Drive letter: Q
    # Shared drive path: \\192.168.51.1\balon$
    # Username: balon
    # Password: coding
    
    import subprocess 
    
    # initialize
    driveLetter = 'Q:' 
    networkPath = '\\\\192.168.51.1\balon$' 
    user = 'balon' 
    password = 'coding'
    
    print('map network drive using subprocess.Popen')
    
    # Disconnect anything on drive letter Q
    winCMD = 'NET USE ' + driveLetter + ' /delete'
    print(winCMD)
    subprocess.Popen(winCMD, stdout=subprocess.PIPE, shell=True)
     
    # Connect to map network drive to letter Q
    winCMD = 'NET USE ' + driveLetter + ' ' + networkPath + ' /User:' + user + ' ' + password
    print(winCMD)
    subprocess.Popen(winCMD, stdout=subprocess.PIPE, shell=True)
    

  3. method using subprocess.call
  4. # Balon Coding, 29 November 2013
    # Map network drive using subprocess.call
    # Drive letter: Q
    # Shared drive path: \\192.168.51.1\balon$
    # Username: balon
    # Password: coding
    
    import subprocess 
    
    # initialize
    driveLetter = 'Q:' 
    networkPath = '\\\\192.168.51.1\balon$' 
    user = 'balon' 
    password = 'coding'
    
    print('map network drive using subprocess.call')
    
    # Disconnect anything on drive letter Q
    winCMD = 'NET USE ' + driveLetter + ' /delete'
    print(winCMD)
    subprocess.call(winCMD, shell=True)
    
    # Connect to map network drive to letter Q
    winCMD = 'NET USE ' + driveLetter + ' ' + networkPath + ' /User:' + user + ' ' + password
    print(winCMD)
    subprocess.call(winCMD, shell=True)
    

Kamis, 28 November 2013

List Available Drive Letters In Python

I'm using Python version 3.3.2
import string
from ctypes import windll

def get_drives():
    drives = []
    bitmask = windll.kernel32.GetLogicalDrives()
    for letter in string.ascii_uppercase:
        if bitmask & 1:
            drives.append(letter)
        bitmask >>= 1

    return drives

if __name__ == '__main__':
    print (get_drives())     # On my PC, this prints ['C', 'D', 'W', 'X', 'Y', 'Z']

Minggu, 17 November 2013

Print 'Hello World' di Python

Pertama kali belajar di Python sudah menghadapi tantangan pertama, yakni hanya untuk memunculkan "Hello World".
>>> print "Hello World!"
     File "", line 1
       print "Hello World!"
                                 ^
SyntaxError: invalid syntax
>>>

Ternyata setelah gugel, ada yang menyatakan ini merupakan syntax yang berlaku di Python 2.x, sementara yang BalonCoding gunakan adalah Python 3.3 yang sudah menggunakan syntax print (). Sehingga untuk menjalankan print "Hello World", maka lakukan seperti berikut ini,
text = "Hello World!"
print (text)

Jumat, 01 November 2013

Starting emulator for AVD - Failed to allocate memory: 8

The solution is edit file config.ini [C:\Users\acer\.android\avd\.avd\ 

from

hw.ramSize=1024

to 

hw.ramSize=1024MB

First Android Tutorial Project Error

I got error messages like this on DisplayMessageActivity.java
Error:(17, 6) Gradle: error: cannot find symbol class SuppressLint
Error:(37, 9) Gradle: error: cannot find symbol class Intent
Error:(41, 9) Gradle: error: cannot find symbol class TextView
Error:(41, 33) Gradle: error: cannot find symbol class TextView
import android.annotation.SuppressLint;
import android.content.Intent;
import android.widget.TextView;