Re: [Tutor] Python equivalent of kill -0 PID

2012-04-26 Thread Martin Walsh
On 04/26/2012 02:24 PM, Sean Carolan wrote: In bash you can do this to see if a process is running: [scarolan@kurobox:~/bin]$ kill -0 24275 [scarolan@kurobox:~/bin]$ echo $? 0 Is there a python equivalent? I tried using os.kill() but did not see any way to capture the output. You might

Re: [Tutor] Help with choices for new database program

2010-07-03 Thread Martin Walsh
On 07/03/2010 10:25 AM, Jim Byrnes wrote: Jeff Johnson wrote: [snip] http://dabodev.com/ Please check it out. And go to www.leafe.com and subscribe to the dabo-user email list. I would like to try out Dabo, but I don't see it in the Ubuntu repositories and I would like to avoid using

Re: [Tutor] PIL problem

2010-05-07 Thread Martin Walsh
Jim Byrnes wrote: Running Unbuntu 9.10. The Synaptic Pkg Mgr reports python-imaging - 1.1.6-3ubuntu1 - Python Imaging Library is installed. But trying to import PhotoImage gives these results: from ImageTk import PhotoImage Traceback (most recent call last): File stdin, line 1, in

Re: [Tutor] accessing Postgres db results by column name

2010-04-09 Thread Martin Walsh
Serdar Tumgoren wrote: Hey everyone, Ricardo was nice enough to post his solution as a recipe on ActiveState. For anyone interested in bookmarking it, here's the link: http://code.activestate.com/recipes/577186-accessing-cursors-by-field-name/ Serdar I really like Ricardo's solution

Re: [Tutor] Running a dos program with python

2010-03-10 Thread Martin Walsh
Armstrong, Richard J. wrote: Hello all, This is my first post to the Tutor@python.org mailto:Tutor@python.org mailing list. I am in the process of switching from Matlab to Python and there is one task that I am having a hard time doing and cannot find the answer on the web. I want to write

Re: [Tutor] Example of use of (?Pname) and (?P=name) in Python regular expressions?

2009-11-28 Thread Martin Walsh
Michael Hannon wrote: Greetings. While looking into the use of regular expressions in Python, I saw that it's possible to name match groups using: (?Pname...) and then refer to them using: (?P=name) I'm not sure you've got that quite right. IIUC, the (?P=name) syntax is used

Re: [Tutor] Iterable Understanding

2009-11-23 Thread Martin Walsh
Stephen Nelson-Smith wrote: Martin, def __iter__(self): while True: for logline in self.logfile: heappush(self.heap, (timestamp(logline), logline)) if len(self.heap) = self.jitter: break try:

Re: [Tutor] Iterable Understanding

2009-11-16 Thread Martin Walsh
Stephen Nelson-Smith wrote: Nope - but I can look it up. The problem I have is that the source logs are rotated at 0400 hrs, so I need two days of logs in order to extract 24 hrs from to 2359 (which is the requirement). At present, I preprocess using sort, which works fine as long as

Re: [Tutor] Iterable Understanding

2009-11-15 Thread Martin Walsh
Stephen Nelson-Smith wrote: I think I'm having a major understanding failure. Perhaps this will help ... http://www.learningpython.com/2009/02/23/iterators-iterables-and-generators-oh-my/ snip So in essence this: logs = [ LogFile( /home/stephen/qa/ded1353/quick_log.gz, 04/Nov/2009 ),

Re: [Tutor] Iterable Understanding

2009-11-15 Thread Martin Walsh
Stephen Nelson-Smith wrote: It's unclear from your previous posts (to me at least) -- are the individual log files already sorted, in chronological order? Sorry if I didn't make this clear. No they're not. They are *nearly* sorted - ie they're out by a few seconds, every so often, but they

Re: [Tutor] Not workin!

2009-09-29 Thread Martin Walsh
Luke Paireepinart wrote: In this case you are saying is their input equal to this list with many elements? and the answer is always going to be No because a string won't be equal to a list unless both are empty. I know you probably didn't mean this as it reads, or as I'm reading it, but an

Re: [Tutor] Confusion with $PATH

2009-09-25 Thread Martin Walsh
Wayne wrote: On Fri, Sep 25, 2009 at 11:32 AM, David Eric cii...@gmail.com mailto:cii...@gmail.com wrote: ok this is really weird . . . i tried running the helloworld again, and it doesnt work :/ DTm:~ davidteboul$ echo $PATH PATH$/Library/Frameworks/

Re: [Tutor] Configuaration files and paths?

2009-08-09 Thread Martin Walsh
Allen Fowler wrote: FWIW: When using relative paths I got extra ../../ terms, so I changed join_relative() to: def join_relative(base, path): return os.path.normpath(os.path.join(script_dir(base), path)) Seems to work... Yeah, good catch ... looks great, and thanks for sharing

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Martin Walsh
Allen Fowler wrote: What is the recommended way to configure my application find the various database and/or configuration files it needs? Recommemded by whom? A lot depends on the OS. Apple for example have one set of recommendations for MacOS, Windows has another and Linux has

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Martin Walsh
Allen Fowler wrote: snip As a follow-up question, how do give my modules stored under ./lib access to the data in my ConfigParser object? (For instance, database connection string, storage path, etc.) I guess a global ConfigParser object would work, but that seems wrong. And yet,

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Martin Walsh
Allen Fowler wrote: Something like this ... # lib/mypaths.py # -- import os def script_path(base): return os.path.realpath(os.path.abspath(base)) def script_dir(base): return os.path.dirname(script_path(base)) def join_relative(base, path): return

Re: [Tutor] Configuaration files and paths?

2009-08-06 Thread Martin Walsh
Allen Fowler wrote: Martin Walsh mwa...@mwalsh.org Allen Fowler wrote: As a follow-up question, how do give my modules stored under ./lib access to the data in my ConfigParser object? (For instance, database connection string, storage path, etc.) I guess a global ConfigParser

Re: [Tutor] How to change the working directory in IDLE

2009-06-16 Thread Martin Walsh
Martin Walsh wrote: Elisha Rosensweig wrote: Hi Tutors, Im using Python 2.6.2 and the IDLE tool (also v. 2.6.2). However, when I open the editor I cannot seem to change the directory so as to allow for easy access to my modules. So, for example, the following occurs: os.chdir('/Users

Re: [Tutor] Help..Concatenaton Error

2009-06-11 Thread Martin Walsh
ayyaz wrote: Randy Trahan wrote: Attached is an error I cannot get to work, I was doing a print concatenation but it won't let me get past + ibly impressive. \ (then to next line) Also Programming Lanquage Question: I have studied and an fairly proficient at XHTML and CSS, I tried

Re: [Tutor] recursive glob -- recursive dir walk

2009-06-10 Thread Martin Walsh
spir wrote: Hello, A foolow-up ;-) from previous question about glob.glob(). I need to 'glob' files recursively from a top dir (parameter). Tried to use os.walk, but the structure of its return value is really unhandy for such a use (strange, because it seems to me this precise use is

Re: [Tutor] How o convert spaces into tabs??

2009-06-02 Thread Martin Walsh
vince spicer wrote: regex will do it import re line = re.sub(r\s+, \t, line) print line The above replaces the newline, which reminds me that even seemingly trivial uses of 're' can become not-so-trivial in a hurry. In [1]: import re In [2]: line = '1 2 3 4 5\n' In [3]:

Re: [Tutor] sqlite3 format data from tables

2009-05-23 Thread Martin Walsh
David wrote: David wrote: I have a budget program I am using to learn from. http://linuxcrazy.pastebin.com/f3b301daf I can not figure out how to get the transaction details to return so that it looks nice. It returns like this now. Your transaction History is: [(1, u'Food', -100), (2,

Re: [Tutor] finding difference in time

2009-05-15 Thread Martin Walsh
Kent Johnson wrote: On Fri, May 15, 2009 at 12:46 AM, R K wolf85boy2...@yahoo.com wrote: Gurus, I'm trying to write a fairly simple script that finds the number of hours / minutes / seconds between now and the next Friday at 1:30AM. I have a few little chunks of code but I can't seem to get

Re: [Tutor] Python popen command using cat textfile .... how to terminate

2009-05-14 Thread Martin Walsh
MK wrote: Hi there, i am using this code to send an cat ThisIsMyUrl with popen. Of cos cat now waits for the CTRL+D command. How can i send this command ? def console_command(cmd): print cmd console = os.popen(cmd,r) output = console.read() console.close()

Re: [Tutor] returning the entire line when regex matches

2009-05-04 Thread Martin Walsh
Nick Burgess wrote: So far the script works fine, it avoids printing the lines i want and I can add new domain names as needed. It looks like this: #!/usr/bin/python import re outFile = open('outFile.dat', 'w') log = file(log.dat, 'r').read().split('Source') # Set the line delimiter for

Re: [Tutor] Add newline's, wrap, a long string

2009-04-29 Thread Martin Walsh
David wrote: Martin Walsh wrote: ... but, you don't need to use subprocess at all. How about (untested), # grep USE /tmp/comprookie2000/emerge_info.txt |head -n1|cut -d\ -f2 infof = open('/tmp/comprookie2000/emerge_info.txt') for line in infof: if 'USE' in line: USE

Re: [Tutor] Add newline's, wrap, a long string

2009-04-29 Thread Martin Walsh
Sander Sweers wrote: 2009/4/29 David da...@abbottdavid.com: Here is the whole program so far, what it does is it logs into a druple web site and posts. I would like to make it better, as you can see I do the same thing over and over. http://linuxcrazy.pastebin.com/m7689c088 What you can

Re: [Tutor] finding mismatched or unpaired html tags

2009-04-28 Thread Martin Walsh
A.T.Hofkamp wrote: Dinesh B Vadhia wrote: I'm processing tens of thousands of html files and a few of them contain mismatched tags and ElementTree throws the error: Unexpected error opening J:/F2/663/blahblah.html: mismatched tag: line 124, column 8 I now want to scan each file and simply

Re: [Tutor] finding mismatched or unpaired html tags

2009-04-28 Thread Martin Walsh
error per file per run, but you can run it until there are no errors remaining. I hope that makes sense. HTH, Marty Message: 7 Date: Tue, 28 Apr 2009 08:54:33 -0500 From: Martin Walsh mwa...@mwalsh.org Subject: Re

Re: [Tutor] Add newline's, wrap, a long string

2009-04-28 Thread Martin Walsh
David wrote: I am getting information from .txt files and posting them in fields on a web site. I need to break up single strings so they are around 80 characters then a new line because when I enter the info to the form on the website it has fields and it errors out with such a long string.

Re: [Tutor] Add newline's, wrap, a long string

2009-04-28 Thread Martin Walsh
David wrote: vince spicer wrote: first, grabbing output from an external command try: import commands USE = commands.getoutput('grep USE /tmp/comprookie2000/emege_info.txt |head -n1|cut -d\\-f2') then you can wrap strings, import textwrap Lines = textwrap.wrap(USE, 80) # return a

Re: [Tutor] PDF to text conversion

2009-04-21 Thread Martin Walsh
Robert Berman wrote: Hello Emad, I have seriously looked at the documentation associated with pyPDF. This seems to have the page as its smallest element of work, and what i need is a line by line process to go from .PDF format to Text. I don't think pyPDF will meet my needs but thank you

Re: [Tutor] Sending a disconnect after openssl s_client command?

2009-04-21 Thread Martin Walsh
Kayvan Sarikhani wrote: On Mon, Apr 20, 2009 at 1:17 PM, Martin Walsh mwa...@mwalsh.org mailto:mwa...@mwalsh.org wrote: from subprocess import Popen, PIPE openssl_cmd = 'openssl s_client -ssl2 -connect somewebsitename:443' openssl = Popen( openssl_cmd, shell=True, stdout

Re: [Tutor] Sending a disconnect after openssl s_client command?

2009-04-20 Thread Martin Walsh
Kayvan Sarikhani wrote: Tutors, I'm working on a script to verify whether a particular website supports SSLv2 via the following: --- BEGIN --- #!/usr/bin/python import os, re checkssl_out = open('checkssl.txt','w') website = 'somewebsitename' sslv2 = 'Protocol : SSLv2' print

Re: [Tutor] String Encoding problem

2009-04-20 Thread Martin Walsh
Matt wrote: Hey everyone, I'm hoping someone here can help me solve an odd problem (bug?). I'm having trouble with string encoding, object deletion, and the xml.etree library. If this isn't the right list to be posting this question, please let me know. I'm new to Python and don't know of

[Tutor] PyCon Videos

2009-04-16 Thread Martin Walsh
Hi All, Not sure if it's common knowledge, particularly for those who didn't make it to PyCon this year, but all of the talks were recorded and will be available online in good time, thanks to Carl Karsten and his merry band of A/V volunteers. I can't even begin to grasp how much work is required

Re: [Tutor] list to string and string to list

2009-04-16 Thread Martin Walsh
johnf wrote: On Thursday 16 April 2009 05:04:39 pm Alan Gauld wrote: johnf jfabi...@yolo.com wrote I want to save the list to the field and when I retrieve the string convert it back to a list. But this does NOT work. mylist=[1,2,3,4] mystr=str(mylist) newlist= list(mystr) I keep

Re: [Tutor] list to string and string to list

2009-04-16 Thread Martin Walsh
Martin Walsh wrote: johnf wrote: On Thursday 16 April 2009 05:04:39 pm Alan Gauld wrote: johnf jfabi...@yolo.com wrote I want to save the list to the field and when I retrieve the string convert it back to a list. But this does NOT work. mylist=[1,2,3,4] mystr=str(mylist) newlist

Re: [Tutor] Executing a C Program from RH Linux in Python for Win

2009-03-18 Thread Martin Walsh
Wayne Watson wrote: If you can execute a C program compiled on a Linux with SWIG, then that's what I'm looking for. There's really no RH dependency according to the above posts. If it were compiled on Debian or Ubuntu, it appears it would not make any difference. That is, one could execute a

Re: [Tutor] Modifying Grayson's Example 5_14

2009-03-17 Thread Martin Walsh
Martin Walsh wrote: Wayne Watson wrote: it. It works pretty well, but puts up a a few probably top level windows that are blank. How do I get around them, and is there anything root = Tk() Try adding this, root.withdraw() dialog = GetPassword(root) HTH, Marty

Re: [Tutor] Fun with Label and Entry--Why NoneType?

2009-03-17 Thread Martin Walsh
Wayne Watson wrote: The program below is derived from an example in Grayson for showing how one might a dialog for entering passwords. The structure seems just like the original, down to the use of self, Label and Entry plus . Yet the print here statement produces: here None type

Re: [Tutor] Modifying Grayson's Example 5_14

2009-03-16 Thread Martin Walsh
Wayne Watson wrote: ... it. It works pretty well, but puts up a a few probably top level windows that are blank. How do I get around them, and is there anything ... root = Tk() Try adding this, root.withdraw() dialog = GetPassword(root) HTH, Marty

Re: [Tutor] merging dictionary values based on key

2009-03-12 Thread Martin Walsh
greg whittier wrote: On Thu, Mar 12, 2009 at 4:24 PM, ski nor...@khine.net wrote: mylist = [{'a': 'x123', 'b':'12'}, {'a': 'x234', 'b': 'd33', 'c': 'a23'}, {'a': 'x234', 'c': 'XX123'} ] where mylist has nth number of dictionaries and i want to merge the values of the keys that are the

Re: [Tutor] probelm pyhton shell doesnt open help please

2009-03-08 Thread Martin Walsh
mustafa akkoc wrote: it gives this message socket error image text IDLE's subprocess didn't make a connection. Either IDLE can't start a subprocess or personal firewall software is blocking the connection. /image text IIRC, this was once a known issue with IDLE when combined with the windows

Re: [Tutor] re.format a file

2009-02-26 Thread Martin Walsh
A.T.Hofkamp wrote: prasad rao wrote: helloThank you Lie and Kent. I forgot about newline character and the fact that string can be sliced. Thanks for your timely help BTW I have gone through the Python library reference and find no examples in fileinput module. The fileinput module

Re: [Tutor] Simple CGI script and Apache configuration

2009-02-24 Thread Martin Walsh
wormwood_3 wrote: I wasn't sure if that was needed, so I took it out, sorry about that. I put ScriptAlias /cgi-bin/ /var/www/samuelhuckins.com/cgi-bin/ in place, reloaded, and it works! I think the problem throughout was that I was mixing up what was necessary between CGI and mod_python.

Re: [Tutor] Simple CGI script and Apache configuration

2009-02-23 Thread Martin Walsh
wormwood_3 wrote: Hello all, Hi Sam, I'll try to give as much detail as I can, but this is a somewhat vague problem. I have a very simple script that I would like to implement as a CGI script, just so I can hit a URL and get some output. However, after following a number of tutorials, I am

Re: [Tutor] Simple CGI script and Apache configuration

2009-02-23 Thread Martin Walsh
wormwood_3 wrote: Thanks for all the suggestions! I tried to go through them, and will relate what results I encountered. I changed my Apache config to: Directory /var/www/samuelhuckins.com/cgi-bin/ AllowOverride None Options ExecCGI

Re: [Tutor] Changing the Attribute of a Variable

2009-02-18 Thread Martin Walsh
Marc Tompkins wrote: Also - config_var_list is a tuple of lists. (I'm guessing you intended to make it a list of lists - that's what the name indicates, after all - but putting it between ( ) makes it a tuple.) Sound advice, but a subtle clarification is warranted I think. It's the comma(s)

Re: [Tutor] Reply All Dilemma of This List

2009-02-10 Thread Martin Walsh
Wayne Watson wrote: I belong to many, many forums, Yahoo Groups, (Usenet) newsgroups, and mail lists. Probably 100 or more. I think it's fair to say that none of them but this one has an implicit Reply All. For newsgroups and mail lists, I just press my Mozilla Seamonkey mailer Reply button

Re: [Tutor] Want to write a Perl based IP to Domain Name converter.

2009-01-31 Thread Martin Walsh
wesley chun wrote: The script in the following can do the batch conversion from domain name to IP: This is a Python list, not Perl! OMG! It's my mistake, sorry for this. Lol..thats okay. Now that you are here and have seen what fun we have writing Python code - why not join the party?

Re: [Tutor] Date comparison across time zones

2009-01-13 Thread Martin Walsh
frenc1z 1z wrote: Hello, I would like to compare some dates (date+time really). The dates all have the following RFC2822 format: Eg. is d1 d2? d1 = Tue, 13 Jan 2009 03:27:29 -0800 d2 = Tue, 13 Jan 2009 02:40:00 -0600 My thinking is that I first need to make these two dates

Re: [Tutor] changing string in place

2009-01-09 Thread Martin Walsh
Jon Crump wrote: Dear all, I've been around and around with this and can't seem to conceptualize it properly. I've got a javascript object in a text file that I'd like to treat as json so that I can import it into a python program via simplejson.loads(); however, it's not proper json

Re: [Tutor] changing string in place

2009-01-09 Thread Martin Walsh
Jon Crump wrote: I'm still faced with the problem of the javascript months being 0 indexed. I have to add 1 to group \2 in order to get my acurate date-string. Obviously I can't do print jdate.sub(r'\1-\2+1-\3', s) because the first argument to sub() is a string. How can I act on \2 before

Re: [Tutor] Script to take a screenshot of my website.

2008-12-22 Thread Martin Walsh
Bryan Fodness wrote: I would like to take a screenshot of my website without opening the browser or importing extra packages. Is there a way to do this? Unless you're keen on writing your own html/css/javascript/etc rendering engine, I'm pretty sure you're going to need extra package(s), or a

Re: [Tutor] subprocess adds %0A to end of string

2008-12-21 Thread Martin Walsh
Hi David, David wrote: Hi everyone. Just learning :) I have one program to parse a podcast feed and put it into a file. Welcome! snip def getFeed(): url = raw_input(Please enter the feed: ) data = feedparser.parse(url) for entry in data.entries: sys.stdout =

Re: [Tutor] subprocess adds %0A to end of string

2008-12-21 Thread Martin Walsh
David wrote: Martin Walsh wrote: Welcome! thanks welcome (uh oh, infinite loop warning) This podcast_file.write('%s: %s' % (entry.updated, entry.link)) writes it in one very long string Copy and paste gets me every time. Try this, and note the presence of the newline ('\n

Re: [Tutor] Class Extend Help

2008-12-20 Thread Martin Walsh
Omer wrote: Hey. I'm trying to do something I think is basic and am failing. The goal is: [mimicking the google urlopen syntax] try: from google.appengine.api.urlfetch import fetch except: from urllib import urlopen as fetch How do I add this fetch the property of

Re: [Tutor] listen in on other program's tcp connections

2008-12-16 Thread Martin Walsh
phpfood wrote: On windows XP, I'm running a program that sends TCP connections on port 5039. I'v ran wireshark to determine this. I want to create a simple program that listens for these connections and intercepts and then turns the data transferred into a string. From there I'd obviously like

Re: [Tutor] Newbie Wondering About Threads

2008-12-06 Thread Martin Walsh
Damon Timm wrote: On Sat, Dec 6, 2008 at 6:25 PM, Python Nutter [EMAIL PROTECTED] wrote: I'm on my phone so excuse the simple reply. From what I skimmed you are wrapping shell commands which is what I do all the time. Some hints. 1) look into popen or subprocess in place of execute for more

Re: [Tutor] using windows wide proxy settings

2008-12-03 Thread Martin Walsh
Tim Michelsen wrote: Hello, is there any possibility in python to retrieve the system wide internet connection settings? I would like to access the proxy settings stored in Internet Explorer - Extras - Options - Connection - LAN settings. I wouldn't believe it if I didn't just see it work

Re: [Tutor] array of different datatypes

2008-09-23 Thread Martin Walsh
Reed O'Brien wrote: On Sep 22, 2008, at 11:50 PM, Steve Willoughby wrote: Dinesh B Vadhia wrote: Thanks Steve. How do you sort on the second element of each list to get: a' = [[42, 'fish'], [1, 'hello'] [2, 'world'] ] something like this would do the trick:

Re: [Tutor] Addition, Dictionary, KeysError

2008-09-13 Thread Martin Walsh
Rilindo Foster wrote: Scratch that, I'm a dork: OrderDict[(o[0])] = OrderDict.get(o[0],0) + float(o[1]) http://www.faqts.com/knowledge_base/view.phtml/aid/4571/fid/541 :D For this case you might also be interested in collections.defaultdict, added in python 2.5 I believe. from

Re: [Tutor] Addition, Dictionary, KeysError

2008-09-13 Thread Martin Walsh
Martin Walsh wrote: Rilindo Foster wrote: Scratch that, I'm a dork: OrderDict[(o[0])] = OrderDict.get(o[0],0) + float(o[1]) http://www.faqts.com/knowledge_base/view.phtml/aid/4571/fid/541 :D For this case you might also be interested in collections.defaultdict, added in python 2.5 I

Re: [Tutor] No Blank Separator between Date and Time Valid?

2008-09-11 Thread Martin Walsh
Wayne Watson wrote: This program segment allows an invalid date to go undetected. See below. def set_time_stamp(d1): # /mm/dd hh:mm:ss in, vmmdd_hhmmss.27 out formatin = '%Y/%m/%d %H:%M:%S' d1 = d1.lstrip() try: date1 =

Re: [Tutor] cmd module

2008-09-04 Thread Martin Walsh
Kent Johnson wrote: On Thu, Sep 4, 2008 at 1:00 AM, Tony Cappellini [EMAIL PROTECTED] wrote: I was just reading the PYMOTW article on the cmd module, and trying the examples. http://www.doughellmann.com/PyMOTW/cmd/cmd.html Scroll down to Auto-Completion. Does the tab key work for anyone

Re: [Tutor] Python open of c:\ path Problem

2008-08-23 Thread Martin Walsh
Alan Gauld wrote: Wayne Watson [EMAIL PROTECTED] wrote BTW, how does one continue a long statement that has, say, a long path to a file? You can create a long string by adding the shorter string elements : f = open( a:/very/long/path/name/that/needs/a/whole/line/to./itself.py, w)

Re: [Tutor] something is fundamentally wrong...

2008-08-09 Thread Martin Walsh
Joshua Nikkel wrote: IDLE 1.2.2 No Subprocess s = 'supercalifragilisticexpialidocious' len(s) Traceback (most recent call last): File pyshell#1, line 1, in module len(s) TypeError: 'str' object is not callable My guess would be that you've reassigned the name 'len' to

Re: [Tutor] Raw string

2008-07-21 Thread Martin Walsh
Neven Goršić wrote: I read from one file plenty of parameters and among them one file name of other file. That file name is 'e:\mm tests\1. exp files\5.MOC-1012.exp' and I hold it in variable s. As John pointed out, if you're really reading this string from a file (with something like

Re: [Tutor] continuouse loop

2008-07-19 Thread Martin Walsh
Monika Jisswel wrote: Thanks or your replies, in fact I need my server to recieve queries from some 40 clients, process the recieved text (some calculations) send a response back to them, in my previouse application I used a database, (they entered thier queries into the db my calculating

Re: [Tutor] creating pop method for stack class

2008-07-18 Thread Martin Walsh
Christopher Spears wrote: I see what you mean. I have tested it, and I have gotten a weird result: def shorten(lst): ... lst = lst[:-1] ... lista = [1,2,3,4] shorten(lista) print lista [1, 2, 3, 4] lista = [1,2,3,4] lista = lista[:-1] print lista [1, 2, 3] Strange...why does it work

Re: [Tutor] continuouse loop

2008-07-17 Thread Martin Walsh
Monika Jisswel wrote: Would a program using a continuouse loop such as in this code take up resources on the system if left for long period ? import sys while 1: self.data = sys.stdin.readline() self.function_1(data) Not much, I would think, until something is

Re: [Tutor] parsing sendmail logs

2008-07-15 Thread Martin Walsh
Monika Jisswel wrote: to say the truth I never thought about additional overhead of getting the input/output data transferred because the suprocess itself will contain the (bash)pipe to redirect output to the next utility used not the python subprocess.PIPE pipe so it will be like one

Re: [Tutor] Another assert() question

2008-07-13 Thread Martin Walsh
Dick Moores wrote: At 11:44 AM 7/13/2008, Steve Willoughby wrote: Dick Moores wrote: Yes! A rule, not logic. I'm not contradicting Kent, just helping myself understand. First the rule, then logic in the application of the rule. And I assume the rule is there in Python because it makes things

Re: [Tutor] Another assert() question

2008-07-12 Thread Martin Walsh
Dick Moores wrote: At 07:39 PM 7/12/2008, Kent Johnson wrote: On Sat, Jul 12, 2008 at 6:03 PM, Dick Moores [EMAIL PROTECTED] wrote: At 01:34 PM 7/12/2008, Kent Johnson wrote: In [2]: assert(False, Asserted false) This is assert condition where the condition is a tuple with two

Re: [Tutor] list objects are unhashable

2008-06-30 Thread Martin Walsh
Hi Norman, Norman Khine wrote: for brain in brains: x = getattr(brain, horizontal) x = string.join(x, '' ) y = getattr(brain, vertical) y = string.join(y, '' ) if x and y and (x, y) in table: table[(x,

Re: [Tutor] Problem Euler 26

2008-06-29 Thread Martin Walsh
kinuthiA muchanE wrote: Hi, Hi Kinuthia, I am trying to solve Problem Number 26 (http://projecteuler.net/index.php?section=problemsid=26) on project Euler but apparently the answer I am submitting is wrong. I am a big fan of Project Euler also. Fun stuff. I suspect I have completely

Re: [Tutor] Problem Euler 26

2008-06-29 Thread Martin Walsh
kinuthiA muchanE wrote: (28, '035714286') (38, '026315789') (81, '012345679') For 28, the digit, in the fractional part, after 8 is 5, so 5 is repeated and as for, 81 the next digit after 7 is 0, so again 0 occurs twice. But for 38, the next digit after 9 is 4, and because it has NOT

Re: [Tutor] local variable 'l1' referenced before assignment

2008-06-28 Thread Martin Walsh
Douglas Drumond wrote: In a2() you do l1 += l2, ie, l1 = l1 + l2 A subtle clarification is warranted I think. l1 += l2 is not the same as l1 = l1 + l2, when l1 and l2 are lists. l1 += l2 is an augmented assignment statement, and as such will perform the operation in place if possible, IIUC.

Re: [Tutor] dollarize.py

2008-06-22 Thread Martin Walsh
Jordan Greenberg wrote: def addcommas(s): # assumes type(s)==str b=[] l=len(s) for i,v in enumerate(s): i+=1 # easier to understand w/ 1-based indexing, i think. b.append(v) if (l-i)%3==0 and not i==l: b.append(',') return ''.join(b)

Re: [Tutor] os.waitpid non spawned pid

2008-06-20 Thread Martin Walsh
John [H2O] wrote: Hello, I would like to write a script that would have a command line option of a pid# (known ahead of time). Then I want my script to wait to execute until the pid is finished. How do I accomplish this? I tried the following: #!/usr/bin/env python import os import sys

Re: [Tutor] dollarize.py

2008-06-20 Thread Martin Walsh
Christopher Spears wrote: I'm working on an exercise from Core Python Programming. I need to create a function that takes a float value and returns the value as string rounded to obtain a financial amount. Basically, the function does this: dollarize(1234567.8901) returns- $1,234,567,89

Re: [Tutor] for loop

2008-06-10 Thread Martin Walsh
Sean Novak wrote: I know I'm going to feel stupid on this one.. I would normally write this in PHP like this: for($i=1; i count($someArray); $i++) { print $someArray[i] } essentially,, I want to loop through an array skipping someArray[0] but in python the for syntax is more like

Re: [Tutor] Modifying files in a directory.

2008-05-29 Thread Martin Walsh
[EMAIL PROTECTED] wrote: . soup = BeautifulSoup(html) . ord_tbl_price = soup.find('td', {'class': 'order_tbl_price'}) . ord_tbl_price td class=order_tbl_pricespan class=order_table_price_small /span $32.66/td So now, how do I reduce the price by 15% and write it back to the document? Not

Re: [Tutor] free loop device

2008-05-06 Thread Martin Walsh
Nathan McBride wrote: Yup, I got some help in IRC. What I ended up doing was using regex to pull out each /dev/loopX. Then took the X and fed it to max which in turn gave me the highest numbered loop device in use. After which I then just added 1 to X and added it to the end of /dev/loop_.

Re: [Tutor] seeking help to a problem w/ sockets

2008-04-27 Thread Martin Walsh
James Duffy wrote: I have a problem w/ a file transfer receiver. They way it works is it binds a port for incoming transfer , when the file transfer is complete. It closes the connection and the socket, then loops back and restarts the bind and listen. I have it set so that the socket is

Re: [Tutor] urllib2.urlopen(url)

2008-04-20 Thread Martin Walsh
Monika Jisswel wrote: Hi, can i stop urllib2.urlopen() from following redirects automatically ? It doesn't answer your question directly, but if you care more about the initial request/response than the content at the other end of a redirect -- you can use httplib. It might look something

Re: [Tutor] PyMOTW: difflib

2008-04-06 Thread Martin Walsh
Dick Moores wrote: See http://blog.doughellmann.com/2007/10/pymotw-difflib.html And my try with the Differ example, http://py77.python.pastebin.com/f41ec1ae8, which also shows the error, E:\Python25\pythonw.exe -u E:\PythonWork\demo_pymotw-difflib.py Traceback (most recent call last):

Re: [Tutor] how to get response from os.system()

2008-03-17 Thread Martin Walsh
Hi Nathan, Nathan McBride wrote: Yup I use the pexpect module for a lot however couldn't get 'pexpect.run' to work with mysqldump piping to gzip Just to hazard a guess -- when you want to pipe commands with pexpect you have to spawn ('run', it seems, would work the same way) the shell

Re: [Tutor] Processing unix style timestamp

2008-03-07 Thread Martin Walsh
Ravi Kondamuru wrote: Hi, I have a log file that prints the date and time in the following format: Mon Feb 11 01:34:52 CST 2008 I am expecting multiple timezone entries (eg: PST, PDT and GMT) on the system running in America/Los Angeles time zone. I am looking for a way to internally store

Re: [Tutor] Output of list

2007-12-23 Thread Martin Walsh
János Juhász wrote: It is nice place to use a generator: def pairs(sliceit): streamlist = list(sliceit) streamlist.reverse() while streamlist: pair = streamlist.pop() try:pair += streamlist.pop() except: pass yield pair ## Probably it

Re: [Tutor] Output of list

2007-12-23 Thread Martin Walsh
János Juhász wrote: Dear Marty, Hi Janos, ... Or, by extending Alan's solution ... def splitStringByN(s, n): for m in range(0, len(s), n): yield s[m:m+n] k = 'abcdefghi' list(splitStringByN(k, 2)) It seems to be the most readable solution for me. For completeness, one

Re: [Tutor] Output of list

2007-12-22 Thread Martin Walsh
Ricardo Aráoz wrote: Emil wrote: hey I want to be capable of converting a string into a list where all the items, in the list, have a fixed length not equal to 1 e.g i have k = 'abcdefgh' and I want the fixed length for all the the items to be 2 then the list would look like ['ab',

Re: [Tutor] Selecting a browser

2007-12-03 Thread Martin Walsh
Ricardo Aráoz wrote: Martin Walsh wrote: Hi Marty, thanks for your help. I've tried your suggestions but they don't seem to work for me. In W's system window I can do : C:/ S:\FirefoxPortable\FirefoxPortable.exe http://www.google.com and it will open my browser ok. But no matter what I try

Re: [Tutor] Selecting a browser

2007-12-01 Thread Martin Walsh
Ricardo Aráoz wrote: Hi, I've checked webbrowser module and so far I find no way of selecting a browser other than the default one. Say I want certain places opened with IE and others with Mozilla, and I don't want to mess with the user's setting of the default browser. Any tips? TIA I think

Re: [Tutor] Python on T-Mobile Wing???

2007-11-21 Thread Martin Walsh
Trey Keown wrote: Hey all, I just got a brand new T-Mobile Wing, and, as you might guess, I want to install python on it. Well, I tried both the pythonce main build (with the .exe), and the build for the smartphone (also used .exe), but once I downloaded them, when I tried to run them, a

Re: [Tutor] subprocess help, nohup

2007-11-18 Thread Martin Walsh
John wrote: Hello, Hi John, I didn't see a response to your question, so I'll make an attempt ... I've written a script which conducts several subprocess calls and then ultimately calls a shell script which runs even more programs... my script is using subprocess to execute a few sed

Re: [Tutor] Wrong version of Python being executed

2007-11-12 Thread Martin Walsh
Alan Gauld wrote: Tony Cappellini [EMAIL PROTECTED] wrote I have to switch between 2.3 and 2.5, so to make it easy, I use an environment variable called CURRENT_PYTHON. (someone on this list or the wxPython list told me I should NOT use PYTHONPATH and modify it the way I am using

Re: [Tutor] Wrong version of Python being executed

2007-11-11 Thread Martin Walsh
Tony Cappellini wrote: Martin Walsh mwalsh at groktech.org Sun Nov 11 06:13:10 CET 2007 That is odd. Try using the full path to python, just to be sure: c:\python25\python script.py -- do you get the same behavior? This works just fine- I would expect it to. Actually, I would have

Re: [Tutor] Wrong version of Python being executed

2007-11-10 Thread Martin Walsh
Tony Cappellini wrote: What do you get if you print sys.path from the interpreter? I've printed out sys.path from inside the script as well, and all references to Python25 are replaced with Python23 FWIW- This isn't a problem unique to this script. I've just printed out sys.path from

  1   2   >