Re: Software Needs Less Idiots

2006-05-21 Thread Jeffrey Schwab
David Steuber wrote: > "PofN" <[EMAIL PROTECTED]> writes: > >> Xah Lee wrote: >>> Software needs philosophers. >> No, software neds less idiots. So please take your medication and >> change profession. > > Perhaps fewer would do. Thank you. I didn't want to be "that guy." -- http://mail.python

Re: Python, equivalent of set command

2006-03-27 Thread Jeffrey Schwab
loial wrote: > In unix shell script I can do the following to get the status and > values returned by a unix command > > OUTPUT=`some unix command` > STATUS=$? > if [ $STATUS -ne 0 ] > then > exit 1 > else > set $OUTPUT > VAL1=$1 > VAL2=$2 > VAL3=$3 > fi > > How can I achieve the same i

Re: Can I use a conditional in a variable declaration?

2006-03-19 Thread Jeffrey Schwab
Georg Brandl wrote: > Jeffrey Schwab wrote: >> [EMAIL PROTECTED] wrote: >> >>> I want the equivalent of this: >>> >>> if a == "yes": >>>answer = "go ahead" >>> else: >>>answer = "stop" >&

Re: Can I use a conditional in a variable declaration?

2006-03-18 Thread Jeffrey Schwab
[EMAIL PROTECTED] wrote: > I want the equivalent of this: > > if a == "yes": >answer = "go ahead" > else: >answer = "stop" > > in this more compact form: > > a = (if a == "yes": "go ahead": "stop") > > is there such a form in Python? I tried playing around with lambda > expressions, bu

Re: Is there no end to Python?

2006-03-18 Thread Jeffrey Schwab
Jeffrey Schwab wrote: > Steve Holden wrote: >> No need for flames. I'll content myself with pointing out that most >> 1.5.2 programs will run unchanged in 2.5, so the backwards >> compatibility picture is very good. Nobody makes you use the new >> features! >

Re: Is there no end to Python?

2006-03-18 Thread Jeffrey Schwab
Steve Holden wrote: > kpp9c wrote: >> I find that if i use >> other folks code, collaborate, or get help from other folks i still >> have to know all the new constructs that i don't often use, and i >> really struggle with iterators and generators and some of the newer >> things and folks seem to

Re: Python execution problem

2006-03-17 Thread Jeffrey Schwab
[EMAIL PROTECTED] wrote: > Using OSX 10.4.5 > > This is more of a unix/tcsh question than a python question. > Somehow I got to the point where I have two files 'a.py' and 'b.py' > which have identical contents and permissions, but one refuses to > execute: > > [blah:/Library/WebServer/CGI-Execut

Re: Counting nested loop iterations

2006-03-17 Thread Jeffrey Schwab
Fredrik Lundh wrote: > Joel Hedlund wrote: > >> I've been thinking about these nested generator expressions and list >> comprehensions. How come we write: >> >> a for b in c for a in b >> >> instead of >> >> a for a in b for b in c >> >> More detailed example follows below. >> >> I feel the latter

Re: Xah's Edu Corner: The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations

2006-03-16 Thread Jeffrey Schwab
SamFeltus wrote: > """Not that Mr. Lee has ever shown much interest in feedback, but you > pretty well have stick to vanilla ASCII to get your notation through > unmangled on newsgroups.""" > > It is the 21st century, so having to do that oughta inspire some sort > of well earned anti Unix rant...

Re: Counting nested loop iterations

2006-03-16 Thread Jeffrey Schwab
Derek Basch wrote: >> Depending on the types of the containers in question, you could use: >> >> len(zoo) * len(animal) > > I think this would give me the total iterations but I wouldn't be able > to get a running count. Correct? Correct. If you need a running count, maintain a counter (or

Re: Counting nested loop iterations

2006-03-16 Thread Jeffrey Schwab
Derek Basch wrote: > What is the best way to count nested loop iterations? I can only figure > to use an index but that seems kludgy. > > index = 0 > for animal in zoo: > for color in animal: > index += 1 Depending on the types of the containers in question, you could use: le

Re: why does close() fail miserably on popen with exit code -1 ?!

2006-03-03 Thread Jeffrey Schwab
Tobiah wrote: > phase:toby:~> echo 'exit -1' | bash > phase:toby:~> echo $? > 255 http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/exitcodes.html Exit Code Number: 255 [1] Meaning: Exit status out of range Example: exit -1 Comments: exit takes o

Re: sort one list using the values from another list

2006-02-26 Thread Jeffrey Schwab
Brian Blais wrote: > Hello, > > I have two lists, one with strings (filenames, actually), and one with a > real-number > rank, like: > > A=['hello','there','this','that'] > B=[3,4,2,5] > > I'd like to sort list A using the values from B, so the result would be > in this example, > > A=['this'

Re: spaces at ends of filenames or directory names on Win32

2006-02-25 Thread Jeffrey Schwab
Larry Bates wrote: > Jeffrey Schwab wrote: > >>Larry Bates wrote: >> >> >>>IMHO leading and/or trailing spaces in filenames is asking for >>>incompatibilities with cross-platform file access. >> >>With what platforms specifically? >>

Re: "Temporary" Variable

2006-02-24 Thread Jeffrey Schwab
Steven D'Aprano wrote: > On Fri, 24 Feb 2006 00:24:25 +, Jeffrey Schwab wrote: > > >>Steven D'Aprano wrote: >> >>>On Thu, 23 Feb 2006 12:05:59 -0800, darthbob88 wrote: >>> >>>My comments inserted inline. >>> >>> >

Re: "Temporary" Variable

2006-02-23 Thread Jeffrey Schwab
Steven D'Aprano wrote: > On Thu, 23 Feb 2006 12:05:59 -0800, darthbob88 wrote: > > My comments inserted inline. > > > >>#!/usr/bin/python >>#simple guessing game, with numbers >>import random >>spam = random.randint(1, 100) > > > It is bad programming practice to give variables uninformative

Re: spaces at ends of filenames or directory names on Win32

2006-02-23 Thread Jeffrey Schwab
Larry Bates wrote: > IMHO leading and/or trailing spaces in filenames is asking for > incompatibilities with cross-platform file access. With what platforms specifically? > Much like > using single-quote in filenames which are perfectly legal in > DOS/Windows, but Linux doesn't like much. Uh...

Re: new wooden door step - fixing and finishing

2006-02-22 Thread Jeffrey Schwab
Jeffrey Schwab wrote: > jkn wrote: > >> Hi all >> I'm considering having a go at replacing the wooden door step to >> our back door. The original is loose and rotting. >> >> I'm sure some of this will be clearer when I remove the (metal) door

Re: new wooden door step - fixing and finishing

2006-02-22 Thread Jeffrey Schwab
jkn wrote: > Hi all > I'm considering having a go at replacing the wooden door step to > our back door. The original is loose and rotting. > > I'm sure some of this will be clearer when I remove the (metal) door > frame - how is such a step fixed? Vertical frame fixings? Depends on your layou

Re: list assignment

2006-02-22 Thread Jeffrey Schwab
Raymond Hettinger wrote: >> [spam, ham] = ['yum', 'YUM'] >> >>I don't see how this is any different than a tuple unpacking assignment: >> >> >>> a, b = 1, 2 > > > It's not different. They are ways of writing the same thing. TMTOWTDI, after all. :) -- http://mail.python.org/mailman/list

Re: How to force creation of a .pyc?

2006-02-22 Thread Jeffrey Schwab
mrstephengross wrote: > I would like to distribute a python program, but only in .pyc form (so > that people cannot simply look at my code). Is there a way to do this? > I've read up a little on the logic by which python creates .pyc's, and > it sounds like python requires the main executed program

Re: Basic coin flipper program - logical error help

2006-02-22 Thread Jeffrey Schwab
wes weston wrote: > DannyB wrote: > >> I'm just learning Python. I've created a simple coin flipper program - ... > Dan, >Looping is easier with: > for x in range(100): >if random.randint(0,1) == 0: > heads += 1 >else: > tails += 1 > Or, continuing with that theme:

Re: That's really high-level: bits of beautiful python

2006-02-22 Thread Jeffrey Schwab
Max wrote: > I have a friend who has been programming in C for many years, and he is > a great fan of the language. However, he (and I) are about to start a > python course, and he has been asking me a lot of questions. He often > responds to my answers with "Urgh! Object-orientation!" and suchl

Re: why does close() fail miserably on popen with exit code -1 ?!

2006-02-22 Thread Jeffrey Schwab
Atanas Banov wrote: > Jeffrey Schwab wrote: > >>_PyPclose returns the exit status of the popened process (the popenee?), >>or -1 on error. Of course, if the status is supposed to be -1, there's >>some confusion. > > > yes, that's what i thought

Re: why does close() fail miserably on popen with exit code -1 ?!

2006-02-20 Thread Jeffrey Schwab
Atanas Banov wrote: > i ran onto this weirdness today: seems like close() on popen-ed > (pseudo)file fails miserably with exception instead of returning exit > code, when said exit code is -1. > > here is the simplest example (under Windows): > > print popen('exit 1').close() > > 1 > p

Re: define loop statement?

2006-02-18 Thread Jeffrey Schwab
Jeffrey Schwab wrote: > class Loop: > def __init__(self, n): > self.n = n > def __call__(self): > self.n = self.n - 1 > return self.n != 0 > > > if __name__ == '__main__': > loop = Loop(10) >

Re: define loop statement?

2006-02-18 Thread Jeffrey Schwab
David Isaac wrote: > I would like to be able to define a loop statement > (nevermind why) so that I can write something like > > loop 10: > do_something > > instead of > > for i in range(10): > do_something > > Possible? If so, how? Ruby and Smalltalk are both good at this kind of thi

Re: Shortest prime number program

2006-02-11 Thread Jeffrey Schwab
[EMAIL PROTECTED] wrote: > swisscheese wrote: > >>r=range(2,99) >>m=[x*y for x in r for y in r] >>[x for x in r if not x in m] > > > How about: > > [2]+[x for x in range(1,99) if 2**x%x==2] 43. I'll be chewing on this one for a while. Thank you. :) -- http://mail.python.org/mailman/listinfo

Re: OS.MKDIR( ) Overwriting previous folder created...

2006-02-02 Thread Jeffrey Schwab
Ernesto wrote: > I couldn't find this with a search, but isn't there a way to overwrite > a previous folder (or at least not perform osmkdir( ) if your program > detects it already exists). Thanks ! Would something like this help? import os def failsafe_mkdir(dirname): try: os.mkdir

Re: triple quoted strings as comments

2006-01-31 Thread Jeffrey Schwab
Steve Holden wrote: > dmh2000 wrote: > >> I recently complained elsewhere that Python doesn't have multiline >> comments. > > > Personally I think it's a win that you couldn't find anything more > serious to complain about :-) +1 QOTW -- http://mail.python.org/mailman/listinfo/python-list

Re: While loop - print several times but on 1 line.

2006-01-26 Thread Jeffrey Schwab
Danny wrote: > Great! It's been solved. > > The line, as Glaudio said has a "," at the end and that makes it go onto > one line, thanks so much man! > > var = 0 > while <= 5: > print a[t[var]], > var = var +1 > prints perfectly, thanks so much guys. Looping over indexes is kinda unpyth

Re: advice : how do you iterate with an acc ?

2005-12-02 Thread Jeffrey Schwab
[EMAIL PROTECTED] wrote: > hello, > > i'm wondering how people from here handle this, as i often encounter > something like: > > acc = []# accumulator ;) > for line in fileinput.input(): > if condition(line): > if acc:#1 > doSomething(acc)#1 > acc = []

Re: ownership problem?

2005-11-21 Thread Jeffrey Schwab
Donn Cave wrote: > In article <[EMAIL PROTECTED]>, > Jeffrey Schwab <[EMAIL PROTECTED]> wrote: > > >>Yes it is. Memory is only one type of resource. There are still files >>and sockets to close, pipes to flush, log messages to be printed, GDI >&

Re: ownership problem?

2005-11-21 Thread Jeffrey Schwab
Fredrik Lundh wrote: > Jeffrey Schwab wrote: > > >>>>>the problem isn't determining who owns it, the problem is determining >>>>>who's supposed to release it. that's not a very common problem in a >>>>>garbage-collected

Re: ownership problem?

2005-11-21 Thread Jeffrey Schwab
Fredrik Lundh wrote: > Jeffrey Schwab wrote: > > >>>the problem isn't determining who owns it, the problem is determining >>>who's supposed to release it. that's not a very common problem in a >>>garbage-collected language... &

Re: about list

2005-11-20 Thread Jeffrey Schwab
[EMAIL PROTECTED] wrote: > Shi Mu wrote: > >>How to run a function to make [1,2,4] become [[1,2],1,4],[2,4]]? >>Thanks! > > > You want [[1,2],[1,4],[2,4]]? That is, all combinations of 2 items > from > the list? You might want to look at: > http://aspn.activestate.com/ASPN/Cookbook/Python/Reci

Re: ownership problem?

2005-11-20 Thread Jeffrey Schwab
Fredrik Lundh wrote: > Jeffrey Schwab wrote: > > >>>Is it correct to say that the typical ownership problem, which >>>frequently arises in C++, does not occur normally in Python? >> >>What "typical ownership problem" do you feel frequently arise

Re: ownership problem?

2005-11-20 Thread Jeffrey Schwab
Gabriel Zachmann wrote: > Is it correct to say that the typical ownership problem, which > frequently arises in C++, does not occur normally in Python? What "typical ownership problem" do you feel frequently arises in C++? If you are referring to the sometimes difficult task of determining whic

Re: PATH environment variable

2005-11-20 Thread Jeffrey Schwab
[EMAIL PROTECTED] wrote: > O/S: Win2K > Vsn of Python:2.4 > > Based on a search of other posts in this group, it appears as though > os.environ['PATH'] is one way to obtain the PATH environment variable. > > My questions: > 1) is it correct that os.environ['PATH'] contains the PATH environment >

Re: generate HTML

2005-11-14 Thread Jeffrey Schwab
[EMAIL PROTECTED] wrote: > hi > i have fucntion that generates a HTML page > > def genpage(arg1,arg2): >print ''' BLAH BLAH.%s %s > ''' % (arg1, arg2) > >print ''' blah blah... %s %s > > ''' % (arg1,arg2)' > > The func is something like that, alot of open'''

Re: Job - PYTHON Engineers, BitTorrent, Inc., San Francisco, CA

2005-11-11 Thread Jeffrey Schwab
camdenjobs wrote: > PYTHON Engineers, BitTorrent, Inc., San Francisco, CA > > Interested candidates should forward their resumes to ... > Please understand that due to the large volume of responses, I will > not be able to acknowledge each of you individually. Now, that's confidence! May su

Re: Pythonising the vim (e.g. syntax popups) -> vimpst

2005-11-09 Thread Jeffrey Schwab
Roman Roelofsen wrote: >>Evening, >> >>Is there a decent way to get that help into vim? Or like showing docstrings >>or help that I get through pydoc on request? I've been working myself >>through a pile of vim macros/plugins but couldn't find even one which >>simplifies programming in Python. Furt

Re: Floating numbers and str

2005-11-09 Thread Jeffrey Schwab
Tuvas wrote: > Wait, one more question. If the number is something like: > > 1.32042 > > It is like > "1.32 stuff" > > I would like it's size to remain constant. Any way around this? s/%g/%f >>> print "%.4f stuff" % 1.3241414515 1.3241 stuff >>> print "%.4f stuff" % 1.32042 1.3204 stuff >>>

Re: Floating numbers and str

2005-11-09 Thread Jeffrey Schwab
Tuvas wrote: > I would like to limit a floating variable to 4 signifigant digits, when > running thorugh a str command. Ei, > > > x=.13241414515 > y=str(x)+" something here" > > But somehow limiting that to 4 sign. digits. I know that if you use the > print statement, you can do something like %

Re: Pythonising the vim (e.g. syntax popups)

2005-11-09 Thread Jeffrey Schwab
Christoph Haas wrote: > Evening, > > I'm an addicted vim user and don't really use the IDLE for anything more > than calculations where I'm too lazy to start KCalc. But one feature is > very pretty: the built-in help for function calls while you type. Like you > enter... > > var1,var2=mystring

Re: Python doc problem example: gzip module (reprise)

2005-11-09 Thread Jeffrey Schwab
Mike Meyer wrote: > "Xah Lee" <[EMAIL PROTECTED]> writes: > > >>Newsgroups: comp.lang.perl.misc >>PS: I won't cross-post as I'm not subscribed to the Python group. > > > Very wisely done. Then from Xah Lee, we get; > > >>I have cross posted it for you. > > > Proving once again that he's stu

Re: Invoking Python from Python

2005-11-08 Thread Jeffrey Schwab
John Henry wrote: > Hi all, > > I have a need to create a Python script on the fly from another Python > program and then execute the script so created. Do I need to invoke > Python through os.spawnl or is there a better way? Could you import the generated script? This might be the way to go if

Re: which feature of python do you like most?

2005-11-08 Thread Jeffrey Schwab
[EMAIL PROTECTED] wrote: > which feature of python do you like most? > > I've heard from people that python is very useful. > Many people switch from perl to python because they like it more. > > I am quite familiar with perl, I've don't lots of code in perl. > Now, I was curious and interested i

Re: Using python for writing models: How to run models in restricted python mode?

2005-11-07 Thread Jeffrey Schwab
vinjvinj wrote: > I have so many things to do to get this to production and writing a > mini language would be a full project in itself. :-<. > > Is there an easy way to do this? If not, I'll go with the steps > outlined in my other post. Do you really think it will be faster to start parsing Pyt

Re: Using Which Version of Linux

2005-11-05 Thread Jeffrey Schwab
[EMAIL PROTECTED] wrote: > ok, i m going to use Linux for my Python Programs, mainly because i > need to see what will these fork() and exec() do. So, can anyone tell > me which flavour of linux i should use, some say that Debian is more > programmer friendly, or shold i use fedora, or Solaris.

Re: Python doc problem example: gzip module (reprise)

2005-11-05 Thread Jeffrey Schwab
Xah Lee wrote: > i've read the official Python tutorial 8 months ago, have spent 30 > minutes with Python 3 times a week since, have 14 years of computing > experience, 8 years in mathematical computing and 4 years in unix admin > and perl I can wiggle my ears. -- http://mail.python.org/mailman/

Re: when and how do you use Self?

2005-11-03 Thread Jeffrey Schwab
bruno at modulix wrote: > Steven D'Aprano wrote: > >>On Thu, 03 Nov 2005 10:14:23 +0100, bruno at modulix wrote: >> >> >> >>>Tieche Bruce A MSgt USMTM/AFD wrote: >>> >>> I am new to python, Could someone explain (in English) how and when to use self? >>> >>>Don't use se

Re: extracting numbers from a file, excluding words

2005-11-01 Thread Jeffrey Schwab
Steve Horsley wrote: > Kristina KudriaĊĦova wrote: > >> 1 Nov 2005 09:19:45 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]>: >> >>> Hi, I have a file with this content: >>> >>> z zzz z >>> ... >>> xxx xx x 34.215 >>> zzz zz >>> ... >>> >> >> Hi, >> >> I'd suggest