On Jul 31, 2:09 am, "steve" wrote:
> Is there a good way to check if a script is running inside Pythonwin?
> Perhaps a property or method that is exposed by that environment?
I've used
if sys.stdin.fileno() < 0:
This is not precisely a test for pythonwin, but indicates whether
standard streams
First, I second Matt's comment about using a boring old for loop when
it is the simplest way to express what you want to do. Being Pythonic
is not about using exotic features to scrunch your code down to a cool
one-liner. It is about expressing your intentions in a simple, direct
way. Sometimes
On Jun 9, 7:29 am, Rainy <[EMAIL PROTECTED]> wrote:
> ... Another question I have is what
> other languages allow this naming scheme?
The most widely used such language would probably be COBOL,
where you write things like
SUBTRACT DISCOUNT FROM LIST-PRICE GIVING AMOUNT-DUE
I doubt that syntax
On Apr 3, 2:57 pm, Brian Vanderburg II <[EMAIL PROTECTED]>
wrote:
>
> I've checked out some ways to get this to work. I want to be able to
> add a new function to an instance of an object. I've tested two
> different methods that cause problems with 'deleting'/garbage collection
> (__del__ may ne
Is there any legal problem with including licenses for languages you
don't use? (But I agree with the other posters that any competitor
worthy of concern will figure it out in short order if they care.)
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 31, 11:48 am, Grant Edwards <[EMAIL PROTECTED]> wrote:
>
> I'm not sure what you're asking. AFAIK, the main reason that
> strings are immutable is so they can be used as dict keys.
>
I think its more fundamental than that. If strings were mutable
you would be constantly worrying about whe
On Jan 24, 11:30 am, Jonathan Gardner <[EMAIL PROTECTED]>
wrote:
>
> A few sample good uses of try/except blocks:
>
> (1) Do something else if an expected exception occurs.
> ...
> (2) Show a friendly error message when an exception occurs over a
> significant chunk of the program. (Useful fo
On Jan 21, 8:48 am, Peter Otten <[EMAIL PROTECTED]> wrote:
> Neal Becker wrote:
> > What's a good/fast way to find the index of the minimum element of a
> > sequence?
...
> >>> min(xrange(len(items)), key=items.__getitem__)
...
Or just
items.index(min(items))
I found this to be significantly
On Dec 20, 5:41 am, Mrown <[EMAIL PROTECTED]> wrote:
> Hi,
> I was wondering if there was a ping implementation written in
> Python.
http://www.gnist.org/~lars/code/ping/ping.html
--
http://mail.python.org/mailman/listinfo/python-list
On Nov 28, 10:51 pm, Benjamin Hell <[EMAIL PROTECTED]> wrote:
> Hi!
>
> I wonder whether there might be a way to find out how a Python
> program was started (in my case in Windows): By double clicking the
> file or by calling it on the "DOS" command line prompt.
>
> Background: I would like to have
Since you are getting the regular expression pattern via an argument I
would first check that searchPattern is what you expect. Shells can do
funny things with arguments containing special characters. Also, is
it possible that the quoted strings in the files contain escapes? For
example if a file
On Aug 16, 9:46 am, MRAB <[EMAIL PROTECTED]> wrote:
>
> As well as the other replies, this also works (as far as I can tell!):
>
> import time
> today = time.localtime()
> yesterday = today[ : 2] + (today[2] - 1, ) + today[3 : ]
> yesterday = time.localtime(time.mktime(yesterday))
This is somethin
On Aug 10, 8:37 am, Zentrader <[EMAIL PROTECTED]> wrote:
>
> If the above does not work
> [/code]test_list = [ 5.32, 10.35634, 289.234 ]
> for num in test_list :
>str_num = "%11.5f" % (num) ## expand to at least 5
>print str_num, "-->", str_num.strip()[:5][/code]
This has the disadva
On Jul 18, 6:52 pm, Gordon Airporte <[EMAIL PROTECTED]> wrote:
> ...
> I've also been assuming that using the re functions that create match
> objects is slower/heavier than dealing with the simple list returned by
> findall(). I've profiled it and these matches are the biggest part of
> the runni
On Jun 22, 10:33 am, James Harris <[EMAIL PROTECTED]>
wrote:
> I have a requirement to store timestamps in a database. Simple enough
> you might think but finding a suitably general format is not easy.
> ...
> Any thoughts on a better way to do this? (Please reply-all. Thanks).
>
> --
> James
My
On Jun 8, 2:07 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>> ...
>
> What has the searching to do with the reading? 10MB easily fit into the
> main memory of a decent PC, so just do
>
> contents = open("file").read() # yes I know I should close the file...
>
> print contents.find('\x0c')
>
On May 17, 10:39 pm, Tartifola <[EMAIL PROTECTED]> wrote:
> Hi,
> I have a list with probabilities as elements
>
> [p1,p2,p3]
>
> with of course p1+p2+p3=1. I'd like to draw a
> random element from this list, based on the probabilities contained in
> the list itself, and return its index.
>
> Any h
On May 4, 12:39 pm, 7stud <[EMAIL PROTECTED]> wrote:
> On May 4, 3:30 pm, [EMAIL PROTECTED] wrote:
>
>
>
> > Hi,
>
> > Can anyone explain the following:
>
> > Python 2.5 (r25:51908, Apr 9 2007, 11:27:23)
> > [GCC 4.1.1 20060525 (Red Hat 4.1.1-1)] on linux2
> > Type "help", "copyright", "credits" o
On Mar 29, 3:05 am, greg <[EMAIL PROTECTED]> wrote:
> In my quest to eliminate C compiler warnings from
> Pyrex output, I've discovered some utterly bizarre
> behaviour from gcc 3.3.
>
> The following code:
>
>void g(struct foo *x) {
>}
>
>void f(void) {
> void (*h)(struct foo *);
On Feb 20, 7:37 pm, "John Machin" <[EMAIL PROTECTED]> wrote:
> On Feb 21, 3:09 pm, Astan Chee <[EMAIL PROTECTED]> wrote:
>
> > Hi,
> > I just tried to do
> > eval('00052') and it returned 42.
> > Is this a known bug in the eval function? Or have I missed the way eval
> > function works?
> > Thanks
On Feb 16, 7:01 am, "Bart Ogryczak" <[EMAIL PROTECTED]> wrote:
> On Feb 16, 4:30 pm, "stdazi" <[EMAIL PROTECTED]> wrote:
>
> > for (i = 0; some_function() /* or other condition */ ; i++)
>
> C's "for(pre,cond,post) code" is nothing more, then shorthand form of
> "pre; while(cond) {code; post;}"
I
The following program gets a TextCtrl's text attributes and sets them
back unchanged. However it reports that the font size is 124, and after
resetting the attributes the text becomes that size. That is, the
window displays a normal-size "foo" and a gigantic "bar". Anyone know
what's going on?
Thi
When I installed Python 2.5 (on Windows XP) I left 2.4 in place "just
in case". Today I decided to remove it. However after doing so (from
the control panel) I found that Windows no longer knows about the
Python file types and associations. Is this behavior expected, or was
there something wrong wi
I was going to ask how to a program can tell whether it was started by
python.exe or pythonw.exe, but after some experimentation I noticed
that sys.stdin.fileno() is -1 in the latter case.
However on a more general note, the only references to pythonw that I
could find in the Python 2.5 documentat
I have a WxPython app that displays images that are typically around
600x600 pixels. I use a wxStaticBitmap, which appears to work fine on
Windows XP. However the documentation states that a StaticBitmap "...
is meant for display of the small icons in the dialog boxes and is not
meant to be a gener
Peter Otten wrote:
> Steve Holden wrote:
>
> > I'll bet you still write
> >
> > if a>3 == True:
> >
> > don't you ;-)
>
> I'll second that.
>
> if (a>3) == True:
>
> is the correct way :-)
>
> Peter
No, to be consistent you'll have to write
if ((a>3) == True) == True:
Oops, I mean,
if (((
Ritesh Raj Sarraf wrote:
> The line
> filename = zipfile.ZipFile(zip_file_name, "a")
> throws an exception if the given filename is not present already.
> Shouldn't it create a file (in case one is not there) since it is
> "append" mode ??
Perhaps it would be nicer that way, but it is working as
[EMAIL PROTECTED] wrote:
> Intel has introduced something called CESR, written in Python, to aid
> C, C++, and Fortran programmers in reducing the sizes of programs
> included in bug reports. Here is a brief description from
> http://cache-www.intel.com/cd/00/00/21/93/219320_relnotes_10.pdf :
> ...
For your example, since the probabilities are all multiples of 0.01 you
could make a list of 100 elements. Set one of them to a, 5 of them to
b, 50 of them to c, etc. Then just randomly sample from the table
(which is O(1)). Of course if the probabilities can be arbitrary
floating point values the
Sybren Stuvel wrote:
> David C Ullrich enlightened us with:
> > I thought that the fact that you could use the same trick for
> > _shuffling_ a list was my idea, gonna make me rich and famous. I
> > guess I'm not the only one who thought of it. Anyway, you can use
> > DSU to _shuffle_ a list by de
Seem to be a lot of regular expression questions lately. There is a
neat little RE demonstrator buried down in
Python24/Tools/Scripts/redemo.py, which makes it easy to experiment
with regular expressions and immediately see the effect of changes. It
would be helpful if it were mentioned in the RE d
The basic problem is that the zipfile interface only reads and writes
whole files, so it may perform poorly or fail on huge files. At one
time I implemented a patch to allow reading files in chunks. However I
believe that the current interface has too many problems to solve by
incremental patching,
If I were you I would see if I could get the Perl script referred to on
the ERIN web page. You might find that the discrepancy is something as
simple as a slightly different value for the Earth's radius. And by the
way, math.radians() might be a bit clearer than the pi/180 business.
--
http://mai
Steve R. Hastings wrote:
> a = 0
> b = 0
> a is b # always true
Is this guaranteed by the Python specification, or is it an artifact of
the current implementation? My understanding has been that an
implementation is free to share integer objects or not, so using 'is'
as an equality test takes yo
First note that zipfile is a plain Python module, so reading
Python.../Lib/zipfile.py will reveal all its secrets.
I don't think it is possible to replace archive members using the
module. You could copy all the files into a new zip file, replacing the
ones you want to change as you go. But it mig
I see that the posixfile module is deprecated. Have the SEEK_SET, etc.
constants moved somewhere else, or do I need to define them myself?
--
http://mail.python.org/mailman/listinfo/python-list
36 matches
Mail list logo