Wednesday, March 28, 2007

copying data from one table to another @ mysql

insert into tbl (field1,field2) select field1,field2 from users

Tuesday, March 27, 2007

Loops @ Ruby

n.times {|i| puts i}

Well, the method Integer#times iterate self times (n in this) and for each iteration calls the block, gives it the current value।

something do |line|
#process something and line here
end

something' is a method and this method call the block with
some value.

For example if you want to read a file, you write

IO.foreach('file') do |line|
# do something with line
end

the method IO::foreach open the file given in argument, read each line and
call the block, given it the current line. At the end, IO::foreach close
the file



n.times {|i| puts i}

or

n.times do |i|
puts i
end


a=["hello","to","you"]
a.each {|i| puts i}

(1..10)each{|i| puts i}

or

for i in (1..10)
puts i
end



Monday, March 26, 2007

File Handling @ Python

A file object maintains state about the file it has open. The tell method of a file object tells you your current position in the open file. Since you haven't done anything with this file yet, the current position is 0, which is the beginning of the file.
The seek method of a file object moves to another position in the open file. The second parameter specifies what the first one means; 0 means move to an absolute position (counting from the start of the file), 1 means move to a relative position (counting from the current position), and 2 means move to a position relative to the end of the file. Since the MP3 tags you're looking for are stored at the end of the file, you use 2 and tell the file object to move to a position 128 bytes from the end of the file.
The tell method confirms that the current file position has moved.
The read method reads a specified number of bytes from the open file and returns a string with the data that was read। The optional parameter specifies the maximum number of bytes to read. If no parameter is specified, read will read until the end of the file. (You could have simply said read() here, since you know exactly where you are in the file and you are, in fact, reading the last 128 bytes.) The read data is assigned to the tagData variable, and the current position is updated based on how many bytes were read.

import os
def filesnsubfiles(root):
file = os.listdir(root)
for i in file:
if os.path.isdir(root + "\\" + i):
filesnsubfiles(root + "\\" + i)
else:
print (root + "\\" + i)