Yes, you should use a for loop in this situation.
Certain functional languages, such as Scheme and various LISP dialects
allow for what is called "tail recursion" which effectively eliminates
this problem by internally converting recursion to iteration. Python
isn't really cut out for heavy recurs
str != ""
returns true if str is NOT the empty string.
str is not None
returns true if str is null (or None as it's called in python).
To check to make sure a string is nonnull and nonempty, do:
str is not None and str != ""
--
http://mail.python.org/mailman/listinfo/python-list
On Mar 25, 1:06 pm, "gslm" <[EMAIL PROTECTED]> wrote:
> Hi!
> I'm too new on phyton.I have installed phyton.But when I write phyton
> command, unfortunately, i can't run.I suppose that it is bacause of
> setting path.But i can't solve.
> Can you help?
You need to set what is called your PATH envir
Tip: don't try learning perl.
I agree the colon is largely redundant, but it's not unreasonable.
--
http://mail.python.org/mailman/listinfo/python-list
It looks like I got readline working. Thanks for the help!
--
http://mail.python.org/mailman/listinfo/python-list
> Have you changed your terminal (either the program itself or its config)
> so that it is no longer sending the correct codes?
I doubt this is the case. Everything works for the bash shell and
common lisp. It's just python acting up.
> When you hit the arrow key, what happens? Do you just get no
Robert Kern wrote:
> tac-tics wrote:
> > I've noticed that in Python 2.5, the interactive prompt does not
> > support intelligent use of arrow keys like 2.4 did (up/down for
> > previous/next statement, left/right for moving the cursor). What
> > exactly is the
I've noticed that in Python 2.5, the interactive prompt does not
support intelligent use of arrow keys like 2.4 did (up/down for
previous/next statement, left/right for moving the cursor). What
exactly is the reason for this and is there an easier fix than
downgradinig to 2.4? Thanks.
--
http://m
> That's not the whole truth. :)
The whole truth is that from a developer's POV, .pyc files are
unimportant.
--
http://mail.python.org/mailman/listinfo/python-list
> Jython is a Java application
That was the intellectual leap I needed to solve the problem. I forgot
that I have total access to Java memory management. It turns out at the
point of slowdown, Java was continually running full GC, causing the
awful loss of performance. I figured out that I was not
I have an application written in jython which has to process a number
of records. It runs fine until it gets to about 666 records (and maybe
that's a sign), and then, it's performance and responsiveness goes down
the toilet. It looks like it's running out of memory and is being
forced to use extend
I have a program which has a GUI front-end which that runs a separate
thread to handle all the important stuff. However, if there is a
problem with the important stuff, I want the GUI to raise a MessageBox
alert to indicate this.
For exceptions, I can simply use a catch-all except statement like:
On Dec 26, 8:53 am, Larry Bates <[EMAIL PROTECTED]> wrote:
> Osiris wrote:
> > what is a usefull IDE for Python on Windows ?
I am a happy user of jEDIT.
--
http://mail.python.org/mailman/listinfo/python-list
Try:
afile = open(filename)
lines = afile.readlines()[:-1] # assigns all except the last element to
a list "lines"
for line in lines:
print line
--
http://mail.python.org/mailman/listinfo/python-list
> > I use 'French units' instead of the term 'metric system' because the
> > latter means 'measurement system,' and of course could validly be
> > applied to _any_ system.Now we know how one contractor ended up using
> > English units when the
> other was using French units and an entire Mars miss
> In musical terms, Python is like a Beatles song, very popular
> and easy to sway and dance to. Lisp is like a Bach fugue.
Very nice analogy.
--
http://mail.python.org/mailman/listinfo/python-list
I think the lesson here is that LISP is the language you use when you
want mathematical elegance and perfection and Python is the language
you use if you want to actually program stuff.
--
http://mail.python.org/mailman/listinfo/python-list
> __len__ is not very special and the
> property len eliminates the redundant parentheses.
One might say the current syntax eliminates the redundant dot.
--
http://mail.python.org/mailman/listinfo/python-list
Strange. It seems to be working just fine now. Maybe I wasn't waiting
for all the symbols to be defined before setting my breakpoint.
On Nov 26, 2:41 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> tac-tics wrote:
> > In the Python debugger (pdb), how do you designate breakpoi
In the Python debugger (pdb), how do you designate breakpoints at the
start of methods?
I've tried:
break methodName
break class.methodName
break object.methodName
but none of these seem to work. What is the trick?
--
http://mail.python.org/mailman/listinfo/python-list
> But of course:
>
> >>> def fun():
> global x = 10
>
> SyntaxError: invalid syntax
> >>>
global x
x = 10
Close enough ^^;
--
http://mail.python.org/mailman/listinfo/python-list
Michael Yanowitz wrote:
> Is it possible to have a static variable in Python -
> a local variable in a function that retains its value.
>
> For example, suppose I have:
>
> def set_bit (bit_index, bit_value):
>static bits = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>bits [bit_index
aljosa wrote:
> is it possible to create transparent text (~50% transparency) on image?
> i'm using the following code to draw text on image:
>
> >>>
> font = ImageFont.truetype(str(self.font_family)+".ttf", self.font_size)
> draw = ImageDraw.Draw(img)
> draw.text((10, 10), self.text, font=font,fil
Simon Forman wrote:
> To me, and perhaps others, "T =
> set(xrange(0, 1, 23))" and "n in T" are somewhat easier to read
> and write than "not n % 23 and 0 <= n < 1", YMMV.
Eh? How is the first easier to read than the second?? You have a nested
function call in the first!
Regardless, test
[EMAIL PROTECTED] wrote:
> Hey there,
> i have been learning python for the past few months, but i can seem to
> get what exactly a lamda is for. What would i use a lamda for that i
> could not or would not use a def for ? Is there a notable difference ?
> I only ask because i see it in code sample
[EMAIL PROTECTED] wrote:
> I love python - I use it as a utility language to complement my C#
> programming every day. However, the reason I do not use it as my
> primary language is - surprise, surprise - not its lack of static type
> checking, but the size of standalone executes (which embed th
Grant Edwards wrote:
> for pete's sake use the comparison operator like god intended.
>
> if 0 <= i <= 1:
I'm assuming you used Python's compound comparison as opposed to the
C-style of and'ing two comparisons together to emphasize the fact it is
god's chosen way of doing this ;-)
--
htt
dwelch91 wrote:
> tac-tics wrote:
> >
> > I'd say the second one. Empty lists are not false. They are empty. Long
> > live dedicated boolean data types.
> >
> Uh, no, empty lists are False in a boolean context:
>
> http://docs.python.org/lib/truth.html
>
> Or even just:
>
> lst = []
>
> ;-)
Indeed.
I'd say the second one. Empty lists are not false. They are empty. Long
live dedicated boolean data types.
--
http://mail.python.org/mailman/listinfo/python-list
Bayazee wrote:
> hi,ThanX
> but i dont want to save the exe file in temp file and run it . i want
> to run it directly from python . maybe such this :
> exec("file("test.exe","rw").read())")
> i want write a cd lock with python tp protect an binary file . and so i
> dont want save it in other temp
Nick Vatamaniuc wrote:
> I really like the set notation idea. Now that sets are first class
> "citizens" along with dicts, lists and tuples I think they should be
> used when it makes sense to use them
In actual usage, though, how often is it strictly required one uses a
set over a list? It is sim
I provide the link below with the conditions that you don't put spaces
between your sentences and the periods which terminate them.
http://wiki.python.org/moin/PythonHosting
--
http://mail.python.org/mailman/listinfo/python-list
> >> What's wrong about arrays of chars?
> >
> > Arrays of chars are dangerous. If you insist, use Python lists of
> > Python "chars" (strings of length 1).
>
> Why are they more dangerous than a self-written mutable string?
I didn't say that. I meant that arrays in the C++ sense are dangerous.
I RTFM harder, and found that paste with an image mask (using the
watermark as the mask) does the trick.
--
http://mail.python.org/mailman/listinfo/python-list
I'm trying to make a simple script which attaches watermarks to every
image in one directory and saves the output image to another. However,
while I understand (in theory at least) what I need to be doing, I
can't figure out where to go from here.
First of all, I have a watermark image and a list
Diez B. Roggisch wrote:
> > Of course, another right way would be to have mutable strings in Python.
> > I understand why strings need to be immutable in order to work with dicts,
> > but is there any reason why (hypothetical) mutable strings should be
> > avoided in situations where they aren't n
I know about os.path.split(), but Is there any standard function for
"fully" splitting a file's pathname? A function that is the opposite of
the os.path.join() function? For example:
>>> ret = myster_function(./foo/bar/moo/lar/myfile.txt)
>>> print ret
['.', 'foo', 'bar', 'moo', 'lar', 'myfile.txt
Use nested list comprehensions:
matrix = [[0.0 for x in xrange(n)] for y in xrange(m)]
This is similar to "float matrix[m][n]" in C.
All cells are independent of each other in doing this.
--
http://mail.python.org/mailman/listinfo/python-list
Philippe Martin wrote:
> I don't know, if I were the genious that made up Python I would not believe
> in any bible (small b)
Take it to alt.religion please.
> I want to learn python.
> I plan to buy a book. I always find printed material more convenient than
> reading on-line tutorials.
I had t
Experimenting, I found that
>>> x.fun = lambda: fun(x)
works as well. Any comments on this way?
--
http://mail.python.org/mailman/listinfo/python-list
> Functions are descriptors[1], and their __get__ method is used to bind
> them to a particular instance::
Thank you muchly.
--
http://mail.python.org/mailman/listinfo/python-list
Python is a crazy language when it comes to object versatility. I know
I can do:
>>> class test:
...def __init__(self):
... pass
>>> x = test()
>>> def fun():
... print "fun"
>>> x.fun = fun
>>> x.fun()
fun
>>>
However, experimenting shows that these attached functions are not
bou
bruce wrote:
> hi...
>
> basic question..
>
> how do i define a multi dimensional array
>
> a[10][10]
I find that list comprehensions are useful for this.
[ [None for x in xrange(10)] for y in xrange(10)]
You could easily write a wrapper for it to clean the syntax a bit.
--
http://mail.pytho
> x = MyClass
> xf = x.f
> while True:
>print xf()
Python has some VERY nasty gotchas concerning parenthesis (or lack
there of).
In the first line here, you assign x = MyClass. That means x becomes an
alias for the class MyClass. not an object like you intended. Look
back
It sounds like you want to use print >>
If you have an open object with a "write" property, you can do
print >> thefile, mystring
and Python will simply redirect the output to "thefile" instead of
sys.stdout.
--
http://mail.python.org/mailman/listinfo/python-list
a wrote:
> can someone tell me how to use them
> thanks
sigh...
You do a google on them:
http://docs.python.org/tut/node7.html#SECTION00714
They are the program equivalent of set builder notation in math:
{x | x in S}
would be written
[x for x in S]
in python.
--
http://
> What am I doing wrong?
Nevermind, I figured it out. -classpath overwrites the classpath
not augments. I needed to use -classpath ".;jython.jar" and it works
fine.
--
http://mail.python.org/mailman/listinfo/python-list
I've got a nice jython application that I wish to freeze. After playing
around with flag settinsg on jythonc, I managed to get it to compile
without warnings or errors, but when I try to run my main class file, I
keep getting the error: Exception in "main" thread,
NoClassDefFoundError. When I just
BartlebyScrivener wrote:
> don't know Jython, but in Python, I think you want:
>
> import os
>
> os.system('mytextfile.txt')
>
> Whatever file you reference should open in the application associated
> with it. At least that's the way it works on Win XP
>
> rd
I didn't think about that. It would pr
49 matches
Mail list logo