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.
--
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 in python?
I
Georg Brandl wrote:
Jeffrey Schwab wrote:
[EMAIL PROTECTED] wrote:
I want the equivalent of this:
if a == yes:
answer = go ahead
else:
answer = stop
def mux(s, t, f):
if s:
return t
return f
But be aware that this is not a complete replacement
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 have
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!
They do if you ever want to read their code
[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, but I couldn't quite get
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 variant is more
[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-Executables]
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:
len(zoo)
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
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...
:)
Not
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 only
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,
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?
Much like
using single-quote in filenames which are perfectly legal in
DOS/Windows
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.
#!/usr/bin/python
#simple guessing game, with numbers
import random
spam = random.randint(1, 100
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...
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 joke names.
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 the root of the problem is.
In the snippet of code below
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 suchlike.
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:
for x
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 to
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. :)
--
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 layout
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
frame - how is such a step fixed? Vertical frame fixings
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
print popen('exit
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 thing, since
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)
while loop:
Whoops. Should be while loop().
print OK
--
http
[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/python-list
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:
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
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 unpythonic in its
[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 = []
else:
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...
Yes it is. Memory is only one type of resource.
Python's garbage collector
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...
Yes it is. Memory is only one type of resource.
Python's garbage collector
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
contexts to free, locks to release, etc. In C
[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
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
which
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 arises in C++?
If you are referring to the sometimes difficult task
[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/Recipe/190465
[EMAIL PROTECTED] wrote:
hi
i have fucntion that generates a HTML page
def genpage(arg1,arg2):
print ''' div align=rightfont size=-1BLAH BLAH.%s %s
''' % (arg1, arg2)
print ''' table blah blah... %s %s
/table''' % (arg1,arg2)'
The func is something
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 such
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 stupider than spam.
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.split(
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 %.4d, but
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
--
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. Further issues
[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 in the
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,
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 Python
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.
--
[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.
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 self. Use other.
Are you serious?
Are you
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 doing this:
f = file('...')
for line
53 matches
Mail list logo