list insertion question

2007-04-16 Thread eight02645999
hi i have a list (after reading from a file), say data = [ 'a','b','c','d','a','b','e','d'] I wanted to insert a word after every 'a', and before every 'd'. so i use enumerate this list: for num,item in enumerate(data): if "a" in item: data.insert(num+1,"aword") if "d" in item:

which version libpcap

2007-04-13 Thread eight02645999
hi from the web, i found 2 kinds of wrappers for libpcap, one is pylibpcap, the other is pcapy. may i know which is more popularly used? thanks -- http://mail.python.org/mailman/listinfo/python-list

Re: an enumerate question

2007-03-19 Thread eight02645999
On Mar 20, 11:00 am, Steven Bethard <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > for n,l in enumerate(open("file")): > >print n,l # this prints current line > >print next line in this current iteration of the loop. > > Depends what you want to happen when you request "next". I

Re: an enumerate question

2007-03-19 Thread eight02645999
On Mar 20, 9:48 am, Paul Rubin wrote: > [EMAIL PROTECTED] writes: > > hi > > say i want to enumerate lines of a file > > eg > > for n,l in enumerate(open("file")): > > # print next line ie > > > is there a way to print out the next line from current line using the >

an enumerate question

2007-03-19 Thread eight02645999
hi say i want to enumerate lines of a file eg for n,l in enumerate(open("file")): # print next line ie is there a way to print out the next line from current line using the above?. Or do i have to do a readlines() first to get it into a list eg d = open("file").readlines() for n, l in enumer

strip question

2007-01-26 Thread eight02645999
hi can someone explain strip() for these : [code] >>> x='www.example.com' >>> x.strip('cmowz.') 'example' [/code] when i did this: [code] >>> x = 'abcd,words.words' >>> x.strip(',.') 'abcd,words.words' [/code] it does not strip off "," and "." .Why is this so? thanks -- http://mail.python.org/m

Re: regexp qns

2007-01-19 Thread eight02645999
James Stroud wrote: > [EMAIL PROTECTED] wrote: > > hi > > suppose i have a string like > > > > test1?test2t-test3*test4*test5$test6#test7*test8 > > > > how can i construct the regexp to get test3*test4*test5 and > > test7*test8, ie, i want to match * and the words before and after? > > thanks > > >

regexp qns

2007-01-19 Thread eight02645999
hi suppose i have a string like test1?test2t-test3*test4*test5$test6#test7*test8 how can i construct the regexp to get test3*test4*test5 and test7*test8, ie, i want to match * and the words before and after? thanks -- http://mail.python.org/mailman/listinfo/python-list

Re: skip last line in loops

2006-12-15 Thread eight02645999
Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > > how can i skip printing the last line using loops (for /while) > > > > eg > > > > for line in open("file): > > print line. > > > > I want to skip printing last line of the file. > > do it lazily: > > last_line = None > for line i

skip last line in loops

2006-12-14 Thread eight02645999
hi, how can i skip printing the last line using loops (for /while) eg for line in open("file): print line. I want to skip printing last line of the file.thanks -- http://mail.python.org/mailman/listinfo/python-list

Re: paramiko public key

2006-12-13 Thread eight02645999
hg wrote: > [EMAIL PROTECTED] wrote: > > > paramiko > http://www.lag.net/paramiko/docs/ > > __str__ ? hi thanks for the tip i done up a function to generate priv/pub key pairs like this def keygen(bits,fil,password=None): k = paramiko.RSAKey.generate(bits) k.write_private_key_fil

paramiko public key

2006-12-11 Thread eight02645999
hi i downloaded paramiko and was trying to create private/pub key pairs from the docs, i use this method to create private key import paramiko k = paramiko.RSAKey.generate(1024) k.write_private_key_file("test_priv") How do i generate the public key for this ? thanks -- http://mail.python.org/ma

changing list items

2006-11-22 Thread eight02645999
hi say i have a list alist = ['a','b','c','e','d','f'] I wanted to change the elements , say alist[2:4] . If i do alist[2:4] = "t" , it gives ['a', 'b', 't', 'd', 'f'] which is not what i want. I wanted alist = ['a','b','t','t','d','f'] My list may have more elements, and i may need to replac

simulate enumerate in python 2.1

2006-07-10 Thread eight02645999
hi, i am using python 2.1. Can i use the code below to simulate the enumerate() function in 2.3? If not, how to simulate in 2.1? thanks from __future__ import generators def enumerate(sequence): index = 0 for item in sequence: yield index, item index += 1 -- http://mail.p

gathering some opinions

2006-07-04 Thread eight02645999
hi i am working on cgi and wish to gather some input on correct/often used methods of what i am going to do. I need to let the user choose (in the form of check boxes) whether they need the data to be emailed to them periodically. So if they click the check box on "activate", then email system will

how to pipe to variable of a "here document"

2006-04-09 Thread eight02645999
hi I need to execute sql command using a "here document" like in unix. os.popen("osql", "w").write("""\ select * from table go """) how can i pipe these result of the select into a variable? thanks -- http://mail.python.org/mailman/listinfo/python-list

passing argument to script

2006-04-07 Thread eight02645999
hi if i have a string like this "ABCE-123456 ABC_DEF_Suggest(abc def ghi).txt" that needs to be passed to a python script and i wanted to get the words inside the brackets after i passed this string. I did a re something like thestring = sys.argv[1:] pat = re.compile(r".*\((.*)\)\.txt$") if pa

ftplib question

2006-04-07 Thread eight02645999
hi my purpose is just to connect to an FTP server and delete all files in a directory Is there a way using ftplib module? something like ftp.delete("*") ? another way i can do is using LIST to list out all the files in that directory, grab the filename, append to an array, then do a for loop to del

a question on re

2006-03-31 Thread eight02645999
hi i tried to search 2 patterns pat1 = re.compile("blah") pat2 = re.compile("blah2") if i do if re.findall(pat1,something) and re.findall(pat2,something): do something if does not work but when i do a nest if, if re.findall(pat1,something) : if re.findall(pat2,s

telnet session

2006-03-29 Thread eight02645999
hi i am using a telnet session to simulate an authentication mechanism USER = "user" PASSWORD = "password" try: telnet = telnetlib.Telnet(HOST) telnet.set_debuglevel(5) telnet.read_until("login: ") telnet.write(USER + "\n") telnet.read_until("Password: ")

telnet session

2006-03-29 Thread eight02645999
hi i am using a telnet session to simulate an authentication mechanism USER = "user" PASSWORD = "password" try: telnet = telnetlib.Telnet(HOST) telnet.set_debuglevel(5) telnet.read_until("login: ") telnet.write(USER + "\n") telnet.read_until("Password: ")

insert chars into string

2006-03-17 Thread eight02645999
hi is there a string method to insert characters into a string? eg str = "abcdef" i want to insert "#" into str so that it appears "abc#def" currently what i did is convert it to a list, insert the character using insert() and then join them back as string.. thanks -- http://mail.python.org/mai

catching java program return

2006-03-13 Thread eight02645999
hi i have to run a java program inside my python script. i have some java classes declared: os.environ['CLASSPATH'] = "blah path" then i used the os.system method to invoke the java program and using ret = os.WEXITSTATUS(os.system(cmd)) to catch the return Java gave me an error about unable to l

a good algo to do this

2006-03-06 Thread eight02645999
hi i need to do something like this eg given a number (as a string) = "123" there are a few combination i want to find with this string, ie "132","321","231","312" and "213". so there are 6 combinations altogether. i remember there's a formula for this, but forgot. Does python have any modules/func

stripping spaces in front of line

2006-03-03 Thread eight02645999
hi wish to ask a qns on strip i wish to strip all spaces in front of a line (in text file) f = open("textfile","rU") while (1): line = f.readline().strip() if line == '': break print line f.close() in "textfile", i added some spaces in and then ran the code

help in converting perl re to python re

2006-03-02 Thread eight02645999
hi i have some regular exp code in perl that i want to convert to python. if $line =~ m#<(tag1)>(.*)# { $variable = $2; } the perl code finds a line that matches something like "sometext<\tag1>" in the line and then assign $variable the value of "sometext" how can i do an equival

Qns on blank lines

2006-03-02 Thread eight02645999
hi i have some regular exp code in perl that i want to convert to python. if $line =~ m#<(tag1)>(.*)# { $variable = $2; } the perl code finds a line that matches something like "sometext<\tag1>" in the line and then assign $variable the value of "sometext" how can i do an equival

multiple email recipients

2006-02-20 Thread eight02645999
hi i currently am using this email function that can send single email address def email(HOST,FROM,TO,SUBJECT,BODY,CC=None): import smtplib import string, sys body = string.join(( "From: %s" % FROM, "To: %s" % TO, "Subject: %s" % SUBJECT, "CC: %s" % CC, "", BODY)

days since epoch

2006-02-17 Thread eight02645999
hi how can i get the number of days since epoch using the time module? or do i have to manually do the arithmetic? thanks -- http://mail.python.org/mailman/listinfo/python-list

pymssql and date format

2006-02-16 Thread eight02645999
hi i am using pymmsql to query a date column in MSSQL database table. However the result shows for example (datetime.datetime(2006, 2, 16, 17, 50, 19) which is supposed to be 2006-02-16 17:50:19.000 anyway to correct query a date column using pymssql so that it gives the correct date format? thanks

removing characters before writing to file

2006-02-08 Thread eight02645999
hi i have some output that returns a lines of tuples eg ('sometext1', 1421248118, 1, 'P ') ('sometext2', 1421248338, 2, 'S ') and so on I tried this re.sub(r" '() ",'',str(output)) but it only get rid of the ' and not the braces. I need to write the output to a file such that sometext1, 142

how to catch error with system()

2005-12-12 Thread eight02645999
hi i have a piece of python code extract that calls an external java program cmd = """java someclass someargs""" try: ret = os.WEXITSTATUS(os.system(cmd)) except: print blah else: dosomething(ret) the thing is, the java class "someclass" produces it's own errors when something goes wrong

passing values from one form to another

2005-11-12 Thread eight02645999
hi i have 3 python cgi scripts created, one is a login page(login.py), another is the main page(main.py) with a lot of user inputs and the last one is a python cgi script results.py to process main.py In main.py, i am able to check for the value of the user and password field, eg if form.has_key

Re: pls help me with strange result

2005-11-07 Thread eight02645999
hi thanks for your advice. yes,the args parameter can be included. Yes , the syntax is valid. I tried and it works for the 2 tables. looks like sybase knows how to distinguish that 2 update statements..as separate ones. cheers -- http://mail.python.org/mailman/listinfo/python-list

Re: pls help me with strange result

2005-11-07 Thread eight02645999
hi thanks! i used your method to rearrange the try,except clauses, and the problem is solved. I also redefined my funcs to get rid of the try/except clauses and leave it to the caller to do the job of try/except. -- http://mail.python.org/mailman/listinfo/python-list

pls help me with strange result

2005-11-07 Thread eight02645999
hi i defined a func db = Sybase.connect(DSN) ... def x_dml(SQL,conn): ''' Connects to database specified, exec the SQL and returns value''' try: c = conn.cursor() try: c.execute(SQL) res = c.rowco

help converting some perl code to python

2005-11-04 Thread eight02645999
hi i need help with converting a piece of perl code to python . my $start = '\[start\]'; my $file = '\[files\]'; my $end = '\[end\]'; while() #open a file { if ( /$start/ .. /$file/ ) { # if line match [start] till [files] do something with $_ } if

how to check for unix password

2005-11-02 Thread eight02645999
hi i created a login page that authenticate the user and his/her password to the unix ssystem. what modules can i used to compare the unix password with what the user typed in the cgi form? the password is encrypted (shadowed) so i need to decrypt it first before comparing to what the user typed. o

Re: python CGI,sybase and environ variables

2005-11-02 Thread eight02645999
i have solved the problem. thanks. -- http://mail.python.org/mailman/listinfo/python-list

python CGI,sybase and environ variables

2005-11-02 Thread eight02645999
hi i am writing a CGI to process some database transactions using the Sybase module. so in my CGI script, i have: ... import Sybase import cgitb; cgitb.enable(display=1 , logdir="/tmp/weblog.txt") ... ... the problem is , everytime i have ImportError: No module named Sybase flagged out. at first

Re: query a port

2005-10-29 Thread eight02645999
thanks alot! that's all there is to it..so it's just a simple connect. Dan M wrote: > On Sat, 29 Oct 2005 20:21:20 -0700, eight02645999 wrote: > > > hi > > in python, how do one query a port to see whether it's up or not? > > thanks > > I'm

query a port

2005-10-29 Thread eight02645999
hi in python, how do one query a port to see whether it's up or not? thanks -- http://mail.python.org/mailman/listinfo/python-list

do cc list from smtplib

2005-10-21 Thread eight02645999
hi i have email code: def email(HOST,FROM,TO,SUBJECT,BODY): import smtplib import string, sys body = string.join(( "From: %s" % FROM, "To: %s" % TO, "Subject: %s" % SUBJECT, "", BODY), "\r\n") print body server = smtplib.SMTP(HOST) server.sendmail(FR

Re: how to return correct value of update stmt

2005-10-19 Thread eight02645999
hi yes , the table is updated. Just feels "uncomfortable" with the return of -1. was also concerned that what if the actual table doesn't exist, will it return -1? anyway, i will go check it out .. thanks -- http://mail.python.org/mailman/listinfo/python-list

how to return correct value of update stmt

2005-10-18 Thread eight02645999
hi i use odbc to update a table in a database but i always get return value of -1 even though i tried to return an integer. the table is updated though ... sql = """ update table set column = 0 where col = "%s" select @@rowcount """

odbc errors

2005-10-16 Thread eight02645999
hi i have a piece of code: ... def connectdb(sql): import dbi import odbc import sys try: s = odbc.odbc('DSN=CONN;UID=user;PWD=pass') cur = s.cursor() # cur.execute("set nocount on") cur.execute(sql) while 1: rec = cur.fetchone()

where to get modules for python

2005-10-11 Thread eight02645999
hi i am new to python and was wondering where can i find modules for python? Something very much like what CPAN has for Perl. I am searching for SSL/SSH modules for use in Python. thanks -- http://mail.python.org/mailman/listinfo/python-list