Re: urgent
Yes, I can. Why do you want python? option: ? What task do you want to solve with python? option: ? Why python? option: ? Why not any other language? option: ? On Tue, Aug 31, 2021 at 3:08 AM Igor Korot wrote: > Hi, > > On Mon, Aug 30, 2021 at 4:34 PM Hari > wrote: > > > > i was download ur python software but it is like boring user interface > for > > me like young student to learn ,can u have any updates? > > Can you elaborate a little: > Why do you want python? > What task do you want to solve with python? > Why python? Why not any other language? > > Thank you. > > > -- > > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
urgent
i was download ur python software but it is like boring user interface for me like young student to learn ,can u have any updates? -- https://mail.python.org/mailman/listinfo/python-list
pywinauto to show the dialog , menu, etc
Hi I am using pywinauto to automate an custom program to startup and load process , execute etc. But cannot determine menuselect. Is there a way or tool which can run against the exe to show the menu, dialog box, list box which are contained within it. Is there a way to get this information using PywinAuto? any ideas? thanks in advance Hari -- http://mail.python.org/mailman/listinfo/python-list
Python libexpat and EXPAT are same/Different?
Hi all, Am very new to XML, I have a query, Does Python libexpat and EXPAT are same or they are diffrent? Thanks in advance. Regards, Hari -- http://mail.python.org/mailman/listinfo/python-list
Word document accessing using python
Hello, I want to fetch some data from the work document and to fill it inside excel sheet. For this I want to perform opening word documents and do some string manipulations for extracting data and to fill it inside excel sheet. Can any one help in this by saying how to do this or by giving some link where I can find some hints. Thanks in advance, Hari -- http://mail.python.org/mailman/listinfo/python-list
sending commands to parallel printer through python
Hi all, I need to automate printer command testing, prinetr supports parallel/ serial/USB.How can i send the commands from python to printer. I have got pyparallel, as am new to python, no idea how to work on it. Please give some tips,The comamnd to be sent to the printer is hex data "1B 40".please give a example,it will be grateful. Thank you. postedthe same in it.comp.lang.python Regards -Hari -- http://mail.python.org/mailman/listinfo/python-list
socket programming related.
I have just started working in network programming using python. written code for socket connection between client and server. Client sent data to server for server processing (also server echoing back rcvd data to client). When there is ("if no data": break ) no data from client then the while loops break in server. The server program process recvd data and my requirement is to send back the *results* to client program for user sake. I did many trials but no use, as these socket calls are blocking, i could not make my req. -- http://mail.python.org/mailman/listinfo/python-list
Re: socket programming related.
On Jul 11, 7:32 pm, [EMAIL PROTECTED] wrote: > I have just started working in network programming using python. > written code for socket connection between client and server. Client > sent data to server for server processing (also server echoing back > rcvd data to client). When there is ("if no data": break ) no data > from client then the while loops break in server. The server program > process recvd data and my requirement is to send back the *results* to > client program for user sake. I did many trials but no use, as these > socket calls are blocking, i could not make my req. I just need to add a line. The while loop in server breaks when the sockObj.close() happens in client program indicating there is no data from client. -- http://mail.python.org/mailman/listinfo/python-list
pattern match !
Extract the application name with version from an RPM string like hpsmh-1.1.1.2-0-RHEL3-Linux.RPM, i require to extract hpsmh-1.1.1.2-0 from above string. Sometimes the RPM string may be hpsmh-1.1.1.2-RHEL3- Linux.RPM. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python-list Digest, Vol 45, Issue 410
Hi all, Have a question which is making me unrest: -Calling a method say aMethod() from another method where i mistakenly initialised a variable with name same as the called method like aMethod = 'string'. When i run this py script triggered "Unbound Local error". can any one explain me whats going here ? curios to learn from my mistake :) -- Warm Regards, Hari On 6/27/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: Send Python-list mailing list submissions to python-list@python.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.python.org/mailman/listinfo/python-list or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than "Re: Contents of Python-list digest..." Today's Topics: 1. Re: Collections of non-arbitrary objects ? (Bruno Desthuilliers) 2. Re: Return name of caller function? (Matthew Peter) 3. Re: ANN: PyDAO - Python Hibernate-like Object-Relational Mapper (Luis M. Gonz?lez) 4. Re: Zip File Woes (Dave Kuhlman) 5. Re: Too many 'self' in python.That's a big flaw in this language. (Bruno Desthuilliers) 6. listing the type of an object (Stef Mientki) 7. Re: equality & comparison by default (was Re: Too many 'self' inpython.That's a big flaw in this language.) (Aahz) 8. Re: listing the type of an object (Thomas Jollans) 9. Re: Too many 'self' in python.That's a big flaw in this language. (John Nagle) 10. log caller (Matthew Peter) -- Forwarded message -- From: Bruno Desthuilliers <[EMAIL PROTECTED]> To: python-list@python.org Date: Thu, 28 Jun 2007 06:36:25 +0200 Subject: Re: Collections of non-arbitrary objects ? walterbyrd a écrit : > On Jun 26, 8:23 am, Bruno Desthuilliers [EMAIL PROTECTED]> wrote: > >>walterbyrda écrit : >> >> >>>>You do program carefully, don't you ?-) >> >>>I try. But things like typos are a normal part a life. >> >>So are they in any language. I fail to see much difference here. >> > > > For example: if I mis-type a variable name in C, the program will > probably not even compile. It sometimes happens - but chances are low, for sure. > Whereas, with Python, the program will > probably run, but may give unexpected results. > Yes, true. Well, in some cases. In one case, to be true: the use of the '=' operator. IIRC, any other use of an undefined symbol will raise an exception. But this has to do with how symbols are defined in Python (ie: the fact that binding => definition), and has nothing to do with static (compile-time) type checking. > >>>Guido >>>must think python has a lot of room for improvement since he's >>>completely throwing out backward compatibility with python 3000. >> >>Not "completely throwing out". Just allowing *some* major breakages - >>the kind you usually get with each major release of other languages, but >>that Python managed to avoid as much as possible so far. > > > I don't know, but here is a direct quote from Guido's blog: "Python > 3.0 will break backwards compatibility. Totally." > > http://www.artima.com/weblogs/viewpost.jsp?thread=208549 Please take it with a grain of the salt. This is mostly about getting rid of long-time deprecated features. > >>>It seems to me that tuple are essentially immutable lists. >> >>They are not (even if you can use them that way too). FWIW and IIRC, >>this is a FAQ. > > A few posters here have stated that tuples are not just immutable but > when I compare lists, to tuples, I notice that both are ordered > collections of arbitrary objects, with the primary difference being > that list are mutable, and tuples are not. This is of course technically true. And you forgot to compare to sets, while we're at it. But the answer to your questions about tuples is not technical - it's about use case. > It seems to me that if a > list were immutable, it would be a tuple. That is the one big > difference. > > Tuples have been compared to records/structures in other languages. > But, in general, I can not use a for loop to loop through the fields > in a record, For which definition of "in general" ? I can do this with at least Python, PHP, Javascript, Ruby, and probably Java (IIRC). > and I can not sort those fields either. Did you try to sort a tuple ? >>> (1, "aaa").sort() Traceback (most recent call last): File "", line 1, in ? AttributeError: 'tuple' object has no att
Unbound Local error --???
Hi all, Have a question which is making me unrest: -Calling a method say aMethod() from another method where i mistakenly initialised a variable with name same as the called method like aMethod = 'string'. When i run this py script triggered "Unbound Local error". can any one explain me whats going here ? curios to learn from my mistake :) -- Warm Regards, Hari -- http://mail.python.org/mailman/listinfo/python-list
variable sub in a list- how to
D- How can I substitute a variable into a list ? ex: list() var = 'Prog' list.append($Prog) //error occur here -- Warm Regards, Hari -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I add users using Python scripts on a Linux machine
That is shell scripting with a python layer on top. Is there a specific reason you have to use python? Why not just use shell, that's what it's designed for? Unless you have some complex maths/networking requirement or something on top. -h On 01/01/07, Daniel Klein <[EMAIL PROTECTED]> wrote: > On 1 Jan 2007 11:33:42 -0800, "Ramdas" <[EMAIL PROTECTED]> wrote: > > >How do I add users using Python scripts on a Linux machine? > > > >Someone has a script? > > This should be as easy as something like: > > os.system("/usr/sbin/useradd -m -d /home/newuser -s /bin/ksh") > > Dan > -- > http://mail.python.org/mailman/listinfo/python-list > -- Hari Sekhon -- http://mail.python.org/mailman/listinfo/python-list
Re: excepthook doesn't give exact line number
Thanks for the pointer, I've now got this giving me the right line number when an exception occurs, although I still get an empty stack trace from print "Stack Trace:\n%s\n" % str(traceback.print_exc(2)) inside the excepthook. Any ideas why this is? Is there no traceback since the traceback was fed to the excepthook? Is there another way of getting the traceback like you see when the exception isn't caught? Thanks for the help. -h Hari Sekhon Peter Otten wrote: Hari Sekhon wrote: The problem is that the excepthook gives the line of the topmost called function rather that the actual line that generated the error the way you get it with a normal traceback. A look into the traceback module shows that tracebacks are stored as a linked list. Here's a way to get hold of its tail: def tbiter(tb): while tb is not None: yield tb tb = tb.tb_next def last(items): for item in items: pass return item # example usage def myexcepthook(type, value, tb): tb_tail = last(tbiter(tb)) print tb_tail.tb_lineno Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: excepthook doesn't give exact line number
I've tried the sample code you provided but it seems to just hang, it must be doing something but unfortunately it must take too long, by which time a second control-c gives an awful dual traceback message showing the original traceback and the new one from the tbiter() func. I've tried a few variations since yesterday but unfortunately those 2 funcs take too long to run to make a viable solution and the script ends up hanging on an uncaught exception. If anybody has any improvements, suggestions or alternatives for getting the proper line number and traceback message inside an excepthook then I'd be grateful to hear them. -h Hari Sekhon Peter Otten wrote: Hari Sekhon wrote: The problem is that the excepthook gives the line of the topmost called function rather that the actual line that generated the error the way you get it with a normal traceback. A look into the traceback module shows that tracebacks are stored as a linked list. Here's a way to get hold of its tail: def tbiter(tb): while tb is not None: yield tb tb = tb.tb_next def last(items): for item in items: pass return item # example usage def myexcepthook(type, value, tb): tb_tail = last(tbiter(tb)) print tb_tail.tb_lineno Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Why do this?
Do whichever makes you happy I'd say The only real difference is coding style and the formatting options of the %s way that I can see. %s is negligibly slower in my tests, but we're talking the tiniest fraction of a second over thousands of iterations, not worth considering... -h Hari Sekhon Matthew Warren wrote: > Ok, not really python focused, but it feels like the people here could > explain it for me :) > > Now, I started programming when I was 8 with BBC Basic. > > I never took any formal classes however, and I have never become an > expert programmer. I'm an average/hobbyist programmer with quite a few > languages under my belt but I cant do any really fancy tricks with any > of them. (although Python might be nudging me into more advanced things, > now I'm starting to get what all the __method__ thingies and operators > are all about) > > I learned over the years to do things like the following, and I like > doing it like this because of readability, something Python seems to > focus on :- > > Print "There are "+number+" ways to skin a "+furryanimal > > But nowadays, I see things like this all over the place; > > print("There are %s ways to skin a %s" % (number, furryanimal)) > > Now I understand there can be additional formatting benefits when > dealing with numbers, decimal places etc.. But to me, for strings, the > second case is much harder to read than the first. > > I hope I'm not being dense. > > The result is that I have pathalogically avoided print "%s" % (thing) > because it seems to just over complicate things. > > > Ta, :) > > Matt. > > > > > > This email is confidential and may be privileged. If you are not the intended > recipient please notify the sender immediately and delete the email from your > computer. > > You should not copy the email, use it for any purpose or disclose its > contents to any other person. > Please note that any views or opinions presented in this email may be > personal to the author and do not necessarily represent the views or opinions > of Digica. > It is the responsibility of the recipient to check this email for the > presence of viruses. Digica accepts no liability for any damage caused by any > virus transmitted by this email. > > UK: Phoenix House, Colliers Way, Nottingham, NG8 6AT UK > Reception Tel: + 44 (0) 115 977 1177 > Support Centre: 0845 607 7070 > Fax: + 44 (0) 115 977 7000 > http://www.digica.com > > SOUTH AFRICA: Building 3, Parc du Cap, Mispel Road, Bellville, 7535, South > Africa > Tel: + 27 (0) 21 957 4900 > Fax: + 27 (0) 21 948 3135 > http://www.digica.com > -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to handle large lists?
So are you saying that using a dict means a faster search since you only need to look up one value? I would think that you would have to look through the keys and stop at the first key that matches since each key has to be uniq, so perhaps if it is nearer the front of the set of keys then perhaps it would be a quicker lookup? On the other hand, if it is nearer the end of the set of keys would it not be slower? Does this make it more dependent on the search order whether a list or a dict is faster? Or am I completely on the wrong track? -h Hari Sekhon Fredrik Lundh wrote: Hari Sekhon wrote: That is surprising since I read on this list recently that lists were faster than dicts depends on what you're doing with them, of course. It was one reason that was cited as to why local vars are better than > global vars. L[int] is indeed a bit faster than D[string] (but not much), but that doesn't mean that you can loop over *all* items in a list faster than you can look up a single key in a dictionary. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to handle large lists?
Jeremy Sanders wrote: Chaz Ginger wrote: What would sets do for me over lists? It's faster to tell whether something is in a set or dict than in a list (for some minimum size). Jeremy That is surprising since I read on this list recently that lists were faster than dicts and that variables stored in lists were faster referenced/used. It was one reason that was cited as to why local vars are better than global vars. The guy actually did a looping test and timed it to show the speed difference. Can anybody please step in and correct us? -h Hari Sekhon -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to handle large lists?
I don't know much about the python internals either, so this may be the blind leading the blind, but aren't dicts much slower to work with than lists and therefore wouldn't your suggestion to use dicts be much slower? I think it's something to do with the comparative overhead of using keys in dicts rather than using positional indexes in lists/arrays... At least that is what I thought. Can anyone confirm this? -h Hari Sekhon Bill Williams wrote: > I don't know enough about Python internals, but the suggested solutions > all seem to involve scanning bigList. Can this presumably linear > operation be avoided by using dict or similar to find all occurrences of > smallist items in biglist and then deleting those occurrences? > > Bill Williams > > > > In article <[EMAIL PROTECTED]>, > Chaz Ginger <[EMAIL PROTECTED]> wrote: > > >> I have a system that has a few lists that are very large (thousands or >> tens of thousands of entries) and some that are rather small. Many times >> I have to produce the difference between a large list and a small one, >> without destroying the integrity of either list. I was wondering if >> anyone has any recommendations on how to do this and keep performance >> high? Is there a better way than >> >> [ i for i in bigList if i not in smallList ] >> >> Thanks. >> Chaz >> -- http://mail.python.org/mailman/listinfo/python-list
excepthook doesn't give exact line number
Hi, I'm wondering if anyone can please help me on figuring out a better way of doing an excepthook. I have a script which is using an excepthook to catch any uncaught exceptions - there usually aren't any except when I am messing with the code, like right now :-) The problem is that the excepthook gives the line of the topmost called function rather that the actual line that generated the error the way you get it with a normal traceback. import sys, traceback def myexcepthook(type,value,tb): exception_message = ( "\nLine no %s: %s - %s\n" "\nStack Trace:\n\n%s\n" % (tb.tb_lineno,type,value,str(traceback.print_exc(2))) ) sys.excepthook = myexcepthook So the tb object that is passed into the function gives the tb.tb_lineno as a line right near the end where the original topmost called function happens. This is a bit useless to me since I don't want to go looking for the exception manually through the entire code. As you can see from my example, I have already used the traceback module which I usually use to give the normal traceback printout via traceback.print_exc(). Here it doesn't seem to work, it always give "None", likely because the excepthook has taken it or something. Any guiding wisdom from the masters out there? Much appreciated, thanks for reading. -h -- Hari Sekhon -- http://mail.python.org/mailman/listinfo/python-list
Re: commands.getstatusoutput result is not command line exit value!!!
yes already noted by Steve, thanks. I should have spotted that myself straight away but I was too wrapped up in this whole "I didn't realise there were 2 sets of numbers" thing, gotta go read some unix programming books it would seem this is a os function that I am not aware of. I still reserve the right to be annoyed at commands for not hiding this from me like everything else, but then is right (as always it would seem) I should not be using such a deprecated thing like commands, I will switch to subprocess... I'm even more surprised since I do so much shell scripting and I've never even heard of this thing before, I guess only the really battle-scarred old skool ones may know of it. -h Hari Sekhon Scott David Daniels wrote: Steve Holden wrote: Hari Sekhon wrote: I'm running a command like import commands result = commands.getstatusoutput('somecommand') print result[0] 3072 ... No, it's just returning the error code in the top half of a sixteen-bit value. You will notice that 3072 == 2 * 256. For the rest of us playing along at home, there is a typo there: The preceding line should read: > value. You will notice that 3072 == 12 * 256. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Making sure script only runs once instance at a time.
The name thing is taken care of by the fact that I use the path not just the script name. The path appears in the command and then is grepped out by that criteria, so if there was another program with the same name and in a different path then it would not affect it. Of course this is defeatable now I think about it if both programs are called the same thing and both are run as ./program_name. I could use the args to test too but this is also defeatable if being pedantic, and I don't want to compound any errors, I'm sure I do that enough without trying... So I guess we come back to using the pids in the lockfiles as you suggested and test against those. I was thinking that I could just adjust it to find the pid of the program by location of the program on the filesystem and if there is a pid for the program then there is a running instance of this exact program in that directory. This would bypass the lockfile thing again but I've just tested this and it doesn't work, the pid will be found for python but not for the python program so it breaks this - dang, that was a very nice thing to do with binaries, I guess it just won't work with python in the same way (or any other interpreted language I expect). I like your method too, it's very pythonic. I'm still weening off bash a bit as you can tell... I guess there is no escaping the lockfile at this stage unless I can think of something else... I may rewrite safety to use your lockfile with pid embedded. I've actually used a very similar method in bash before for something, saving the pid and env vars and then using the binary kill -0 to test if a program is alive by finding out whether a signal could be sent to it. Works nicely there too. -h Hari Sekhon Fredrik Lundh wrote: Hari Sekhon wrote: How exactly do you check that the pid is still active in python? Is there a library or something that will allow me to manipulate system processes and listings etc the way everybody does in unix shells by passing zero to the os.kill primitive: os.kill(pid, 0) if this raises an OSError, there's no active process with the given pid. I'm a huge fan of shell so I've done my own thing which leans on shell as follows: import sys,commands,os scriptpath = sys.argv[0] scriptname = os.path.basename(scriptpath) number_procs=commands.getstatusoutput('ps -ef|grep %s|grep -v grep|wc -l' % scriptpath) if number_procs > 1: print "There appears to be another %s process running." % scriptname what if you have commands with overlapping names (e.g. "bar.py" and "foobar.py"), or some other user on the machine happens to run a command that, on purpose or by accident, contains your script's name (e.g. "emacs mybar.py") ? -- http://mail.python.org/mailman/listinfo/python-list
Re: commands.getstatusoutput result is not command line exit value!!!
ok, I was thinking of shifting using subprocess, guess I'd better do that and forget about this waste of time. thanks Hari Sekhon Fredrik Lundh wrote: Hari Sekhon wrote: I'm sorry, this may seem dense to you but I have to ask. What on earth are you talking about? > Why is it shifted 8 bits to the left? Why is there bitshifting at all? Why doesn't commands give the same exit value as os.system() and the unix cli? because that's how Unix's wait() operation returns the status code (as mentioned in the "commands" section of the library reference). you can use the os.WIFEXITED(status) and os.WEXITSTATUS(code) helpers to convert between wait return codes and signal numbers/exit codes. see: http://docs.python.org/lib/os-process.html or you can forget about the obsolete "commands" module, and use the new subprocess module instead; e.g. def getstatusoutput(command): from subprocess import Popen, PIPE, STDOUT p = Popen(command, stdout=PIPE, stderr=STDOUT, shell=True) s = p.stdout.read() return p.wait(), s print getstatusoutput("ls -l /bin/ls") (0, '-rwxr-xr-x1 root root68660 Aug 12 2003 /bin/ls\n') the subprocess module is highly flexible; see the library reference for details. -- http://mail.python.org/mailman/listinfo/python-list
Re: commands.getstatusoutput result is not command line exit value!!!
I'm sorry, this may seem dense to you but I have to ask. What on earth are you talking about? Why is it shifted 8 bits to the left? Why is there bitshifting at all? Why doesn't commands give the same exit value as os.system() and the unix cli? When you choose to exit a program you give it a return value to exit with, so why would this change, I exit with the number 1 then expect that number to be the exit code, right? Where do these higher numbers come into the equation and why? Please assume that I am not a mind reader and require explanation before I can understand. Perhaps you aren't a mind reader either and don't know why the writers of the commands lib chose to do this insanity either? It seems the os.system() guys did the right thing, I wonder why commands.getstatusoutput doesn't... Having just tested it manually with a shell script returning 2, commands.getstatusoutput did give the exit code as 512, so it does seem to generically shift the exit code 8 bits to the left or multiply it by 256 for those of us who need some more straight talking... ugg, perhaps it's time to stop using this thing and use a better lib module. any explanations welcome... -h Hari Sekhon Steve Holden wrote: > A famous Holden typo - it should have been "12 * 256 == 3072", but > really it shouldn't have been beyond you to perform a division of 3072 > by 12 (given that you already knew the number 12 was potentially > involved). > > Basically the value you want is shifted up 8 bits. Perhaps I should > more understandably have said: > > 12 << 8 == 3072 > > regards > Steve > > Hari Sekhon wrote: >> I don't quite understand what you are saying here: >> >> 2 * 256 is 512, >> 2 ** 256 is some extremely large number. >> >> 2**12 is 4096. >> >> So how does 3072 factor into this? >> >> Could you explain what you mean by "the error in the top half of a >> sixteen-bit value"? >> >> This makes no sense to me at this moment. >> >> -h >> >> Hari Sekhon >> >> >> >> Steve Holden wrote: >> >>> Hari Sekhon wrote: >>> >>> >>>> I'm running a command like >>>> >>>> import commands >>>> result = commands.getstatusoutput('somecommand') >>>> print result[0] >>>> 3072 >>>> >>>> >>>> However, this exit code made no sense so I ran it manually from the >>>> command line in bash on my linux server and it gives the exit code >>>> as 12, not this weird 3072 number. >>>> >>>> So I tried os.system('somecommand') in the interactive python shell >>>> and it too returned the same result for the exit code as the unix >>>> shell, 12, but re-running the commands.getstatusoutput() with the >>>> exact same command still gave 3072. >>>> >>>> >>>> Is commands.getstatusoutput() broken or something? >>>> >>>> >>>> -h >>>> >>>> >>> No, it's just returning the error code in the top half of a >>> sixteen-bit value. You will notice that 3072 == 2 * 256. >>> >>> That's always been the way the Unix return code has been returned >>> programattically, but the shell shifts it down to make it more usab;e. >>> >>> regards >>> Steve >>> >>> > > -- http://mail.python.org/mailman/listinfo/python-list
Re: commands.getstatusoutput result is not command line exit value!!!
I don't quite understand what you are saying here: 2 * 256 is 512, 2 ** 256 is some extremely large number. 2**12 is 4096. So how does 3072 factor into this? Could you explain what you mean by "the error in the top half of a sixteen-bit value"? This makes no sense to me at this moment. -h Hari Sekhon Steve Holden wrote: Hari Sekhon wrote: I'm running a command like import commands result = commands.getstatusoutput('somecommand') print result[0] 3072 However, this exit code made no sense so I ran it manually from the command line in bash on my linux server and it gives the exit code as 12, not this weird 3072 number. So I tried os.system('somecommand') in the interactive python shell and it too returned the same result for the exit code as the unix shell, 12, but re-running the commands.getstatusoutput() with the exact same command still gave 3072. Is commands.getstatusoutput() broken or something? -h No, it's just returning the error code in the top half of a sixteen-bit value. You will notice that 3072 == 2 * 256. That's always been the way the Unix return code has been returned programattically, but the shell shifts it down to make it more usab;e. regards Steve -- http://mail.python.org/mailman/listinfo/python-list
commands.getstatusoutput result is not command line exit value!!!
I'm running a command like import commands result = commands.getstatusoutput('somecommand') print result[0] 3072 However, this exit code made no sense so I ran it manually from the command line in bash on my linux server and it gives the exit code as 12, not this weird 3072 number. So I tried os.system('somecommand') in the interactive python shell and it too returned the same result for the exit code as the unix shell, 12, but re-running the commands.getstatusoutput() with the exact same command still gave 3072. Is commands.getstatusoutput() broken or something? -h -- Hari Sekhon -- http://mail.python.org/mailman/listinfo/python-list
Re: Making sure script only runs once instance at a time.
AMENDMENT: The line number_procs=commands.getstatusoutput('ps -ef|grep %s|grep -v grep|wc -l' % scriptpath) was supposed to be number_procs=int(commands.getstatusoutput('ps -ef|grep %s|grep -v grep|wc -l' % scriptpath)[1]) -h Hari Sekhon Hari Sekhon wrote: Fredrik Lundh wrote: Hari Sekhon wrote: I'm not sure if that is a very old way of doing it, which is why I was reluctant to do it. My way actually uses the process list of the os (linux) and counts the number of instances. If it is more than 0 then another process is running and the script exits gracefully. the code that reliably identifies instances of a given program would be interesting to see. Also, apart from the fact the using lockfiles feels a bit 1970s, I have > found that in real usage of other programs within the company that use > lockfiles, it sometimes causes a bit of troubleshooting time when > it stops working due to a stale lockfile. to minimize that risk, store the pid in the lockfile (and preferrably also the host name), and make sure that the program checks that the pid is still active before it "stops working". How exactly do you check that the pid is still active in python? Is there a library or something that will allow me to manipulate system processes and listings etc the way everybody does in unix shells I'm a huge fan of shell so I've done my own thing which leans on shell as follows: import sys,commands,os scriptpath = sys.argv[0] scriptname = os.path.basename(scriptpath) number_procs=commands.getstatusoutput('ps -ef|grep %s|grep -v grep|wc -l' % scriptpath) if number_procs > 1: print "There appears to be another %s process running." % scriptname print "Please do not run more than one instance of this program" print "Quitting for safety..." sys.exit(200) This works nicely for me. You might also want to add a bit of discrimination to the script (something along the lines of "get a decent os"...since this won't work on windows) import platform if platform.system() != 'Linux': print "Sorry but this program can only be run on Linux" sys.exit(201) #todo: should do a bit extra for our bsd cousins here Let me know if you think you have a better way. Please provide a code snippet if so. -h -- http://mail.python.org/mailman/listinfo/python-list
Re: Making sure script only runs once instance at a time.
Fredrik Lundh wrote: Hari Sekhon wrote: I'm not sure if that is a very old way of doing it, which is why I was reluctant to do it. My way actually uses the process list of the os (linux) and counts the number of instances. If it is more than 0 then another process is running and the script exits gracefully. the code that reliably identifies instances of a given program would be interesting to see. Also, apart from the fact the using lockfiles feels a bit 1970s, I have > found that in real usage of other programs within the company that use > lockfiles, it sometimes causes a bit of troubleshooting time when > it stops working due to a stale lockfile. to minimize that risk, store the pid in the lockfile (and preferrably also the host name), and make sure that the program checks that the pid is still active before it "stops working". How exactly do you check that the pid is still active in python? Is there a library or something that will allow me to manipulate system processes and listings etc the way everybody does in unix shells I'm a huge fan of shell so I've done my own thing which leans on shell as follows: import sys,commands,os scriptpath = sys.argv[0] scriptname = os.path.basename(scriptpath) number_procs=commands.getstatusoutput('ps -ef|grep %s|grep -v grep|wc -l' % scriptpath) if number_procs > 1: print "There appears to be another %s process running." % scriptname print "Please do not run more than one instance of this program" print "Quitting for safety..." sys.exit(200) This works nicely for me. You might also want to add a bit of discrimination to the script (something along the lines of "get a decent os"...since this won't work on windows) import platform if platform.system() != 'Linux': print "Sorry but this program can only be run on Linux" sys.exit(201) #todo: should do a bit extra for our bsd cousins here Let me know if you think you have a better way. Please provide a code snippet if so. -h -- http://mail.python.org/mailman/listinfo/python-list
Re: Making sure script only runs once instance at a time.
I'm not sure if that is a very old way of doing it, which is why I was reluctant to do it. My way actually uses the process list of the os (linux) and counts the number of instances. If it is more than 0 then another process is running and the script exits gracefully. Also, apart from the fact the using lockfiles feels a bit 1970s, I have found that in real usage of other programs within the company that use lockfiles, it sometimes causes a bit of troubleshooting time when it stops working due to a stale lockfile. This especially happens when the program is killed, the lockfile remains and causes minor annoyance (to somebody who knows that is, more annoyance to somebody who doesn't). -h Hari Sekhon Paul Rubin wrote: Hari Sekhon <[EMAIL PROTECTED]> writes: Seeing as there doesn't seem to be a good answer to this (or at least not one that we have so far some up with) I have decided to fall back to my old friend the unix shell. It's as portable as python, but is very flexible and fast at doing real things and will tell me if another process by this name is running. If so, print msg and exit. simple. Huh? The obvious way to check for another instance is with a lock file. Just open the file and use fcntl to set an exclusive lock. If the lock acquisition fails, another instance has the file. -- http://mail.python.org/mailman/listinfo/python-list
Re: Making sure script only runs once instance at a time.
Seeing as there doesn't seem to be a good answer to this (or at least not one that we have so far some up with) I have decided to fall back to my old friend the unix shell. It's as portable as python, but is very flexible and fast at doing real things and will tell me if another process by this name is running. If so, print msg and exit. simple. -h Hari Sekhon MaR wrote: > A very brutal but simple and effective method is to bind() to a socket > on localhost eg (127.0.0.1, 4711), listen() but never accept(). > Any other process trying to to bind() on the same port will fail.. > When the process dies, the port is released automatically, pending som > timedelay.. > > But this assumes you have an execution environment where this is > acceptable. A sysadmin may have objections ;o) > > -- http://mail.python.org/mailman/listinfo/python-list
Making sure script only runs once instance at a time.
I have written a script and I would like to ensure that the script is never run more than once at any given time. What is the best way of testing and exiting if there is another version of this script running somewhere on this machine? I guess what I'm asking is how to handle system processes the way I can in shell. I am running this on linux. Thanks -h -- Hari Sekhon -- http://mail.python.org/mailman/listinfo/python-list
Re: best way of testing a program exists before using it?
Tim Williams wrote: > Alternatively there is os.path.exists which works for files or > directories, but calling it every time you use the wrapper is probably > more expensive than using the try statement when the program *does* > exist. > > import os.path > if not os.path.exists('/dir1/dir2/filename'): >print_something_and_exit(filename) > > :) > problem with that is that the path may change between installations on different machine and I can't guarantee /dir1/dir2 which is why a test of all dirs in the path is more portable. -- Hari Sekhon -- http://mail.python.org/mailman/listinfo/python-list
Re: best way of testing a program exists before using it?
Tim Williams wrote: > On 11/09/06, Hari Sekhon <[EMAIL PROTECTED]> wrote: >> >> Steve Holden wrote: >> Hari Sekhon wrote: >> >> >> The easiest way to test whether the command will run is to try and run >> it. If the program doesn't exist then you'll get an exception, which you >> can catch. Otherwise you'll be stuck with non-portable mechanisms for >> each platform anyway ... >> >> regards >> Steve >> >> >> Yeah, this occurred to me just after I sent the mail, but I don't >> really >> want to run the program because it will go off and do some work and take >> time to come back. If there is a better way then that would be great. I >> can't think of anything other than what you have suggested with a >> message >> saying that the program wasn't found in the path which would be the most >> appropriate error since the path could also be wrong. > > > If you run your wrapper and the program exists then you don't have to > test for it, so the overall process is quicker and cleaner than > testing-for *then* running the program > > If you run your wrapper and the program doesn't exist, then you have > performed your "if exists" test without extra code and with very > little processing, and the raised exception will lead you nicely into > your "not exists" scenario. > > try: >run_somecommand > except: >print "you don't have %s installed" % somecommand > > > HTH :) > The down side to that is the program has to be run which consumes time and slows the script down a fair bit (as well as outputting garbage to the screen) -h -- Hari Sekhon -- http://mail.python.org/mailman/listinfo/python-list
Re: best way of testing a program exists before using it?
Steven Bethard wrote: Hari Sekhon wrote: I am writing a wrapper to a binary command to run it and then do something with the xml output from it. What is the best way of making sure that the command is installed on the system before I try to execute it, like the python equivalent of the unix command "which"? There is the which module: http://trentm.com/projects/which/ But I'd probably just try the command and catch the exception, e.g.: >>> import subprocess >>> try: ... subprocess.call(['foo']) ... except OSError: ... print "you don't have foo installed" ... you don't have foo installed >>> try: ... subprocess.call(['svm_learn']) ... except OSError: ... print "you don't have svm_learn installed" ... 1 STeVe looks good, although I agree with you on the try it and see simplicity. I think if the which.py was part of the standard lib then I would use it, but as it is I will stick to the original path search that you recommended (I'm not gonna both dealing with the pathext just yet) -- Hari Sekhon -- http://mail.python.org/mailman/listinfo/python-list
Re: best way of testing a program exists before using it?
Rob Wolfe wrote: Hari Sekhon wrote: I am writing a wrapper to a binary command to run it and then do something with the xml output from it. What is the best way of making sure that the command is installed on the system before I try to execute it, like the python equivalent of the unix command "which"? Otherwise I'd have to do something like: if os.system('which somecommand') != 0: print "you don't have %s installed" % somecommand sys.exit(1) I know that isn't portable which is why a python solution would be better (although this will run on unix anyway, but it'd be nice if it ran on windows too). IMHO this is pretty portable: def is_on_path(fname): ... for p in os.environ['PATH'].split(os.pathsep): ... if os.path.isfile(os.path.join(p, fname)): ... return True ... return False HTH, Rob That works well and is portable, fits nicely. I was actually curious if somebody already came across this and perhaps put a func like this in the standard modules... Thanks. -h -- Hari Sekhon -- http://mail.python.org/mailman/listinfo/python-list
Re: best way of testing a program exists before using it?
Steve Holden wrote: Hari Sekhon wrote: I am writing a wrapper to a binary command to run it and then do something with the xml output from it. What is the best way of making sure that the command is installed on the system before I try to execute it, like the python equivalent of the unix command "which"? Otherwise I'd have to do something like: if os.system('which somecommand') != 0: print "you don't have %s installed" % somecommand sys.exit(1) I know that isn't portable which is why a python solution would be better (although this will run on unix anyway, but it'd be nice if it ran on windows too). The easiest way to test whether the command will run is to try and run it. If the program doesn't exist then you'll get an exception, which you can catch. Otherwise you'll be stuck with non-portable mechanisms for each platform anyway ... regards Steve Yeah, this occurred to me just after I sent the mail, but I don't really want to run the program because it will go off and do some work and take time to come back. If there is a better way then that would be great. I can't think of anything other than what you have suggested with a message saying that the program wasn't found in the path which would be the most appropriate error since the path could also be wrong. Perhaps I'll just bite the bullet and get the program to do something as small as possible to test it. I guess I'll just have to continue to miss my unix commands... -h -- Hari Sekhon -- http://mail.python.org/mailman/listinfo/python-list
best way of testing a program exists before using it?
I am writing a wrapper to a binary command to run it and then do something with the xml output from it. What is the best way of making sure that the command is installed on the system before I try to execute it, like the python equivalent of the unix command "which"? Otherwise I'd have to do something like: if os.system('which somecommand') != 0: print "you don't have %s installed" % somecommand sys.exit(1) I know that isn't portable which is why a python solution would be better (although this will run on unix anyway, but it'd be nice if it ran on windows too). -h -- Hari Sekhon -- http://mail.python.org/mailman/listinfo/python-list
Re: sending emails using python
Grant Edwards wrote: On 2006-09-07, Tim Williams <[EMAIL PROTECTED]> wrote: Wouldn't you use a SMTP client to send email? I would, but I don't use exchange server. :) The one exchange server I used in the past didn't accept SMTP mail. errr, I used to admin Exchange, if it does accept SMTP then how could it function as a live mail server? Did you mean *doesn't accept* ?? One presumes he did. There are a couple of possibilities at least, of the top of my head: * The IMC / IMS (smtp connector) is located on a different server within its Exchange organisation, or a DMZ'ed exchange server that is only used for SMTP. * The server doesn't accept SMTP from local IP ranges, only from external (ie inbound email) I believe it was the latter. I'm pretty sure there was only one server. When I first started at that company it did accept SMTP connections on it's internal network interface. Outlook / Exchange clients use MAPI, internal SMTP is only a requirement if you have non-MAPI clients sending email through the server. And BOFH was horrified by non-MS software, so he shut off IMAP support and SMTP support on the internal network as a way to force everybody to switch to Outlook. I did mean *doesn't accept*, sorry was in a rush... BOFH? lol If he were a better op then perhaps he would be using unix based system himself and wouldn't be so discriminating... but then you can't hope for the world with windows only "techies"... although in fairness, Exchange and Outlook is a great combination... you could always try ximian's exchange connector for evolution, I managed to get some emails with that... but anyway, ot... Hari Sekhon -- http://mail.python.org/mailman/listinfo/python-list
Re: sending emails using python
Grant Edwards wrote: On 2006-09-07, Sybren Stuvel <[EMAIL PROTECTED]> wrote: Tim Williams enlightened us with: Can you send email via it using outlook express or a similar POP3/IMAP mail client? Wouldn't you use a SMTP client to send email? I would, but I don't use exchange server. :) The one exchange server I used in the past didn't accept SMTP mail. errr, I used to admin Exchange, if it does accept SMTP then how could it function as a live mail server? Hari Sekhon -- http://mail.python.org/mailman/listinfo/python-list
Re: are there any lib for receive hotmail ?
Tim Chase wrote: And receiving hotmail (or any outher webmail) using scraping techniques is a daunting task, to say the least - you should forget about that IMHO. There's a perl project called "gotmail" that will do the scraping to dump in a local mailbox file (I don't remember whether it's MH or mbox format). You can snag it at http://gotmail.sf.net Thus, there's evidence that Hotmail can be scraped, but it seems they have a never-ending battle against Hotmail, trying to keep up with changes. I don't know of any Python projects doing the same sort of thing. It might not be too hard to port the Perl project over to Python, but one would be an extra level removed from scraping Hotmail, playing catchup not only with Hotmail, but then porting the latest fixes from Gotmail. There are a couple other Hotmail-to-mbox scrapers I've heard of, but haven't tried. -tkc I know this isn't technically helping, but why use hotmail when gmail is so much better and gives you pop access? Even old yahoo gives you pop access to your mailbox Hari Sekhon -- http://mail.python.org/mailman/listinfo/python-list
Testing a website with HTTPS login and cookies
Hi everyone, I want to create a test that will do a proper login test to a web site but I need some pointers. I need to login to the website by accessing an https url and posting to that, which should return a very small 302 reply with the address of the internal page. I need to take that page href and then access it, if I can do all that then the test passes. Of course because I have to access two urls I also need cookies for session handling. I've already tried bash which would have worked but for the cookie handling and webinject which is written in Perl, but this doesn't do exactly what I want in terms of output so I'd rather write something myself. (I'm also curious as to the best way to do this) If anybody knows how to do this could they please give me a quick pointer and tell me what libraries I need to go read up on? Thanks Hari -- http://mail.python.org/mailman/listinfo/python-list
Re: os.path.normpath
[EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: I am using a windows box and passing a string like "../foo/../foo2" to normpath which then returns "..\\foo2". But if this string is going into a webpage link it should really be "../foo". Is there any way to tell os.path.normpath to act like we are an a unix style box? Use posixpath.normpath() instead. I can't seem to find posixpath in the docs, but I can import posixpath and a dir shows it does indeed have a normpath. -h -- http://mail.python.org/mailman/listinfo/python-list
Re: Open file handles?
danielx wrote: Is there an equivalent in windows? Jon wrote: Perhaps using os you could work with lsof [http://www.linuxcommand.org/man_pages/lsof8.html] Jon Thomas Bartkus wrote: This may be more of a Linux question, but I'm doing this from Python. . How can I know if anything (I don't care who or what!) is in the middle of using a particular file? This comes in context of needing to copy a file BUT only if I can verify that something else doesn't have an open write handle to that file. IOW - I need to decline the operation if something else hasn't finished writing to the file. How can I know? Thomas Bartkus yes, handle by sysinternals. www.sysinternals.com not really a python question, more along the lines of bash, which is why I could answer it -h -- http://mail.python.org/mailman/listinfo/python-list
xml.sax problem, help needed.
getValue('extrainfo') ) else: self.host['extrainfo'].append('') elif name == 'state': self.host['state'].append( attributes.getValue('state') ) def endElement(self,name): if name == 'host': network.append(self.host.copy()) self.host = {} self.host['status'] = "" self.host['address']= "" self.host['hostname'] = "" self.host['port'] = [] self.host['protocol'] = [] self.host['service']= [] self.host['state'] = [] self.host['product']= [] self.host['version']= [] self.host['extrainfo'] = [] def parse(): global network parser = xml.sax.make_parser() parser.setContentHandler( scanparser() ) network = [] parser.parse ( scan_results ) parse() (Well, really it runs from cherrypy but for brevity I've left that out) Any help or pointers anybody could give would be greatly appreciated... Hari -- http://mail.python.org/mailman/listinfo/python-list
Re: cherrypy tracing back all the time
On 23/07/06, Hari Sekhon <[EMAIL PROTECTED]> wrote: I've got a very simple script with cherrypy but for some reason the cherrypy server is constantly tracing back but it stays up, kind of, the performance etc though shows that something is wrong.import cherrypy import threading def someFunc(): while 1: print "working"threading._start_new_thread( someFunc , () )class someClass(): def index(self): test="this is a test" return test index.exposed=Truecherrypy.root=someClass()cherrypy.config.update( file="cherrypyconfig.txt" )cherrypy.server.start()The tracebacks I get are:Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 242, in run request.parse_request() File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 134, in parse_request method,path,version = request_line.strip().split(" ", 2)ValueError: need more than 1 value to unpackTraceback (most recent call last): File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 242, in run request.parse_request() File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 134, in parse_request method,path,version = request_line.strip().split(" ", 2)ValueError: need more than 1 value to unpack Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 242, in run request.parse_request() File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 134, in parse_request method,path,version = request_line.strip().split(" ", 2)ValueError: need more than 1 value to unpackTraceback (most recent call last): File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 242, in run request.parse_request() File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 134, in parse_request method,path,version = request_line.strip().split(" ", 2)ValueError: need more than 1 value to unpack Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 242, in run request.parse_request() File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 134, in parse_request method,path,version = request_line.strip().split(" ", 2)ValueError: need more than 1 value to unpackTraceback (most recent call last): File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 242, in run request.parse_request() File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 134, in parse_request method,path,version = request_line.strip().split(" ", 2)ValueError: need more than 1 value to unpack 2006/07/23 17:58:46 INFO Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgi.py", line 110, in wsgiApp environ['wsgi.url_scheme'], File "/usr/lib/python2.4/site-packages/cherrypy/_cpserver.py", line 227, in request requestLine, headers, rfile, scheme) File "/usr/lib/python2.4/site-packages/cherrypy/_cphttptools.py", line 181, in __init__ self.parseFirstLine() File "/usr/lib/python2.4/site-packages/cherrypy/_cphttptools.py", line 223, in parseFirstLine request.method, path, request.protocol = request.requestLine.split()ValueError: too many values to unpackI don't understand, all I've asked the stupid cherrypy thing to do is to print one line... Ok, when the somefunc() that is executed by threading runs, it doesn't cause the tracing back I showed above, it occurs only when I use one of the other two functions I have in it's place in the script via threading. The thing is, those other two functions both use try excepts inside to make sure there are no exceptions generated beyond the internal function, and neither of those functions can touch anything to do with the class used as the index of the cherrypy document root. What is going on? -- http://mail.python.org/mailman/listinfo/python-list
cherrypy tracing back all the time
I've got a very simple script with cherrypy but for some reason the cherrypy server is constantly tracing back but it stays up, kind of, the performance etc though shows that something is wrong.import cherrypyimport threading def someFunc(): while 1: print "working"threading._start_new_thread( someFunc , () )class someClass(): def index(self): test="this is a test" return test index.exposed=Truecherrypy.root=someClass()cherrypy.config.update( file="cherrypyconfig.txt" )cherrypy.server.start()The tracebacks I get are:Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 242, in run request.parse_request() File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 134, in parse_request method,path,version = request_line.strip().split(" ", 2)ValueError: need more than 1 value to unpackTraceback (most recent call last): File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 242, in run request.parse_request() File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 134, in parse_request method,path,version = request_line.strip().split(" ", 2)ValueError: need more than 1 value to unpack Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 242, in run request.parse_request() File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 134, in parse_request method,path,version = request_line.strip().split(" ", 2)ValueError: need more than 1 value to unpackTraceback (most recent call last): File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 242, in run request.parse_request() File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 134, in parse_request method,path,version = request_line.strip().split(" ", 2)ValueError: need more than 1 value to unpack Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 242, in run request.parse_request() File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 134, in parse_request method,path,version = request_line.strip().split(" ", 2)ValueError: need more than 1 value to unpackTraceback (most recent call last): File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 242, in run request.parse_request() File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgiserver.py", line 134, in parse_request method,path,version = request_line.strip().split(" ", 2)ValueError: need more than 1 value to unpack 2006/07/23 17:58:46 INFO Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/cherrypy/_cpwsgi.py", line 110, in wsgiApp environ['wsgi.url_scheme'], File "/usr/lib/python2.4/site-packages/cherrypy/_cpserver.py", line 227, in request requestLine, headers, rfile, scheme) File "/usr/lib/python2.4/site-packages/cherrypy/_cphttptools.py", line 181, in __init__ self.parseFirstLine() File "/usr/lib/python2.4/site-packages/cherrypy/_cphttptools.py", line 223, in parseFirstLine request.method, path, request.protocol = request.requestLine.split()ValueError: too many values to unpackI don't understand, all I've asked the stupid cherrypy thing to do is to print one line... -- http://mail.python.org/mailman/listinfo/python-list
threading._start_new_thread executes twice?
I'm got a script which has a function with a while 1: loop that seems to execute the line it's doing twice instead of just once on each pass when called in a thread...#Script Startimport threading,time,cherrypy def func(): while 1: print time.ctime() time.sleep(30)threading._start_new_thread( func,() )class somename(): def index(self): test="this is a test" return test index.exposed=Truecherrypy.root=somename()cherrypy.config.update( file = cherrypy.conf )cherrypy.server.start()#end of script(The contents of the cherrypy.conf is below: )[global]server.socketPort=8080server.environment="development"server.threadpool = 10The output on the console is at followsWed Jul 19 23:25:34 2006Wed Jul 19 23:25:34 2006 2006/07/19 23:25:34 CONFIG INFO Server parameters:2006/07/19 23:25:34 CONFIG INFO server.environment: development2006/07/19 23:25:34 CONFIG INFO server.logToScreen: True2006/07/19 23:25:34 CONFIG INFO server.logFile: 2006/07/19 23:25:34 CONFIG INFO server.protocolVersion: HTTP/1.02006/07/19 23:25:34 CONFIG INFO server.socketHost: 2006/07/19 23:25:34 CONFIG INFO server.socketPort: 80802006/07/19 23:25:34 CONFIG INFO server.socketFile: 2006/07/19 23:25:34 CONFIG INFO server.reverseDNS: False2006/07/19 23:25:34 CONFIG INFO server.socketQueueSize: 52006/07/19 23:25:34 CONFIG INFO server.threadPool: 02006/07/19 23:25:34 HTTP INFO Serving HTTP on http://localhost:8080/Wed Jul 19 23:26:04 2006Wed Jul 19 23:26:04 2006Wed Jul 19 23:26:34 2006Wed Jul 19 23:26:34 2006If I just replace the threading._start_new_thread line with func()func()func()then the time is output only once every thrity seconds, so it seems that threading._start_new_thread is calling func() twice initially?Why is func() executing twice when called from the thread? -- http://mail.python.org/mailman/listinfo/python-list
Re: Progress Bars in python
On 12/07/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > If the output of the script is sent to a logfile, this tends to puke all> over the logfile... creating one additional entry per iteration, but it's a> good start and I'll look at that link which looks very promising. there's no way to do this without sending more stuff to stdout than yousee; however, it's easy to *disable* the spinner if you're redirecting theoutput. hint:$ python -c "import sys; print sys.stdout.isatty ()"True$ python -c "import sys; print sys.stdout.isatty()" >out$ more outFalseThanks, that will do nicely. It will be sufficient to do this testing using isatty() and have the progress bar or spinner. -h -- http://mail.python.org/mailman/listinfo/python-list
Progress Bars in python
Hi, I've written a script which backs up a huge bunch of files, but I don't want the script to output the file names as it does this as it clutters the screen, I only output errors. So in order to see that the script is working and not stuck, I'd like to implement some kind of progress bar or something, perhaps like the spinning thing that you often see in linux or freebsd consisting of switching / - \ | on the spot to get the appearance of a spinning bar I can figure out that the spinning bar is done by switching these four chars but I don't know how they get each char to replace the last one instead of printing them in succession. Does anybody have any good suggestions about what the best way of doing this or any other suggestions for the best ways to show that the script is processing...? Hari -- http://mail.python.org/mailman/listinfo/python-list
catching syntax errors via excepthook?
I've written an except hook into a script as shown below which works well for the most part and catches exceptions. import sys def myexcepthook(type,value,tb): do something sys.excepthook=myexcepthook rest of script (now protected by catchall exception hook) I've been intentionally introducing errors into the code to try to test it and while it catches import errors and other things, it doesn't catch syntax errors. Is there a way to get it to catch syntax errors? Or is there a better way? -h -- http://mail.python.org/mailman/listinfo/python-list
Re: Unbound Local error? How?
Bruno Desthuilliers wrote: Hari Sekhon wrote: I've got some code as follows: import re re_regexname = re.compile('abc') . . various function defs . def func1(): ... func2() ... def func2(): if re_regexname.match('abc'): if __name__ == '__main__': func1() but this returns the Traceback: UnboundLocalError: local variable 're_regexname' referenced before assignment this is *not* the traceback. This is only the error message. The traceback contains all needed informations (or at least all possible information at this point) to know what happened. But you did not post the traceback. Nor did you post the minimal runnable code snippet producing this error. How? How could we know ? sorry, I know it looks like I was being stingy but the traceback was not that helpful, not without seeing more a huge amount more of the code. I was trying to abbreviate. Traceback (most recent call last): File "./backup.py", line 649, in ? backup(machine,share) File "./backup.py", line 364, in backup backupdir(source,destination) File "./backup.py", line 398, in backupdir (dirlist,filelist) = getdirlisting( source ) File "./backup.py", line 445, in getdirlisting if re_skip_dirs.match(x): UnboundLocalError: local variable 're_skip_dirs' referenced before assignment This doesn't really show that much, I figured the problem was the following: def getdirlisting(): re_skip_dirs = re_skip_top_dirs #Here's the culprit where both these regex compiled objects were declared at the top level, it seems that the assignment is trying to use the local variable re_skip_top_dirs which doesn't exist, that's why I'm getting a traceback, commenting out this line it runs fine. -h -- http://mail.python.org/mailman/listinfo/python-list
Re: Unbound Local error? How?
Diez B. Roggisch wrote: Hari Sekhon wrote: import re re_regexname = re.compile('abc') . . various function defs . def func1(): ... func2() ... def func2(): if re_regexname.match('abc'): if __name__ == '__main__': func1() The above clearly is not what you have. See the attached version of the above that works. So - go check for a typo or something like that. Diez import re re_regexname = re.compile('abc') def func1(): func2() def func2(): if re_regexname.match('abc'): print " whohoo!" if __name__ == '__main__': func1() you're right, it wasn't that, I was trying to locally override a regex object as follows: re_somepattern = re.compile('abc') re_someotherpattern = re.compile('def') def func(): if somecondition: re_somepattern = re_someotherpattern re_somepattern.match('something') not sure how to override this the way I want, it'd be quite messy if I had to do huge if blocks to handle this inside the other code blocks that use this re_somepattern.match() or perhaps I'm going about this all wrong -h -- http://mail.python.org/mailman/listinfo/python-list
Unbound Local error? How?
I've got some code as follows: import re re_regexname = re.compile('abc') . . various function defs . def func1(): ... func2() ... def func2(): if re_regexname.match('abc'): if __name__ == '__main__': func1() but this returns the Traceback: UnboundLocalError: local variable 're_regexname' referenced before assignment How? It was declared in the zero level indentation near the top of the script! I don't understand this, isn't a function supposed to be able to reference stuff in the containing function or the top level? -- http://mail.python.org/mailman/listinfo/python-list
Re: how to do -vv for very verbose?
Fredrik Lundh wrote: Hari Sekhon wrote: I'm using optparse.Optionparser to take switches for a script I'm writing, but I can't see how to give it -vv for very verbose. the option for -v is simply set to True by the option parser if present, whereas I really want a numeric value, 1 if there is -v and 2 if there is -vv. action="" ? yeah, I realised this just after I sent it, sort it out. Thanks. -h -- http://mail.python.org/mailman/listinfo/python-list
Re: style question
Claudio Grondi wrote: > Hari Sekhon wrote: >> On 26/06/06, *Claudio Grondi* <[EMAIL PROTECTED] >> <mailto:[EMAIL PROTECTED]>> wrote: >> >> Scott David Daniels wrote: >> > Claudio Grondi wrote: >> > <<>> >> > >> >> When necessary to skip first line _and_ indentation: >> >> message = """ >> >> This is line 1 >> >> This is line 2 >> >> This is line 3 >> >> """.replace('\n ', '\n')[1:] # adjust here '\n ' to >> indentation >> > >> > >> > Riffing on this idea: >> > message = """ >> > This is line 1 >> > This is line 2 >> > This is line 3 >> > """.replace(""" >> > """, '\n')[1:] >> >> This was intended as an excercise for the OP in case he likes >> that kind >> of solution ... >> >> Claudio >> >> > >> > --Scott David Daniels >> > [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> >> I've decided to go with >> >>message = ( >>"This is line1. " >>"This is line2 " >>"This is line3\n") >> >> since I'm declaring many different messages inside various functions >> I feel it is important to keep the indentaion and code both aligned >> properly so the code looks nice and the output looks nice. >> >> It is easier than doing replace and splicing since I want to keep it >> as simple and clean as possible, in true pythonic tradition... >> >> Thanks for the input! >> >> -h >> > Thanks for the reply and the explanation what you finally decided to > go with. > I am so happy to have the triple quotes in Python, that I use them > whenever possible - this has probably something to do with my bias > towards plain text files with human readable content, so as > readability is very important to me (and probably to many other > Pythonistas) I like most the proposed by me triple quote style as the > quotation marks in the style you prefer make the text of the 'message' > less easy to read. > > Now we can start a flame war about which style is more 'pythonic' ;-) > > Claudio > I already explained that the triple quotes don't work tidily with indentation, either the code is out of alignment or the printout is. Either way isn't good. Triple quotes are best at top level, but since I had to use many messages inside functions etc, they broke the layout of the code. I think they're both best depending on where you are putting them. I'm doing very custom messages for each different result, so it would be messy to do this at the top level. -h -- http://mail.python.org/mailman/listinfo/python-list
how to do -vv for very verbose?
I'm using optparse.Optionparser to take switches for a script I'm writing, but I can't see how to give it -vv for very verbose. the option for -v is simply set to True by the option parser if present, whereas I really want a numeric value, 1 if there is -v and 2 if there is -vv. Any ideas on how to do this? I think I'll have to stop using action="store_true". -h -- http://mail.python.org/mailman/listinfo/python-list
Re: style question
On 26/06/06, Claudio Grondi <[EMAIL PROTECTED]> wrote: Scott David Daniels wrote:> Claudio Grondi wrote:> <<> When necessary to skip first line _and_ indentation:>> message = """ >> This is line 1>> This is line 2>> This is line 3>> """.replace('\n ', '\n')[1:] # adjust here '\n ' to indentation>>> Riffing on this idea: > message = """> This is line 1> This is line 2> This is line 3> """.replace("""> """, '\n')[1:] This was intended as an excercise for the OP in case he likes that kindof solution ...Claudio>> --Scott David Daniels> [EMAIL PROTECTED] --http://mail.python.org/mailman/listinfo/python-listI've decided to go with message = ( "This is line1. " "This is line2 " "This is line3\n") since I'm declaring many different messages inside various functions I feel it is important to keep the indentaion and code both aligned properly so the code looks nice and the output looks nice. It is easier than doing replace and splicing since I want to keep it as simple and clean as possible, in true pythonic tradition... Thanks for the input! -h -- http://mail.python.org/mailman/listinfo/python-list
Re: style question
MTD wrote: Hari Sekhon wrote: Is it better to do: message = """This is line1. This is line2 This is line3\n""" or message = "This is line1.\n message = message + "This is line2\n" message = message + "This is line3\n" Is there any reason you can't do it in one line? message = "This is line1.\nThis is line2.\nThis is line3.\n" this would also be ugly though, a huge lone line for the paragraph I want to output, which would wrap around and break the visual indentation. otherwise I could do it in one line. but if I was going to do that and it was going to be so long, I'd just use """...""" -- http://mail.python.org/mailman/listinfo/python-list
style question
Is it better to do: message = """This is line1. This is line2 This is line3\n""" or message = "This is line1.\n message = message + "This is line2\n" message = message + "This is line3\n" Since the first method does not follow python's clean and easy looking indentation structure but the second just looks crude and ugly anyway. If I indent the first version so the text is lined up to match code indentation then this comes out in the input and isn't aligned there. -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the best way to wrap a whole script in try..except?
On 21/06/06, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: Hari Sekhon wrote:> I want to wrap a whole script in try ... except. What is the best way of> doing this?>> Consider the following: ->> try:>import > >>>def notifyme(traceback):> code to tell me there is a problem>> except Exception, traceback:>notifyme(traceback)>>> Would this code not work because if any part of encounters an > exception then it won't reach the notifyme() function definition and> therefore the whole thing won't work and I won't get notified when a> traceback occurs, in fact the call to notifyme() under except will > itself probably trace back as well!Yes.> Do I have to instead do:>> import > def notifyme():>code to tell me there is a problem> > try:>>> except Exception, traceback:>notifyme(traceback)>Would work, but...> How you you handle this?I don't put the main logic at the top level - I use a main() function. import def notifyme(e): # code here...def main(*args): try:# code herereturn 0 except Exception, e:notifyme(e)return if __name__ == '__main__': import sys sys.exit(main(*sys.argv))--bruno desthuillierspython -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) forp in ' [EMAIL PROTECTED]'.split('@')])"--http://mail.python.org/mailman/listinfo/python-listWhy bother passing the args in def main(*args): and main(* sys.argv)? Couldn't you just use sys.argv straight off inside main, no passing args aroundI can see you are probably a C programmer as well?-h -- http://mail.python.org/mailman/listinfo/python-list
Re: memory error with zipfile module
Fredrik Lundh wrote: Hari Sekhon wrote: I take it that it's still a work in progress to be able to pythonify everything, and until then we're just gonna have to rely on shell and those great C coded coreutils and stuff like that. Ok, I'm rather fond of Bash+coreutils, highest ratio of code lines to work I've ever seen it's the real strength of Linux. Shame about Windows... you make very little sense. how so, this is effectively what we do when we run os.system(). Usually people are running system commands on unix like machines using coreutils written in C to do things that are either difficult or near impossible to do in python... I've seen people using everything from zip to touch, either out of laziness or out of the fact it wouldn't work very well in python, this zip case is a good example. Sometimes when doing system scripts, they're effectively Bash scripting, but taking longer to do in many more lines of code cos it's in python. That makes very little sense. -- http://mail.python.org/mailman/listinfo/python-list
Re: memory error with zipfile module
Fredrik Lundh wrote: Hari Sekhon wrote: Is it me or is having to use os.system() all the time symtomatic of a deficiency/things which are missing from python as a language? it's you. I take it that it's still a work in progress to be able to pythonify everything, and until then we're just gonna have to rely on shell and those great C coded coreutils and stuff like that. Ok, I'm rather fond of Bash+coreutils, highest ratio of code lines to work I've ever seen it's the real strength of Linux. Shame about Windows... -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the best way to wrap a whole script in try..except?
Hari Sekhon wrote: Jon Ribbens wrote: In article <[EMAIL PROTECTED]>, Hari Sekhon wrote: I want to wrap a whole script in try ... except. What is the best way of doing this? You could do this maybe: import sys def excepthook(exc_type, exc_value, tb): import modules_needed_to_notify_exception ... sys.excepthook = excepthook import modules_needed_by_script ... having tested this more, I was worried about a recursive call to exception should an exception be raised inside the function but luckily python deals and give you a double traceback. batteries included indeed. Thanks again Hari I see that the exceptionhook is handed 3 things, the name of the error, the explanation, and the traceback object. Does anybody know how I can get the linenumber of the error the way it does normally, since this is very useful info when debugging. I think I need the traceback module but I can't see how to extract the extra info from the traceback object passed to excepthook. -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the best way to wrap a whole script in try..except?
Jon Ribbens wrote: In article <[EMAIL PROTECTED]>, Hari Sekhon wrote: I want to wrap a whole script in try ... except. What is the best way of doing this? You could do this maybe: import sys def excepthook(exc_type, exc_value, tb): import modules_needed_to_notify_exception ... sys.excepthook = excepthook import modules_needed_by_script ... having tested this more, I was worried about a recursive call to exception should an exception be raised inside the function but luckily python deals and give you a double traceback. batteries included indeed. Thanks again Hari -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the best way to wrap a whole script in try..except?
Jon Ribbens wrote: In article <[EMAIL PROTECTED]>, Hari Sekhon wrote: I want to wrap a whole script in try ... except. What is the best way of doing this? You could do this maybe: import sys def excepthook(exc_type, exc_value, tb): import modules_needed_to_notify_exception ... sys.excepthook = excepthook import modules_needed_by_script ... I've been trying this out and your method is by far the best I've seen. This is overriding the default exception handler. I don't know the deep magic yet but it works nicely. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: memory error with zipfile module
On 20/05/06, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: Roger Miller a écrit :> The basic problem is that the zipfile interface only reads and writes> whole files, so it may perform poorly or fail on huge files. At one> time I implemented a patch to allow reading files in chunks. However I > believe that the current interface has too many problems to solve by> incremental patching,Yeps, that was the general tone of some thread on python-dev. And fromwhat I saw of the source code, it may effectively not be the cleanest part of the stdlib. But what, it does what it was written for at first :provide working support for zipped packages.> and that a zipfile2 module is probably warranted.> (Is anyone working on this?) Seems like Bob Ippolito was on the rank, but I guess you'll get betteranswers on python-dev.> In the meantime I think the best solution is often to just run an> external zip/unzip utility to do the heavy lifting. Indeed !-)But while having zip/unzip installed OOTB on a unix-like system is closeto warrented, it may not be the case on Windows.-- http://mail.python.org/mailman/listinfo/python-listShame, I would like to try to improve this but seeing as Roger Miller has already submitted a patch I don't know how much I can do for this. In the end I resorted to using an external zip utility via os.system().I'll be interested to know if there is any work done on improving this as I'm in favour of native python usage, rather than using os.system() and relying on the operating system having a zip command, which I'm not convinced is the case on all windows machines, and also, I'm sure gentoo installs don't have zip by default, since I had to emerge it on a server for this script to work. Is it me or is having to use os.system() all the time symtomatic of a deficiency/things which are missing from python as a language? Not that I'm complaining, I'm just curious... I'm a fledgeling programmer so I don't mind being gently corrected by any veterans around. Hari -- http://mail.python.org/mailman/listinfo/python-list
Re: WinPops
If you were going to do this you may as well just do something likeif sys.platform='win32': os.system('net send ')elif sys.platform[:5]='linux' os.system('smblcient -M etc...') This would be more portable and simpler than the alternatives I've seen. It would be better if there was just a cross platform library for this protocol so you could justimport winpopwinpop.send (host,message)Too much to ask?HariOn 01/06/06, Peter Gsellmann <[EMAIL PROTECTED] > wrote:Roger Upole wrote:>> "Hari Sekhon" < [EMAIL PROTECTED]> wrote in message> news:[EMAIL PROTECTED]>> Hi,>> Is there a way of sending winpops (Windows Pop-Up / Net Send messages) >> in python?>>>> Perhaps some library or something that I can use under both Windows and>> Linux?>>>> Hari>> On Windows, you can use win32net.NetMessageBufferSend .>> Roger>On Linux, i use the smbclient binary: from subprocess import * q=Popen(['smbclient','-M','maggy'],stdin=PIPE) q.stdin.write('hello!') q.stdin.close() q.wait ()Peter--http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: difference between import from mod.func() and x=mod.func()
I take it that it's not worth listening to that tutorial and just using good old "import from", which I suspect is better anyway since it imports less..."uneducated premature optimisation" - I take it this is insulting a that programmer's progexuality...! "import from" it is then unless anybody has anything else to say on the matter.ThanksHariOn 20/06/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote: Hari Sekhon wrote:> What is the difference in terms of efficiency and speed between>> from os import path>> and>> import os> path=os.paththe only difference is that the former only sets the "path" variable, while the latter leaves both "os" and "path" in your namespace.> I would think that the import from would be better, just curious since I> read somewhere on the web, some guy's code tutorial where he did the > latter and said it was for efficiency/speed.sounds like "uneducated premature optimization" to me.-- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
What's the best way to wrap a whole script in try..except?
I want to wrap a whole script in try ... except. What is the best way of doing this? Consider the following: - try: import def notifyme(traceback): code to tell me there is a problem except Exception, traceback: notifyme(traceback) Would this code not work because if any part of encounters an exception then it won't reach the notifyme() function definition and therefore the whole thing won't work and I won't get notified when a traceback occurs, in fact the call to notifyme() under except will itself probably trace back as well! Do I have to instead do: import def notifyme(): code to tell me there is a problem try: except Exception, traceback: notifyme(traceback) How you you handle this? Hari -- http://mail.python.org/mailman/listinfo/python-list
difference between import from mod.func() and x=mod.func()
What is the difference in terms of efficiency and speed between from os import path and import os path=os.path I would think that the import from would be better, just curious since I read somewhere on the web, some guy's code tutorial where he did the latter and said it was for efficiency/speed. Not sure if this is right. Seeing as python folks seem to value simplicity and cleanness, is there a preferred coding method? (again I would think the first to the the preferred) Hari -- http://mail.python.org/mailman/listinfo/python-list
WinPops
Hi, Is there a way of sending winpops (Windows Pop-Up / Net Send messages) in python? Perhaps some library or something that I can use under both Windows and Linux? Hari -- http://mail.python.org/mailman/listinfo/python-list
memory error with zipfile module
I do import zipfile zip=zipfile.ZipFile('d:\somepath\cdimage.zip') zip.namelist() ['someimage.iso'] then either of the two: A) file('someimage.iso','w').write(zip.read('someimage.iso')) or B) content=zip.read('someimage.iso') but both result in the same error: Traceback (most recent call last): File "", line 1, in ? File "D:\u\Python24\lib\zipfile.py", line 357, in read bytes = dc.decompress(bytes) MemoryError I thought python was supposed to handle memory for you? The python zipfile module is obviously broken... Any advise? -- http://mail.python.org/mailman/listinfo/python-list
Re: Strange IO Error when extracting zips to a network location
I put a try-pass around the line "outfile.write(zip.read(x)) " so that everything extracts regardless. After extraction I checked the file size of every single file in the directory tree and only 2 files on the network drive are of different size to the ones extracted locally. Both these files are .dbf files that are over 100MB when extracted. Both of them is short by exactly 4 KB. Strange. I wonder if I'm hitting a size limit or something with this "zipfile" module, or perhaps a python limitation on buffer or something? I've change the code to contents=zip.read(x) outfile.write(contents) but I still get the same result. -h Hari Sekhon wrote: > Hi, > I've written a script to run on windows to extract all zips under a > given directory path to another directory path as such: > > python extractzips.py extracted files under this dir> > > The purpose of this script is to retrieve backup files which are > individually zipped under a backup directory tree on a backup server. > > This scripts works nicely and has input validation etc, exiting > gracefully and telling you if you gave a non existent start or target > path... > > When running the script as follows > > python extractzips.py \\backupserver\backupshare\machine\folder > d:\unziphere > > the script works perfectly, but if I do > > python extractzips.py \\backupserver\backupshare\machine\folder > \\anetworkmachine\share\folder > > then it unzips a lot of files, recreating the directory tree as it > goes but eventually fails with the traceback: > > File "extractzips.py", line 41, in zipextract >outfile.write(zip.read(x)) > IOError: [Errno 22] Invalid argument > > > But I'm sure the code is correct and the argument is passed properly, > otherwise a hundred files before it wouldn't have extracted > successfully using this exact same piece of code (it loops over it). > It always fails on this same file every time. When I extract the same > tree to my local drive it works fine without error. > > I have no idea why pushing to a network share causes an IO Error, > shouldn't it be the same as extracting locally from our perspective? > > It pulls fine, why doesn't it push fine? > > > Thanks for any help or suggestions anybody can give me. > > Hari > -- http://mail.python.org/mailman/listinfo/python-list
Strange IO Error when extracting zips to a network location
Hi, I've written a script to run on windows to extract all zips under a given directory path to another directory path as such: python extractzips.py The purpose of this script is to retrieve backup files which are individually zipped under a backup directory tree on a backup server. This scripts works nicely and has input validation etc, exiting gracefully and telling you if you gave a non existent start or target path... When running the script as follows python extractzips.py \\backupserver\backupshare\machine\folder d:\unziphere the script works perfectly, but if I do python extractzips.py \\backupserver\backupshare\machine\folder \\anetworkmachine\share\folder then it unzips a lot of files, recreating the directory tree as it goes but eventually fails with the traceback: File "extractzips.py", line 41, in zipextract outfile.write(zip.read(x)) IOError: [Errno 22] Invalid argument But I'm sure the code is correct and the argument is passed properly, otherwise a hundred files before it wouldn't have extracted successfully using this exact same piece of code (it loops over it). It always fails on this same file every time. When I extract the same tree to my local drive it works fine without error. I have no idea why pushing to a network share causes an IO Error, shouldn't it be the same as extracting locally from our perspective? It pulls fine, why doesn't it push fine? Thanks for any help or suggestions anybody can give me. Hari -- http://mail.python.org/mailman/listinfo/python-list
How to get a part of string which follows a particular pattern using shell script
Hi all, I need to get a part of string which follows a pattern 'addr=' For example: a)test="192.168.1.17:/home/ankur/nios_fson/mnt/tmptype nfs(rw,addr=192.168.1.17)" b)test="/dev/root on / typr nfs (rw,v2,rsize=1024,wsize=1024,hard,udp,nolock,addr=192.168.1.93)" I need to get the ipaddress from the above two strings a and b which follows 'addr='. I tried to use cut, but it accepts only single charter as delimiter. If I give delimiter as 'addr=' for cut command it gives me a error. So please help me. A bunch of thanks in advance. Regards, P.R.Hariram -- http://mail.python.org/mailman/listinfo/python-list
Getting File Permissions
Hi, For getting permissions of a file, the following script has been suggested in the same group import os, stat st = os.stat(myfile) mode = st[stat.ST_MODE] print "mode is", octal(mode & 0777) But while executing I am getting error message as follows Traceback (most recent call last): File "", line 1, in ? NameError: name 'octal' is not defined Since I am new to python, can any one help me to solve this error? A bunch of thanks in advance. Hari -- http://mail.python.org/mailman/listinfo/python-list
Parsing bash_history and inputting into mysql (Intrusion Detection)
I have a seemingly tough assignment for my Senior Project. I need to develop an Intrusion Detection System. My approach is to parse the bash_history file of each user into a mysql database, assign a threshold for commands or sequences of commands and then alert the admin of nethin fishy is found. My advisor reccomended I use python for writing the scripts. I am absolutely new to python and have no prior experience in it. That said Could any one tell me how exactly to go abt all this? Any tools or code that would make my life easier? Suggestions (which modules to use etc) ? Cheers, Sreekanth -- http://mail.python.org/mailman/listinfo/python-list