Search This Blog
Wednesday, June 4, 2008
Sending mail in python
def send_mail(destination, source, subject, text, smtp_addr='localhost'):
"""Simple function to send an email.
destination
The email address that the message should be sent to.
source
The 'From' address that will be used for the email.
subject
The subject/ title of the email.
text
The actual message/ content of the email.
smtp_addr
The hostname or IP address of the SMTP server that will deliver the
email.
Example usage:
send_mail('my_friend@test.com', 'bgates@microsoft.com',
'Hi!', 'Just checking in.')
"""
import email.Message
import smtplib
mail = email.Message.Message()
mail['To'] = destination
mail['From'] = source
mail['Subject'] = subject
mail.set_payload(text)
server = smtplib.SMTP(smtp_addr)
server.sendmail(source, destination, mail.as_string())
server.quit()
Tuesday, June 3, 2008
Dot Net
What is .NET ?
# It is a platform neutral framework.
# Is a layer between the operating system and the programming language.
# It supports many programming languages, including VB.NET, C# etc.
# .NET provides a common set of class libraries, which can be accessed from any .NET based programming language. There will not be separate set of classes and libraries for each language. If you know any one .NET language, you can write code in any .NET language!!
# In future versions of Windows, .NET will be freely distributed as part of operating system and users will never have to install .NET separately.
What is Not ?
Monday, June 2, 2008
Get command line parameters for a program in PYTHON
Example of a function by which you can get command line parameters for a program in python
Note : Kindly do the indentatoin of your own.........
def GetCommandLineParameters(commandline_temp): position = 0 fcrontmpfile,entrytoignore,fcronsourcefile = '','','' length = len(commandline_temp) while position < fcrontmpfile =" commandline_temp[position]" entrytoignore =" commandline_temp[position]" fcronsourcefile =" commandline_temp[position]" style="font-weight: bold;">Example of a Usage Function def Usage(): print "\nPlz go through the USAGE." print "Note : \n\t*\tThis suid can read or write in a fcron file. ignoreprogram is the entry which \n\t\tyou would like to remove to avoid duplication. \n\n\t*\tIt would be prefered to give the full program name with the path so that \n\t\tther e is no duplication with the new entry. \n\n\t*\t--fcrontempfile and --ignoreprogram are mandatory if you want to read the \ n\t\tfcron or --fcronsourcefile is mandatory if u want to change the fcron of the firewall." print "\nUSAGE: python writeinfcron.py [OPTION...]" print "-------------------------------------------------------------------------------------------------" print "\n--fcrontempfile -------> A temp file with path where the fcrondata will be written." print "--ignoreprogram -------> An entry which you would like to ignore." print "--fcronsourcefile -------> Fcron Source file which will be wriiten in the cron file" print "-------------------------------------------------------------------------------------------------"
Monday, May 26, 2008
To Create a Database in MySQL and few commanfs to refer
mysql> create database newonw;
Query OK, 1 row affected (0.00 sec)
Basic CREATE TABLE statement
A very basic CREATE TABLE statement which should work in any SQL database:
mysql> CREATE TABLE example (
id INT,
data VARCHAR(100)
);
Query OK, 0 rows affected (0.03 sec)
Creating a table with a particular storage engine
MySQL provides a variety of different table types with differing levels of functionality. The usual default, and most widely used, is MyISAM. Other storage types must be explicitly defined:
mysql> CREATE TABLE example_innodb (
id INT,
data VARCHAR(100)
) TYPE=innodb;
Query OK, 0 rows affected (0.03 sec)
Note that beginning with MySQL 4.1 ENGINE=innodb is the preferred method of defining the storage type.
Use SHOW CREATE TABLE (see below) to check that MySQL has created the table as you defined it.
Creating a table with auto_increment
Often you'll want to be able to automatically assign a sequential value to a column:
mysql> CREATE TABLE example_autoincrement (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
data VARCHAR(100)
);
Query OK, 0 rows affected (0.01 sec)
mysql> INSERT INTO example_autoincrement (data)
-> VALUES ('Hello world');
Query OK, 1 row affected (0.01 sec)
mysql> SELECT * FROM example_autoincrement;
+----+-------------+
| id | data |
+----+-------------+
| 1 | Hello world |
+----+-------------+
1 row in set (0.01 sec)
Creating a table with the current timestamp
Often it's useful to have an automatic timestamp on each record. The MySQL special datatype TIMESTAMP enables you to keep track of changes to a record:
mysql> CREATE TABLE example_timestamp (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
data VARCHAR(100),
cur_timestamp TIMESTAMP(8)
);
Query OK, 0 rows affected (0.00 sec)
mysql> INSERT INTO example_timestamp (data)
VALUES ('The time of creation is:');
Query OK, 1 row affected (0.00 sec)
mysql> SELECT * FROM example_timestamp;
+----+--------------------------+---------------------+
| id | data | cur_timestamp |
+----+--------------------------+---------------------+
| 1 | The time of creation is: | 2004-12-01 20:37:22 |
+----+--------------------------+---------------------+
1 row in set (0.00 sec)
mysql> UPDATE example_timestamp
SET data='The current timestamp is: '
WHERE id=1;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> SELECT * FROM example_timestamp;
+----+---------------------------+---------------------+
| id | data | cur_timestamp |
+----+---------------------------+---------------------+
| 1 | The current timestamp is: | 2004-12-01 20:38:55 |
+----+---------------------------+---------------------+
1 row in set (0.01 sec)
The column cur_timestamp is automagically updated every time the record is changed.
Creating a table with TIMESTAMP DEFAULT NOW()
MySQL supports the construct TIMESTAMP DEFAULT NOW() only from verson 4.1:
CREATE TABLE example_default_now (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
data VARCHAR(100),
created TIMESTAMP DEFAULT NOW()
);
In this case the column created retains its initial value and is not changed during subsequent updates.
For versions prior to 4.1, the only workaround is to create two timestamp columns in a table, and explicitly set the second one when inserting the record. Remember: the first TIMESTAMP will be automagically updated on each record update.
Viewing a table definition
For basic information on table columns, use DESC tablename:
mysql> DESC example;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| data | varchar(100) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
Exact definition of the table:
mysql> SHOW CREATE TABLE example;
+---------+------------------------------------------------+
| Table | Create Table |
+---------+------------------------------------------------+
| example | CREATE TABLE `example` (
`id` int(11) default NULL,
`data` varchar(100) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+---------+------------------------------------------------+
1 row in set (0.00 sec)
Subscribe to:
Posts (Atom)