Friday, February 7, 2014

How do we share a directory in Dropbox without moving it under Dlopbox directory?

There is a directory in your local computer. For example,

D:\Homework 

You want to share it in Dropbox but you don't want to move it under DropBox directory. For example,

C:\Users\Count_Chu\Dropbox

You want to keep the path. How do you do? I found a way to solve the problem. For Windows 7+, you can use mklink to make a symbolic link from your directory to the linked directory in Dropbox. For example,

mklink /D C:\Users\Count_Chu\Dropbox\Homework D:\Homework

Then please open Dropbox directory, you can find that the directory linked in Dropbox directory. For example,



Therefore your directory (e.g., Homework) is shared under Dropbox and you don't need to really move the path (e.g., D:\Homework). The directory will be automatically synchronized with Dropbox.

But there is a problem that the new files cannot be updated on Dropbox. To solve the it, you can move your directory into Dropbox directory and run mklink to make a symbolic link from your directory in Dropbox to the linked directory you moved. For example,

move D:\Homework C:\Users\Count_Chu\Dropbox\Homework     
mklink /D D:\Homework C:\Users\Count_Chu\Dropbox\Homework

-Count

Monday, February 3, 2014

How to avoid cx_Freeze generating Library.zip when packing Python files?

The cx_Freeze is a tool that packs Python files to generate a EXE file. How do we avoid it generating Library.zip? The following source tree is an example.

[Workspace]
  [MyApp]
    Setup.py ---- cx_Freeze setup program
    MyApp.py ---- the python file that will be packed in EXE.
  [build]    ---- The directory is generated by cx_Freeze

The content of the Setup.py is:

We perform the following command to pack MyApp.py in MyApp.exe.

Workspace> python MyApp\Setup.py build

You cannot find Library.zip in the build directory because create_shared_zip is assigned to False.

-Count

Sunday, February 2, 2014

When do we use Python's "with as"?

Generally, we use the below Python code with three lines to write data into a file.

f = open ("Test.txt", "w")
f.writelines (Lines)
f.close ()

Sometimes, we are lazy to use one line to do the same thing.

open ("Test.txt", "w").writelines (Lines)

That is OKAY. Data will be automatically written into the file because f.close() is automatically called when the Python program exits.

But there is a problem. The below second line cannot read any new data from the file because new data has not been written by the first line.

open ("Test.txt", "w").writelines (Lines)
Lines = open ("Test.txt").readlines ()

We found that Lines are empty because the file "Test.txt" is not closed.

We can use "with as" supported by Python 2.6 to solve the problem.

with open ("Test.txt", "w") as f:
    f.writelines (Lines)
Lines = open ("Test.txt").readlines ()

When the block of "with as" finishes, f.close() is automatically called. Therefore the third line can read data from the file into Lines.

We can refer the below page for more detail of "with as".
http://openhome.cc/Gossip/Python/WithAs.html

-Count