from datetime import datetime
# batteries included
today = datetime.now()
xmas = datetime(today.year,12,25)
if (xmas - today).days > 1:
print "%d days until Christmas" % (xmas - today).days
else:
print "Merry Christmas!"
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 14, 6:01 pm, "Calvin Spealman" <[EMAIL PROTECTED]> wrote:
>
> attribute access (foo.bar) binds more tightly than subscripting (foo[bar]).
That certainly looks right, and in retrospect I wonder that I even
doubted it. But even the official docs seem to me to specify
otherwise:
http://docs.
I wrote some code to test the precedence of getitem vs getattr; it
shows that getitem binds tighter.
I have been handed some code that relies on the observed behavior.
However, the Nutshell precedence list claims the opposite. Is the
Nutshell wrong or am I missing something or is this a bug?
clas
I think you are talking about "screen scraping".
Your program can get the html for the page, and search for an
appropriate pattern.
Look at the source for a YouTube view page and you will see a string
var embedUrl = 'http://
You can write code to search for that in the html text.
These answers are too elaborate and abstract for the question.
Emmanouil,
Here is a program "myprog" which takes input and writes output to a
file. It happens to be python but it could be anything.
#
#!/usr/bin/env python
a = int(raw_input("enter thing 1 "))
b = int(raw_input("enter thing 2
Thanks all! What a remarkable set of answers, intelligent, thought
provoking and informative without exception.
Of course, now I can't use Paul's version; it hardly counts as a japh
if someone else wrote it! It is probably the closest to my original
vision, alas. Miles' second suggestion was the o
I came across the "japh" concept today and decided to do one of my
own, obviously, interpreting the 'p' somewhat loosely,
http://en.wikipedia.org/wiki/JAPH
but I'm not entirely satisfied with it:
# japh, for certain values of 'p'
f=lambda(r,N):N and f((" acdefijlmnopqrstuv"[N%19]+r,N/19))o
http://effbot.org/zone/python-objects.htm still says it best.
mt
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 11, 8:40 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> Read the OP's post again. His (her?) users aren't expected to create the
> toolkit, merely to use it. To create good toolkits you need both a master
> programmer and an expert in the field. It is an advantage if th
On Jan 11, 6:15 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> Your users are *scientists*, and you don't trust their intellectual
> ability to learn a programming language as simple as Python?
>
> Instead of spending time and effort writing, debugging and maintaining
> such a
Perhaps what you are looking for is here:
http://www.scipy.org/Mailing_Lists
mt
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 19, 11:51 pm, James Stroud <[EMAIL PROTECTED]> wrote:
> What's wrong with just saying the current indent level? I'd much rather
> hear "indent 4" than "tab tab tab tab".
Alternatively, you might also consider writing a simple pre and
postprocessor so that you could read and write python th
http://diveintopython.org/
mt
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 4, 9:32 am, Neil Cerutti <[EMAIL PROTECTED]> wrot
> With Python, you won't find anything like that. Python is too
> huge.
That's silly. Python is small in the sense that C is small. The Python
standard library is probably much bigger than the C standard library,
but Kernghan and Richie don
It appears to be correct for positive numbers.
if conval >= 2**16:
conval -= 2**32
would appear to patch things up.
It's not very pretty, though. You could at least start with
input1 = [c_ushort(item) for item in input]
instead of your first 9 lines.
mt
--
http://mail.python.org/mailman/
On May 24, 5:03 am, Richard Jones <[EMAIL PROTECTED]>
wrote:
> Michael Tobis wrote:
> >http://tinyurl.com/yr62r3
>
> > seems to short-circuit some pointless hoop-jumping to get you to the
> > article.
>
> Hoop-jumping implemented to prevent just this kind of d
Is education Python's killer app? I think it could be.
I used the occasion of the Python Papers to motivate my efforts, and
you can see what I came up with here on pages 8-15.
The part that makes me especially queasy is the CP4E section on pages
10-11. I wish I had more to say there. It's fairly
Different strokes for different folks.
You might get better advice about where to start if you tell us a bit
about yourself. Do you have any other programming experience? Do you
have specific goals in mind as a programmer?
mt
--
http://mail.python.org/mailman/listinfo/python-list
I think
http://www.diveintopython.org/
would be very suitable for you.
mt
--
http://mail.python.org/mailman/listinfo/python-list
> Doing a Ctrl+C
> interrupt would be a not-so-clean-way of performing such a thing, and
> it would quit the application altogether. I'd rather have the function
> return a status object of what it has accomplished thus far.
Just in case you are unaware that you can explicitly handle ^C in your
py
On May 9, 2:41 pm, [EMAIL PROTECTED] wrote:
> On May 9, 1:13 am, Charles Sanders <[EMAIL PROTECTED]>
> wrote:
> > or even this monstrosity ...
>
> > def permute2( s, n ):
> >return [ ''.join([ s[int(i/len(s)**j)%len(s)]
> > for j in range(n-1,-1,-1)])
> >for i in range(len(s)**n)
Thanks castironpi and alex, for this:
def p(a,b):
if not b: return ['']
return [i+j for i in a for j in p(a,b-1)]
That is a thing of beauty! As usual you guys didn't disappoint.
(Validity check of alphabet removed; you didn't check for duplicate
characters.)
Here is the bloated
I want a list of all ordered permutations of a given length of a set
of tokens. Each token is a single character, and for convenience, they
are passed as a string in ascending ASCII order.
For example
permute("abc",2)
should return ["aa","ab","ac","ba","bb","bc","ca","cb","cc"]
and permute("135
I think it's pretty clear that we aren't understanding what you mean
by "open a text file and disply its content".
I conclude that by "edna" you mean this thing: http://edna.sourceforge.net/
I suspect you are not asking a Python question at all.
Did you try opening
file:edna-0.6/templates/d
I feel obligated to fan the flames a bit by pointing to
http://www.fortranstatement.com/ a site which advocates discontinuing
development of Fortran and does a good job of summarizing the problems
with the contemporary development of that language.
I am not convinced that a new high performance la
_ wrote:
> (I did google for this, I promise)
>
> How do I get python NOT to insert newlines into string representations
> of lists when I do something like this:
>
> strCollector += "%s" % (['a', 'list', 'with', 'lots', 'of', 'elements']
> * 100)
It shouldn't and doesn't insert newlines.
##
I am not happy with any of the Python-as-a-First-Language books out
there. My vague inclination to write one has not yet formed into a firm
intention, but it's close.
Of the books that are out there, Learning Python and Dive Into Python
are best for the hobbyist as opposed to classroom setting, bu
OT, sort of, but...
[EMAIL PROTECTED] wrote:
>If that
> quoting mechanism is available on the web interface and I haven't found
> it - I'd love to know how to use it.
Click "show options" and THEN hit "reply". It's a bit counterintuitive,
but the entire message to which you reply is then shown.
> According to your silly rule the shortest book on a subject would be the
> best. Now why is that false?
No, according to the rule, the shorter of two books **containing the
same information** would be best.
I don't think I'm a zealot. The original quote said "all else equal".
Certainly legible
John Bokma wrote:
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> > Ok I'm going to end with a flamebait - but I would posit, ALL OTHER
> > THINGS BEING EQUAL - that a smaller number of characters and lines in
> > code is more maintainable than larger number of characters and lines in
> > the c
Sorry, data about reports about X *is* data about X unless you believe
the reports are uninfluenced by X. Like any proxy measure, it
introduces noise and uncertainty, but it is still data.
I can't imagine a motivation for Edward to make this up, so I accept
his anecdotes as data.
While it is poss
"The plural of anecdote is not data."
It's a pithy quote, but it isn't QOTW in my book, simply because it
isn't true in general. Talk to some paleoclimatologists.
There is no way to get uniform measures of ancient climate. What should
we do then? Should we ignore the information we have? Are the
I think by "regular expressions" you mean "expressions". "regular
expressions" are what you get from "import re" .
mt
--
http://mail.python.org/mailman/listinfo/python-list
A more Monty sort of Python logo would be fine with me. A flying sheep
perhaps? An exploding penguin? A giant hedgehog? A dog license with the
word "dog" crossed out and "cat" written in crayon? A great big book on
how to put your budgie down?
This http://www.informatik.uni-trier.de/~roth/bilder/m
www.pygame.org
Yes but he obviously wants this to be delivered to the browser. (Also
the site is broken today... )
This comes up a lot, but I don't think there's an answer to it as yet.
mt
--
http://mail.python.org/mailman/listinfo/python-list
> Not that I'm disagreeing, but how to you rate "resonance with the product"?
Hmm, I'm not a marketing professional, but this is would I would do
with my focus groups:
Ask people familar with the product to name what they like about the
image, and what they like about the product, and look for an
> Sorry dude, but it looks like a hairdryer!
I'm afraid you have a point :-/ .
> I think that the current logo is fine. Much more professional than the old
> image.
Yes, it is a MUCH more professional rendering than the old image, and
it leaves a MUCH better first impression of the homepage.
T
Don't you think the Python Boys ought to have something to say about
it?
Eric Idle is going to be at my favorite Borders bookstore in half an
hour. Should I go ask him? (I'm not going to do that; it's just an odd
coincidence from my point of view.)
I think there are trademark issues similar to th
Although somewhat more elegant, Python slices follow Matlab's slice
notation. In simpler cases they are identical.
mt
--
http://mail.python.org/mailman/listinfo/python-list
> Too rigid-looking somehow.
Hey, I'm an amateur... There are lots of variations on the concept I
can think of. I want someone with a lot of design talent *and a little
familiarity with the language* to take enough interest to have a go at
it.
At least (unlike the tadpoles) it has some resonanc
You may be interested in Programming Patterns in Python:
http://www.amazon.com/gp/product/0130409561/103-9277940-9267015?v=glance&n=283155
It's out of print but Amazon has some; not everyone likes it but I
think it tries to do what you are asking for.
mt
--
http://mail.python.org/mailman/listi
"Is this the right room for an argument?"
http://geosci.uchicago.edu/~tobis/snake.png
ok, so my execution is pretty crude, but you can at least see my idea.
I trust you to imagine it professionally executed in cheerful colors.
Advantages of proposed logo over existing logo
--
I'm afraid I can't be very helpful to you, but you could be most
helpful to some of us.
Can you elaborate on what specifically you found difficult? In some
circles Python is regarded as a direct competitor to Matlab. Your
preference for Python for "other things than standard mathematical
work" in
It appears that doctest does not work straightforwardly within iPython.
I would like to be able to use doctest within a file conditionally, so
that I can develop it within ipython and test it otherwise.
It would seem that this would work:
Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 200303
It appears that doctest does not work straightforwardly within iPython.
I would like to be able to use doctest within a file conditionally, so
that I can develop it within ipython and test it otherwise.
It would seem that this would work:
Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 200303
Proving yet again that it's possible to write Fortran in any language.
You aren't getting any benefit from numpy or python here. Are you
aiming for speed or legibility?
Also, with this code, you are using radius for the dimensions of the
enclosing box, as well as the radius of the circle, so it'
Yeah, this was *much* easier than I expected.
My candidate was in second place according to /usr/share/dict/words
which has ixodid but not dioxid; I'm really not confident that dioxid
is a word.
I recall that I had also found the third place word now that I look at
it.
What I had to do was print
Yeah, this was *much* easier than I expected.
My candidate was in second place according to /usr/share/dict/words
which has ixodid but not dioxid; I'm really not confident that dioxid
is a word.
I recall that I had also found the third place word now that I look at
it.
What I had to do was print
The first piece of code that I ever voluntarily wrote was intended to
solve this puzzle:
Assign the number 2 to 'a', 3 to 'b' ... 27 to 'z'. To each word assign
the value of the product of its characters. Find the English (or
language of your choice) word whose product is closest to a million (or
Well, Bill Mill and I simultaneously and independently decided to write
a preprocessor to strip out the unfortunate "@" decorator syntax. I
think we were both aiming at a polemic purpose rather than a practical
one, but as time fades it seems less clear what we were simultaneously
inspired to achie
We had some discussion of this in the edu-sig meeting at PyCon.
I alleged that I had read that there is no such thing as a Python
sandbox. Others claimed that one could simply preprocess and disallow
"dangerous" constructs. My allegation was based on an argument from
authority; I recalled reading
I think you ought to make your own class and define some of the special
methods.
mt
--
http://mail.python.org/mailman/listinfo/python-list
Yeah, I misread the question, but the gist of my query remains.
> The odds are 100% if there is at least one solution.
Let's not get too philosophical. My question was whether there was an a
priori reason for believing that there is a solution.
> You want permutations with replacement, so there
First do a little estimation. We know we have to find four out of 16
switches, so the number of possibilities to search is only C(4,16) =
1820, so an exhaustive search will work.
These will turn on 15 lights in each set of 20, of which the number of
possibilities is C(15,20)**4 = 57779667567968256
Wow. Six simultaneous responses! Python rocks!
Anyway, I actually tried it, and persisted through the secondary
confusion about the lurking .pyc file, so even though I'm in sixth
place I get points for completeness...
mt
--
http://mail.python.org/mailman/listinfo/python-list
1) remove the file random.pyc in your working directory
2) rename the file random.py to something else and run it.
The import mechanism is looking for random.pyc or random.py, but you
have already named your file that! Your current directory is above your
library directory in python's search path
Are you sure this is what you want to do? It seems an odd objective for
a preliminary effort.
Forgive me if I am reading this wrong, but I am concerned that you
think you need to do all this work to use the package. If so, you are
asking the wrong questions. Please look into the PYTHONPATH environ
OK, but Python IS clever, so its logo ought to be too.
Since you are acknowledging they are tadpoles, I guess you've heard my
gripes...
mt
--
http://mail.python.org/mailman/listinfo/python-list
I think this is great work but imagine what you could do with a real
logo!
Besides the pleasant colors what do you like about it?
I have in mind something with a coil motif but I can't execute it worth
a damn.
mt
--
http://mail.python.org/mailman/listinfo/python-list
Still a bit confused actually. Any explanation of the following?
mt
def getf(method,name):
def f(self, *a, **k): return method(self.val, *a, **k)
f.func_name = name
return f
class myint(object):
def __init__(self, val):
self.val = int(val)
for spec in 'str repr has
Thanks! Only a minor correction: the last line should be
_setdelegate(myint, int,'__%s__' % spec)
The business with f.func_name struck me as unnecessary, but I was quite
wrong.
This was an interesting exercise for me. Thanks.
Michael
--
http://mail.python.org/mailman/listinfo/python-list
I'd appreciate an explanation of why this doesn't work and any
workarounds.
It's not a showstopper, but I'd like to pseudo-inherit a bunch of magic
methods from an attribute, and would prefer to abstract the definitions
into a loop rather than write them all out.
thanks
mt
###
import ne
> What were you planning to do with this object exactly that didn't involve
> binding it to any other names during its lifetime?
Nothing so silly as that.
The idea is not to prevent other references from binding to the object,
but to allow the object to ensure that a certain symbol always points
This behavior seems to be commonly wanted by people discovering Python,
and it is the rare case of something one can imagine that is really a
stretch to achieve in Python. Because more or less than one name may
refer to an object, in general an object can't know its name.
You can get part of the w
Paul, thanks for the enlightening intro to pyparsing!
We don't really know what the application is (I suspect it's homework),
but whether it's homework or a real-world one-off this all seems like
overkill to me. There's a time for elegance and a time for quick and
dirty. Assuming line oriented inp
I think a logo contest is a good idea, and I am already working on my
entry.
I could also imagine a stylesheet contest.
The issue is who does the judging and what are the criteria.
Steve, what you say is true. Possibly people who are experienced in
making a six page site for their aunt's caterin
I like cheeseshop just fine, but have been a Monty Python fan since
they appeared on the CBC in, I think, 1969. I'm one of those people who
is always surprised when a MP bon mot is greeted with confusion and the
suspicion that I have finally lost my mind altogether. So...
If we are moving to the s
The name isn't changing, so it's a "make lemonade" situation.
What's the best use we can make of the name; how do we make it stick in
people's minds positively? How do we make a positive image out of it?
Shy tadpoles, by the way, ( http://python.org/images/python-logo.gif )
isn't it.
mt
--
ht
I think I agree with Steve here.
I suspect you should either have sufficiently trained your users in
Python, or have limited them to one-line statements which you could
then strip of leading whitespace before passing them to Python, or even
offered the alternative of one or the other. This would n
> No one
> of the complainers and negativists do claim that they could do it much
> better.
Indeed, I do not have to be able to write a particular program to
notice it has bugs.
On the other hand, (since I think the design, while not brilliant, is
good) fixing the logo is something that can be ac
While the new one is much better than the old website, the logo strikes
me as awful.
I tried to suggest repurposing the much better PyCon logo, but it
didn't raise the vast groundswell of support I wanted it to. But for
whatever its worth I'll try again. My rant is here:
http://tinyurl.com/rkq3s
> Indentation
> makes all kinds of inlined code extremely clumsy or practically impossible
> in Python.
This is the only sensible argument against the indentation thing I've
heard. Python squirms about being inlined in a presentation template.
Making a direct competitor to PHP in pure Python is pr
> I have met no problems using F90 together with f2py
Thank you for the correction. I should have qualified my statement.
Our group must cope with F90 derived types to wrap a library that we
need. f2py fails to handle this case. While the f2py site alleges that
someone is working on this, I conta
1) indentation:
I claim that this is a trivial matter. Indentation is enforced, but if
you want to end all your blocks with #end, feel free.
Or write a preprocessor to go from your preferred block style to
python's
2) self.something tedious to look at.
Again, you can somewhat work around this i
> $ rm `find . -name "*.pyc"`
Ouch. Is that a true story?
While we're remeniscing about bad typos and DEC, I should tell the
story about the guy who clobberred his work because his English wasn't
very strong.
Under RT-11, all file management was handled by a program called PIP.
For example to
ou know
everything you need to know, and I strongly recommend you reconsider
this attitude. For one thing, you misjudged which side of the divide I
started on.
Michael Tobis
(While I dislike credentialism on usenet, I will reply in kind. I hold
a Ph.D. in geophysical fluid dynamics.)
--
http://mail.python.org/mailman/listinfo/python-list
I think the answers so far are unnecessarily confusing and off the
mark.
Here is what I think you think you want to know:
1) import only works once. If you try import again, it will see the
module already exists, and will ignore you
2) the functionality you think you want is reload.
>>> reload m
Someone asked me to write a brief essay regarding the value-add
proposition for Python in the Fortran community. Slightly modified to
remove a few climatology-related specifics, here it is.
I would welcome comments and corrections, and would be happy to
contribute some version of this to the Pytho
> Read his post again. He didn't ask a specific question at all, and he
> certainly didn't mention execution speed.
agreed
> He asked a vague, meaningless question about whether Python was "slow
> compared to C".
No, that is both wrong and gratuitously harsh. He had heard vague
meaningless com
Experienced programmers learning Python should read this:
http://effbot.org/zone/python-objects.htm
Try to understand the advantages of this approach, and understand its
costs.
Essentially, everything you do in Python (or related languages)
involves resolving a name. Sometimes the number of dict
An incremental approach and a redesign are not the same thing. It might
be insurmountably difficult to acheeve both in a move to another
platform.
mt
--
http://mail.python.org/mailman/listinfo/python-list
What about some permutation of the PyCon logo? It is really quite
brilliant.
Solves many problems:
dynamic, doesn't just sit there, looks like it is moving toward a
goal
direction of motion surprising and memorable
refers to software in the minds of experienced coders
takes advanta
I like the design, though I'd prefer stronger colors. I think it would
be a major improvement except for the logo.
I agree with others that the logo is a serious disappointment. Although
the symmetry has some initial appeal, I do not see or want to see a
two-ness about Python, and I find it distur
newer success stories please...
mt
--
http://mail.python.org/mailman/listinfo/python-list
Clearly the Ruby/Rails folks are making an effort to place themselves
as an easy-to-learn first language for people who might otherwise drift
into the rather awkward template-first way of thinking that is PHP.
I note that the Rails people are closely affiliated with the 37signals
people who in tur
I apparently don't understand this question in the same way the way
others do. I think the question is about the mutability of strings.
To my understanding of your question, it is impossible, at least if the
referenced objects are strings or other objects of immutable type.
'cabbage' cannot be c
> confusion regarding some of the basics...
Reset your brain.
This came up recently, and despite there being a pending quibble, I
think it's extremely useful to the experienced programmer/new
Pythonista:
http://effbot.org/zone/python-objects.htm
And since Frederik is apparenlty reading this thr
bout a software project as it is an
article using that project to present an alternative way of thinking
about how object oriented programming (and Python!) can relate to high
performance simulations.
I welcome comments.
mt
--
Michael Tobis
Geophysical Sciences
University of Chicago
--
http://mail.pyt
Well, many scientists and engineers don't have the time, motivation or
ability to master the intricacies of recent fortran vintages either.
That's the problem.
Very large codes written by teams of software engineers for
well-delimited application spaces will continue to be written in some
version
Alex Martelli wrote:
> Michael Tobis <[EMAIL PROTECTED]> wrote:
>...
> > .x = 1
> > .def foo():
> > . if False:
> > . global x
> > . x = 2
> > .foo()
> > .print x
> >
> > prints "1"
>
> Wrong:
> &
Summary of my understanding of a recent interesting thread:
General usage has "declaration" meaning "statement which does not
generate executable bytecode but merely affects the compiler". My
assertion that decorator syntax is "declarative" is therefore formally
false.
The common assertion that "
> All in all, I fail to see what gains would be expected by making
Python
> into a single-assignment or single-binding language, even on a module
by
> module basis, to repay this kind of awkwardness.
Just to be clear, if anyone was suggesting that, it wasn't me.
It would be helpful on occasion in
We apologise for the previous apology.
http://arago4.tn.utwente.nl/stonedead/albums-cds/sketches/another-monty-python-record/apologies.html
--
mt
--
http://mail.python.org/mailman/listinfo/python-list
> How common is it for a local variable to be bound in
> more than one place within a function?
It's more natural for a beginner to read or write
.mystr = ""
.for snippet in snippets:
. if ilike(snippet):
. mystr = mystr + snippet
than
.mylist = []
.for snippet in snippets:
. if ilike(
Given the behavior, the documentation is gratifyingly correct.
Given that the syntax is legal, though, the behavior is not what one
would intuitively expect, and is therefore unPythonic by (rather
dramatically) violating the principle of least surprise.
It's also, to me, understandable why it's d
Alex Martelli wrote:
> Michael Tobis <[EMAIL PROTECTED]> wrote:
> he can perfectly
> well correct his misexpression if he cares to -- not my job to try to
> read his mind and perform exegesis on his words.
Well, I hate to try to tell you your job, but it doesn't seem to
This is definitely a wart:
... z = 42.3
...
... def f():
...if False:
... global z
...z = -666
...
... f()
... print z
--
http://mail.python.org/mailman/listinfo/python-list
> that's a nice theory, but since the decorator line is executed by the
inter-
> preter, it's a little weak.
Well, uh, who else would process it?
"use strict' and 'my epsilon' in perl are executed by the perl
interpreter as well, but they have a declarative flavor.
A decorator is a modifier to a
With all due respect, I think "so go away if you don't like it" is
excessive, and "so go away if you don't like it and you obviously don't
like it so definitely go away" is more so. The writer is obviously
neither a native speaker of English nor an accomplished user of Python,
so there are two lang
[EMAIL PROTECTED] wrote:
> Michael Tobis wrote:
> Fortran 90/95 is more expressive than Fortran 77 in many ways, as
> described in ...
> http://www.nr.com/CiP97.pdf .
>
> ... expresses more science per
> line of code and per programming workday.
The example shown on p 10
1 - 100 of 105 matches
Mail list logo