zip list with different length

2007-04-04 Thread s99999999s2003
hi suppose i have 2 lists, a, b then have different number of elements, say len(a) = 5, len(b) = 3 >>> a = range(5) >>> b = range(3) >>> zip(b,a) [(0, 0), (1, 1), (2, 2)] >>> zip(a,b) [(0, 0), (1, 1), (2, 2)] I want the results to be [(0, 0), (1, 1), (2, 2) , (3) , (4) ] can it be done? thanks --

Re: which methods to use?

2007-03-28 Thread s99999999s2003
On Mar 29, 12:56 pm, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Wed, 28 Mar 2007 18:16:31 -0700, ss2003 wrote: > > what do you mean by create new object when using list comprehensoin or > > list()? Does using slicing create a new object as well? > > Ye

Re: which methods to use?

2007-03-28 Thread s99999999s2003
On Mar 29, 8:25 am, Florian Leitner <[EMAIL PROTECTED]> wrote: > * [EMAIL PROTECTED] wrote, On 3/29/07 2:09 AM: > > > hi > > which is the best methods to use for list copying. using list() , [:] > > or create list through list comprehension. what are the differences > > between these ? > > thanks

which methods to use?

2007-03-28 Thread s99999999s2003
hi which is the best methods to use for list copying. using list() , [:] or create list through list comprehension. what are the differences between these ? thanks -- http://mail.python.org/mailman/listinfo/python-list

Re: using regexp

2007-03-19 Thread s99999999s2003
On Mar 20, 1:57 pm, Shane Geiger <[EMAIL PROTECTED]> wrote: > import re > line = '123456789123456789' > print re.findall('([0-9]{3})', line) > > > > Shane Geiger wrote: > > You don't even need regex. > > > def > > split_seq(seq,size): > > ># this is sort of the inverse of > > flatten > > >#

using regexp

2007-03-19 Thread s99999999s2003
hi how can i use regexp to group these digits into groups of 3? eg line 123456789123456789 i have : pat = re.compile("line\s+(\d{3})" , re.M|re.DOTALL) but this only gives the first 3. I also tried "line\s+(\d{3})+" but also not working. I need output to be ['123' ,'456','789', '123','456','78

match nested parenthesis

2007-01-22 Thread s99999999s2003
hi i wish to find an reg exp for matching nested parenthesis of varying level like string = "somewords1(words(somewords2)-(some(some)words3)somestuff)somestuff" and be able to evaluate the pair starting from the inner most(the deepest level) , ie (some) up till the outer most. What is a good reg ex

Re: printing variables

2006-10-05 Thread s99999999s2003
Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > > say i have variables like these > > > > var1 = "blah" > > var2 = "blahblah" > > var3 = "blahblahblah" > > var4 = "" > > var5 = "...".. > > > > bcos all the variable names start with "var", is there a way to > > conveniently print

printing variables

2006-10-05 Thread s99999999s2003
hi say i have variables like these var1 = "blah" var2 = "blahblah" var3 = "blahblahblah" var4 = "" var5 = "...".. bcos all the variable names start with "var", is there a way to conveniently print those variables out... eg print var* ?? i don't want to do : print var1, var2, var3, var4 .

switch user

2006-10-02 Thread s99999999s2003
hi due to certain constraints, i will running a python script as root inside this script, also due to some constraints, i need to switch user to user1 to run the rest of the script...is there a way ?thanks -- http://mail.python.org/mailman/listinfo/python-list

concat next line with previous

2006-09-26 Thread s99999999s2003
hi what is the python way to concat 2 lines eg line 1 with some text line 2 with some text i want to bring line 2 up , such that i get one whole string. line 1 with some text line 2 with some text -- http://mail.python.org/mailman/listinfo/python-list

Upgrading question

2006-09-20 Thread s99999999s2003
hi just want to get some opinions i am working in unix and my Python version is 2.4.1 I would like to upgrade my version to 2.5 stable. but i have many scripts already running using 2.4.1. Can i just install 2.5 onto another directory, and then just change every shebang (#! in first line) in my scr

excel in unix?

2006-08-10 Thread s99999999s2003
hi is it possible to create excel files using python in Unix env? if so, what module should i use? thanks -- http://mail.python.org/mailman/listinfo/python-list

platform independent process check

2006-08-04 Thread s99999999s2003
hi is there any Python modules that can list the processes that are running on a machine? I don't wish to shell out using the "ps" command because the "ps" command is not available in Windows.. thanks? -- http://mail.python.org/mailman/listinfo/python-list

switching users in cgi

2006-07-07 Thread s99999999s2003
hi i am developing cgi script that read a unix user name and password, After authentication, i need to switch the environment to that of that user and display his/her files in her/his home directory. As my web server runs as nobody , it cannot have access to files in the user's home. What is a corr

logging module question

2006-06-29 Thread s99999999s2003
hi i have defined a function def logger(logfile,msg): import logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%a, %d %b %Y %H:%M:%S',

classes and interfaces

2006-06-27 Thread s99999999s2003
hi i come from a non OO environment. now i am learning about classes. can i ask, in JAva, there are things like interface. eg public interface someinterface { public somemethod (); ... } In python , how to implement interface like the above? is it just define a class?? class someint

joining NoneType and DateTimeType

2006-06-14 Thread s99999999s2003
hi i have some databse results that are NoneType and DateTimeType. now i have trouble joining these row results together like "|".join(result) as it says cannot join NoneType , DateTimeType . How can i change these types so i can join the columns together as string? thanks -- http://mail.python.o

assign operator as variable ?

2006-06-06 Thread s99999999s2003
hi in python is there any way to do this op = "<" a = 10 b = 20 if a op b : print "a is less than b" ?? thanks -- http://mail.python.org/mailman/listinfo/python-list

attribute error using fnmatch

2006-06-04 Thread s99999999s2003
hi i have script like this: from fnmatch import fnmatch from glob import glob ... f = ['file1','file2','file3'] r = "d:\\somepath" pat = "*.bat" listof_files = [i for i in f if not fnmatch(os.path.join(r,i),pat) and os.path.isfile(os.path.join(r,i))] ... .. I get this error: File "C:\Pyth

a good explanation

2006-05-25 Thread s99999999s2003
hi my friend has written a loop like this cnt = 0 files = [a,b,c,d] while cnt < len(files) : do_something(files[cnt]) i told him using for fi in files: do_something(fi) is better, because the while loop method makes another call to len..which is slower.. am i partly right? or is there a bet

grabbing portions of a file to output files

2006-05-22 Thread s99999999s2003
hi. I have a file with this kind of structure: Hxxx . . . x Hxxx ... ... x H . and so onlines starting with 'H' are headers. I wish to get the parts of the file where l

a project to standardize script writing in my environment

2006-04-12 Thread s99999999s2003
hi in my environment, besides shell scripts written for sys admin tasks, there are shell scripts that call java programs which in turn will do various processing like connecting to databases and doing manipulation of data. My programmers all know only Java and so this is how the java programs come

waiting for file lock?

2006-04-10 Thread s99999999s2003
hi i need to go into a directory to grab some files and do some processing. The thing is, i need to wait till the process that generates the files in that directory to finish before i can grab the files. eg if file A is being generated and has not finished, my python script will not go into the dir

how to create file with spaces

2006-04-06 Thread s99999999s2003
hi i have a dir that contains directories with names and spaces in between example rootdir | > ABC DEF A | ---> BDD SD N I wanted to touch a file with the same name as the directories inside each directory rootdir | > ABC DEF A |---> ABC DEF A-dummy | -

how to touch a file

2006-04-06 Thread s99999999s2003
hi i have a dir that contains directories with names and spaces in between example rootdir | > ABC DEF A | ---> BDD SD N I wanted to touch a file with the same name as the directories inside each directory rootdir | > ABC DEF A |---> ABC DEF A-dummy | -

How to work with directories and files with spaces

2006-04-06 Thread s99999999s2003
hi I am working in unix and i have some directories names with spaces eg ABC DEF A how can i work effectively with spaces in directory/file names in python? sometimes when i do os.path.join(dir_with_spaces,"-somestring" ) , it gives me "-somestring" as the name only...without ABC DEF A it should

cgi error

2006-03-31 Thread s99999999s2003
hi I have a little function to use ftputil module to get a file from a server def getfile(filename): import ftputil host = ftputil.FTPHost(svr, usr,pswd) host.chdir("/somewhere") try: host.download(filename,filename,"a") except ftputil.FTPErr

Re: sending ctrl C to a process

2006-03-28 Thread s99999999s2003
hi thanks for the reply.Actually, i should clarify what i am doing. the program's output will be displayed to a web browser using cgi, so there is no keyboard interrupt. The backend cgi script (python script) will have to send Ctrl-C to break the program. thanks -- http://mail.python.org/mailman

sending ctrl C to a program

2006-03-28 Thread s99999999s2003
hi i have a program that works very similar to tail -f in Unix It will need a Ctrl-C in order to break out of the program. I wish to run this program using python (either thru os.system() or some other subprocess modules) and how can i pass Ctrl-C to this program to terminate it in python? thanks

sending ctrl C to a process

2006-03-28 Thread s99999999s2003
hi i have a program that works very similar to tail -f in Unix It will need a Ctrl-C in order to break out of the program. I wish to run this program using python (either thru os.system() or some other subprocess modules) and how can i pass Ctrl-C to this program to terminate it in python? thanks

how to capture os.execvp into variable

2006-03-27 Thread s99999999s2003
hi i am using this code to run a ps command in unix def run(program, *args): pid = os.fork() if not pid: os.execvp(program, (program,) + args) return os.wait()[0] run("ps", "-eo pid,ppid,args") It runs fine, but i wish to store the results into a variablehow can i do thi

removing file by inode

2006-03-22 Thread s99999999s2003
hi this is pertain to unix environment. is it possible to remove a file by it's inode and not it's filename using Python? Just curious... thanks. -- http://mail.python.org/mailman/listinfo/python-list

remove a directory with special chars

2006-03-17 Thread s99999999s2003
hi i have a filen with a funny name like \177\177. I guess someone hit backspace or something before saving it. It's hidden and it shows when i type ls with the -b switch on unix. How can i remove this file using python? -- http://mail.python.org/mailman/listinfo/python-list

remove a directory with special chars

2006-03-17 Thread s99999999s2003
hi i have a filen with a funny name like \177\177. I guess someone hit backspace or something before saving it. It's hidden and it shows when i type ls with the -b switch on unix. How can i remove this file using python? thanks -- http://mail.python.org/mailman/listinfo/python-list

Re: comparing huge files

2006-03-16 Thread s99999999s2003
thanks for the reply, I have used another method to solve my problem. ie 1) get the total count of the first file 2) write this total count to basecnt eg basecnt 3) get another file, get the total count of this file. eg filecnt 4) if filecnt > basecnt, read in the values from file[basecnt:filecnt]

comparing huge files

2006-03-15 Thread s99999999s2003
hi i wrote some code to compare 2 files. One is the base file, the other file i got from somewhere. I need to compare this file against the base, eg base file abc def ghi eg another file abc def ghi jkl after compare , the base file will be overwritten with "jkl". Also both files tend to grow tow

spliting on ":"

2006-03-04 Thread s99999999s2003
hi i have a file with xxx.xxx.xxx.xxx:yyy xxx.xxx.xxx.xxx:yyy xxx.xxx.xxx.xxx:yyy xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx:yyy i wanna split on ":" and get all the "yyy" and print the whole line out so i did print line.split(":")[-1] but line 4 and 5 are not printed as there is no ":" t

getting the line just before or after a pattern searched

2006-02-16 Thread s99999999s2003
hi i have a file something like this abcdefgh ijklmnopq 12345678 rstuvwxyz . . . 12345678 . whenever i search the file and reach 12345678, how do i get the line just above and below ( or more than 1 line above/below) the pattern 12345678 and save to variables? thanks -- http://

Re: Question regarding mkdir of ftputil

2006-02-13 Thread s99999999s2003
Problem solved. Used try and except method -- http://mail.python.org/mailman/listinfo/python-list

Question regarding mkdir of ftputil

2006-02-13 Thread s99999999s2003
hi i am currently using the FTP wrapper from http://cheeseshop.python.org/pypi/ftputil/2.0.3 The documentation states "In the current implementation, this doesn't construct "intermediate" directories which don't already exist". i would like to make directories at the remote server whenever the path

efficient 'tail' implementation

2005-12-07 Thread s99999999s2003
hi I have a file which is very large eg over 200Mb , and i am going to use python to code a "tail" command to get the last few lines of the file. What is a good algorithm for this type of task in python for very big files? Initially, i thought of reading everything into an array from the file and

Re: generate HTML

2005-11-15 Thread s99999999s2003
thanks i will check out the example you have given.actually my html output is a bit dynamic in the sense that i may have different number of rows depending on some inputs. so i am putting everything into a list and using 'extend' to append to that list for every dynamically generated rows using for

Re: generate HTML

2005-11-15 Thread s99999999s2003
hi thanks for all the help actually i am doing it the hard way alist = [ 'TEST', '', 'blah' ] f = open('test.html",'w') f.writelines(alist) f.close() but everytime i hit ... alist = [ ' ValueError: unsupported format character '"' (0x22) at index 14 what does it mean? i tried alist = [ 'TE

generate HTML

2005-11-14 Thread s99999999s2003
hi i have fucntion that generates a HTML page def genpage(arg1,arg2): print ''' BLAH BLAH.%s %s ''' % (arg1, arg2) print ''' blah blah... %s %s ''' % (arg1,arg2)' The func is something like that, alot of open''' and closing ''' triple quotes. anyway, i wish to

modify dictionary while iterating

2005-11-10 Thread s99999999s2003
hi I wish to pop/del some items out of dictionary while iterating over it. a = { 'a':1, 'b':2 } for k, v in a.iteritems(): if v==2: del a[k] the output say RuntimeError: dictionary changed size during iteration how can i suppress this message in an actual script and still get the final

Re: getting results into one variable

2005-11-10 Thread s99999999s2003
Steve Holden wrote: > [EMAIL PROTECTED] wrote: > > That's a nice email address :-) > > hi > > the database "execute" function returns a list of logical results. Each > > logical result is a list of row tuples, as explained in the documents. > > > In a DB-API-compliant module, execution of the quer

getting results into one variable

2005-11-10 Thread s99999999s2003
hi the database "execute" function returns a list of logical results. Each logical result is a list of row tuples, as explained in the documents. everytime i use it to execute various statements, it returns me, for example ([(0,)], [(0,)], [(0,)]) and sometimes , ([(0,)], [(0,)]) or ([(0,)]) in m

Re: problem generating rows in table

2005-11-07 Thread s99999999s2003
thanks for all the help. problem solved by taking out range(). -- http://mail.python.org/mailman/listinfo/python-list

problem generating rows in table

2005-11-07 Thread s99999999s2003
hi i wish to generate a table using cgi toprint = [('nickname', 'justme', 'someplace')] print ''' User Name Address ''' for i in range(0,len(toprint)-1): for j in range(0,len(toprint[0])-1): print

Re: re sub help

2005-11-05 Thread s99999999s2003
thanks for the reply. i am still interested about using re, i find it useful. am still learning it's uses. so i did something like this for a start, trying to get everything in between [startdelim] and [enddelim] a = "this\nis\na\nsentence[startdelim]this\nis\nanother[enddelim]this\nis\n" t = re

re sub help

2005-11-04 Thread s99999999s2003
hi i have a string : a = "this\nis\na\nsentence[startdelim]this\nis\nanother[enddelim]this\nis\n" inside the string, there are "\n". I don't want to substitute the '\n' in between the [startdelim] and [enddelim] to ''. I only want to get rid of the '\n' everywhere else. i have read the tutorial

reading a config file

2005-11-03 Thread s99999999s2003
hi i used ConfigParser to read a config file. I need the config file to have identical sections. ie : [server] blah = "some server" [destination] blah = "some destination" [end] end= '' [server] blah = "some other server" [destination] blah = "some other destination" [end] end='' and i need to c

dictionary that have functions with arguments

2005-11-02 Thread s99999999s2003
hi i have a dictionary defined as execfunc = { 'key1' : func1 } to call func1, i simply have to write execfunc[key1] . but if i have several arguments to func1 , like execfunc = { 'key1' : func1(**args) } how can i execute func1 with variable args? using eval or exec? thanks -- http://mail.