building python from source on HP
appreciate hints or pointers for building python on HP. running 'make test' fails with following cryptic message, after running configure, & make. Attempting to build python from source on HP-UX B.11.11 U 9000/800 3314646674 unlimited-user license *** Error exit code 1 Stop. not sure if output from configure and make would make a difference. If so I can send them. thanks in advance Edwin The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: Continually check object status
updated creature running in its own thread will get you started. try it for yourself, change sleep times per your need. import os, sys, threading, time class Creature: def __init__(self, status): self.status = status self.state = 'run' def start(self): self.athread = threading.Thread(target=self.print_status) self.athread.start() def change_status(self, new_status): self.status = new_status def print_status(self): while self.state == 'run': print self.status time.sleep(1) def stop(self): self.state = 'stop' self.athread.join() #main loop c = Creature('happy') c.start() time.sleep(3) #wait some time c.change_status('managing') time.sleep(3) #wait some more time c.change_status('bye') time.sleep(1) c.stop() concept would be similar with GUI as well -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Saturday, August 02, 2008 1:54 PM To: python-list@python.org Subject: Re: Continually check object status On Aug 2, 1:05 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] schrieb: > > > > > Beginner, so please bare with me. I'm not sure what to call what it > > is I'm looking for. > > > If I have an object class, let's call it "Creature": > > > class Creature: > > def __init__(self, status): > > self.status = "happy" > > > def change_status(self, new_status): > > self.status = new_status > > > def print_status(self): > > print self.status > > > I would like to be able to print out the Creature's status every 20 > > seconds. Let's say I use a script like this: > > > import time > > while True: > > time.sleep(20) > > Creature.print_status() > > > But, while cycling through printing the status, I would like to be > > able to update Creature.status to something new. > > > I might be approaching this from the wrong direction entirely. Thanks > > for your input. > > The "simple", yet possibly dangerous answer is: you need > multi-threading. Multi-threading is a technique that allows several > (quasi)-parallel paths of execution whilst sharing memory and objects > inside that memory. The module in python to achieve this is called > "threading". > > However, concurrent programming is a very advanced topic, ridded with > pitfalls for even experienced developers. > > There are other ways to solve the problem, commonly known as event-loops > and timers. These are usually part of frameworks for e.g GUI-creation an > such, but you can also roll your own if you like. > > So, the better answer might be a question: what do you ultimately want > to achieve? Given the name of your class, Creature, I assume you are > writing on some game or such. Depending on how you plan to do that, you > might have a framwork providing you with the needed tools/library calls > or whatever. > > Diez I was afraid that someone was going to mention threading. I have read about it before but not been able to do much with it. My ultimate goal is to create some sort of tamagotchi style virtual pet to interact with. Over time it gets hungry or bored, but the process can be fixed by a user "feeding" or "playing with" it. I wanted to take this opportunity to teach myself some PyGTK coding as well, but I thought that maybe I could build the creature object and looping in such a way that it would be possible to add a GUI to it later. -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: Decimals not equalling themselves (e.g. 0.2 = 0.2000000001)
for nth square root: use math.sqrt n times for example >>> import math >>> num = 625 >>> how_many_sqrt = 2 >>> for i in range(how_many_sqrt): .. num = math.sqrt(num) .. >>> num 5.0 all comparisons work fine for arbitrary floating point numbers... For readability print them with required precision. for example >>> a = .2 >>> b = .4 >>> b = b/2 >>> a == b True >>> a, b (0.20001, 0.20001) >>> '%.2f' % a, '%.2f' % b ('0.20', '0.20') >>> thx. Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of CNiall Sent: Sunday, August 03, 2008 10:03 AM To: python-list@python.org Subject: Decimals not equalling themselves (e.g. 0.2 = 0.21) I am very new to Python (I started learning it just yesterday), but I have encountered a problem. I want to make a simple script that calculates the n-th root of a given number (e.g. 4th root of 625--obviously five, but it's just an example :P), and because there is no nth-root function in Python I will do this with something like x**(1/n). However, with some, but not all, decimals, they do not seem to 'equal themselves'. This is probably a bad way of expressing what I mean, so I'll give an example: >>> 0.5 0.5 >>> 0.25 0.25 >>> 0.125 0.125 >>> 0.2 0.20001 >>> 0.33 0.33002 As you can see, the last two decimals are very slightly inaccurate. However, it appears that when n in 1/n is a power of two, the decimal does not get 'thrown off'. How might I make Python recognise 0.2 as 0.2 and not 0.20001? This discrepancy is very minor, but it makes the whole n-th root calculator inaccurate. :\ -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: xlrd
here is working code that will read & display contents of all rows & columns in all the sheets, you need xlrd 0.6.1 import xlrd, os, sys book = xlrd.open_workbook(sys.argv[1]) print "The number of worksheets is", book.nsheets for shx in range(book.nsheets): sh = book.sheet_by_index(shx) print 'tab:%s rows:%s cols:%s ' % (sh.name, sh.nrows, sh.ncols) for rx in range(sh.nrows): for cx in range(sh.ncols): try: if sh.row_types(rx)[cx] and sh.row_values(rx)[cx]: print '%4s %s' % (xlrd.cellname(rx, cx), sh.row_values(rx)[cx]) except: print xlrd.cellname(rx, cx), 'Exception - could not read' print -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gary Herron Sent: Monday, August 04, 2008 5:01 AM Cc: python-list@python.org Subject: Re: xlrd Yeats wrote: > Hi, > > Years ago i use xlrd to read data from excel and now I need again, but > i get strange result. The code is: > > from xlrd import * > > Planilha = open_workbook('C:\\Resultados.xls') > Resultados = Planilha.sheet_by_name('Resultados') > c = (Resultados.cell_value(2,2)) > print c > > and the result is: 0, but the value in cell is : VERDADEIRO > > What´s the problem I've never used xlrd, but based on other packages for accessing spread sheets, here's one guess. Cells can have numeric values or string values. Your cell apparently has a string, but you are asking for a numeric value, so you get a zero. Should you be asking for a string value? (That's the way OpenOffice/python works if I remember correctly.) Or are you accessing a different cell because you've confused 0-based / 1-based indexing? Or are you using old outdated versions of xlrd, Python or Excel? Gary Herron > > Thanks and sorry my bad english > Yeats > > > > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: UnicodeDecodeError, how to elegantly deal with this?
if you can print out values of 'filemask', and 'thefile' variables, when it crashes, I can help. thx. Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jorgen Bodde Sent: Monday, August 04, 2008 2:24 PM To: python-list@python.org Subject: UnicodeDecodeError, how to elegantly deal with this? Hi All, I am relatively new to python unicode pains and I would like to have some advice. I have this snippet of code: def playFile(cmd, args): argstr = list() for arg in appcfg.options[appcfg.CFG_PLAYER_ARGS].split(): thefile = args["file"] filemask = u"%file%" therep = arg.replace(filemask, thefile) # error here argstr.append(therep) argstr.insert(0, appcfg.options[appcfg.CFG_PLAYER_PATH]) try: subprocess.Popen( argstr ) except OSError: cmd.html = "Can't play file" + args["file"] return cmd.redirect = _getBaseURL("series?cmd_get_series=%i" % args["id"]) cmd.html = "" --- It crashes on this: 20:03:49: File "D:\backup\important\src\airs\webserver\webdispatch.py", line 117, in playFile therep = arg.replace(filemask, thefile) 20:03:49: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 93: ordinal not in range(128) 20:03:49: Unhandled Error: : 'ascii' codec can't decode byte 0xc2 in position 93: ordinal not in range(128) It chokes on a ` character in a file name. I read this file from disk, and I would like to play it. However in the replace action it cannot translate this character. How can I transparently deal with this issue because in my eyes it is simply replacing a string with a string, and I do not want to be bothered with unicode problems. I am not sure in which encoding it is in, but I am not experienced enough to see how I can solve this Can anybody guide me to an elegant solution? Thanks in advance! - Jorgen -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
soap call through firewall
hi, any hints/pointers appreciated if you have succeeded in making a soap call through a firewall. other than this http://www.ibm.com/developerworks/xml/library/x-tipfire.html cannot find much. thanks in advance Edwin The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
SOAPpy how to
unable to get past local proxy server with SOAPpy client. In the code below using 'thproxy' or 'httpproxy' variable for http_proxy fails. from SOAPpy import WSDL proxyuser='..' proxypass='.. httpproxy="a.b.c.com:1234" theproxy='http://'+proxyuser+':'+proxypass+'@'+httpproxy wsdl='sample.wsdl' #soap service provided by the soap server defined in the wsdl server = WSDL.Proxy(wsdl, http_proxy=httpproxy) #fails with SOAPpy.Errors.HTTPError: #server = WSDL.Proxy(wsdl, http_proxy=theproxy) #fails with socket.gaierror: (7, 'getaddrinfo failed') a = server.aTestMethod( arg1, arg2, ) print a any suggestions or hints any one.. thanks in advance Edwin The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
python equivalent for this perl soap client
use SOAP::Lite; use Data::Dumper; $ENV{HTTP_proxy} = "my_proxy_server_not_soap_proxy_server"; $ENV{HTTP_proxy_user} = ""; #set correct value $ENV{HTTP_proxy_pass} = ""; #set correct value my $soap = SOAP::Lite ->service('file:./local_file_copy_of_wsdl.wsdl'); my $som = $soap->soapMethod("method", "args", "as", "required"); print Dumper($som); although above perl code (yes it works!), connects to the soap server through the http proxy with proper credentials, I would rather do it python. has any out there succeeded in making a soap request through firewall using wsdl something like below from SOAPpy import WSDL server = WSDL.Proxy('./local_file_copy_of_wsdl.wsdl') res = server.soapMethod("method", "args", "as", "required") tried every which way but cannot get it to work. any hints, suggestions appreciated. thanks in advance Edwin The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using an DTD not specified in XML file for validation
can you edit the xml and add the dtd/scheama ? .Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ben Finney Sent: Wednesday, August 06, 2008 7:07 PM To: python-list@python.org Subject: Re: Using an DTD not specified in XML file for validation Brian Quinlan <[EMAIL PROTECTED]> writes: > I'm trying to figure out how I can validate an XML file using a DTD > that isn't specified in the XML file. When your inention is to start a new discussion, you could compose a new message, *not* reply to an existing message. Your message here is now part of an existing thread of discussion, yet is confusingly unrelated in its content, and will not be noticed by most readers. -- \ "Whatever you do will be insignificant, but it is very | `\important that you do it." -Mahatma Gandhi | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: A question about string and float number
type(s) == type(float()) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Wei Guo Sent: Wednesday, August 06, 2008 9:23 PM To: python-list@python.org Subject: A question about string and float number Hi all, I am new of python. Could anyone help me a question as below? Is there any function that can judge a string s is a float number or not? FOr example, if s = '1.232' or s='1e+10', then it returns true, otherwise, it will return false. isdigit() in string doesn't work. float() will throw an exception and I just need true or false as result. Thanks a lot in advance, Wei The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: A question about string and float number
#this is a better way of testing a string for float def isFloat(s): try: s = float(s) except: return False return True -Original Message- From: Madari, Edwin Sent: Wednesday, August 06, 2008 10:22 PM To: 'Wei Guo'; python-list@python.org Subject: RE: A question about string and float number type(s) == type(float()) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Wei Guo Sent: Wednesday, August 06, 2008 9:23 PM To: python-list@python.org Subject: A question about string and float number Hi all, I am new of python. Could anyone help me a question as below? Is there any function that can judge a string s is a float number or not? FOr example, if s = '1.232' or s='1e+10', then it returns true, otherwise, it will return false. isdigit() in string doesn't work. float() will throw an exception and I just need true or false as result. Thanks a lot in advance, Wei The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: Testing for the first few letters of a string
use re module import re template = '^My name is alex' astring = 'My name is alex, and I like pie' if re.match(template, astring): print 'Found it' else: print '%s does not begin with %s' % (astring, template) good luck. Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alexnb Sent: Thursday, August 07, 2008 11:40 AM To: python-list@python.org Subject: Testing for the first few letters of a string Okay, I have a fix for this problem, but it is messy and I think there might be a better way. Heres an example: Lets say I have a string: "My name is alex" and I have another string "My name is alex, and I like pie". I want to test to see if just the "My name is alex" part is there. I don't care about the pie part. My first instinct was to just create a for loop and test for the string like this: n = 0 for x in string1: if string1[n] == string2[n] n = n +0 else: break and then later testing to see what n was = to and figuring out if it got through the whole loop. I feel like there should be an easier way to do this, and probably is. So Does anyone have a suggestion? -- View this message in context: http://www.nabble.com/Testing-for-the-first-few-letters-of-a-string-tp18873375p18873375.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: very newbie question
delete the extra 'tries += 1' after else: print "Higher..." tries += 1 #delete this while at it, and add this line as the first line in function ask_number() global the_number, tries good luck. Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of garywood Sent: Thursday, August 07, 2008 1:56 PM To: python-list@python.org Subject: very newbie question stuck on python for absolute beginners chapter 6 i actually done what i was supposed to do use the function ask_number for guess a number but for some reason it does not count correctly the number of tries # Guess My Number # # The computer picks a random number between 1 and 100 # The player tries to guess it and the computer lets # the player know if the guess is too high, too low # or right on the money import random print "\tWelcome to 'Guess My Number'!" print "\nI'm thinking of a number between 1 and 100." print "Try to guess it in as few attempts as possible.\n" # set the initial values def ask_number(): the_number = random.randrange(100) + 1 guess = int(raw_input("Take a guess: ")) tries = 1 while (guess != the_number): if (guess > the_number): print "Lower..." else: print "Higher..." tries += 1 guess = int(raw_input("Take a guess: ")) tries += 1 ask_number() print "You guessed it! The number was", the_number print "And it only took you", tries, "tries!\n" raw_input("\n\nPress the enter key to exit.") The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: sending to an xterm
since I do not have access to xterm, here is the interactive session for spawning bash(another session if you will), sending ls command to it, and retrieving the results. things to note are: 1. after spawning expect for the prompt, timeout, and eof #which ever happens first 2. return value is the action that matched 3. if prompt matched, the 'before' has the results 4. even the command 'ls' with '\r\n' will be in the results. actual session-- [EMAIL PROTECTED]:/c/Edwin/Projects/expect $ python Python 2.5.1 (r251:54863, May 18 2007, 16:56:43) [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> import pexpect >>> c = pexpect.spawn('/bin/bash') >>> c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ ']) 2 >>> c.before '[EMAIL PROTECTED]:/c/Edwin/Projects/expect\r\n' >>> c.after '$ ' >>> c.sendline('ls') 3 >>> c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ ']) 2 >>> c.before '[EMAIL PROTECTED]:/c/Edwin/Projects/expect\r\n' >>> c.after '$ ' >>> >>> exit() [EMAIL PROTECTED]:/c/Edwin/Projects/expect $ --- good luck Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kent Tenney Sent: Friday, August 08, 2008 4:25 PM To: python-list@python.org Subject: sending to an xterm Howdy, I want to open an xterm, send it a command and have it execute it. I thought pexpect would do this, but I've been unsuccessful. term = pexpect.spawn('xterm') starts an xterm, but term.sendline('ls') doesn't seem to do anything. Suggestions? Thanks, Kent -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: Extract string from log file
from each line separate out url and request parts. split the request into key-value pairs, use urllib to unquote key-value pairs..as show below... import urllib line = "GET /stat.gif?stat=v&c=F-Secure&v=1.1%20Build%2014231&s=av%7BNorton%20360%20%28Symantec%20Corporation%29+69%3B%7Dsw%7BNorton%20360%20%28Symantec%20Corporation%29+69%3B%7Dfw%7BNorton%20360%20%28Symantec%20Corporation%29+5%3B%7Dv%7BMicrosoft%20Windows%20XP+insecure%3BMicrosoft%20Windows%20XP%20Professional+f%3B26027%3B26447%3B26003%3B22452%3B%7D&r=0.9496 HTTP/1.1" words = line.split() for word in words: if word.find('?') >= 0: req = word[word.find('?') + 1:] kwds = req.split('&') for kv in kwds: print urllib.unquote(kv) stat=v c=F-Secure v=1.1 Build 14231 s=av{Norton 360 (Symantec Corporation)+69;}sw{Norton 360 (Symantec Corporation)+69;}fw{Norton 360 (Symantec Corporation)+5;}v{Microsoft Windows XP+insecure;Microsoft Windows XP Professional+f;26027;26447;26003;22452;} r=0.9496 good luck Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Saturday, August 09, 2008 10:48 AM To: python-list@python.org Subject: Extract string from log file 203.114.10.66 - - [01/Aug/2008:05:41:21 +0300] "GET /stat.gif? stat=v&c=F-Secure&v=1.1%20Build%2014231&s=av%7BNorton %20360%20%28Symantec%20Corporation%29+69%3B%7Dsw%7BNorton %20360%20%28Symantec%20Corporation%29+69%3B%7Dfw%7BNorton %20360%20%28Symantec%20Corporation%29+5%3B%7Dv%7BMicrosoft%20Windows %20XP+insecure%3BMicrosoft%20Windows%20XP%20Professional+f %3B26027%3B26447%3B26003%3B22452%3B%7D&r=0.9496 HTTP/1.1" 200 43 "http://dfstage1.f-secure.com/fshc/1.1/release/devbw/1.1.14231/ card.html" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)" does anyone know how can i extract certain string from this log file using regular expression in python or using XML. can teach me. -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: "shelve" save object
since choice of dbm used by shelve http://docs.python.org/lib/node327.html depends on os, and whats available on it, shevle files saved on one os, most likely do not work on another os, sometimes on similar os but different machines might not work either - goes back to what's available on that machine. inter operability of shelve files with similar os-es works! yes I had used it. For inter-operability of saved information across os-es, roll up your own bit of code to write it out into pickle files. Yes pickle files are inter-operable. Consider a database for persistent storage and retrieval from many os-es good luck. Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of hypermonkey2 Sent: Saturday, August 09, 2008 3:33 PM To: python-list@python.org Subject: "shelve" save object Hi there! I am using the "shelve" module in a script to save information in between runtime sessions of the program. (its a sort of data collector, so its important to hold on to anything computed ). In any case, I shelve into a file "test.txt". I notice that when i try running the program on a different computer (by either emailing or transfering the file "test.txt" via USB key), the program is unable to load the shelve file. What can I do to fix this? It would be a great shame to see that after collecting all this information and shelving it that I cannot move to another computer or share the information through the "save.txt" file. Thanks in advance! Jon -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: How to round a floating point to nearest 10?
>>> round(76.1, -2) 100.0 >>> round(76.1, -1) 80.0 >>> round(76.1) 76.0 >>> builtin function round, will work for you.. Help on built-in function round in module __builtin__: round(...) round(number[, ndigits]) -> floating point number Round a number to a given precision in decimal digits (default 0 digits). This always returns a floating point number. Precision may be negative. good luck.. Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Machin Sent: Saturday, August 09, 2008 5:54 PM To: python-list@python.org Subject: Re: How to round a floating point to nearest 10? On Aug 10, 1:19 am, Mensanator <[EMAIL PROTECTED]> wrote: > On Aug 9, 6:31 am, Will Rocisky <[EMAIL PROTECTED]> wrote: > > > I want my 76.1 to be rounded to decimal 80 and 74.9 to decimal 70. > > How can I achieve that? > >>> print '%.0e' % 74.9 > 7e+01 > >>> print '%.0e' % 76.1 > > 8e+01 But: >>> print '%.0e' % 176.1 2e+002 Giving the Subject ("How to round a floating point to nearest 10?"), there's a strong presumption that the OP would want the answer to be 180, not 200. -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: regular expression extracting groups
if its *NOT* an exercise in re, and if input is a bunch of lines within '{' and '}' and each line is key="value" pairs, I would not go near re. instead simply parse keys and array of values into a dictionary, and process them from the dictionary as below, and the key option correctly has 2 entries 'value' and '7' in the right order. will work with any input... # assuming variable s has the string.. s = """{ option=value foo=bar another=42 option=7 }""" >>> for line in s.split(): .. ix = line.find('=') .. if ix >= 0: .. key = line[:ix] .. val = line[ix + 1: ] .. try: .. data[key].append(val) .. except KeyError: .. data.setdefault(key, [val]) .. >>> >>> >>> for k, v in data.items(): .. print 'key=%s val=%s' % (k, v) .. .. key=foo val=['bar'] key=option val=['value', '7'] key=another val=['42'] with another dictionary of keys to be processed with a function to process values for that key, its a matter of iterating over keys.. hope that simplifies and helps.. thx Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Sunday, August 10, 2008 8:30 AM To: python-list@python.org Subject: regular expression extracting groups Hi list, I'm trying to use regular expressions to help me quickly extract the contents of messages that my application will receive. I have worked out most of the regex but the last section of the message has me stumped. This is mostly because I want to pull the content out into regex groups that I can easily access later. I have a regex to extract the key/value pairs but it ends up with only the contents of the last key/value pair encountered. An example of the section of the message that is troubling me appears like this: { option=value foo=bar another=42 option=7 } So it's basically a bunch of lines. Every line is terminated with a '\n' character. The number of key/value fields changes depending on the particular message. Also notice that there are two 'option' keys. This is allowable and I need to cater for it. A couple of example messages are: xpl-stat\n{\nhop=1\nsource=vendor-device.instance\ntarget=*\n} \nhbeat.basic\n{\ninterval=10\n}\n xpl-stat\n{\nhop=1\nsource=vendor-device.instance\ntarget=vendor- device.instance\n}\nconfig.list\n{\nreconf=newconf\noption=interval \noption=group[16]\noption=filter[16]\n}\n As all messages follow the same pattern I'm hoping to develop a generic regex, instead of one for each message kind - because there are many, that can pull a message from a received packet. The regex I came up with looks like this: # This should match any xPL message GROUP_MESSAGE_TYPE = 'message_type' GROUP_HOP = 'hop' GROUP_SOURCE = 'source' GROUP_TARGET = 'target' GROUP_SRC_VENDOR_ID = 'source_vendor_id' GROUP_SRC_DEVICE_ID = 'source_device_id' GROUP_SRC_INSTANCE_ID = 'source_instance_id' GROUP_TGT_VENDOR_ID = 'target_vendor_id' GROUP_TGT_DEVICE_ID = 'target_device_id' GROUP_TGT_INSTANCE_ID = 'target_instance_id' GROUP_IDENTIFIER_TYPE = 'identifier_type' GROUP_SCHEMA = 'schema' GROUP_SCHEMA_CLASS = 'schema_class' GROUP_SCHEMA_TYPE = 'schema_type' GROUP_OPTION_KEY = 'key' GROUP_OPTION_VALUE = 'value' XplMessageGroupsRe = r'''(?P<%s>xpl-(cmnd|stat|trig)) \n # message type \ {\n # hop=(?P<%s>[1-9]{1}) \n # hop count source=(?P<%s>(?P<%s>[a-z0-9]{1,8})-(?P<%s>[a-z0-9]{1,8})\.(?P< %s>[a-z0-9]{1,16}))\n # source identifier target=(?P<%s>(\*|(?P<%s>[a-z0-9]{1,8})-(?P<%s>[a-z0-9]{1,8})\.(?P< %s>[a-z0-9]{1,16})))\n # target identifier \} \n # (?P<%s>(?P<%s>[a-z0-9]{1,8})\.(?P<%s>[a-z0-9]{1,8}))\n # schema \ {\n # (?:(?P<%s>[a-z0-9\-]{1,16})=(?P<%s>[\x20-\x7E]{0,128})\n){1,64} # key/value pairs \}\n''' % (GROUP_MESSAGE_TYPE, GROUP_HOP, GROUP_SOURCE, GROUP_SRC_VENDOR_ID, GROUP_SRC_DEVICE_ID, GROUP_SRC_INSTANCE_ID, GROUP_TARGET, GROUP_TGT_VENDOR_ID, GROUP_TGT_DEVICE_ID, GROUP_TGT_INSTANCE_ID, GROUP_SCHEMA, GROUP_SCHEMA_CLASS, GROUP_SCHEMA_TYPE, GROUP_OPTION_KEY, GROUP_OPTION_VALUE) XplMessageGroups = re.compile(XplMessageGroupsRe, re.VERBOSE | re.DOTALL) If I pass the second example message through this regex the 'key' group ends up containing 'option' and the 'value' group ends up containing 'filter[16]' which are the last key/value pairs in that message. So the problem I have lies in the key/value regex extraction section. It handles multiple occurrences of the pattern and writes the content into the single key/value group hence I can't extract and access all fields. Is there some other way to do this which allows me to store all the key/value pairs into the regex mat
Re: SSH utility
for similar tasks, I use pexpect http://pypi.python.org/pypi/pexpect. spawning bash process and simulate an interactive session. Here sending ls command, retrieving results and exiting. In the spawned process ssh or any other command, is just another command. actual session-- $ python Python 2.5.1 (r251:54863, May 18 2007, 16:56:43) [GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> import pexpect >>> c = pexpect.spawn('/bin/bash') >>> c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ ']) 2 >>> c.before, c.after ('[EMAIL PROTECTED]:~\r\n', '$ ') >>> c.sendline('ls') 3 >>> c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ ']) 2 >>> c.before, c.after ('ls\r\x.txt xx.txt xy.txt [EMAIL PROTECTED]:~\r\n', '$ ') >>> c.sendline('exit') 5 >>> c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ ']) 1 >>> c.before, c.after ('exit\r\nexit\r\n', ) >>> exit() [EMAIL PROTECTED]:~ $ --- hope that helps. regards. Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of James Brady Sent: Monday, August 11, 2008 12:26 AM To: python-list@python.org Subject: SSH utility Hi all, I'm looking for a python library that lets me execute shell commands on remote machines. I've tried a few SSH utilities so far: paramiko, PySSH and pssh; unfortunately all been unreliable, and repeated questions on their respective mailing lists haven't been answered... It seems like the sort of commodity task that there should be a pretty robust library for. Are there any suggestions for alternative libraries or approaches? Thanks! James -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: for x,y in word1, word2 ?
sounds like *soundex* is what you are looking for. google soundex regards Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Marc 'BlackJack' Rintsch Sent: Monday, August 11, 2008 3:09 AM To: python-list@python.org Subject: Re: for x,y in word1, word2 ? On Sun, 10 Aug 2008 23:14:50 -0700, ssecorp wrote: > I know zip but lets say I have a word "painter" and I want to compare it > to a customer's spelling, he might have written "paintor" and I want to > check how many letters are the same. > > Now I know how I could do this, it is not hard. I am just wondering if > these is any specific simple syntax for it. No special syntax for that, but you can combine the `sum()` function, a generator expression and `zip()`: In [40]: sum(int(a == b) for a, b in zip('painter', 'paintor')) Out[40]: 6 Or this way if you think it's more clear: In [41]: sum(1 for a, b in zip('painter', 'paintor') if a == b) Out[41]: 6 Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Checking a file's time stamp.
os.paht.gmtime(path) returns the last modification of path. check out http://docs.python.org/lib/module-os.path.html regards Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of William Purcell Sent: Tuesday, August 12, 2008 1:47 PM To: Python List Subject: Checking a file's time stamp. Hi all, I am wanting to check to see the last time a file was edited. For example, I have a directory containing two text files, file1.txt and file2.txt. I want to be able to process these files but only if they have been edited since the last time they were processed. I think that I want to be able to check the time stamp of each file. Can anyone tell me how to do that or point me in a better direction of checking the last time a file was edited? Thanks, Bill The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: Random Problems
use songs.extend( asongs ) #append is for single item - where ever it might be. >>> l1 = range(5) >>> l2 = range(5,10) >>> l1 [0, 1, 2, 3, 4] >>> l2 [5, 6, 7, 8, 9] >>> l1.extend(l2) >>> l1 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> good luck. Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Cousin Stanley Sent: Wednesday, August 13, 2008 10:19 PM To: python-list@python.org Subject: Re: Random Problems > Well the othe day I was making a program to make a list > of all the songs in certian directorys but I got a problem, > only one of the directorys was added to the list. > > Here's some code that illustrates yours import glob songs = glob.glob( '/path/to/somewhere/*.mp3' ) asongs = glob.glob( 'path/to/somewhere/else/*.mp3' ) songs.append( asongs ) # repeat a few times appending lists from other dirs > all goes well but pick awalys is from the first directory > but songs awalys includes all the files I want it to. songs.append( asongs ) is appending the entire asongs list as a single item to the end of the songs list, not adding each individual song as an entry For example >>> l1 = range( 0 , 5 ) >>> l2 = range( 5 , 10 ) >>> l3 = range( 11 , 15 ) >>> >>> l1 [0, 1, 2, 3, 4] >>> >>> l2 [5, 6, 7, 8, 9] >>> >>> l3 [11, 12, 13, 14] >>> >>> l1.append( l2 ) >>> >>> l1 [0, 1, 2, 3, 4, [5, 6, 7, 8, 9]] >>> >>> l1.append( l3 ) >>> >>> l1 [0, 1, 2, 3, 4, [5, 6, 7, 8, 9], [11, 12, 13, 14]] So, if you have a lot of entries in the original songs list you're only adding a few entries to it in the form of another list and most likely you didn't run enough random.choice tests to flush out a pick that turned out to be one of the entire asong lists that you added You might try something like the following where each tune gets added individually to the song pool un-tested # --- import random import glob base_dir = 'c:/Documents and Settings/Admin/My Documents' list_subdirs = [ 'LimeWire/Saved/*.mp3' , 'Downloads/*/*.mp3' , 'Downloads/*/*/*.mp3' , 'Downloads/*/*/*/*.mp3 ] song_pool = [ ] for this_dir in list_subdirs : list_songs = glob.glob( "'%s/%s'" % ( base_dir , this_dir ) if list_songs : for this_song in list_songs : song_pool.append( this_song ) npicks = 41 print for n in range( npicks ) : this_pick = random.choice( song_pool ) print ' ' , this_pick # --- -- Stanley C. Kitching Human Being Phoenix, Arizona -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: Formatting input text file
save following code in script.py, and run it as 'python script.py ' with your sample data this prints out following which is what you are looking for (i think) 3.08333 9.05526 3.13581 4.08322 4.02526 3.95891 import sys data = [] row = [] fh = open(sys.argv[1]) for line in fh: line = line.strip() if not line or line.startswith(''): continue if line.startswith('X'): if row: data.append(row) row = [] continue row.append(line.split()[1]) if row: data.append(row) for i in data: print ' '.join(i) = good luck. Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Thursday, August 14, 2008 7:07 AM To: python-list@python.org Subject: Formatting input text file Hi, it's me again with tons of questions. I hava an input file structured like this: X XYData-1 1. 3.08333 2. 9.05526 3. 3.13581 ... X XYData-2 1. 4.08322 2. 4.02526 3. 3.95891 ... i want to format it so i only get the second column, in order to place it in a mxn matrix. Let's say i want this: number1 number2 number3 number4 number5 number6 i hope it is not too hard to do. Any help greatly apreciated. Thanks, Victor -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: Fixed-length text file to database script
here is a working code snippet to read from MySQL db. python tutorial has examples of reading from files. put them together to do your task. === import MySQLdb con = MySQLdb.connect(host='127.0.0.1', port=4321, user='joe', passwd='shmoe', db='tst') cursor = con.cursor() sql = 'select * from YOUR_TABLE' cursor.execute(sql) results = cursor.fetch() con.close() = hope that helps. good luck Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Diez B. Roggisch Sent: Thursday, August 14, 2008 7:11 AM To: python-list@python.org Subject: Re: Fixed-length text file to database script Stacey wrote: > Hi Guys, > > I'm new to Python (mostly) and I'm wanting to use it for a new project > I'm faced with. > > I have a machine (PLC) that is dumping its test results into a > fixed-length text file. I need to pull this data into a database > (MySQL most likely) so that I can access it with Crystal Reports to > create daily reports for my engineers. > > I've been reading the Python manual for about a week now and I'm > learning a lot. Unfortunately, I was given a deadline today that I > cannot meet without a little help. > > I need to know how to write a script that will DAILY pull this text > file into a MySQL database. > > Can anyone show me how to do this? Show us code & data, and we show you how to improve the code. Or would you be able to write the script with the above information? Diez -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: a question about mysqldb
replace the name of table before calling *.execute. s.dbptr.execute(str % (e[0])) good luck. Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Evan Sent: Thursday, August 14, 2008 11:27 AM To: python-list@python.org Subject: a question about mysqldb a simple problem but I do not know why...:(, could anyone help me? MySQLdb nominally uses just the %s placeholder style, in my script, i got error if you want to use placeholder(%s) for table name: + >>> str="select tID,tNote from %s where tID=1" < check here >>> >>> e=["tmp"] >>> s.dbptr.execute(str,e) Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line 166, in execute self.errorhandler(self, exc, value) File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line 35, in defaulterrorhandler raise errorclass, errorvalue _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''tmp') where tID=1' at line 1") >>> But sql worked but the I got no query result: >>> str="select tID,tNote from tmp where %s = %s" <--check here >>> e=["tID",int(1)] >>> s.dbptr.execute(str,e) 0L<-- check here >>> >>> s.dbptr.fetchall() () >>> And then, it worked if I do: >>> str="select tID,tNote from %s where %s = %s" % ("tmp","tID",1) >>> >>> str 'select tID,tNote from tmp where tID = 1' >>> s.dbptr.execute(str) 1L >>> >>> s.dbptr.fetchall() ({'tID': 1L, 'tNote': 'kao'},) mysql> desc tmp -> ; +---+-+--+-+-++ | Field | Type| Null | Key | Default | Extra | +---+-+--+-+-++ | tID | int(11) | NO | PRI | NULL| auto_increment | | tDate | date| YES | | NULL|| | tSID | int(11) | NO | | NULL|| | tCom | varchar(15) | YES | | NULL|| | tNote | text| YES | | NULL|| +---+-+--+-+-++ 5 rows in set (0.00 sec) + mysql> mysql> Thanks, -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: a question about mysqldb
db module properly formats arguments, if input arguments are separated from table_name and colum_names. columns = ('tID', 'tNote') table_name = 'tmp' sql = 'select %s from %s where tID=:1' % ( ', '.join(columns), table_name) cursor.execute(sql, (1,)) # sql is now 'select tID, tNote from tmp where tID=:1' # note the comma in argument tuple to execute (1,) thanks Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Eric Wertman Sent: Thursday, August 14, 2008 2:13 PM To: python-list@python.org Subject: Re: a question about mysqldb I also like to use escaped identifiers in cases like this: sql = "select tID,tNote from %s where %s = %%s" % ("tmp","tID") cursor.execute(sql,1) should work fine. -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: Fixed-length text file to database script
#your thought is right. === def sizes2fields(sizes): d = [] begin = 0 for i in sizes: if begin: end = begin + i else: end = i d.append((begin, end)) begin += i return tuple(d) def slicestring(s, fields): d = [] for i in fields: d.append(s[i[0]:i[1]]) return tuple(d) sizes = [16,4,8,8,8] s = '123456789012345678901234567890123456789012345678901234567890' print slicestring(s, sizes2fields(sizes)) == prints out: ('1234567890123456', '7890', '12345678', '90123456', '78901234') hope it helps. thanks Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Eric Wertman Sent: Thursday, August 14, 2008 1:59 PM To: python-list@python.org Subject: Re: Fixed-length text file to database script I have a machine (PLC) that is dumping its test results into a fixed- length text file. While it has nothing to do with python, I found that creating a MySQL table with the proper fixed length char() fields and using 'load data infile' was the easiest way to deal with that sort of scenario. The python script is the secondary part, that handles the normalization and proper typing of the first table to the second, permanent storage area. But in this case, the more advanced bits are the database and SQL details, and python is just a very convenient way to build the SQL statements and execute them. I'm really not sure what the best way to deal with fixed length data is in python. I might define a list with the field lengths and use a string slicing to get the items.. as a first thought: myfile = '/somewhere/somefile.txt' sizes = [16,4,8,8,8] fd = open(myfile,r) for line in fd.readlines() : idx1 = 0 for l in sizes : -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: threading
1. check out the Caveats for thread module: http://docs.python.org/lib/module-thread.html Threads interact strangely with interrupts: the KeyboardInterrupt exception will be received by an arbitrary thread. (When the signal module is available, interrupts always go to the main thread.) i.e., all threads (including main) to catch interrupt exceptions, and propagate that information to other threads. 2. since there is no way to interrupt a sleep (not aware of any), sleep is not the choice. use something else like napping. I mean, take shorter intervals of sleep, check every thing is fine and go back to napping. if something is fishy - go catch it. hope that helps. Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Rhamphoryncus Sent: Thursday, August 14, 2008 2:52 PM To: python-list@python.org Subject: Re: threading On Aug 14, 3:30 am, "Mathieu Prevot" <[EMAIL PROTECTED]> wrote: > 2008/8/13 Parimala <[EMAIL PROTECTED]>: > > > > > Hello, > > > I am using python2.5.1 version to run my test scripts. I want to use > > 'threading' module in my tests. As a startup program, I had run the > > following one. > > > importthreading > > import sys > > import time > > > def hello(): > > i=0 > > try: > > while i<10: > > print "hi" > > time.sleep(1) > > i+=1 > > except KeyboardInterrupt: > > print 'KeyboardInterrupt' > > raise KeyboardInterrupt > > > try: > > thread=threading.Thread(target=hello,args=()) > > thread.start() > > except KeyboardInterrupt: > > print 'KeyboardInterrupt' > > raise KeyboardInterrupt > > > once program starts, problem is.. > > I am not able to abort the thread using (CTRL+C) KeyboardInterrupt. While > > running if I press CTRL+C, it won't generate any exception until the end of > > the execution. Once the execution gets over, it will give "Exception > > exceptions.KeyboardInterrupt in > 'C:\python25\lib\threading.py'> ignored" this message and exits. > > > I had gone through some documents, it says if a thread is joined with > > .join() method then we can't stop that process until it releases the lock > > what it acquired. But in the above program I didn't use .join() method but > > still I am not able to abort the thread. > > > Could you please suggest me how can I abort the thread at any point in time > > using CTRL+C. > > Hi, > > a terminate method is given here:http://sebulba.wikispaces.com/recipe+thread2 > > so you can terminate the thread by: > > (...) > t.start() > (...) > > while True: > try: > #some code > except KeyboardInterrupt: > t.terminate() > break > > Mathieu (For some reason the OP hasn't come through to groups.google.com.. odd) Note that it won't interrupt any blocked I/O, which is often what you need the most. If your threads are CPU-bound you can simply have them check a flag and exit if it becomes True. -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: urldecode function?
afraid not.. simple to create your own, NOTE that key words can be supplied more than once. Hence... import urllib def urldecode(query): d = {} a = query.split('&') for s in a: if s.find('='): k,v = map(urllib.unquote, s.split('=')) try: d[k].append(v) except KeyError: d[k] = [v] return d s = 'Cat=1&by=down&start=1827&start=1234&anotherCat=me%3Dow%7e' print urldecode(s) prints out following and preserves the order of inputs for those keys given more than once as with 'start' key {'start': ['1827', '1234'], 'anotherCat': ['me=ow~'], 'by': ['down'], 'Cat': ['1']} hope that helps.. Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Thursday, August 14, 2008 12:32 PM To: python-list@python.org Subject: urldecode function? hi is there a function that does the opposite of urllib.urlencode? for example urldecode('Cat=1&by=down&start=1827') returns a dictionary with {'Cat':1, 'by':'down','start':1827) thanks The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: SOAPpy and ArrayOfString
for someMethod(Field1 ArrayOf_xsd_string, other_parameters) a call someMethod( ['str1', 'str2', 'str3'], other_parameters) *works for me* with SOAPpy 0.12.0. yes sir it does. in PERL, let alone array types, even for simple types it was hard for me with all the '->', and '$' prefixing for objects and variables. I use following snippet to check arguments, and return types from a wsdl for each method. If any on them is not a simple type, check the wsdl manually for details of the data type. import os, sys, glob from SOAPpy import WSDL def checkwsdl(file): if os.path.isfile(file): print 'wsdl:%s' % file server = WSDL.Proxy(file) for ct, k in enumerate(server.methods.keys()): args =[] rets = [] callInfo = server.methods[k] for ct2, name in enumerate(callInfo.inparams): args.append('%s %s' % (name.name.encode(), name.type[1].encode())) for ct2, name in enumerate(callInfo.outparams): rets.append('%s %s' % (name.name.encode(), name.type[1].encode())) print '%s. %s(%s)\n\treturns(%s)' % ( ct+1, k.encode(), ',\n\t\t'.join(args), ',\n\t\t'.join(rets)) print if __name__ == '__main__' : args = sys.argv[1:] for arg in args: for file in glob.glob(arg): checkwsdl(file) Even though a method may be asking for an array, server may be accepting only up to a certain number of elements in the array. And check the data type for elements in the array. of course I had to tweak a couple of SOAPpy modules to accept long data type, and work from behind a firewall. hope that helps... thanks Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of annu miya Sent: Thursday, August 14, 2008 12:11 PM To: python-list@python.org Subject: SOAPpy and ArrayOfString Hi, In the article below you mention that you were succesful at doing this through perl. Would it be possible to send me the perl code? http://mail.python.org/pipermail/python-list/2007-January/423311.html Thank You Regards Sid The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: updating dictionaries from/to dictionaries
if the values for any of the keys are None, both do not work as can be seen below!!. since both loops are iterating over keys(), 'get' method which would return a '0' for non existing key does not encounter any non-existing keys. import copy, sys foo = { 'one' : 1, 'two' : 2, 'three' : None } bar = copy.deepcopy(foo) try: for key in foo: foo[key] += bar.get(key, 0) except: print 'foo', sys.exc_info()[:2] try: for key in bar: foo[key] += bar[key] except: print 'bar', sys.exc_info()[:2] foo (, TypeError("unsupported operand type(s) for +=: 'NoneType' and 'NoneType'",)) bar (, TypeError("unsupported operand type(s) for +=: 'NoneType' and 'NoneType'",)) hope that helps to clarify both point of views. thanks Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Brandon Sent: Thursday, August 14, 2008 8:35 PM To: python-list@python.org Subject: Re: updating dictionaries from/to dictionaries > (1) iterating over foo: > for key in foo: >foo[key] += bar.get(key, 0) > > (2) iterating over bar: > for key in bar: >foo[key] += bar[key] > > I (again) challenge you to say *why* you feel that the "iterating over > bar" solution will not work. Well if you're going to be clever enough to iterate over bar and then send the results to another dictionary altogether, I obviously cannot put up a good argument on this matter! Thanks for the input, I appreciate it. -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
RE: updating dictionaries from/to dictionaries
by the way, iterating over bar will throw KeyError if that key does not exist in foo. to see that in action, simply set another key in bar after copy.deepcopy stmt in this example.. bar['xtra'] = 0 and re-run fun learning with python... Edwin -Original Message- From: Madari, Edwin Sent: Thursday, August 14, 2008 9:24 PM To: 'Brandon'; python-list@python.org Subject: RE: updating dictionaries from/to dictionaries if the values for any of the keys are None, both do not work as can be seen below!!. since both loops are iterating over keys(), 'get' method which would return a '0' for non existing key does not encounter any non-existing keys. import copy, sys foo = { 'one' : 1, 'two' : 2, 'three' : None } bar = copy.deepcopy(foo) try: for key in foo: foo[key] += bar.get(key, 0) except: print 'foo', sys.exc_info()[:2] try: for key in bar: foo[key] += bar[key] except: print 'bar', sys.exc_info()[:2] foo (, TypeError("unsupported operand type(s) for +=: 'NoneType' and 'NoneType'",)) bar (, TypeError("unsupported operand type(s) for +=: 'NoneType' and 'NoneType'",)) hope that helps to clarify both point of views. thanks Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Brandon Sent: Thursday, August 14, 2008 8:35 PM To: python-list@python.org Subject: Re: updating dictionaries from/to dictionaries > (1) iterating over foo: > for key in foo: >foo[key] += bar.get(key, 0) > > (2) iterating over bar: > for key in bar: >foo[key] += bar[key] > > I (again) challenge you to say *why* you feel that the "iterating over > bar" solution will not work. Well if you're going to be clever enough to iterate over bar and then send the results to another dictionary altogether, I obviously cannot put up a good argument on this matter! Thanks for the input, I appreciate it. -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
any success in compiling mod_python3.3 on cygwin for apache2.2
has any one out there succeeded in compiling/installing mod_python for apache2 and python 2.5. I am using python 2.5 on cygwin. thanks in advance Edwin The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python does not get environment variable when using cron.
source in or execute .profile (or .bash_profile which ever is applicable to you) as a first thing in the cron to get environment variables. hope that helps. Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Eric Wertman Sent: Sunday, August 17, 2008 9:39 PM To: python-list@python.org Subject: Re: Python does not get environment variable when using cron. I'm not sure about the environment variable, but os.uname() should give you what you need otherwise. -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Vmware api
do the ESX server provide any api's or an interactive session may ? thx. Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Eric Wertman Sent: Sunday, August 17, 2008 2:43 PM To: python-list@python.org Subject: Re: Vmware api I would also be interested in anything anyone can offer. I spend some time looking around, and took a fair stab at using the wsdl2py that comes with The ZSI package. Ultimately I couldn't get anything to work, and reverted to using perl (yuk). I'm interested mostly in interrogating the ESX servers to get configuration and performance data, from external hosts. Thanks! Eric -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to delete a line with re?
running this snippet, is blanking out ^abdc$.. what is the issue ? abcd efg hijk lmn $ efg hijk lmn regards Edwin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peng Yu Sent: Sunday, August 17, 2008 11:47 PM To: python-list@python.org Subject: How to delete a line with re? Hi, I want to delete the line with abc in the following program. But the following program does not do what I want. Can somebody let me know how to do it? Thanks, Peng #!/usr/bin/python import re file="""abcd efg hijk lmn """ regex = re.compile("^abcd$", re.MULTILINE) print file, print "$" print regex.sub('', file), -- http://mail.python.org/mailman/listinfo/python-list The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie problem inserting into MySQL
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > ython.org] > On Behalf Of len > Sent: Monday, August 18, 2008 11:55 AM > To: python-list@python.org > Subject: Newbie problem inserting into MySQL > > > Hi All > > I have started a little pet project to learn python and MySQL. The > project involves figuring out all the combinations for a 5 number > lottery and storing the data in a MySQL file. > > The file looks like this; > +--+-+--+-+- > ++ > | Field| Type| Null | Key | Default | > Extra | > +--+-+--+-+- > ++ > | lottryid | int(11) | NO | PRI | NULL| > auto_increment | > | lottryno | char(10)| YES | | NULL > || > | no1 | tinyint(3) unsigned | NO | | NULL > || > | no2 | tinyint(3) unsigned | NO | | NULL > || > | no3 | tinyint(3) unsigned | NO | | NULL > || > | no4 | tinyint(3) unsigned | NO | | NULL > || > | no5 | tinyint(3) unsigned | NO | | NULL > || > | nosum| tinyint(3) unsigned | NO | | NULL > || > | nohits | int(10) unsigned| YES | | NULL > || > +--+-+--+-+- > ++ > > The code looks as follows; > #!/usr/lib/env python > > import MySQLdb > import datetime > > db = MySQLdb.Connection(host="localhost", user="lenyel", > passwd="lsumnler", \ > db="lottery") > > cursor = db.cursor() > > cursor.execute('delete from littlelottery') > > listofrec = [] > > tupcnt = 0 > print "first tuple created" > for a in xrange(1,36): > for b in xrange(2,37): > for c in xrange(3,38): > for d in xrange(4,39): > for e in xrange(5,40): > tupcnt += 1 > thekey = ('%02i%02i%02i%02i%02i' % (a,b,c,d,e)) > mysum = a + b + c + d + e > rectuple = tupcnt, thekey, a, b, c, d, e, mysum, 0 > listofrec.append(rectuple) > if tupcnt % 1 == 0: > print "beginnign of mysql write" > print datetime.datetime.now().time() > cursor.executemany('''insert into > littlelottery > values (?,?,?,?,?,?,?,?,?)''', listofrec) > db.close() > print "end of mysql write" > print datetime.datetime.now().time() > os._exit() > > print "insert into mysql completed" > > i get the following error on insert; > raise errorclass, errorvalue > TypeError: not all arguments converted during string formatting > Script terminated. > > Do I have to covert all of the fields in the tuple records to string > or what? > > Len Sumnler > -- > http://mail.python.org/mailman/listinfo/python-list > statement prepared first and executed many times with exectemany - db API http://www.python.org/dev/peps/pep-0249/ inline statemets can be exeucuted only. hope that helps Edwin The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie problem inserting into MySQL
> -Original Message- > From: Madari, Edwin > Sent: Monday, August 18, 2008 3:03 PM > To: 'len'; python-list@python.org > Subject: Re: Newbie problem inserting into MySQL > > > -Original Message- > > From: > [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] > > ython.org] > > On Behalf Of len > > Sent: Monday, August 18, 2008 11:55 AM > > To: python-list@python.org > > Subject: Newbie problem inserting into MySQL > > > > > > Hi All > > > > I have started a little pet project to learn python and MySQL. The > > project involves figuring out all the combinations for a 5 number > > lottery and storing the data in a MySQL file. > > > > The file looks like this; > > +--+-+--+-+- > > ++ > > | Field| Type| Null | Key | Default | > > Extra | > > +--+-+--+-+- > > ++ > > | lottryid | int(11) | NO | PRI | NULL| > > auto_increment | > > | lottryno | char(10)| YES | | NULL > > || > > | no1 | tinyint(3) unsigned | NO | | NULL > > || > > | no2 | tinyint(3) unsigned | NO | | NULL > > || > > | no3 | tinyint(3) unsigned | NO | | NULL > > || > > | no4 | tinyint(3) unsigned | NO | | NULL > > || > > | no5 | tinyint(3) unsigned | NO | | NULL > > || > > | nosum| tinyint(3) unsigned | NO | | NULL > > || > > | nohits | int(10) unsigned| YES | | NULL > > || > > +--+-+--+-+- > > ++ > > > > The code looks as follows; > > #!/usr/lib/env python > > > > import MySQLdb > > import datetime > > > > db = MySQLdb.Connection(host="localhost", user="lenyel", > > passwd="lsumnler", \ > > db="lottery") > > > > cursor = db.cursor() > > > > cursor.execute('delete from littlelottery') > > > > listofrec = [] > > > > tupcnt = 0 > > print "first tuple created" > > for a in xrange(1,36): > > for b in xrange(2,37): > > for c in xrange(3,38): > > for d in xrange(4,39): > > for e in xrange(5,40): > > tupcnt += 1 > > thekey = ('%02i%02i%02i%02i%02i' % (a,b,c,d,e)) > > mysum = a + b + c + d + e > > rectuple = tupcnt, thekey, a, b, c, d, > e, mysum, 0 > > listofrec.append(rectuple) > > if tupcnt % 1 == 0: > > print "beginnign of mysql write" > > print datetime.datetime.now().time() > > cursor.executemany('''insert into > > littlelottery > > values (?,?,?,?,?,?,?,?,?)''', listofrec) > > db.close() > > print "end of mysql write" > > print datetime.datetime.now().time() > > os._exit() > > > > print "insert into mysql completed" > > > > i get the following error on insert; > > raise errorclass, errorvalue > > TypeError: not all arguments converted during string formatting > > Script terminated. > > > > Do I have to covert all of the fields in the tuple records to string > > or what? > > > > Len Sumnler > > -- > > http://mail.python.org/mailman/listinfo/python-list > > > > statement prepared first and executed many times with > exectemany - db API http://www.python.org/dev/peps/pep-0249/ > inline statemets can be exeucuted only. > > hope that helps > Edwin another thing - cumulative inserts will result, since listofrec is not emptied after each sql execution. regards Edwin The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: who to call a list of method inside the class itself
[EMAIL PROTECTED] wrote: > Hi, > > Is the following code is ok. who to call all method. > It is working but the call to m() without a reference to self seems > strange > > Thanks for your help > > class CustomMethod: > def method1(self): > > def method2(self): > > def method3(self): > > > def getAllMethod(self): > return [self.method1, self.method2, self.method3] > > def applyAll(self): > for m in self.getAllMethod(): > # how to call all methods ? > # is it correct > m() 1. return string names of required methods in getAllMethod return ['method1', 'method2', 'method3'] 2. use gettattr on self and then exetute methods in applyAll def applyAll(self): for method_name in self.getAllMethod(): method = gettattr(self,method_name) method() #execute method now regards. Edwin The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: who to call a list of method inside the class itself
[EMAIL PROTECTED] wrote: > > [EMAIL PROTECTED] wrote: > > > 1. return string names of required methods in getAllMethod > > return ['method1', 'method2', 'method3'] > > 2. use gettattr on self and then exetute methods in applyAll > > def applyAll(self): > > for method_name in self.getAllMethod(): > > method = gettattr(self,method_name) > > method() #execute method now > > why? ensure instance's method invocation with all state information to that point, rather than relying on implemenation. regards. Edwin The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib fails to connect
jlist wrote: > > I found out why. I set a proxy in IE and I didn't know > ActiveState Python use IE proxy! > > > I'm running ActiveState Python 2.5 on Windows XP. It used > > to work fine. Today however I get (10061, 'Connection refused') > > for any site I try with urllib.urlopen(). > switching to urllib2, installing the proxy opener, worked for me. here is the sample. variable names are self explanatory import urllib2 proxy=urllib2.ProxyHandler({"http":'http://'+proxyuser+':'+proxypass+'@'+httpproxy}) opener=urllib2.build_opener(proxy, urllib2.HTTPHandler) urllib2.install_opener(opener) req = urllib2.Request(url, form, headers) fd = urllib2.urlopen(req) print fd.code, fd.info(), fd.read() regards Edwin The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: cx_oracle and commands
gaius hammond Wrote: >Hi all, > > >I am having a very strange problem with cx_Oracle, has anyone >seen this kind of behavior before: > > > >ActivePython 2.5.2.2 (ActiveState Software Inc.) based on >Python 2.5.2 (r252:60911, Mar 27 2008, 18:53:24) [C] on sunos5 >Type "help", "copyright", "credits" or "license" for more information. from commands import getstatusoutput (status, output) = getstatusoutput('ls') status >0 from cx_Oracle import connect, SYSDBA db = connect(mode=SYSDBA) (status, output) = getstatusoutput('ls') >Traceback (most recent call last): > File "", line 1, in > File "/opt/ASpy25/lib/python2.5/commands.py", line 55, in >getstatusoutput >sts = pipe.close() >IOError: [Errno 10] No child processes > > > >Basically, once I have made a connection to Oracle I can no >longer use getstatusoutput(). This is a real problem as >I need to get a list of things to work on from Oracle then >spawn commands to process them... > > >Thanks, > There is no mode parameter to connect. use try-catch around db = connect(mode=SYSDBA) line to see what's going on. Edwin The information contained in this message and any attachment may be proprietary, confidential, and privileged or subject to the work product doctrine and thus protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it and all copies and backups thereof. Thank you. -- http://mail.python.org/mailman/listinfo/python-list