>>> a='To be or not to be'
>>> ' '.join(a.split())
'To be or not to be'
Use ' '.join(a.split())
A little script i've written to convert an amount of upto 14 digits before the decimal into words.I have a 14 digit limit which conforms with the accounting package tally which is predominantly used here.Million, billions trillions etc aren't used to decribe large sums of money but lakhs and crores are used instead..
XX,XX,XXX
The indian format does not seperate the number in 3's as done in the US here its 2-2-3
So for 14 digits the separation is as follows
XX,XX,XXX,XX,XX,XXX
instructions: paste the code and call the the in_words() function passing it a float formatted to 2 digits after the decimal.
#Constants
ONES={0:'',1:'One',2:'Two',3:'Three',4:'Four',
5:'Five',6:'Six',7:'Seven',8:'Eight',
9:'Nine',10:'Ten',11:'Eleven',12:'Twelve',
13:'Thirteen',14:'Fourteen',15:'Fifteen',
16:'Sixteen',17:'Seventeen',18:'Eighteen',19:'Nineteen'}
TENS={2:'Twenty',3:'Thirty',4:'Forty',5:'Fifty',6:'Sixty',7:'Seventy',8:'Eighty',9:'Ninety'}
#Functions
#split into 7 chunks.. since its to be used with tally which supports 14 digits -done manually
def amt2words(n):
ns=str(n)
if len(ns)>14:
return 'Number too large'
if len(ns)<=7:
return '%s'%(parse_amt2words(ns[-7:]),)
else:
return '%s Crore %s'%(parse_amt2words(ns[-14:-7]),parse_amt2words(ns[-7:]))
#take the number seperate at decimal point for decimal use 2 digits only
def in_words(x):
#return mdc_report_func.amt2words(int(x))
if isinstance(x,float):
rs=int(x)
ps=int(str(x)[-2:])
elif isinstance(x,int):
rs=int(x)
ps=0
else:
return x
if rs>0:
rs1=amt2words(rs)
else:
rs1=''
if ps>0:
ps1=' And %s Paise'%(amt2words(ps),)
else:
ps1=''
y = '%s%s Only'%(rs1,ps1)
return y
May not the best or even the best piece of code to do this task but it took me about 20 minutes to do and it works so.. use it at your own risk if you need help to understand it drop me a line..
SELECT TOP 10 * FROM table, becomes SELECT * FROM table LIMIT 10 you can also use the maxrows attribute of CFQUERY to do this, if you want cross db code (which is good). MySQL also uses the LIMIT sytax, but Oracle uses yet another syntaxSELECT * FROM table WHERE LOWER(column) LIKE '%#LCase(var)#%' (Or you can use the ILIKE operator) SELECT firstname + ' ' + lastname AS fullname becomes SELECT firstname || ' ' || lastname AS fullname this way works on both servers. Ive got an MS Access accdb file that from which I need to extract data programatically and insert it into Postgresql
This post deals with connecting to and querying data from MS Access 2007 on Windows 7 using Python 2.7
>>> import pyodbc
>>> conn = pyodbc.connect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ
=C:\\access\\site_be.accdb;")
>>> cursor = conn.cursor()
>>> sql = "select * from dist_code;"
>>> for row in cursor.execute(sql):
... print row.dist_code
...
250
500
750
1000
1250
1500
1750
2000
2250
2500
2750
3000
WT140
WT180
>>> cursor.close()
>>> conn.close()
>>>
Traceback (most recent call last):
File "", line 1, in conn = pyodbc.connect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=;")Error: ('HY000', "[HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x167c Thread 0x1568 DBC 0x1c67a5c
Jet'. (63) (SQLDriverConnectW); [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x167c Thread 0x1568 DBC 0x1c67a5c
Jet'. (63); [HY000] [Microsoft][ODBC Microsoft Access Driver] Not a valid file name. (-1044); [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x167c Thread 0x1568 DBC 0x1c67a5c
Jet'. (63); [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x167c Thread 0x1568 DBC 0x1c67a5c
Jet'. (63); [HY000] [Microsoft][ODBC Microsoft Access Driver] Not a valid file name. (-1044)")
Compiled from:
http://en.wikibooks.org/wiki/Python_Programming/Database_Programming
http://code.google.com/p/pyodbc/wiki/GettingStarted
How do I find open ports on Linux / FreeBSD server?
There are different commands on both Linux and UNIX server to find out what tcp/udp ports are listening or open on your own server. You can use netstat command, which print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships etc. Another (and suggested) option is to use lsof command, which list open files, and ports on Linux, FreeBSD, Solaris and other Unixish systems.
# netstat --listen
To display open ports and established TCP connections, enter:
$ netstat -vatn
To display only open UDP ports try the following command:
$ netstat -vaun
If you want to see FQDN (full dns hostname), try removing the -n flag:
$ netstat -vat
To display the list of open ports, enter:
# lsof -i
To display all open files, use:
# lsof
To display all open IPv4 network files in use by the process whose PID is 9255, use:
# lsof -i 4 -a -p 9255
You can use the sockstat command lists open Internet or UNIX domain sockets, enter:
$ sockstat
$ sockstat -l
$ sockstat -4 -l
$ sockstat -6 -l
Q. How do I kill process in Linux?
A. Linux and all other UNIX like oses comes with kill command. The command kill sends the specified signal (such as kill process) to the specified process or process group. If no signal is specified, the TERM signal is sent.
kill command works under both Linux and UNIX/BSD like operating systems.
Use ps command or pidof command to find out process ID (PID). Syntax:
ps aux | grep processname
pidof processname
For example if process name is lighttpd, you can use any one of the following command to obtain process ID:
# ps aux | grep lighttpdOutput:
lighttpd 3486 0.0 0.1 4248 1432 ? S Jul31 0:00 /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conflighttpd 3492 0.0 0.5 13752 3936 ? Ss Jul31 0:00 /usr/bin/php5-cg
OR use pidof command which is use to find the process ID of a running program:
# pidof lighttpdOutput:
3486
Above command tell you PID (3486) of lighttpd process. Now kill process using this PID:
# kill 3486
OR
# kill -9 3486
Where,
DO NOT USE killall command on UNIX system (Linux only command). You can also use killall command. The killall command kill processes by name (no need to find PID):
# killall -9 lighttpd
Kill Firefox process:
# killall -9 firefox-bin
As I said earlier killall on UNIX system does something else. It kills all process and not just specific process. Do not use killall on UNIX system (use kill -9).
After installing the Guest Additions I managed to get the screen resizing/ full screen functionality to work. However I wasn't able to share the clipboard between the Host and the Guest OS.
My next best option was using the 'Shared Folder' functionality which wasn't very intuitive
I was trying out VirtualBox on ubuntu 11.04 and I wanted to install the "Guest Additions" package in order to increase the screen size of the guest which was ubuntu 10.04.
So i got the guest os running and then clicked on Devices>Install Guest Additions (Note: the Devices Menu is on the common menu bar on the top in 11.04 and not on the window for Vbox)
A prompt asked me to download the VBoxGuestAdditions_4.0.4.iso and then another prompt asked to mount it..
Here i got an error
"Failed to open the CD/DVD image (then indicated the file path for the ISO)
Could not get Storage format of the medium (again indicated the file path of the ISO)
VERR_NOT_SUPPORTED"
I retried the process about 3 times but in vain..
Basically the iso file was not downloaded completely.. its about 36 mb and only 10 mb was downloaded before the prompt to mount came up.
The solution to this is pretty simple.