Re: Module python-magic on/for Windows?

2008-05-11 Thread Larry Hale
On May 11, 11:42 pm, Larry Hale <[EMAIL PROTECTED]> wrote:
> THANKS, AGAIN, for the reply!  :)
>
> Okay, now I -really- feel silly...  :>
>
> So, when I was going to try what you'd suggested, I noticed something
> peculiar: I hadn't "changed" anything on my system, but now, when I
> tried to "import magic" I got a missing DLL error.  For a DIFFERENT
> DLL!  This got me to thinking...
>
> Turns out, when I was having "success" earlier, I was -in- the C:
> \Program Files\GnuWin32\bin directory (where file.exe and related .dll
> files are).
>
> So I added C:\Program Files\GnuWin32\bin to the (system/Windows)
> PATH.  Everything worked.  I removed all the copious copies of the
> DLL, the magic files, etc., littering my hard drive in every other
> location.  Still worked.
>
> 'Course, I don't honestly know why it didn't work with the files
> copied to other locales contained in the sys/Py paths... perhaps it
> was, as you mentioned, wanting the tree-structure to be the same?  (I
> haven't the heart to check this out fully right now... *maybe* at a
> later time...  ;) )
>
> Yeah, I know.  But HONESTLY!  I could have -sworn- I'd already tried
> THAT... you know, all the "obvious"/"I've been programming/working in
> computers (albeit 'Windows' until lately) for ~25 years; yeah, I'm a
> 'hacker'..." stuff.  I -swear-!
>
> [EGG ON FACE]
>
> [SIGH]  Well, I'd say "live and learn", but I'm still scratching my
> head.  But, 'nough of that.  Thanks for your replies, Michael, and I'm
> off to work _with_ the module now, then work-up my HowTo (and
> experiment with making an "egg"?? ;) )...
>
> Caio!
> -Larry  :P  :)
>
> On May 11, 11:09 pm, Michael Torrie <[EMAIL PROTECTED]> wrote:
>
> > Larry Hale wrote:
> > > ALSO: I've even tried putting the 4 "magic" files INTO the .egg
> > > file... still no-go.  :/
>
> > It's often the custom of programs ported from unix to windows to use the
> > dll location as a key to find the other files that are typically in
> > share, or etc.  GTK, for example uses ../share and ../etc from the
> > location where the dlls are stored (if the dlls are in a folder called bin).
>
> > In this case I'd try making a folder in the Python25 folder called
> > "share" and put the contents of the gnuwin32 share/file stuff in there.
> >  Should look something like this:
>
> > c:/python25/share/file/magic.mime.mgc
> > c:/python25/share/file/magic
> > c:/python25/share/file/magic.mgc
> > c:/python25/share/file/magic.mime
>
> > Or, judging by a string I found in the dll itself, you might have to put
> > the files here:
>
> > c:/progra~1/File/share/file/magic
>
> > Although if such a path really is hardcoded into the dll, this is
> > certainly a bug, since it will fail on certain non-english windows systems.
>
> > Anyway, who knows.  Give these options a try.



UPDATE: HOORAY!!!  Well, actually, was about two steps forward, one
back.  But I've gotten it all sorted out now!  :)

I added C:\Program Files\GnuWin32\bin to the system/Windows PATH.
This takes care of the various required DLLs/libs.

The file source (previously linked from http://hupp.org/adam/hg/python-magic/)
has the man pages.  I'd overlooked these as they were only modified as
necessary; the "BSD" part made me think they'd be the same as the same
online versions I'd already read (that were *nix specific).
Obviously, I was wrong.  These had the default paths to the magic*
files listed; C:\Program Files\File\share\file\.

If one creates said directory structure and moves/copies/unpacks the
magic ("database") files THERE, then one may do:

>>> import magic
>>> test = magic.Magic() # <-- New Magic class instance
>>> test.from_file( 'C:\\startrek.exe' ) # <-- Yeah, I have an old
Star Trek game file here to test with...  :)
'MS-DOS executable, MZ for MS-DOS'  # <-- This is what's
returned...

Alternately, if one wishes to leave/place the magic files elsewhere,
do like:

>>> test = magic.Magic( magic_file = 'C:\\Program Files\\GnuWin32\
\share\\file\\magic' ) # <-- spec where/what the file is

NOTE: Even if the "magic_file" location *is* specified, "mime = True"
still works fine.  (Haven't checked, but I presume the source simply
tacks ".mime" to the filename automagically.)  Obviously/also, one
needn't specify the argument names if one uses proper argument order:
magic.Magic( mime, magic_file )  :)


THANKS SO MUCH, Michael, for your answers and helping me alone the
way...  :)


Cheers,
-Larry
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is there no single/uniform RDBMS access API module for Python ?

2008-05-11 Thread Banibrata Dutta
Found that SnakeSQL does implement DB2.0 API. However are there such
implementations for MySQL ?

On 5/12/08, Banibrata Dutta <[EMAIL PROTECTED]> wrote:
>
>
> On 5/12/08, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
>>
>> Banibrata Dutta írta:
>>
>>> Hi,
>>>  Again a noob question.
>>>  Based on this URL http://wiki.python.org/moin/DatabaseInterfaces , is
>>> it correct to conclude that there is no RDBMS agnostic, single/uniform DB
>>> access API for Python ?
>>> Something in the lines of JDBC for Java, DBD for Perl etc. ?
>>>  How is the RDBMS change handled for solutions which need to work with
>>> different RDBMSs ??
>>>
>> http://www.python.org/dev/peps/pep-0249/
>>
>
>
> That appears to be only an API specification. Are there any implementations
> of that ?
>
> --
> regards,
> Banibrata
> http://www.linkedin.com/in/bdutta
> http://octapod.wordpress.com
>



-- 
regards,
Banibrata
http://www.linkedin.com/in/bdutta
http://octapod.wordpress.com
--
http://mail.python.org/mailman/listinfo/python-list

Re: Is there no single/uniform RDBMS access API module for Python ?

2008-05-11 Thread Banibrata Dutta
On 5/12/08, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
>
> Banibrata Dutta írta:
>
>> Hi,
>>  Again a noob question.
>>  Based on this URL http://wiki.python.org/moin/DatabaseInterfaces , is it
>> correct to conclude that there is no RDBMS agnostic, single/uniform DB
>> access API for Python ?
>> Something in the lines of JDBC for Java, DBD for Perl etc. ?
>>  How is the RDBMS change handled for solutions which need to work with
>> different RDBMSs ??
>>
> http://www.python.org/dev/peps/pep-0249/
>


That appears to be only an API specification. Are there any implementations
of that ?

-- 
regards,
Banibrata
http://www.linkedin.com/in/bdutta
http://octapod.wordpress.com
--
http://mail.python.org/mailman/listinfo/python-list

Re: Is there no single/uniform RDBMS access API module for Python ?

2008-05-11 Thread Laszlo Nagy

Banibrata Dutta írta:

Hi,
 
Again a noob question.
 
Based on this URL http://wiki.python.org/moin/DatabaseInterfaces , is 
it correct to conclude that there is no RDBMS agnostic, single/uniform 
DB access API for Python ?

Something in the lines of JDBC for Java, DBD for Perl etc. ?
 
How is the RDBMS change handled for solutions which need to work with 
different RDBMSs ??

http://www.python.org/dev/peps/pep-0249/

--
http://mail.python.org/mailman/listinfo/python-list


Re: computing with characters

2008-05-11 Thread Gabriel Genellina
En Tue, 06 May 2008 08:16:55 -0300, <[EMAIL PROTECTED]> escribió:

> I tend to do ", ".join("%s" % e for e in item)
>
> Is there any difference between this and str()?

Use the timeit module to measure performance:

C:\TEMP>python -m timeit "for i in xrange(1): str(i)"
10 loops, best of 3: 81.8 msec per loop

C:\TEMP>python -m timeit "for i in xrange(1): '%s' % i"
10 loops, best of 3: 78.5 msec per loop

The %s version consistently wins in my system -2.5.1 on WinXP- for a wide range 
of inputs.

-- 
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Module python-magic on/for Windows?

2008-05-11 Thread Larry Hale
On May 11, 11:42 pm, Larry Hale <[EMAIL PROTECTED]> wrote:
> THANKS, AGAIN, for the reply!  :)
>
> Okay, now I -really- feel silly...  :>
>
> So, when I was going to try what you'd suggested, I noticed something
> peculiar: I hadn't "changed" anything on my system, but now, when I
> tried to "import magic" I got a missing DLL error.  For a DIFFERENT
> DLL!  This got me to thinking...
>
> Turns out, when I was having "success" earlier, I was -in- the C:
> \Program Files\GnuWin32\bin directory (where file.exe and related .dll
> files are).
>
> So I added C:\Program Files\GnuWin32\bin to the (system/Windows)
> PATH.  Everything worked.  I removed all the copious copies of the
> DLL, the magic files, etc., littering my hard drive in every other
> location.  Still worked.
>
> 'Course, I don't honestly know why it didn't work with the files
> copied to other locales contained in the sys/Py paths... perhaps it
> was, as you mentioned, wanting the tree-structure to be the same?  (I
> haven't the heart to check this out fully right now... *maybe* at a
> later time...  ;) )
>
> Yeah, I know.  But HONESTLY!  I could have -sworn- I'd already tried
> THAT... you know, all the "obvious"/"I've been programming/working in
> computers (albeit 'Windows' until lately) for ~25 years; yeah, I'm a
> 'hacker'..." stuff.  I -swear-!
>
> [EGG ON FACE]
>
> [SIGH]  Well, I'd say "live and learn", but I'm still scratching my
> head.  But, 'nough of that.  Thanks for your replies, Michael, and I'm
> off to work _with_ the module now, then work-up my HowTo (and
> experiment with making an "egg"?? ;) )...
>
> Caio!
> -Larry  :P  :)
>
> On May 11, 11:09 pm, Michael Torrie <[EMAIL PROTECTED]> wrote:
>
> > Larry Hale wrote:
> > > ALSO: I've even tried putting the 4 "magic" files INTO the .egg
> > > file... still no-go.  :/
>
> > It's often the custom of programs ported from unix to windows to use the
> > dll location as a key to find the other files that are typically in
> > share, or etc.  GTK, for example uses ../share and ../etc from the
> > location where the dlls are stored (if the dlls are in a folder called bin).
>
> > In this case I'd try making a folder in the Python25 folder called
> > "share" and put the contents of the gnuwin32 share/file stuff in there.
> >  Should look something like this:
>
> > c:/python25/share/file/magic.mime.mgc
> > c:/python25/share/file/magic
> > c:/python25/share/file/magic.mgc
> > c:/python25/share/file/magic.mime
>
> > Or, judging by a string I found in the dll itself, you might have to put
> > the files here:
>
> > c:/progra~1/File/share/file/magic
>
> > Although if such a path really is hardcoded into the dll, this is
> > certainly a bug, since it will fail on certain non-english windows systems.
>
> > Anyway, who knows.  Give these options a try.



UPDATE: HOORAY!!!  Well, actually, was about two steps forward, one
back.  But I've gotten it all sorted out now!  :)

I added C:\Program Files\GnuWin32\bin to the system/Windows PATH.
This takes care of the various required DLLs/libs.

The file source (previously linked from http://hupp.org/adam/hg/python-magic/)
has the man pages.  I'd overlooked these as they were only modified as
necessary; the "BSD" part made me think they'd be the same as the same
online versions I'd already read (that were *nix specific).
Obviously, I was wrong.  These had the default paths to the magic*
files listed; C:\Program Files\File\share\file\.

If one creates said directory structure and moves/copies/unpacks the
magic ("database") files THERE, then one may do:

>>> import magic
>>> test = magic.Magic() # <-- New Magic class instance
>>> test.from_file( 'C:\\startrek.exe' ) # <-- Yeah, I have an old
Star Trek game file here to test with...  :)
'MS-DOS executable, MZ for MS-DOS'  # <-- This is what's
returned...

Alternately, if one wishes to leave/place the magic files elsewhere,
do like:

>>> test = magic.Magic( magic_file = 'C:\\Program Files\\GnuWin32\
\share\\file\\magic' ) # <-- spec where/what the file is

NOTE: Even if the "magic_file" location *is* specified, "mime = True"
still works fine.  (Haven't checked, but I presume the source simply
tacks ".mime" to the filename automagically.)  Obviously/also, one
needn't specify the argument names if one uses proper argument order:
magic.Magic( mime, magic_file )  :)


THANKS SO MUCH, Michael, for your answers and helping me alone the
way...  :)


Cheers,
-Larry
--
http://mail.python.org/mailman/listinfo/python-list


Re: anonymous assignment

2008-05-11 Thread Arnaud Delobelle
Yves Dorfsman <[EMAIL PROTECTED]> writes:

> Is there anyway to tell python I don't care about a value ?
>
> Say I want today's year and day, I'd like to do something like:
>
> import time
> y, None, d, None, None, None, None = time.localtime()
>
> I know you can't assign anything to None, but I'm sure you get what I
> mean, a special keyword that means I don't care about this value. In
> this particular case, there's got to be a better way than:
>
> d = time.local()
> y = d[0]
> d = d[1]
>

I use Paul Rubin's solution (which is frown upon by many:), but it's
true it would be nice for tuples to have something like an extract()
method:

y, d = time.localtime.extract(0, 2)

Where 

mytuple.extract(i1, i2, i3...)

would mean:

tuple(mytuple[i] for i in (i1, i2, i3...))

Or perhaps allow indexing by tuples:

mytuple[i1, i2, i3...]

-- 
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list


Re: anonymous assignment

2008-05-11 Thread Ben Finney
Yves Dorfsman <[EMAIL PROTECTED]> writes:

> Paul Rubin wrote:
> > Yves Dorfsman <[EMAIL PROTECTED]> writes:
> >> import time
> >> y, None, d, None, None, None, None = time.localtime()
> >>
> >> I know you can't assign anything to None, but I'm sure you get what I
> >> mean, a special keyword that means I don't care about this value.
> >
> > You can just use a variable name than you ignore.  It's traditional to
> > use _ but it's not a special keyword, it's just a another variable name:
> >
> >y, _, d, _, _, _, _, _, _ = time.localtime()
> 
> But you still have have a variable that's using memory for nothing.

No, you have one extra unused name binding. The values that you don't
want to use have *already* been allocated by the time the above
statement is executed. Name binding doesn't copy the values, it merely
binds a name to them. There's no "variable" in the above statement.

-- 
 \   “Holy human pressure cookers, Batman!” —Robin |
  `\   |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Paddy
On May 11, 9:28 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
Hi John, Arnaud;

> Contrived example:
>
> # Print 'hello' 10 times; x is not used
> for x in xrange(10):
> print 'hello'

I've used Fortran and C and so would tend to use either i,j,k as the
unused loop variable above, or, for clarity, call it something
descriptive like loop_count, if the loop body would be clearer.

I would also just use range for small, (especially small constant),
ranges.

>
> # By changing what is iterated over, no unused variable:
> from itertools import repeat
> for msg in repeat('hello', 10):
> print msg
I guess I would not go to the trouble of using itertools.repeat unless
it was simplifying/homogenising a larger expression - i.e if it was
part of some functional expression

I've never fealt the need for a separate repeat statement myself
either.

- Paddy.

P.S: I do understand that your examples are contrived. Just my
thoughts.

--
http://mail.python.org/mailman/listinfo/python-list


Re: cgitb performance issue

2008-05-11 Thread Gabriel Genellina
En Mon, 05 May 2008 15:56:26 -0300, Ethan Furman <[EMAIL PROTECTED]> escribió:

> I tried adding a form to our website for uploading large files.
> Personally, I dislike the forms that tell you you did something wrong
> and make you re-enter *all* your data again, so this one cycles and
> remembers your answers, and only prompts for the file once the rest of
> the entered data is good.  However, the first time the form loads it can
> take up to 30 seconds... any ideas why?

Hard to tell without looking at the code... And what has cgitb to do with this?

-- 
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Ben Finney
Ivan Illarionov <[EMAIL PROTECTED]> writes:

> >> In such cases, the name 'dummy' is conventionally bound to the items
> >> from the iterator, for clarity of purpose
> [..]
> > If a value isn't used, then I think the most clear name for it is
> > "unused".
> [...]
> 
> Maybe my brain works differently, but I find both "dummy" and
> "unused" are extremely confusing names for loop counters. The loop
> begins to look like it doesn't iterate at all if its counter is
> dummy or unused.
> 
> If it *counts* it is *used* and it's *not* dummy.

The value is unused by any of the code inside the block. For the
purposes of that block, it is a dummy value.

That something *else* (the iterator driving the 'for') is taking care
of knowing when the loop is finished is great. However, in the code
the programmer is writing, the loop counter is entirely unused.

> Why reinvent the wheel when "a common identifier naming convention
> is for the loop counter to use the variable names i, j and k (and so
> on if needed)" (from Wikipedia
> http://en.wikipedia.org/wiki/Loop_counter )

That is also regrettably common in Python code. It still suffers from
being unnecessarily ambiguous, since there are *also* plenty of loops
using 'i', 'j', etc. where the loop counter *is* used.

Differentiating these use cases by appropriate naming is, IMO, worth
the effort of choosing a meaningful name.

-- 
 \  "Ignorance more frequently begets confidence than does |
  `\   knowledge." —Charles Darwin, _The Descent of Man_, 1871 |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

hai friends

2008-05-11 Thread chandran . ramu1
hai dear,
"may all good things come into your life today and always"
www.goodhistory5.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best technology for agent/web server architecture

2008-05-11 Thread Gabriel Genellina
> 2008/5/8 M.-A. Lemburg <[EMAIL PROTECTED]>:
>
>> SOAP would be a good choice if you want to send to data to other
>> servers as well, e.g. Java-based ones.
>>
>> XML-RPC and JSON are better for simple data structures.
>>
>> If you have control over both client and server and don't
>> need to bother with other backends or frontends, Python
>> pickle is the best choice.

En Fri, 09 May 2008 05:41:07 -0300, Florencio Cano <[EMAIL PROTECTED]> escribió:

> I have control over agent and client but I'm not sure how to use
> pickle for this task. Do you suggest to pickle the objects that I want
> to send and send it over a usual socket? I have searched a bit in
> Google and I have seen that Pickle is insecure by default. What do you
> think about this?

"insecure" means that someone could build a specially crafted pickle able to 
run arbitrary code on the unpickling environment. One way to avoid that is to 
only accept pickles from trusted sources: using SSL by example.

-- 
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: anonymous assignment

2008-05-11 Thread Marc 'BlackJack' Rintsch
On Mon, 12 May 2008 03:40:03 +, Yves Dorfsman wrote:

> Paul Rubin wrote:
>
>> You can just use a variable name than you ignore.  It's traditional to
>> use _ but it's not a special keyword, it's just a another variable
>> name:
>> 
>>y, _, d, _, _, _, _, _, _ = time.localtime()
> 
> But you still have have a variable that's using memory for nothing. I
> find this unsatisfactory...

Get over it…

Or use `operator.itemgetter()`:

In [36]: operator.itemgetter(0, 2)(time.localtime())
Out[36]: (2008, 12)

:-)

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list

Re: Mathematics in Python are not correct

2008-05-11 Thread Terry Reedy

"Mark Dickinson" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
On May 11, 9:36 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
|> Do you have in mind any situations in which it is advantageous to have 
0**0
|> undefined?

| (Playing devil's advocate here.) If you regard x**y as exp(y*log(x))

Which, of course, I was not, but for the sake of discussion

| then it's not at all clear that 0.**0. should be considered well-defined.

Then it seems equally dubious that 0.**y, y>0, should be well-defined.
It seems to me that lim as x goes to 0. exp(y*log(x)) is equally well 
defined whether y is 0 or not, even though there is a discontinuity in the 
limit.
.
...
| The big problem here is that the power operation is really trying
| to combine two subtly different functionalities (integer powers
| and real powers), with quite distinct use-cases, into a single
| function.  Which leads to problems:  witness the mess that's
| C99's pow specification:  why does it make sense for (-2.0)**2.0 to
| return 4.0, while (-2.0)**1.9 returns NaN?

2.5 raises an exception.  In 3.0,
>>> (-2)**1.
(3.999722741113-1.2566370355167477e-07j)

| Incidentally, the decimal module is slightly schizophrenic about this:

That module follows the IBM-led standard, no matter how crazy.

Terry Jan Reedy



--
http://mail.python.org/mailman/listinfo/python-list


Is there no single/uniform RDBMS access API module for Python ?

2008-05-11 Thread Banibrata Dutta
Hi,

Again a noob question.

Based on this URL http://wiki.python.org/moin/DatabaseInterfaces , is it
correct to conclude that there is no RDBMS agnostic, single/uniform DB
access API for Python ?
Something in the lines of JDBC for Java, DBD for Perl etc. ?

How is the RDBMS change handled for solutions which need to work with
different RDBMSs ??

-- 
regards,
Banibrata
http://www.linkedin.com/in/bdutta
http://octapod.wordpress.com
--
http://mail.python.org/mailman/listinfo/python-list

Re: Accepting text input

2008-05-11 Thread Gabriel Genellina
En Mon, 12 May 2008 01:54:28 -0300, Collin <[EMAIL PROTECTED]> escribió:

> Collin wrote:
>> I'm pretty new to Python, but this has really bugged me. I can't find a
>> way around it.
>>
>>
>> The problem is that, when I use raw_input("sajfasjdf") whatever, or
>> input("dsjfadsjfa"), you can only have numerical values as answers.
>>
>> Any help would be appreciated. Thanks.
>
>
> Oh, wow. I feel so stupid. Please disregard this message. <_<

No need to apologize...

> I read the error message just now a bit more carefully, and I tried
> something. I tried defining "yes" as some random numerical value. Then
> when I did:
> (example code)
>
> yes = 123123983 #some number
> test = input("Test test test ")
> if test == yes:
>   print "It worked."
> else:
>   print "failed"
>
> (example code off)

The usual way for Python<3.0 is:

answer = raw_input("Test test test ").lower()
if answer == "yes":
 ...

The input() function evaluates user input as an expression: if he types 2+5 the 
input() function returns the integer 7. I would never use input() in a program 
- it's way too unsafe; use always raw_input instead.

-- 
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python, are you ill?

2008-05-11 Thread castironpi
On May 11, 6:26 pm, Tim Roberts <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
>
> >If you are in the interactive prompt of the Python interpreter and you
> >do this
>
> >print """Testing\"""   or   print '''Testing\'''
>
> >you get three dots [...] as if Python expects a code block.
>
> ...which it does.
>
> >If you
> >press Enter, you get three dots again, and again, and again... You
> >can't get out of the code block with pressing the Enter key; you have
> >to press Ctrl+Z (if you're in Linux) in order to get out of that code
> >block,
>
> No, you don't.  You can also enter """ or ''' to properly close the quote.
>
> >If you do
>
> >print "Testing\"   or   print 'Testing\'
>
> >you get an error, but not of you use the triple quotes. Is that a bug
> >in the interpreter perhaps?
>
> As a general rule, when you are just beginning to learn some product, it is
> safe to assume that anything you see as a bug in the product is almost
> certainly a flaw in your understanding of the product.
> --
> Tim Roberts, [EMAIL PROTECTED]
> Providenza & Boekelheide, Inc.

I hold further, it is more profitable, unless you can change it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: pickle problem

2008-05-11 Thread castironpi
On May 11, 6:21 pm, [EMAIL PROTECTED] wrote:
> On May 8, 7:29 pm, [EMAIL PROTECTED] wrote:
>
>
>
>
>
> > On May 8, 4:35 pm, Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
>
> > > Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes:
>
> > > > On Thu, 08 May 2008 08:55:35 -0700, krustymonkey wrote:
>
> > > >> The thing is, I'm not using slots by choice.  I'm using the standard
> > > >> lib "socket" class, which apparently uses slots.
>
> > > > `socket` objects can't be pickled.  Not just because of the
> > > > `__slot__`\s but because a substantial part of their state lives in
> > > > the operating system's space.
>
> > > Of course, if it makes sense to pickle sockets in the application, one
> > > is can do so by defining __getstate__ and __setstate__:
>
> > > class Connection(object):
> > >     def __init__(self, host, port):
> > >         self.host = host
> > >         self.port = port
> > >         self.init_sock()
>
> > >     def init_sock(self):
> > >         self.sock = socket.socket()
> > >         self.sock.connect((host, port))
> > >         ... init communication ...
>
> > >     def __getstate__(self):
> > >         # pickle self as a (host, port) pair
> > >         return self.host, self.port
>
> > >     def __setstate__(self, state):
> > >         # reinstate self by setting host and port and
> > >         # recreating the socket
> > >         self.host, self.port = state
> > >         self.init_sock()
>
> > I, local, am mystified that you'd want to pickle a socket.  It's a
> > live connection, which flies on a pocket dollar.  You don't want it on
> > disk, do you?
>
> > If you're running a net buoy through a cluster somewhere, do you want
> > to drop a server and reconnect?  Is Amazon's EC2 up and running?
>
> > Certainly no one was talking on the internet.  Were you?
>
> > I don't think you hit anything but banks surfing the web, and the
> > American dollar is notoriously stuffy.  Pump a wi-fi to a diner,
> > though, and you're just talking more.  Where's Usenet?
>
> The idea is a pre-fork socket server.  What I want to do is fork off
> some child processes from the parent and use IPC to send the
> connection object (via socket.accept()) over a pipe to one of the
> preexisting child processes and have said child handle the
> transaction.  Think Apache, if you want an example of what I'm trying
> to do here.  This alleviates the process startup cost that occurs when
> you fork.  If the socket object can't be serialized, is there another
> way to go about handling this in python?- Hide quoted text -
>
> - Show quoted text -

That's out of my expertise.  You would have to either hack it on a
router you are running (masquerade), or choose a different family of
sockets.  For HTTP, you could issue a 'reroute' return.  Just multi-
thread your server process.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Make Python create a tuple with one element in a clean way

2008-05-11 Thread MC

Hi!


You want 2*(3+4) to return (7,7)?


For have that:  2*(3+4,)




--
@-salutations

Michel Claveau


--
http://mail.python.org/mailman/listinfo/python-list


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Ben Finney
John Salerno <[EMAIL PROTECTED]> writes:

> Ben Finney wrote:
> 
> > John Salerno <[EMAIL PROTECTED]> writes:
> >
> >> num = 33
> >> 
> >> for x in xrange(10):
> >> print num += 1
> >
> > Which is better done by 'num += 10'.
> >
> > Can you come up with an example that isn't trivially replaced with
> > clearer code? That might make it clearer what your concern is.
> 
> ::sigh:: No, unfortunately I don't have a strong enough grasp of
> Python to give a really in-depth example.

It need not be in-depth, merely illustrative of the problem being
addressed.

> I understand what you're asking though. Perhaps people don't use
> this idiom as much as I think they do, so to give a trivial example
> to support my point isn't helpful.

I think that the idiom

for unused in xrange(10):
# do stuff with no reference to 'unused'

is quite common. Is that what you're asking about?

> As far as I know, though, I think this is used often enough, so I
> thought I'd just ask if there are purists out there who don't like
> this use of the loop and feel it's an abuse of the syntax.

No, it seems quite a normal usage of the syntax and a good use of an
iterator.

With "do something N times", there must be *something* to keep track
of which iteration we're up to (or, equivalently, how many iterations
remain) at a given moment. A Python iterator seems a fine choice to
hold that information, and better than many alternatives.

-- 
 \ "My house is on the median strip of a highway. You don't really |
  `\notice, except I have to leave the driveway doing 60 MPH."  -- |
_o__)Steven Wright |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Ivan Illarionov
>> In such cases, the name 'dummy' is conventionally bound to the items
>> from the iterator, for clarity of purpose
[..]
> If a value isn't used, then I think the most clear name for it is
> "unused".
[...]

Maybe my brain works differently, but I find both "dummy" and "unused" 
are extremely confusing names for loop counters. The loop begins to look 
like it doesn't iterate at all if its counter is dummy or unused.

If it *counts* it is *used* and it's *not* dummy.

Why reinvent the wheel when "a common identifier naming convention is for 
the loop counter to use the variable names i, j and k (and so on if 
needed)" (from Wikipedia http://en.wikipedia.org/wiki/Loop_counter )

-- Ivan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Accepting text input

2008-05-11 Thread Collin

Collin wrote:
I'm pretty new to Python, but this has really bugged me. I can't find a 
way around it.



The problem is that, when I use raw_input("sajfasjdf") whatever, or 
input("dsjfadsjfa"), you can only have numerical values as answers.


Any help would be appreciated. Thanks.



Oh, wow. I feel so stupid. Please disregard this message. <_<

I read the error message just now a bit more carefully, and I tried 
something. I tried defining "yes" as some random numerical value. Then 
when I did:

(example code)

yes = 123123983 #some number
test = input("Test test test ")
if test == yes:
print "It worked."
else:
print "failed"

(example code off)

Collin
--
http://mail.python.org/mailman/listinfo/python-list


Accepting text input

2008-05-11 Thread Collin
I'm pretty new to Python, but this has really bugged me. I can't find a 
way around it.



The problem is that, when I use raw_input("sajfasjdf") whatever, or 
input("dsjfadsjfa"), you can only have numerical values as answers.


Any help would be appreciated. Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Module python-magic on/for Windows?

2008-05-11 Thread Larry Hale
THANKS, AGAIN, for the reply!  :)

Okay, now I -really- feel silly...  :>

So, when I was going to try what you'd suggested, I noticed something
peculiar: I hadn't "changed" anything on my system, but now, when I
tried to "import magic" I got a missing DLL error.  For a DIFFERENT
DLL!  This got me to thinking...

Turns out, when I was having "success" earlier, I was -in- the C:
\Program Files\GnuWin32\bin directory (where file.exe and related .dll
files are).

So I added C:\Program Files\GnuWin32\bin to the (system/Windows)
PATH.  Everything worked.  I removed all the copious copies of the
DLL, the magic files, etc., littering my hard drive in every other
location.  Still worked.

'Course, I don't honestly know why it didn't work with the files
copied to other locales contained in the sys/Py paths... perhaps it
was, as you mentioned, wanting the tree-structure to be the same?  (I
haven't the heart to check this out fully right now... *maybe* at a
later time...  ;) )

Yeah, I know.  But HONESTLY!  I could have -sworn- I'd already tried
THAT... you know, all the "obvious"/"I've been programming/working in
computers (albeit 'Windows' until lately) for ~25 years; yeah, I'm a
'hacker'..." stuff.  I -swear-!

[EGG ON FACE]

[SIGH]  Well, I'd say "live and learn", but I'm still scratching my
head.  But, 'nough of that.  Thanks for your replies, Michael, and I'm
off to work _with_ the module now, then work-up my HowTo (and
experiment with making an "egg"?? ;) )...


Caio!
-Larry  :P  :)



On May 11, 11:09 pm, Michael Torrie <[EMAIL PROTECTED]> wrote:
> Larry Hale wrote:
> > ALSO: I've even tried putting the 4 "magic" files INTO the .egg
> > file... still no-go.  :/
>
> It's often the custom of programs ported from unix to windows to use the
> dll location as a key to find the other files that are typically in
> share, or etc.  GTK, for example uses ../share and ../etc from the
> location where the dlls are stored (if the dlls are in a folder called bin).
>
> In this case I'd try making a folder in the Python25 folder called
> "share" and put the contents of the gnuwin32 share/file stuff in there.
>  Should look something like this:
>
> c:/python25/share/file/magic.mime.mgc
> c:/python25/share/file/magic
> c:/python25/share/file/magic.mgc
> c:/python25/share/file/magic.mime
>
> Or, judging by a string I found in the dll itself, you might have to put
> the files here:
>
> c:/progra~1/File/share/file/magic
>
> Although if such a path really is hardcoded into the dll, this is
> certainly a bug, since it will fail on certain non-english windows systems.
>
> Anyway, who knows.  Give these options a try.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Free Memory

2008-05-11 Thread Gabriel Genellina
En Sun, 11 May 2008 01:06:13 -0300, Patrick Mullen <[EMAIL PROTECTED]> escribió:

> Yeah I don't know much about locals or globals.  I've never used them
> before, just know they are there.  But anyway, to illustrate what I meant by
> the interesting behavior, here is the output (and sorry for it being so
> long):
>
> IDLE 2.6a2
 globals()
> {'__builtins__': , '__name__': '__main__',
> '__doc__': None, '__package__': None}
 globals().clear()
 globals()
> {'__builtins__': {'bytearray': , 'IndexError':  'exceptions.WindowsError'>}}

>
> The OP wanted to clear the interpreter and I took a very broad (and highly
> unresearched) stab at it, and saw some behavior that I wasn't expecting.
> So before, all the builtin variables are hidden away in __builtins__, but
> after clearing globals, they are filled into globals.  This doesn't really
> make sense to me, but I don't know much about __builtins__ or globals.

Look more carefully:

py> globals().clear()
py> len(globals())
1
py> globals().keys()
['__builtins__']

globals() contains now a single entry, the namespace of the __builtin__ module 
(that is, __builtin__.__dict__), not the individual builtin entries (these are 
the dictionary entries that you posted).
As you later noticed, this happens only on IDLE. I don't know why IDLE behaves 
that way, but avoid entering "restricted mode" may be a reason (see 
http://docs.python.org/lib/restricted.html )
Usually, __builtins__ contains a reference to the __builtin__ module itself 
*only* in __main__; in all other modules, __builtins__ contains a reference to 
the __builtin__ namespace (like what you got in IDLE after clearing globals). I 
don't know *why* they are different either.

-- 
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Convention for name indicating "don't care about the value" (was: Is using range() in for loops really Pythonic?)

2008-05-11 Thread Carl Banks
On May 11, 11:41 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:
> Carl Banks <[EMAIL PROTECTED]> writes:
> > On May 11, 6:44 pm, Ben Finney <[EMAIL PROTECTED]>
> > wrote:
> > > In such cases, the name 'dummy' is conventionally bound to the items
> > > from the iterator, for clarity of purpose::
>
> > > for dummy in range(10):
> > > # do stuff that makes no reference to 'dummy'
>
> > Is this documented?
>
> It's not a documented standard, to my knowledge.
>
> > I've never heard of this convention. It's not PEP 8, and I've never
> > seen consistent usage of any name. I'd be interested in knowing
> > where you read that this was a convention, or in what subcommunities
> > it's a convention in.
>
> It has been in this forum that the use of the name '_' for "don't care
> about the value" was deprecated, since that name is already overloaded
> with other meanings.

That doesn't follow at all from what you wrote: no one in this thread
had even mentioned the usage of "_" for unused values--how did you
expect us to know you were talking about something no one brought up?

So it seems that usage of "dummy" is not a convention, and avoidance
of "_" is not really a convention except on this group.


> > I think dummy is a terrible name to use for this, since in no other
> > usage I can think of does the word "dummy" suggest something isn't
> > used.
>
> I think it's far superior to '_'. I'd be just as happy with any other
> name that explicitly distinguishes itself for this purpose.
>
> > If a value isn't used, then I think the most clear name for it is
> > "unused".
>
> Sounds good to me. Now we merely need to convince the world.

I'm happy to discourage the world from using "_" for this purpose;
ambivalent whether you even need to use a specific name.


Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list


Re: threading - race condition?

2008-05-11 Thread Gabriel Genellina
En Sun, 11 May 2008 13:16:25 -0300, skunkwerk <[EMAIL PROTECTED]> escribió:

> the only issue i have now is that it takes a long time for 100 threads
> to initialize that connection (>5 minutes) - and as i'm doing this on
> a webserver any time i update the code i have to restart all those
> threads, which i'm doing right now in a for loop.  is there any way I
> can keep the thread stuff separate from the rest of the code for this
> file, yet allow access?

Like using a separate thread to create the other 100?

-- 
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Module python-magic on/for Windows?

2008-05-11 Thread Michael Torrie
Larry Hale wrote:
> ALSO: I've even tried putting the 4 "magic" files INTO the .egg
> file... still no-go.  :/

It's often the custom of programs ported from unix to windows to use the
dll location as a key to find the other files that are typically in
share, or etc.  GTK, for example uses ../share and ../etc from the
location where the dlls are stored (if the dlls are in a folder called bin).

In this case I'd try making a folder in the Python25 folder called
"share" and put the contents of the gnuwin32 share/file stuff in there.
 Should look something like this:

c:/python25/share/file/magic.mime.mgc
c:/python25/share/file/magic
c:/python25/share/file/magic.mgc
c:/python25/share/file/magic.mime

Or, judging by a string I found in the dll itself, you might have to put
the files here:

c:/progra~1/File/share/file/magic

Although if such a path really is hardcoded into the dll, this is
certainly a bug, since it will fail on certain non-english windows systems.

Anyway, who knows.  Give these options a try.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread John Salerno
Ben Finney wrote:

> John Salerno <[EMAIL PROTECTED]> writes:
>
>> num = 33
>> 
>> for x in xrange(10):
>> print num += 1
>
> Which is better done by 'num += 10'.
>
> Can you come up with an example that isn't trivially replaced with
> clearer code? That might make it clearer what your concern is.

::sigh:: No, unfortunately I don't have a strong enough grasp of Python
to give a really in-depth example. I understand what you're asking
though. Perhaps people don't use this idiom as much as I think they do,
so to give a trivial example to support my point isn't helpful.

As far as I know, though, I think this is used often enough, so I
thought I'd just ask if there are purists out there who don't like this
use of the loop and feel it's an abuse of the syntax.
--
http://mail.python.org/mailman/listinfo/python-list


Re: anonymous assignment

2008-05-11 Thread Ben Finney
Paul Rubin  writes:

> Yves Dorfsman <[EMAIL PROTECTED]> writes:
> > I know you can't assign anything to None, but I'm sure you get what I
> > mean, a special keyword that means I don't care about this value.

Snap. This topic was raised today in another thread.

> You can just use a variable name than you ignore. It's traditional
> to use _ but it's not a special keyword, it's just a another
> variable name:
> 
>y, _, d, _, _, _, _, _, _ = time.localtime()

It's a terrible name for that purpose, since it doesn't indicate the
intention explicitly, and it's already overloaded in meaning by a
pre-existing convention (ref. the 'gettext' module in Python and many
other languages).

Far better to use the name 'unused' as suggested by Carl Banks earlier
today.

(good sigmonster, have a cookie)

-- 
 \"Choose mnemonic identifiers. If you can't remember what |
  `\mnemonic means, you've got a problem." —Larry Wall |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: anonymous assignment

2008-05-11 Thread Yves Dorfsman

D'Arcy J.M. Cain wrote:

On Mon, 12 May 2008 02:28:13 GMT
Yves Dorfsman <[EMAIL PROTECTED]> wrote:

particular case, there's got to be a better way than:

d = time.local()
y = d[0]
d = d[1]


Like this?

y, d = time.local()[:2]


Sorry this was a typo (again :-), I meant:

d = time.local()
  y = d[0]
  d = d[2]

Yves.
http://www.SollerS.ca
--
http://mail.python.org/mailman/listinfo/python-list


Convention for name indicating "don't care about the value" (was: Is using range() in for loops really Pythonic?)

2008-05-11 Thread Ben Finney
Carl Banks <[EMAIL PROTECTED]> writes:

> On May 11, 6:44 pm, Ben Finney <[EMAIL PROTECTED]>
> wrote:
> > In such cases, the name 'dummy' is conventionally bound to the items
> > from the iterator, for clarity of purpose::
> >
> > for dummy in range(10):
> > # do stuff that makes no reference to 'dummy'
> 
> Is this documented?

It's not a documented standard, to my knowledge.

> I've never heard of this convention. It's not PEP 8, and I've never
> seen consistent usage of any name. I'd be interested in knowing
> where you read that this was a convention, or in what subcommunities
> it's a convention in.

It has been in this forum that the use of the name '_' for "don't care
about the value" was deprecated, since that name is already overloaded
with other meanings.

> I think dummy is a terrible name to use for this, since in no other
> usage I can think of does the word "dummy" suggest something isn't
> used.

I think it's far superior to '_'. I'd be just as happy with any other
name that explicitly distinguishes itself for this purpose.

> If a value isn't used, then I think the most clear name for it is
> "unused".

Sounds good to me. Now we merely need to convince the world.

-- 
 \  “Software patents provide one more means of controlling access |
  `\  to information. They are the tool of choice for the internet |
_o__) highwayman.” —Anthony Taylor |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: anonymous assignment

2008-05-11 Thread Yves Dorfsman

Paul Rubin wrote:

Yves Dorfsman <[EMAIL PROTECTED]> writes:

import time
y, None, d, None, None, None, None = time.localtime()

I know you can't assign anything to None, but I'm sure you get what I
mean, a special keyword that means I don't care about this value.


You can just use a variable name than you ignore.  It's traditional to
use _ but it's not a special keyword, it's just a another variable name:

   y, _, d, _, _, _, _, _, _ = time.localtime()


But you still have have a variable that's using memory for nothing. I find 
this unsatisfactory... I don't want to compare languages, but I find the 
perl "undef" elegant.



Yves.
http://www.SollerS.ca
--
http://mail.python.org/mailman/listinfo/python-list


Re: Module python-magic on/for Windows?

2008-05-11 Thread Larry Hale
On May 10, 11:41 pm, Larry Hale <[EMAIL PROTECTED]> wrote:
> I've heard tell of a Python binding for libmagic (file(1) *nixy
> command; seehttp://darwinsys.com/file/).  Generally, has anybody
> built this and worked with it under Windows?
>
> The only thing I've been able to find is the python-magic module 
> athttp://hupp.org/adam/hg/python-magic/.
>
> [1] Is this "THE" python-magic module.  (It seems to be to me, but
> obviously I don't know. :)
>
> [2] Has anybody been able to build THIS version under Windows?
>
> I've gotten as far as completing the "setup.py install" process.
> (After many troubles; I'll post the top-to-bottom HowTo-like info if/
> when I ever get it to work.  :)
>
> At this point, there -is- a "magic" module that can be imported
> (attempted-to, that is), but it fails.
>
> If I go to a cmd window, run the Py interpreter, and do "import magic"
> I get:
>
> [1] an error pop-up (Windows window, which is blocking [as opposed
> to "non-blocking", not "obscuring", though it does that, too] the cmd
> window):
>
> (X) This application has failed to start because magic1.dll
> was not found.  Re-installing the application may fix this problem.
> [OK]
>
> [2] then, within the interpreter, I get:
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "build\bdist.win32\egg\magic.py", line 2, in 
>   File "build\bdist.win32\egg\cmagic.py", line 7, in 
>   File "build\bdist.win32\egg\_cmagic.py", line 7, in 
>   File "build\bdist.win32\egg\_cmagic.py", line 6, in
> __bootstrap__
> ImportError: DLL load failed: The specified module could not
> be found.
>
> I'm using Python 2.5 on Windows XP Pro.  I've got CYGWIN installed
> (more info can be provided if necessary) for a copy of file.exe (and
> libmagic.a @ 357KB and libmagic.dll.a @ 25KB in C:\cygwin\lib).  I
> also have GNUWin32, also for file.exe alternatively (and
> libmagic.dll.a @ ~ 8KB in C:\Program Files\GnuWin32\lib).
>
> magic.py in C:\Program Files\Python25\Lib\site-packages\magic-0.1-
> py2.5-win32.egg imports cmagic.py (also in this egg), which imports
> _cmagic.py, which has the following:
>
> def __bootstrap__():
>global __bootstrap__, __loader__, __file__
>import sys, pkg_resources, imp
>__file__ =
> pkg_resources.resource_filename(__name__,'_cmagic.pyd')
>del __bootstrap__, __loader__
>imp.load_dynamic(__name__,__file__)
> __bootstrap__()
>
> Now I *presume* my problem (at this point) is that I need to have
> libmagic named as "magic1.dll" -wherever- this module is looking for
> it.  I'm just not sure, let alone if this is true, WHERE Python/
> modules expect to find such things.
>
> Also, which version(s)/file(s) should be placed where, or...??
>
> Thanks for any/all help/pointers.  I apologize up-front if I left out
> any pertinent info; I'm paranoid about putting in too much (and some
> that may be worthless) already...  :)
>
> Cheers,
> Larry Hale

ALSO: I've even tried putting the 4 "magic" files INTO the .egg
file... still no-go.  :/


Thanks, all!
-Larry
--
http://mail.python.org/mailman/listinfo/python-list


Re: Mathematics in Python are not correct

2008-05-11 Thread Mark Dickinson
On May 11, 9:36 pm, "Terry Reedy" <[EMAIL PROTECTED]> wrote:
> Do you have in mind any situations in which it is advantageous to have 0**0
> undefined?

(Playing devil's advocate here.) If you regard x**y as exp(y*log(x))
then it's not at all clear that 0.**0. should be considered
well-defined. And since Python likes integer and floating-point
operations to match numerically (as far as possible), 0**0 then
also comes into question.

The big problem here is that the power operation is really trying
to combine two subtly different functionalities (integer powers
and real powers), with quite distinct use-cases, into a single
function.  Which leads to problems:  witness the mess that's
C99's pow specification:  why does it make sense for (-2.0)**2.0 to
return 4.0, while (-2.0)**1.9 returns NaN?  And why
should (-2.0)**infinity be well-defined?

It looks like that same mess is going to make it into IEEE 754r.
There were suggestions on the 754r mailing list to separate
the pow functionality out into two separate functions: pown
for integer powers and powr for real powers.  pown(0.0, 0) would
be 1, while powr(x, y) would be defined strictly as exp(y*log(x))
and so powr(0.,0.) would raise the invalid signal.

I have to admit that almost all my uses of ** are with
integer exponents, and I'd be very upset if anyone took
0**0 == 1 away...

Incidentally, the decimal module is slightly schizophrenic about
this:  Decimal(0)**Decimal(0) raises an exception, but
Decimal('Inf')**Decimal(0) returns Decimal(1).  Which doesn't
make a lot of sense, since every reason for making 0**0
undefined seems to apply equally well to infinity**0...

Mark

--
http://mail.python.org/mailman/listinfo/python-list


Re: anonymous assignment

2008-05-11 Thread D'Arcy J.M. Cain
On Mon, 12 May 2008 02:28:13 GMT
Yves Dorfsman <[EMAIL PROTECTED]> wrote:
> particular case, there's got to be a better way than:
> 
> d = time.local()
> y = d[0]
> d = d[1]

Like this?

y, d = time.local()[:2]

-- 
D'Arcy J.M. Cain <[EMAIL PROTECTED]> |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Corum Bubble Diamond Steel Pink Ladies Watch 196-151-47-0F08-PN96S

2008-05-11 Thread yxs046
Corum Bubble Diamond Steel Pink Ladies Watch 196-151-47-0F08-PN96S

Corum Bubble Diamond Steel Pink Ladies Watch 196-151-47-0F08-PN96S
Link :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F08-PN96S.html

Corum Bubble Diamond Steel Pink Ladies Watch 196-151-47-0F08-PN96S
Information :

Brand :   Corum Watches ( http://corum.hotwatch.org/ )
Gender :  Ladies
Code :   Corum-Ladies-Watch-196-151-47-0F08-PN96S
Item Variations :   196-151-47-0F08-PN96S, 196151470F08PN96S,
Corum-196-151-47-0F08-PN96S
Movement :Quartz
Bezel :   Diamond
Case Material :Stainless Steel
Case Diameter :   35.5mm
Dial Color :   Pink Mother-of-pearl
Crystal : Scratch Resistant Sapphire
Clasp :   Pink Leather
Water Resistant : 50m/165ft

Stainless Steel Case. Pink Leather Coated Rubber Strap. Pink Mother-of-
pearl Dial. Diamond Bezel. Push Button Deployment Clasp. Domed Scratch
Resistant Sapphire Crystal. Date Displays At 6 O'clock Position.
Chronograph Measures 1/10th Second, 30 Minutes, And 60 Seconds. Case
Diameter 35.5mm. Case Thickness 18mm. Quartz Movement. Water Resistant
At 50 meters (165 feet).

The Same Corum Watches Series :

Corum Bubble Diamond Steel Pink Ladies Watch 196-151-47-0F08-PN96R :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F08-PN96R.html

Corum Bubble Diamond Steel Blue Ladies Watch 196-151-47-0F03-FB30S :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F03-FB30S.html

Corum Bubble Diamond Steel Blue Ladies Watch 196-151-47-0F03-FB30R :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F03-FB30R.html

Corum Bubble Diamond Steel Brown Ladies Watch 196-151-47-0F02-EB30R :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F02-EB30R.html

Corum Bubble Diamond Steel Black Ladies Watch 196-151-47-0F01-PN94S :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F01-PN94S.html

Corum Bubble Diamond Steel Black Ladies Watch 196-151-47-0F01-PN94R :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F01-PN94R.html

Corum Bubble Diamond Steel Black Ladies Watch 196-151-47-0F01-FM30S :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F01-FM30S.html

Corum Bubble Diamond Steel Black Ladies Watch 196-151-47-0F01-FM30R :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-151-47-0F01-FM30R.html

Corum Bubble Steel Orange Ladies Watch 196-150-20-0F14-FM30R :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-150-20-0F14-FM30R.html

Corum Bubble Steel Orange Ladies Watch 196-150-20-0F14-EB30S :
http://corum.hotwatch.org/Corum-Ladies-Watch-196-150-20-0F14-EB30S.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: anonymous assignment

2008-05-11 Thread Paul Rubin
Yves Dorfsman <[EMAIL PROTECTED]> writes:
> import time
> y, None, d, None, None, None, None = time.localtime()
> 
> I know you can't assign anything to None, but I'm sure you get what I
> mean, a special keyword that means I don't care about this value.

You can just use a variable name than you ignore.  It's traditional to
use _ but it's not a special keyword, it's just a another variable name:

   y, _, d, _, _, _, _, _, _ = time.localtime()
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Ivan Illarionov
On Sun, 11 May 2008 18:52:48 -0700, Carl Banks wrote:

> On May 11, 6:44 pm, Ben Finney <[EMAIL PROTECTED]>
> wrote:
>> In such cases, the name 'dummy' is conventionally bound to the items
>> from the iterator, for clarity of purpose::
>>
>> for dummy in range(10):
>> # do stuff that makes no reference to 'dummy'
> 
> Is this documented?  I've never heard of this convention.  It's not PEP
> 8, and I've never seen consistent usage of any name.  I'd be interested
> in knowing where you read that this was a convention, or in what
> subcommunities it's a convention in.
> 
> I think dummy is a terrible name to use for this, since in no other
> usage I can think of does the word "dummy" suggest something isn't used.
>  In fact, quite the opposite.  For example, the dummy_threads module is
> most definitely used; the word dummy means that it's stripped down. 
> Based on that, your usage of the symbol dummy above would suggest to me
> that it's a value used in lieu of something else (such as a calculated
> value).
> 
> In mathematics, a dummy argument another name for the independent
> variable of a function (or more accurately, the symbol used to represent
> it), which also doesn't match your usage.
> 
> If a value isn't used, then I think the most clear name for it is
> "unused".
> 
> 
> Carl Banks

I agree with Carl. This group is the only place I've heard about this 
convension and it looks terrible IMO. Even if a value is not used, the 
variable still has a meaning: it is a counter, or an index.

I know about the other convention: "for i in xrange" or "for i in range".
Wikipedia agrees with me:
http://en.wikipedia.org/wiki/For_loop
Examples in wikipedia article use either "i" or "counter".

It is established convention in almost every programming language and its 
origins are in mathematics (matrix indices).

Google search for "for dummy in range" (with quotes) gives 164 results
While "for dummy in range" gives 146 000 results. Almost thousand times 
more.

So, "i" is more conventional and as such is more readable.

-- Ivan
--
http://mail.python.org/mailman/listinfo/python-list


anonymous assignment

2008-05-11 Thread Yves Dorfsman

Is there anyway to tell python I don't care about a value ?

Say I want today's year and day, I'd like to do something like:

import time
y, None, d, None, None, None, None = time.localtime()

I know you can't assign anything to None, but I'm sure you get what I mean, 
a special keyword that means I don't care about this value. In this 
particular case, there's got to be a better way than:


d = time.local()
y = d[0]
d = d[1]



Thanks.


Yves.
http://www.SollerS.ca
--
http://mail.python.org/mailman/listinfo/python-list


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread 7stud
On May 11, 5:50 pm, Gary Herron <[EMAIL PROTECTED]> wrote:
> bc90021 wrote:
> > You are a perfect example of exactly what I was talking about, and why
> > the Python community is such a poor one.
>
> I though you were treated quite fairly all things considered.   (You
> started the personal attacks, the whining about the group, the
> accusations of arrogance, and the refusal to believe we all *knew* the
> error was in your file name calculation and not in Python threads.)
>
> This group is widely acknowledged as one of the more friendly groups
> around,  and in fact we keep it that way by coming down rather hard on
> those who abuse either the members of the group or the purpose of the
> group.

That is a blantant lie.   This group has well known members that are
some of the biggest jackasses I've ever encountered on the internet.
I've never heard a peep out of anyone criticizing their behavior.  If
I were their employer, and I read some of the stuff they posted, I
would fire them on the spot.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Saving an audio file's waveform into an image

2008-05-11 Thread Larry Hale
On May 9, 1:55 am, Julien <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I would like to pull out the waveform of an audio file and save it
> into an image file, for example in GIF format. Is that achievable, and
> if so, how?
>
> I heard about the Snack module, but the project looks dead and un-
> maintained.
>
> Your advice would be greatly appreciated.
>
> Thanks!
>
> Julien


Would you please provide more info on what you're wanting to
accomplish?

As for "Snack module", all I could find was 
http://www.wanware.com/tsgdocs/snack.html,
which seems "dead", although the Google cached version at
http://64.233.167.104/search?q=cache:gNGrrPqY5RsJ:www.wanware.com/tsgdocs/snack.html+python+snack+module&hl=en&ct=clnk&cd=1&gl=us
makes it sound rather UNlike what you're talking about.  (Other ref's
for my Google search of 
http://www.google.com/search?hl=en&q=python+snack+module&btnG=Google+Search
seemed to show the same thing.)


The short answer is: Huh?/What?/Why?  Why not put the picture + sound
==> video file.  (Sure the image remains static, but there's the
Soundtrack with it!  ;) )


Cheers,
-Larry Hale
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Carl Banks
On May 11, 6:44 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:
> In such cases, the name 'dummy' is conventionally bound to the items
> from the iterator, for clarity of purpose::
>
> for dummy in range(10):
> # do stuff that makes no reference to 'dummy'

Is this documented?  I've never heard of this convention.  It's not
PEP 8, and I've never seen consistent usage of any name.  I'd be
interested in knowing where you read that this was a convention, or in
what subcommunities it's a convention in.

I think dummy is a terrible name to use for this, since in no other
usage I can think of does the word "dummy" suggest something isn't
used.  In fact, quite the opposite.  For example, the dummy_threads
module is most definitely used; the word dummy means that it's
stripped down.  Based on that, your usage of the symbol dummy above
would suggest to me that it's a value used in lieu of something else
(such as a calculated value).

In mathematics, a dummy argument another name for the independent
variable of a function (or more accurately, the symbol used to
represent it), which also doesn't match your usage.

If a value isn't used, then I think the most clear name for it is
"unused".


Carl Banks
--
http://mail.python.org/mailman/listinfo/python-list


Re: list object

2008-05-11 Thread Larry Hale
On May 10, 12:39 pm, Gandalf <[EMAIL PROTECTED]> wrote:
> my manual contain chapter about lists with python. when i try to copy
> paste :
>
> li = ["a", "b", "mpilgrim", "z", "example"] (1)
>
> it i get this errore:
>
> "TypeError: 'list' object is not callable"
>
> i was wondering if their is  any special module I should import before
> i use this function
>
> i know i ask foolish questions it's my first day with python and i
> have experience only with PHP and javascript, so please be patient
>
> thanks


To expand upon what others have already mentioned, and/or to explain
what's going on...

li ==>> a label for a "list" (presume the author used it as short-
hand?); trying to set it to point-to/"equal"...

["a", "b", "mpilgrim", "z", "example"] ==>> THE LIST

A "list" is a mutable (changeable in-place) container object.
See e.g.: http://www.diveintopython.org/native_data_types/lists.html

(1) ==>> the Python interpreter will interpret this as if you're
attempting to "call" the list object (["a", "b", ...]) as if it were a
function/method


Indeed, the "(1)" is what's causing the problem, but it's -because-
the list *object* is, well, "not callable".  :)

As an aside, see what "li" contains if you do:

li = ["a", "b", "mpilgrim", "z", "example"][1]

;)


Cheers!
-Larry Hale
--
http://mail.python.org/mailman/listinfo/python-list


Re: python without while and other "explosive" statements

2008-05-11 Thread Matt Nordhoff
ivo talvet wrote:
> Hello,
> 
> Is it possible to have a python which not handle the execution of
> "while", "for", and other loop statements ? I would like to allow
> remote execution of python on a public irc channel, so i'm looking for
> techniques which would do so people won't be able to crash my computer
> (while 1: os.fork(1)), or at least won't won't freeze my python in a
> infinite loop, make it unresponsive. Is there a compiling option (or
> better, something i can get with apt-get cos i think compiling myself
> and handle all the metastuff myself is somehow dirty) for have a
> "secure python" (you can guess what i mean by "secure" in my case) or
> must i touch myself the source disable some code lines ? If last
> solution, which modifications in which files should i do ? (sorry for
> my bad english)
> 
> Thanks.
> 
> Ivo

 is a pastebin-like website that lets people upload
code in a dozen different languages, and it runs it. They have info up
about how it's secure at .

I'm pretty sure there's another similar website that's specific to
Python, but I can't remember it. Anyway, it was similar, using virtual
machines, a firewall, and killing stuff that ran for longer than 20
seconds, IIRC.

(Thanks for the link to codepad, habnabit.)
-- 
--
http://mail.python.org/mailman/listinfo/python-list


Re: Orlando Florida Python Tutor Needed

2008-05-11 Thread Larry Hale
On May 10, 11:42 am, vbgunz <[EMAIL PROTECTED]> wrote:
> I will pay anyone for a face-to-face tutoring in the Orlando Florida
> area. I will pay $20.00 per hour (minimum 2 hours needed). What I need
> are lessons in Decorators and Class methods. If I can walk away with
> at least 5 lessons taught in both subjects I will be happy to offer an
> additional $20.00.
>
> If you are interested in this offer feel free to either reply through
> email OR here on this thread. There are no string attached, catches,
> etc. I need to learn and if you can teach well, I will be happy to
> learn.
>
> Best Regards
> Victor B. Gonzalez


I know you're looking for "one-on-one" help, direction, and/or
tutelage, but since you've not received an answer (yet), here's some
general info...

---

For Class Methods, perhaps you could mention more of what you need to
know?  Otherwise, generically see:

http://docs.python.org/tut/node11.html#SECTION001134
http://www.geocities.com/foetsch/python/new_style_classes.htm

http://www.diveintopython.org/object_oriented_framework/defining_classes.html

and obviously

http://www.google.com/search?hl=en&q=python+class+methods&btnG=Google+Search

---

For Decorators, have a gander at:


http://www.ddj.com/web-development/184406073;jsessionid=QCNTPTSNXZP2WQSNDLPCKHSCJUNN2JVN?_requestid=749134
http://www.ibm.com/developerworks/linux/library/l-cpdecor.html

and obviously

http://www.google.com/search?hl=en&q=python+decorators&btnG=Google+Search

Decorators are still rather new to -me-, and I've yet to "need" 'em,
but they _seem_ like a handy feature.  (Personally, I don't care too
much for the syntax, but other than explicitly DOING what they do,
which would be [1] messier and/or [2] non-transparent/duplicative, I
sadly have no alternative thought[s]...  ;) )


Cheers,
-Larry Hale
--
http://mail.python.org/mailman/listinfo/python-list


Re: Make Python create a tuple with one element in a clean way

2008-05-11 Thread Asun Friere
On May 11, 10:54 pm, [EMAIL PROTECTED] wrote:
> To create a tuple with one element, you need to do this:
>
> >>> my_tuple = (1,)# Note the trailing comma after the value 1
> >>> type(my_tuple)
>
> 
>

You needn't at all.  You could simply do this:

>>> your_tuple = 1,

You see, it's not the parentheses that make the tuple.


> But if you do this
>
> >>> my_tuple = (1)
> >>> type(my_tuple)
>
> 
>
> you don't get a tuple.

For which the BDFL should make us eternally grateful.

> it would be clean if Python would convert anything put into ( ) to
> be a tuple

You seriously want 2*(3+4) to return (7,7)?  You call that "clean"?!

At least type(my_tuple) would always return 'tuple,' whether it was or
not. ;)

--
http://mail.python.org/mailman/listinfo/python-list


Re: Mathematics in Python are not correct

2008-05-11 Thread Terry Reedy

"Tim Roberts" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| [EMAIL PROTECTED] wrote:
| >
| >I am stunned that this simple misunderstanding of mine ended in a
| >mathematical clash of a sort. :)  You guys really blew me away wih
| >your mathematical knowledge. And also the 0**0 is a thing I've never
| >thought about trying, until now that is. If the mathematical rule is
| >that EVERYTHING raised to the power of 0 is 1, then we should accept
| >that, even in the case of 0**0. This is just the way it is.
|
| Sure, but it's ALSO the mathematical rule that 0 raised to any power is 
0.

That may be some people's (partial) rule but not everyone's.
There is only agreement on 0 to a positive power.

| Thus, there are multiple solutions to this problem, meaning that there is
| NO solution to the problem.

Only for some people.
a**b := reduce(mul, [a]*b, 1) for all counts a and b is a simple, uniform, 
and useful rule.
Do you have in mind any situations in which it is advantageous to have 0**0 
undefined?

tjr



--
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE 3.0a5 has problems with Unicode

2008-05-11 Thread Terry Reedy

"Sven Siegmund" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
|> I have a source code which IDLE 3.0a5 cannot parse, but Python 3.0a5
| > can:
|
| Oh I see the posts in this newsgroup do not yet support Unicode.

I think this depends on the reader and maybe the fonts on the system.
OutlookExpress displays hatted c, for instance, fine.

 Most
| of the special characters in my source code have been messed up. But
| anyway, those who know Czech can handle it. The error is replicable
| even with the messed-up characters.



--
http://mail.python.org/mailman/listinfo/python-list


Re: how to separate words from a string?

2008-05-11 Thread Benjamin Kaplan
On Sun, May 11, 2008 at 8:15 PM, David Anderson <[EMAIL PROTECTED]>
wrote:

> Hi, how can I separate words from a sentence in a string? Like the
> java.String.split method
> I need something that gets an string "This is a sentence", and return to em
> a list["This","is","a","sentence"]
> Can anyone help?
> Thx
>

You should probably look in the docs before posting here. Python strings
also have a split method, that does the same thing as in java.
http://docs.python.org/lib/string-methods.html
--
http://mail.python.org/mailman/listinfo/python-list

Re: Module python-magic on/for Windows?

2008-05-11 Thread Larry Hale
After putting the magic1.dll file to C:\Program Files\Python25\DLLs
(looking at the directory structure, that seemed as good a place as
any), now I can *import* the module, but...

>>> import magic
>>> test = magic.Magic()
Traceback (most recent call last):
  File "", line 1, in 
  File "build\bdist.win32\egg\magic.py", line 32, in __init__
  File "build\bdist.win32\egg\magic.py", line 72, in _check_error
magic.MagicException: could not find any magic files!

I've placed

  474,146 magic
1,037,440 magic.mgc
   32,203 magic.mime
   45,696 magic.mime.mgc
   77,312 magic1.dll

into

C:\windows\system32
in Windows/System PATH
AND (simultaneously)
C:\Program Files\python25\DLLs
in sys.path/PYTHONPATH

(I've also tried putting copies into different dirs in both PYTHONPATH
and system PATH, to no avail.)

Obviously, magic1.dll/magic.py (et al) can't FIND the needed file(s),
but I'm not sure how to go about discerning WHERE it/they are looking
- any thought(s)/suggestion(s), anyone??


Thanks in advance!
-Larry


P.S.: Thanks, again, Michael!  ;)  - L
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Jonathsn Cronin
On Sun, 11 May 2008 16:16:53 -0400, John Salerno wrote
(in message <[EMAIL PROTECTED]>):

> XLiIV wrote:
> 
>> The range() function returns a list and list is a sequence, isn't?
> 
> I think you're missing the point. To me, there seems to be a fundamental 
> difference between these two things:
> 
> ---
> 
> people = ['Sam', 'Bob', 'Fred']
> 
> for name in people:
>  print name
> 
> ---
> 
> AND
> 
> ---
> 
> num = 33
> 
> for x in xrange(10):
>  print num += 1
> 
> ---
> 
> To me, the first example is a pure use of the for loop. You are 
> iterating through an object and *using* the items you are stepping through.
> 
> The second example, however, is simply doing something 10 times, and 
> what it's doing has nothing to do with 'x' or xrange. So it seems like 
> an abuse of the for loop.

I agree in principle; the first is iteration and the second is repetition.
In Python, the common idiom for a fixed number of repetitions is iterating 
over a number range.  This is true in most languages I am familiar with, 
probably because fixed repetition, where you don't care about the "index" 
value, is rarely used.

The only language I've used that does have fixed repetition is an (old) 
dialect of lisp, and I'm not sure it even made it into Common Lisp.  
Smalltalk and Ruby do have fixed repetition.

Using range may not be entirely elegant, but is pragmatic, and not, to me, 
particularly ugly.  In Python, unlike some languages, you don't have to 
declare the x.

I think you could add it without too much change to the parsing.

for :
  

Seeing a ":" instead of "in" would mean a repetition statement which would
be interpreted as:
-- if  evaluates to an integer, execute the block that number of 
times.
-- If  evaluates to an iterator, execute the block until the 
iterator is exhausted.

Even if possible, I see this at best a minor improvement and more likely a 
negative because the for keyword is now overloaded. (see "static" in C/Java.) 
You could add a new keyword but the benefit here is much to small to justify 
the trouble.

Jonathan

--
http://mail.python.org/mailman/listinfo/python-list


how to separate words from a string?

2008-05-11 Thread David Anderson
Hi, how can I separate words from a sentence in a string? Like the
java.String.split method
I need something that gets an string "This is a sentence", and return to em
a list["This","is","a","sentence"]
Can anyone help?
Thx
--
http://mail.python.org/mailman/listinfo/python-list

Re: Module python-magic on/for Windows?

2008-05-11 Thread Larry Hale
(quoted text below my reply)

THANK YOU SO MUCH, Michael!

Criminitly!  Figures!  HA!  I had it the WHOLE TIME, but didn't
realize it!  ;)  (As mentioned, I had FILE installed from GnuWin32.)
DUH!  I just neglected to do a search for "magic1.dll"... the most
obvious of the obvious!

I copied it from C:\Program Files\GnuWin32\bin\magic1.dll to C:
\Program Files\python25\libs.

Imports fine now.  (I'll *test* it later.  Then write-up my HowTo... I
think I'll even see if I can make an EGG for others... SOUNDS "easy"
with EasyInstall [http://peak.telecommunity.com/DevCenter/
EasyInstall]...  I'll -see-...  :) )

Ah, sometimes one CAN'T see the forest for the trees; a few hours
hacking away at getting things going to THIS point will do it to ya...
err, or at least "to me"!  :D


Thanks, again, Michael...
-Larry



On May 11, 11:34 am, Michael Torrie <[EMAIL PROTECTED]> wrote:
> Larry Hale wrote:
> > Now I *presume* my problem (at this point) is that I need to have
> > libmagic named as "magic1.dll" -wherever- this module is looking for
> > it.  I'm just not sure, let alone if this is true, WHERE Python/
> > modules expect to find such things.
>
> > Also, which version(s)/file(s) should be placed where, or...??
>
> The dll you are looking for is here:
>
> http://downloads.sourceforge.net/gnuwin32/file-4.21-bin.zip?modtime=1...
>
> The .dll.a file you mention is just a linker stub for when you want to
> compile against it (as you are doing when building python-magic).
>
> The magic1.dll file in the file-4.21-bin.zip package should be placed
> anywhere in the path.  Since you'll be using it with python, you could
> probably stick it in the python25/bin folder (where ever your python
> system is installed).

--
http://mail.python.org/mailman/listinfo/python-list


Re: python without while and other "explosive" statements

2008-05-11 Thread Grant Edwards
On 2008-05-11, ivo talvet <[EMAIL PROTECTED]> wrote:

> Is it possible to have a python which not handle the execution of
> "while", "for", and other loop statements ? I would like to allow
> remote execution of python on a public irc channel, so i'm looking for
> techniques which would do so people won't be able to crash my computer
> (while 1: os.fork(1)), or at least won't won't freeze my python in a
> infinite loop, make it unresponsive.

The easiest thing to to is to limit the amount of files,
disk-space, file descriptors, inodes, memory, cpu, and
processes that the users are allowed.  If bash is your shell,
the builtin "ulimit" provides most of those features.  The file
system quota features provide the rest.

> Is there a compiling option (or better, something i can get
> with apt-get cos i think compiling myself and handle all the
> metastuff myself is somehow dirty) for have a "secure python"
> (you can guess what i mean by "secure" in my case) or must i
> touch myself the source disable some code lines ? If last
> solution, which modifications in which files should i do?

My advice is don't try to secure Python itself: secure the
environment in which the users are using it.

-- 
Grant Edwards   grante Yow!  Did I SELL OUT yet??
  at   
   visi.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread Gary Herron

bc90021 wrote:
You are a perfect example of exactly what I was talking about, and why 
the Python community is such a poor one.


I though you were treated quite fairly all things considered.   (You 
started the personal attacks, the whining about the group, the 
accusations of arrogance, and the refusal to believe we all *knew* the 
error was in your file name calculation and not in Python threads.)


This group is widely acknowledged as one of the more friendly groups 
around,  and in fact we keep it that way by coming down rather hard on 
those who abuse either the members of the group or the purpose of the 
group.  And you've done both and been reprimanded for it.   Now, either 
go away, or change your attitude and join the group. (You would be 
welcome if the attitude changed.)  Either way, this group will be it's 
usual friendly self.



Gary Herron





Gary Herron wrote:

bc90021 wrote:

...and the exact error message was?

Here is a tip: if you want people to help you, then you have to help
them to help you.  Personally, I wouldn't respond to anymore of your
questions because you seem incapable of posting the information 
that was

requested.



So far, the people who have answered this post have gone on the 
assumption that I'm stupid.  I'm not.  I took perfectly working 
code, cut it from one class, and put it in another.  It stopped 
working in the second class.  I've spent days on this and trust me, 
given what I've experienced of the Python community so far, if I 
didn't have to ask, I wouldn't.


(I really must say that so far the help I am getting in the Python 
community is a big let down.  Whether it's on IRC or here, everyone 
has an arrogance that I don't find anywhere else in the open source 
community, and it seriously makes me question the choice of language 
that I've made.)
  


Sorry, the arrogance is yours.
   Expecting us to help with only partial information.

   Expecting us to help when your posts of the error message changes 
from one post to the next.


   Expecting us to help when you refuse to post the traceback.

   Expecting us to believe that it has anything to do with threads.  
(No one believes that for a moment.)



While acknowledging that any piece of code may have bugs, Python's 
threading included, the problem here looks to be some simple mistake 
in the computation of the name of the file to be opened.   Then I 
look at the convoluted quoting surrounding your computation of the 
file name, and my confidence in that as an explanation sky-rockets.  
Then someone in another post has found an extra set of quotes 
embedded in your filename you compute, and it's clear that we are on 
the right track.




The error message was at the top of the thread (am I incapable of 
posting it, or are you incapable of following a thread?), but here 
it is again:


IOError: [Errno 2] no such file u'tempfileName'

--
http://mail.python.org/mailman/listinfo/python-list
  








--
http://mail.python.org/mailman/listinfo/python-list


python without while and other "explosive" statements

2008-05-11 Thread ivo talvet
Hello,

Is it possible to have a python which not handle the execution of
"while", "for", and other loop statements ? I would like to allow
remote execution of python on a public irc channel, so i'm looking for
techniques which would do so people won't be able to crash my computer
(while 1: os.fork(1)), or at least won't won't freeze my python in a
infinite loop, make it unresponsive. Is there a compiling option (or
better, something i can get with apt-get cos i think compiling myself
and handle all the metastuff myself is somehow dirty) for have a
"secure python" (you can guess what i mean by "secure" in my case) or
must i touch myself the source disable some code lines ? If last
solution, which modifications in which files should i do ? (sorry for
my bad english)

Thanks.

Ivo
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python, are you ill?

2008-05-11 Thread Tim Roberts
[EMAIL PROTECTED] wrote:
>
>If you are in the interactive prompt of the Python interpreter and you
>do this
>
>print """Testing\"""   or   print '''Testing\'''
>
>you get three dots [...] as if Python expects a code block.

...which it does.

>If you
>press Enter, you get three dots again, and again, and again... You
>can't get out of the code block with pressing the Enter key; you have
>to press Ctrl+Z (if you're in Linux) in order to get out of that code
>block, 

No, you don't.  You can also enter """ or ''' to properly close the quote.

>If you do
>
>print "Testing\"   or   print 'Testing\'
>
>you get an error, but not of you use the triple quotes. Is that a bug
>in the interpreter perhaps?

As a general rule, when you are just beginning to learn some product, it is
safe to assume that anything you see as a bug in the product is almost
certainly a flaw in your understanding of the product.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: pickle problem

2008-05-11 Thread krustymonkey
On May 8, 7:29 pm, [EMAIL PROTECTED] wrote:
> On May 8, 4:35 pm, Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
>
>
>
> > Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> writes:
>
> > > On Thu, 08 May 2008 08:55:35 -0700, krustymonkey wrote:
>
> > >> The thing is, I'm not using slots by choice.  I'm using the standard
> > >> lib "socket" class, which apparently uses slots.
>
> > > `socket` objects can't be pickled.  Not just because of the
> > > `__slot__`\s but because a substantial part of their state lives in
> > > the operating system's space.
>
> > Of course, if it makes sense to pickle sockets in the application, one
> > is can do so by defining __getstate__ and __setstate__:
>
> > class Connection(object):
> > def __init__(self, host, port):
> > self.host = host
> > self.port = port
> > self.init_sock()
>
> > def init_sock(self):
> > self.sock = socket.socket()
> > self.sock.connect((host, port))
> > ... init communication ...
>
> > def __getstate__(self):
> > # pickle self as a (host, port) pair
> > return self.host, self.port
>
> > def __setstate__(self, state):
> > # reinstate self by setting host and port and
> > # recreating the socket
> > self.host, self.port = state
> > self.init_sock()
>
> I, local, am mystified that you'd want to pickle a socket.  It's a
> live connection, which flies on a pocket dollar.  You don't want it on
> disk, do you?
>
> If you're running a net buoy through a cluster somewhere, do you want
> to drop a server and reconnect?  Is Amazon's EC2 up and running?
>
> Certainly no one was talking on the internet.  Were you?
>
> I don't think you hit anything but banks surfing the web, and the
> American dollar is notoriously stuffy.  Pump a wi-fi to a diner,
> though, and you're just talking more.  Where's Usenet?

The idea is a pre-fork socket server.  What I want to do is fork off
some child processes from the parent and use IPC to send the
connection object (via socket.accept()) over a pipe to one of the
preexisting child processes and have said child handle the
transaction.  Think Apache, if you want an example of what I'm trying
to do here.  This alleviates the process startup cost that occurs when
you fork.  If the socket object can't be serialized, is there another
way to go about handling this in python?
--
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE 3.0a5 has problems with Unicode

2008-05-11 Thread hdante
On May 11, 7:27 pm, Sven Siegmund <[EMAIL PROTECTED]> wrote:
> #!/usr/bin/python

 Notice that this line is probably not what you want, unless you
overwrote the default python 2 installation. The line should be:

 #!/usr/bin/env python3.0

 (this is irrelevant to the bug, however)

> IDLE complains about "invalid character in identifier" and highlights
> "zdroj" red in the first line (sic!).

 It worked here (Python 3.0a5 (r30a5:62856, May 11 2008, 19:52:04)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2). I started IDLE 3.0a5,
clicked the open menu, loaded the file, then run->run module. I've
copied and pasted your code and created the "slovník.txt" file. I'm
using tk 8.4.16.

 Would you mind reinstalling and notice any warning message during
compilation ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Yves Dorfsman

John Salerno wrote:


To me, the first example is a pure use of the for loop. You are 
iterating through an object and *using* the items you are stepping through.


The second example, however, is simply doing something 10 times, and 
what it's doing has nothing to do with 'x' or xrange. So it seems like 
an abuse of the for loop.


Well, I would say this:
myl = ['a', 'b', 'c', 'd']
for i in xrange(len(myl)):
  print myl[i]

As you would see in other languages, is an abuse in python. But in you need 
to iterate 5 times over something. Do you have a cleaner / python'er 
alternative ?


Do you find the following cleaner:

x = 0
while x <= 4:
  print x
  x += 1



Yves.
http://www.SollerS.ca
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Ben Finney
John Salerno <[EMAIL PROTECTED]> writes:

> num = 33
> 
> for x in xrange(10):
> print num += 1

Which is better done by 'num += 10'.

Can you come up with an example that isn't trivially replaced with
clearer code? That might make it clearer what your concern is.

> The [above] example [...] is simply doing something 10 times, and
> what it's doing has nothing to do with 'x' or xrange. So it seems
> like an abuse of the for loop.

In such cases, the name 'dummy' is conventionally bound to the items
from the iterator, for clarity of purpose::

for dummy in range(10):
# do stuff that makes no reference to 'dummy'

Also note that 'range' will return an iterator (not a list) in Python
3.0, and 'xrange' is removed since it's then obsolete
http://www.python.org/dev/peps/pep-3100/#built-in-namespace>.

-- 
 \  “Isn’t it enough to see that a garden is beautiful without |
  `\  having to believe that there are fairies at the bottom of it |
_o__) too?” —Douglas Adams |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: IDLE 3.0a5 has problems with Unicode

2008-05-11 Thread Sven Siegmund
> No, it's now a known bug (at least I don't know it). Whether or not it
> gets fixed might depend on whether or not it gets reported to
> bugs.python.org.

Ok, I'll repost it there.

S.
--
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE 3.0a5 has problems with Unicode

2008-05-11 Thread Sven Siegmund
> I have a source code which IDLE 3.0a5 cannot parse, but Python 3.0a5
> can:

Oh I see the posts in this newsgroup do not yet support Unicode. Most
of the special characters in my source code have been messed up. But
anyway, those who know Czech can handle it. The error is replicable
even with the messed-up characters.

S.
--
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE 3.0a5 has problems with Unicode

2008-05-11 Thread Martin v. Löwis
> Is this a known bug if IDLE 3.0a5 which will be fixed in the final
> release?

No, it's now a known bug (at least I don't know it). Whether or not it
gets fixed might depend on whether or not it gets reported to
bugs.python.org.

Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to call a file

2008-05-11 Thread Yves Dorfsman

Gary Herron wrote:

First of all, some terminology: You are not *calling* a file, you are 
*opening* it or reading.


Wouldn't it be more correct to say that, in python, you either create a file 
object, or call a method for that object, once the object has been created ?




Yves.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Mathematics in Python are not correct

2008-05-11 Thread Tim Roberts
[EMAIL PROTECTED] wrote:
>
>I am stunned that this simple misunderstanding of mine ended in a
>mathematical clash of a sort. :)  You guys really blew me away wih
>your mathematical knowledge. And also the 0**0 is a thing I've never
>thought about trying, until now that is. If the mathematical rule is
>that EVERYTHING raised to the power of 0 is 1, then we should accept
>that, even in the case of 0**0. This is just the way it is.

Sure, but it's ALSO the mathematical rule that 0 raised to any power is 0.
Thus, there are multiple solutions to this problem, meaning that there is
NO solution to the problem.
-- 
Tim Roberts, [EMAIL PROTECTED]
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


IDLE 3.0a5 has problems with Unicode

2008-05-11 Thread Sven Siegmund
Hello,

I am testing Python 3.0a5's handling of unicode strings. Since SPE is
not yet for Python 3.0, I have begun to write in IDLE 3.0a5.

I have a source code which IDLE 3.0a5 cannot parse, but Python 3.0a5
can:

#!/usr/bin/python
# -*- coding: utf-8 -*-

def načtiSlovník(zdroj='slovník.txt'):
soubor = open(zdroj, mode='r', encoding='utf_8')
řádky = soubor.readlines()
for řádek in řádky:
print(řádek, end='')

načtiSlovník()
# End of source code

I have set up Default Source Encoding to UTF-8 in IDLE's general
configuration. Still, when I open that source code and try to run it,
IDLE complains about "invalid character in identifier" and highlights
"zdroj" red in the first line (sic!).

However, when I run the source code from command line (by "python
"), it gets executed well and does what it shall do.

I should probably add, that I have installed py3k:62932M, May 9 2008,
16:23:11 [MSC v.1500 32 bit (Intel)] on win32. I use Windows XP SP 3.

Is this a known bug if IDLE 3.0a5 which will be fixed in the final
release?

Greetings,

S.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Some error messages in Python are ugly

2008-05-11 Thread Matthieu Brucher
Please, really please, stop asking question and go read some books about/get
some courses on Linux shell and then finally Python.
Before you do that, the only thing will have is upset people telling you to
_think_ (clearly that's something you are n,ot used to do, but you will have
to start at some point) before sending a mail.

Matthieu

2008/5/11 <[EMAIL PROTECTED]>:

> This really looks ugly for an error message:
>
> [1]+  Stopped python
>
>
> Please explain to me the role of the '+' sign. And why is there such a
> gap between 'Stopped' and 'python'?
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher
--
http://mail.python.org/mailman/listinfo/python-list

Re: diffing and uniqing directories

2008-05-11 Thread castironpi
On May 11, 2:44 pm, Dan Stromberg <[EMAIL PROTECTED]> wrote:
> On Sat, 26 Apr 2008 23:44:17 +0530, Rustom Mody wrote:
> > Over years Ive collected tgz's of my directories. I would like to diff
> > and uniq them
>
> > Now I guess it would be quite simple to write a script that does a walk
> > or find through a pair of directory trees, makes a SHA1 of each file and
> > then sorts out the files whose SHA1s are the same/different. What is
> > more difficult for me to do is to write a visual/gui tool to help me do
> > this.
>
> > I would guess that someone in the python world must have already done it
> > [The alternative is to use some of the tools that come with version
> > control systems like git. But if I knew more about that option I would
> > not be stuck with tgzs in the first place ;-)]
>
> > So if there is such software known please let me know.
>
> > PS Also with the spam flood that has hit the python list I dont know if
> > this mail is being read at all or Ive fallen off the list!
>
> It doesn't have a GUI, but here's a python program I wrote for dividing
> large collections of files up into identical groups:
>
> http://stromberg.dnsalias.org/~strombrg/equivalence-classes.html- Hide quoted 
> text -
>
> - Show quoted text -

I want to question terminology!

Question 'identical' groups over related!

--
http://mail.python.org/mailman/listinfo/python-list


Re: what does int means for python ?

2008-05-11 Thread castironpi
On May 11, 5:05 am, alefajnie <[EMAIL PROTECTED]> wrote:
> > try arr[2][3] instead.
>
> > basically your version is trying to index an array with a tuple argument 
> > (2,3).
>
> > --irmen
>
> oh, you're right.
>
> btw, is any simple way to create multi-dimension array ?
> any built-in function ?

it is not clear that two-dim arrays are faster than hashes in all
implementations of Python, or in every general language, or if they're
the right symbol for your program.

>>> a= { }
>>> a[ 0, 1 ]= True
>>> a[ 4, 0 ]= True
>>> a[ 0, 1 ]
True

however, this one:

>>> a[ 2, 1 ]

results in a KeyError.  do you want a particular thing, or are you on
the clock?

if you want to define 'blanks', that takes time too.  is it initally
empty?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple question

2008-05-11 Thread Bjoern Schliessmann
Gandalf wrote:
> On May 10, 2:36 pm, Bjoern Schliessmann > It depends on your web server configuration. To get your web
>> server execute Python code, there are several alternatives like
>>
>> * CGI
>> * FastCGI
>> * mod_python
>
> my server is my computer 

I didn't mean which server hardware you use, but which web server
application. You need a web server application to use your "WWW
directory" in such a way.

> and all i did way to install python on it.

Nah, you probably have at least an operating system beneath Python.

Regards,


Björn

-- 
BOFH excuse #264:

Your modem doesn't speak English.

--
http://mail.python.org/mailman/listinfo/python-list


Re: multiple Python versions, but on Windows (how to handle registry updates)

2008-05-11 Thread Gabriel Genellina
En Sun, 11 May 2008 01:17:22 -0300, Banibrata Dutta <[EMAIL PROTECTED]> 
escribió:

> I realized that my query was not making much sense, or a bit convoluted. A
> simler form of the question:
>
> For packages which do contain .dlls & .pyd's (not pure Python) their latest
> version may be compatible with -- say Python 2.5, whereas I need the version
> compatible for Python2.2. Is this a completely manual exercise ?

You don't have to try - binaries for different Python versions *are* *not* 
compatible (up to the second digit: 2.4 and 2.5 are not compatible, but 2.5.1 
and 2.5.2 are). So any extension using a .pyd/.dll will have to be recompiled, 
at least.
Even pure Python code written for 2.5 may use features not available in 2.2.

Packages built using setuptools (eggs) may contain explicit dependency 
information but I don't know for sure.

-- 
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python GUIs and custom controls

2008-05-11 Thread Joe P. Cool
On 9 Mai, 10:14, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> If you can work with the license (GPL), I suggest Qt4

Thanks for your helpful hints, guys.

--
Joe P. Cool
--
http://mail.python.org/mailman/listinfo/python-list


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread Gary Herron

bc90021 wrote:

...and the exact error message was?

Here is a tip: if you want people to help you, then you have to help
them to help you.  Personally, I wouldn't respond to anymore of your
questions because you seem incapable of posting the information that was
requested.



So far, the people who have answered this post have gone on the 
assumption that I'm stupid.  I'm not.  I took perfectly working code, 
cut it from one class, and put it in another.  It stopped working in the 
second class.  I've spent days on this and trust me, given what I've 
experienced of the Python community so far, if I didn't have to ask, I 
wouldn't.


(I really must say that so far the help I am getting in the Python 
community is a big let down.  Whether it's on IRC or here, everyone has 
an arrogance that I don't find anywhere else in the open source 
community, and it seriously makes me question the choice of language that 
I've made.)
  


Sorry, the arrogance is yours. 


   Expecting us to help with only partial information.

   Expecting us to help when your posts of the error message changes 
from one post to the next.


   Expecting us to help when you refuse to post the traceback.

   Expecting us to believe that it has anything to do with threads.  
(No one believes that for a moment.)



While acknowledging that any piece of code may have bugs, Python's 
threading included, the problem here looks to be some simple mistake in 
the computation of the name of the file to be opened.   Then I look at 
the convoluted quoting surrounding your computation of the file name, 
and my confidence in that as an explanation sky-rockets.  Then someone 
in another post has found an extra set of quotes embedded in your 
filename you compute, and it's clear that we are on the right track.




The error message was at the top of the thread (am I incapable of posting 
it, or are you incapable of following a thread?), but here it is again:


IOError: [Errno 2] no such file u'tempfileName'

--
http://mail.python.org/mailman/listinfo/python-list
  


--
http://mail.python.org/mailman/listinfo/python-list


Re: Keeping two lists aligned after processing

2008-05-11 Thread Terry Reedy

"Paul Rubin" <"http://phr.cx"@NOSPAM.invalid> wrote in message 
news:[EMAIL PROTECTED]
| philly_bob <[EMAIL PROTECTED]> writes:
| > algs=['AlgA', 'AlgB', 'AlgC', 'AlgD', 'AlgE']
| > accs=[]
| > for alg in algs:
| >thisacc=getattr(alg.accuracy)()
|> # picked this technique on comp.lang.python last month

I don't believe that you actually ran this.
What you should have picked up for the above was something like
globals()[alg].accuracy().  What you probably saw was something
like getattr(ob_with_call_attr, 'callable_name')().
But a list of alg objects instead of names, as Paul suggested,
is almost always better.

| >accs.append(thisacc)

| I think what you mean is (untested):
|
| algs = [AlgA, AlgB, AlgC, AlgD, AlgE]
| accs = sorted(((alg.accuracy(), alg.name()) for alg in algs), 
reverse=True)

Use alg.__name__ instead of alg.name().

| for i,(alg_acc, alg_name) in enumerate(accs):
|print '%2d %5s %0.2f'% (i, alg_name, alg_acc)
|
| This assumes a method alg.name() which tells you the name of the 
algorithm.

See above.  In 3.0, function names are also .__name__ instead of 
.func_name,
so one can mix callables in a list and get their definitions names 
uniformly.

| I don't understand how you're converting the string 'AlgA'
| to an algorithm object in your example above.

He was trying to convert name to method with the buggy getattr call.

tjr




--
http://mail.python.org/mailman/listinfo/python-list


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread 7stud
On May 11, 2:11 pm, bc90021 <[EMAIL PROTECTED]> wrote:
> [CUT]
>
> > I have in no way assumed that you are stupid.  I have tried to help you
> > formulate your problem better so that people on the list can help you.
> > I believe I have done so respectfully, with the aim of introducing you
> > to the modus operandi of this group.
>
> I appreciate your help.  However, the comments I got from other people
> that "I'm sure you have quotes here..." type comments are incredibly
> insulting.  To tell someone that you're sure that they have quotes around
> something when they don't is the height of arrogance and rudeness.
>

The best way to get help is to post a simple example that demonstrates
your problem and that anyone can run and get the same error you are
getting.  That means you need take your real code and you start
hacking out the bits that are irrelevant to the problem.  With
judicious use of print statements you should be able to narrow the
problem down.

Your first post was about as far away from that as it could be.  Your
first post was essentially equivalent to asking:

> Why does this line:

>print name

>display "Jack" and not "Jill".

When you post a question like that, then you are either going to be
met with silence or people will attempt to debug your imaginary code
and guess at the problem, which sometimes works and sometimes
doesn't.  If you find the guesses insulting, then post a better model
of your problem.  The fact that you found these guesses insulting,
even though they were respectfully given and they were the obvious
answers in light of how little information you gave, means you are
probably going to have problems on any newsgroup you post to.

The python community has some real jerks in it, but you didn't meet
any of them in this thread.





> >> (I really must say that so far the help I am getting in the Python
> >> community is a big let down.  Whether it's on IRC or here, everyone has
> >> an arrogance that I don't find anywhere else in the open source
> >> community, and it seriously makes me question the choice of language
> >> that I've made.)
>
> > Don't judge too quickly.  I think this newsgroup is on the whole
> > extremely helpful.  I have learnt a lot from it.  But you have to get
> > used to its ways, and until you are familiar with them, approach it with
> > humility.
>
> Unfortunately, this is not my first interaction with the Python IRC
> communities or Python newsgroups.  I had tried working with this language
> a while back (around 2000) and the answers I got were unhelpful and
> usually rude.  I decided to give it another shot for the program I'm
> writing, and I'm regretting that.  It's possible that I'm to blame - I'm
> the common factor in both instances, but at the same time, when you ask a
> question in #python and NO ONE ANSWERS at all, and they all just sit
> there not talking at all, what's the point of having the IRC channel?  If
> newbies can't go there for help, what's the point?  When there are 70
> people in a channel, and no one even acknowledges your question has been
> asked, where does one go for help?  It's like talking to yourself.
>
> >> The error message was at the top of the thread (am I incapable of
> >> posting it, or are you incapable of following a thread?), but here it
> >> is again:
>
> >> IOError: [Errno 2] no such file u'tempfileName'
>
> > This is different from the error message that you posted in your
> > original message.
>
> > Anyway, what is useful to us is a full traceback, no just an error
> > message.
>
> It is not "different" except that I posted the full name the second
> time.  (tempfileName instead of the previously simplified fileName)  The
> code itself is actually irrelevant, in my humble opinion.  In one place a
> file creation line does not work; in the second place it does.  How can
> the same line of code do two different things in two places?  Either it
> creates a file or it doesn't.  It should create the file in either place,
> regardless of where it's being called.
>
> Either way, I figured it out.

--
http://mail.python.org/mailman/listinfo/python-list


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread Ville M. Vainio
bc90021 <[EMAIL PROTECTED]> writes:


> The error message was at the top of the thread (am I incapable of posting 
> it, or are you incapable of following a thread?), but here it is again:
>
> IOError: [Errno 2] no such file u'tempfileName'

Typically, when you report an error message, it helps to paste the
whole traceback. For example, it may be that you are seeing an error
from an old version of the file that has quotes around tempfileName,
or the error is coming from somewhere else.

But to answer your original question: no, there are no problems with
threading and files, and this is just simple human mistake somewhere.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Arnaud Delobelle
John Salerno <[EMAIL PROTECTED]> writes:

> John Salerno wrote:
>> I know it's popular and very handy, but I'm curious if there are purists
>> out there who think that using something like:
>>
>> for x in range(10):
>> #do something 10 times
>>
>> is unPythonic. The reason I ask is because the structure of the for loop
>> seems to be for iterating through a sequence. It seems somewhat
>> artificial to use the for loop to do something a certain number of
>> times, like above.
>>
>> Anyone out there refuse to use it this way, or is it just impossible to
>> avoid?
>
> Ok, I think most people are misunderstanding my question a little. I
> probably should have said xrange instead of range, but the point of my
> question remains the same:
>
> Should a for loop be used simply to do something X number of times, or
> should it strictly be used to step through an iterable object for the
> purpose of processing the items in that object?

It makes me feel slightly uncomfortable too, but AFAIK there is no
better way in Python.  What I sometimes do is make the for loop bind
its variable to something useful instead of an unused counter.
Contrived example:

# Print 'hello' 10 times; x is not used
for x in xrange(10):
print 'hello'

# By changing what is iterated over, no unused variable:
from itertools import repeat
for msg in repeat('hello', 10):
print msg

-- 
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread John Salerno

XLiIV wrote:


The range() function returns a list and list is a sequence, isn't?


I think you're missing the point. To me, there seems to be a fundamental 
difference between these two things:


---

people = ['Sam', 'Bob', 'Fred']

for name in people:
print name

---

AND

---

num = 33

for x in xrange(10):
print num += 1

---

To me, the first example is a pure use of the for loop. You are 
iterating through an object and *using* the items you are stepping through.


The second example, however, is simply doing something 10 times, and 
what it's doing has nothing to do with 'x' or xrange. So it seems like 
an abuse of the for loop.

--
http://mail.python.org/mailman/listinfo/python-list


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread bc90021
On Sun, 11 May 2008 19:55:31 +, Duncan Booth wrote:

> 7stud <[EMAIL PROTECTED]> wrote:
> 
> 
>>                             tempfileName = "\"proctemp\\"
>>                             +
>> self.matrix[c][0] + "_other.txt\""
> 
> It wouldn't exactly result in either of the error messages you posted,
> but I expect the spurious quote marks round the filename will be giving
> you problems.
> 
> Surely you want the filename to be something like
> 'proctemp\fred_other.txt' rather than '"proctemp\fred_other.txt"' with
> the spurious double quotes?

Yup, that's what it was.  I figured it out two seconds before this post.  
However, it will be interesting to see how it handles files with spaces 
in the name...

Thanks for your help!

--
http://mail.python.org/mailman/listinfo/python-list

Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread John Salerno

John Salerno wrote:

I know it's popular and very handy, but I'm curious if there are purists
out there who think that using something like:

for x in range(10):
#do something 10 times

is unPythonic. The reason I ask is because the structure of the for loop
seems to be for iterating through a sequence. It seems somewhat
artificial to use the for loop to do something a certain number of
times, like above.

Anyone out there refuse to use it this way, or is it just impossible to
avoid?


Ok, I think most people are misunderstanding my question a little. I 
probably should have said xrange instead of range, but the point of my 
question remains the same:


Should a for loop be used simply to do something X number of times, or 
should it strictly be used to step through an iterable object for the 
purpose of processing the items in that object?

--
http://mail.python.org/mailman/listinfo/python-list


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread bc90021
[CUT]
> I have in no way assumed that you are stupid.  I have tried to help you
> formulate your problem better so that people on the list can help you. 
> I believe I have done so respectfully, with the aim of introducing you
> to the modus operandi of this group.

I appreciate your help.  However, the comments I got from other people 
that "I'm sure you have quotes here..." type comments are incredibly 
insulting.  To tell someone that you're sure that they have quotes around 
something when they don't is the height of arrogance and rudeness.

>> (I really must say that so far the help I am getting in the Python
>> community is a big let down.  Whether it's on IRC or here, everyone has
>> an arrogance that I don't find anywhere else in the open source
>> community, and it seriously makes me question the choice of language
>> that I've made.)
> 
> Don't judge too quickly.  I think this newsgroup is on the whole
> extremely helpful.  I have learnt a lot from it.  But you have to get
> used to its ways, and until you are familiar with them, approach it with
> humility.

Unfortunately, this is not my first interaction with the Python IRC 
communities or Python newsgroups.  I had tried working with this language 
a while back (around 2000) and the answers I got were unhelpful and 
usually rude.  I decided to give it another shot for the program I'm 
writing, and I'm regretting that.  It's possible that I'm to blame - I'm 
the common factor in both instances, but at the same time, when you ask a 
question in #python and NO ONE ANSWERS at all, and they all just sit 
there not talking at all, what's the point of having the IRC channel?  If 
newbies can't go there for help, what's the point?  When there are 70 
people in a channel, and no one even acknowledges your question has been 
asked, where does one go for help?  It's like talking to yourself.

>> The error message was at the top of the thread (am I incapable of
>> posting it, or are you incapable of following a thread?), but here it
>> is again:
>>
>> IOError: [Errno 2] no such file u'tempfileName'
> 
> This is different from the error message that you posted in your
> original message.
> 
> Anyway, what is useful to us is a full traceback, no just an error
> message.

It is not "different" except that I posted the full name the second 
time.  (tempfileName instead of the previously simplified fileName)  The 
code itself is actually irrelevant, in my humble opinion.  In one place a 
file creation line does not work; in the second place it does.  How can 
the same line of code do two different things in two places?  Either it 
creates a file or it doesn't.  It should create the file in either place, 
regardless of where it's being called.

Either way, I figured it out.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is using range() in for loops really Pythonic?

2008-05-11 Thread Terry Reedy

"XLiIV" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
On May 11, 4:19 am, John Salerno <[EMAIL PROTECTED]> wrote:
> I know it's popular and very handy, but I'm curious if there are purists
> out there who think that using something like:
>
> for x in range(10):
> #do something 10 times
>
> is unPythonic. The reason I ask is because the structure of the for loop
> seems to be for iterating through a sequence. It seems somewhat
> artificial to use the for loop to do something a certain number of
> times, like above.
>
> Anyone out there refuse to use it this way, or is it just impossible to
> avoid?

|The range() function returns a list and list is a sequence, isn't?

yes, for loops iterate thru any iterable 



--
http://mail.python.org/mailman/listinfo/python-list


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread 7stud
On May 11, 2:01 pm, 7stud <[EMAIL PROTECTED]> wrote:
> On May 11, 1:28 pm, bc90021 <[EMAIL PROTECTED]> wrote:
>
>
>
> > > ...and the exact error message was?
>
> > > Here is a tip: if you want people to help you, then you have to help
> > > them to help you.  Personally, I wouldn't respond to anymore of your
> > > questions because you seem incapable of posting the information that was
> > > requested.
>
> > So far, the people who have answered this post have gone on the
> > assumption that I'm stupid.  I'm not.  I took perfectly working code,
> > cut it from one class, and put it in another.  It stopped working in the
> > second class.  I've spent days on this and trust me, given what I've
> > experienced of the Python community so far, if I didn't have to ask, I
> > wouldn't.
>
> > (I really must say that so far the help I am getting in the Python
> > community is a big let down.  Whether it's on IRC or here, everyone has
> > an arrogance that I don't find anywhere else in the open source
> > community, and it seriously makes me question the choice of language that
> > I've made.)
>
> > The error message was at the top of the thread (am I incapable of posting
> > it, or are you incapable of following a thread?), but here it is again:
>
> > IOError: [Errno 2] no such file u'tempfileName'
>
> Well, it appears to me that this error message is different than the
> one in your first post.  But maybe I'm on LSD right now and things
> will be appear differently tomorrow.
>
> In addition, I've never seen a python error message that doesn't
> include the traceback, which you were asked to post, but apparently
> are still incapbable of doing.  Also, any line numbers in the error
> message should be marked in your code with comments.  That will help
> other people help you, remember?

In addition, posting the exact output from this:

>print "We're in copying, and tempfileName is: %s...\n" % tempfileName
> #The above line correctly prints the temporary file name every time!
> The directory exists, too!

would be helpful.

In addition, reducing your code to a simple 10 line example that
produces the same problem and that anyone can run would be helpful.
You might find that making the effort to produce a simple 10 line
example that mimics the problem, will actually result in your solving
the problem yourself.


--
http://mail.python.org/mailman/listinfo/python-list


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread 7stud
On May 11, 1:28 pm, bc90021 <[EMAIL PROTECTED]> wrote:
> > ...and the exact error message was?
>
> > Here is a tip: if you want people to help you, then you have to help
> > them to help you.  Personally, I wouldn't respond to anymore of your
> > questions because you seem incapable of posting the information that was
> > requested.
>
> So far, the people who have answered this post have gone on the
> assumption that I'm stupid.  I'm not.  I took perfectly working code,
> cut it from one class, and put it in another.  It stopped working in the
> second class.  I've spent days on this and trust me, given what I've
> experienced of the Python community so far, if I didn't have to ask, I
> wouldn't.
>
> (I really must say that so far the help I am getting in the Python
> community is a big let down.  Whether it's on IRC or here, everyone has
> an arrogance that I don't find anywhere else in the open source
> community, and it seriously makes me question the choice of language that
> I've made.)
>
> The error message was at the top of the thread (am I incapable of posting
> it, or are you incapable of following a thread?), but here it is again:
>
> IOError: [Errno 2] no such file u'tempfileName'

Well, it appears to me that this error message is different than the
one in your first post.  But maybe I'm on LSD right now and things
will be appear differently tomorrow.

In addition, I've never seen a python error message that doesn't
include the traceback, which you were asked to post, but apparently
are still incapbable of doing.  Also, any line numbers in the error
message should be marked in your code with comments.  That will help
other people help you, remember?



--
http://mail.python.org/mailman/listinfo/python-list


Re: observer pattern (notification chain synchronization)

2008-05-11 Thread Ville M. Vainio
Alan Isaac <[EMAIL PROTECTED]> writes:


> OK, thanks.
>
> Another approach is to begin with a set of stocks
>
> and remove them as they report.  You can then trigger
>
> a report with the empty set instead of repeatedly
>
> calling ``all``. After a report the set can be
>
> "refilled".

Ah, and I obviously didn't read the whole thread before posting ;-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: observer pattern (notification chain synchronization)

2008-05-11 Thread Ville M. Vainio
Alan Isaac <[EMAIL PROTECTED]> writes:


> Here is one way:
>
> - for each fund, create a ``reportreceived`` dict that maps stocks to 
> booleans (initially False)
> - as each stock notifies its funds, the fund changes False to True and checks 
> ``all(reportreceived.values())`` to determine whether it is ok to notify 
> investors.
> - When it is ok, the fund notifies investors and resets all the
> ``reportreceived`` values.
>
> Is this sensible enough? What are standard and better ways?

You could explore the performance of popping items from the dict/set,
instead of toggling the value so to true. Once the dict is empty, you
are done. Of course the dict/set would be called
stocks_that_havent_reported, or a saner & shorter variant of that.

The idea here is that checking a dict/set for emptiness is
close-to-zero time operation.


--
http://mail.python.org/mailman/listinfo/python-list


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread Duncan Booth
7stud <[EMAIL PROTECTED]> wrote:

>>                                     
>                             tempfileName = "\"proctemp\\" +
> self.matrix[c][0] + "_other.txt\"" 

It wouldn't exactly result in either of the error messages you posted, but 
I expect the spurious quote marks round the filename will be giving you 
problems.

Surely you want the filename to be something like 'proctemp\fred_other.txt' 
rather than '"proctemp\fred_other.txt"' with the spurious double quotes?
--
http://mail.python.org/mailman/listinfo/python-list


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread Duncan Booth
bc90021 <[EMAIL PROTECTED]> wrote:

> The error message was at the top of the thread (am I incapable of
> posting it, or are you incapable of following a thread?), but here it
> is again: 
> 
> IOError: [Errno 2] no such file u'tempfileName'

So which was it? At the top of the thread you said it was:

IOError: [Errno 2] no such file u'fileName'

How about posting the exact error message you got, including all of the 
traceback and the complete original code: even when you posted "Here's the 
thread class" you actually posted a modified version of your thread class 
(with sarky comments added even if nothing else was changed).

If you post complete code and the full traceback then you'll probably get a 
quick and accurate response telling you what the problem is. If you 
continue to paraphrase and post bits and pieces you'll continue to get 
random guesses.

--
http://mail.python.org/mailman/listinfo/python-list


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread Arnaud Delobelle
bc90021 <[EMAIL PROTECTED]> writes:

>> ...and the exact error message was?
>> 
>> Here is a tip: if you want people to help you, then you have to help
>> them to help you.  Personally, I wouldn't respond to anymore of your
>> questions because you seem incapable of posting the information that was
>> requested.
>
> So far, the people who have answered this post have gone on the 
> assumption that I'm stupid.  I'm not.  I took perfectly working code, 
> cut it from one class, and put it in another.  It stopped working in the 
> second class.  I've spent days on this and trust me, given what I've 
> experienced of the Python community so far, if I didn't have to ask, I 
> wouldn't.

I have in no way assumed that you are stupid.  I have tried to help
you formulate your problem better so that people on the list can help
you.  I believe I have done so respectfully, with the aim of
introducing you to the modus operandi of this group.

> (I really must say that so far the help I am getting in the Python 
> community is a big let down.  Whether it's on IRC or here, everyone has 
> an arrogance that I don't find anywhere else in the open source 
> community, and it seriously makes me question the choice of language that 
> I've made.)

Don't judge too quickly.  I think this newsgroup is on the whole
extremely helpful.  I have learnt a lot from it.  But you have to get
used to its ways, and until you are familiar with them, approach it
with humility.

> The error message was at the top of the thread (am I incapable of posting 
> it, or are you incapable of following a thread?), but here it is again:
>
> IOError: [Errno 2] no such file u'tempfileName'

This is different from the error message that you posted in your
original message.

Anyway, what is useful to us is a full traceback, no just an error
message.

-- 
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread 7stud
bc90021 wrote:
> Hi All,
>
> Thanks in advance for any and all help!
>
> I have this code:
>
> g = open(fileName, 'a')
>
> where fileName is defined before the line it's used in.  It works fine
> when I use it outside a thread class.
>
> When I put the same line in a thread class, it no longer works, and I get
> an error:
>
> IOError: [Errno 2] no such file u'fileName'
>
> Are threads not allowed to create files?

...oh yeah:

import threading
import time

fname = "data.txt"
f = open(fname)
print f.read()
f.close()

f = open(fname, "a")
f.write("some text\n")
f.close()

f = open(fname)
print f.read()
f.close()


class MyThread(threading.Thread):
def __init__(self, file_name):
threading.Thread.__init__(self)

def run(self):
time.sleep(3)

f = open(fname)
print f.read()
f.close()

f = open(fname, "a")
f.write("other text\n")
f.close()

f = open(fname)
print f.read()
f.close()


my_t = MyThread(fname)
my_t.start()
my_t.join()


--output:--
hello
world

hello
world
some text

hello
world
some text

hello
world
some text
other text
--
http://mail.python.org/mailman/listinfo/python-list


Re: diffing and uniqing directories

2008-05-11 Thread Dan Stromberg
On Sat, 26 Apr 2008 23:44:17 +0530, Rustom Mody wrote:

> Over years Ive collected tgz's of my directories. I would like to diff
> and uniq them
> 
> Now I guess it would be quite simple to write a script that does a walk
> or find through a pair of directory trees, makes a SHA1 of each file and
> then sorts out the files whose SHA1s are the same/different. What is
> more difficult for me to do is to write a visual/gui tool to help me do
> this.
> 
> I would guess that someone in the python world must have already done it
> [The alternative is to use some of the tools that come with version
> control systems like git. But if I knew more about that option I would
> not be stuck with tgzs in the first place ;-)]
> 
> So if there is such software known please let me know.
> 
> PS Also with the spam flood that has hit the python list I dont know if
> this mail is being read at all or Ive fallen off the list!

It doesn't have a GUI, but here's a python program I wrote for dividing 
large collections of files up into identical groups:

http://stromberg.dnsalias.org/~strombrg/equivalence-classes.html

--
http://mail.python.org/mailman/listinfo/python-list


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread bc90021
> ...and the exact error message was?
> 
> Here is a tip: if you want people to help you, then you have to help
> them to help you.  Personally, I wouldn't respond to anymore of your
> questions because you seem incapable of posting the information that was
> requested.

So far, the people who have answered this post have gone on the 
assumption that I'm stupid.  I'm not.  I took perfectly working code, 
cut it from one class, and put it in another.  It stopped working in the 
second class.  I've spent days on this and trust me, given what I've 
experienced of the Python community so far, if I didn't have to ask, I 
wouldn't.

(I really must say that so far the help I am getting in the Python 
community is a big let down.  Whether it's on IRC or here, everyone has 
an arrogance that I don't find anywhere else in the open source 
community, and it seriously makes me question the choice of language that 
I've made.)

The error message was at the top of the thread (am I incapable of posting 
it, or are you incapable of following a thread?), but here it is again:

IOError: [Errno 2] no such file u'tempfileName'

--
http://mail.python.org/mailman/listinfo/python-list


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread 7stud
On May 11, 12:42 pm, bc90021 <[EMAIL PROTECTED]> wrote:
> > It's difficult to know what's wrong with the code you posted because:
>
> > * it is not self-contained: otherFile, fileName, pattern are names
> >   which you do not define;
>
> > * the IOError you reported earlier can't arise as a result of running
> >   this code.
>
> > * you claim it works unless you put it in a subclass of
> >   threading.Thread.  Why don't you post this instead, and show us the
> >   traceback?
>
> > HTH
>
> > FWIW, my crystal ball (whose predictions I don't usually report!) tells
> > me the same as Garry Herron's.
>
> Here's the thread class:
>
> #single file is the file we're working on, whose name is passed into the 
> class and which does exist
> #matrix is a list of lists that contains info about the files - for this 
> example, [c][0] contains a string, [c][2] contains true or false, and [c][3] 
> contains a pattern to match
> #tfValue is another true or false value
>
> class FileProcThread(threading.Thread):
>         def __init__(self, singleFile, matrix, tfValue):
>                 self.singleFile = singleFile
>                 self.matrix = matrix
>                 self.tfValue = tfValue
>                 threading.Thread.__init__(self)
>         def run(self):
>                 (dirName, fileName) = os.path.split(self.singleFile)
>                 f = open(self.singleFile).readlines()
>                 copying = False
>                 for i in range(len(f)):
>                         for c in range (len(self.matrix)):
>                                 if (re.search(self.matrix[c][3], f[i])):
>                                         if (self.matrix[c][2] == True):
>                                                 copying = True
>                                                 if os.name == "posix":
>                                                         if (self.tfValue == 
> False):
>                                                                 tempfileName 
> = "\"proctemp/" + self.matrix[c][0] + "_tmp_" + fileName +
> ".txt\""
>                                                         else:
>                                                                 tempfileName 
> = "\"proctemp/" + self.matrix[c][0] + "_other.txt\""
>                                                 else:
>                                                         if (self.tfValue == 
> False):
>                                                                 tempfileName 
> = "\"proctemp\\" + self.matrix[c][0] + "_tmp_" + fileName + ".txt\""
>                                                         else:
>                                                                 tempfileName 
> = "\"proctemp\\" + self.matrix[c][0] + "_other.txt\""
>                                         else:
>                                                 copying = False
>                                 if (re.search(self.matrix[c][4], f[i])):
>                                         copying = False
>                         if (copying):
>                                 print "We're in copying, and tempfileName is: 
> %s...\n" % tempfileName
>                                 #The above line correctly prints the 
> temporary file name every time!  The directory exists, too!
>                                 g = open(tempfileName, 'a')  #This does not 
> work.  Notice I do NOT have quotes around tempfileName, as I said.
>                                 g.write(f[i])
>                                 g.close()
>
> Like I said, this works FINE outside the thread class.  I hope that the 
> formatting comes through...

...and the exact error message was?

Here is a tip: if you want people to help you, then you have to help
them to help you.  Personally, I wouldn't respond to anymore of your
questions because you seem incapable of posting the information that
was requested.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with custom events in wxpython

2008-05-11 Thread 7stud
On May 11, 7:23 am, Jimmy <[EMAIL PROTECTED]> wrote:
> hi, all
>
> I'm having a problem with creating custom events in wxpython.
>
> I have a class A handling some data processing work and another class
> B of GUI matter. I need GUI to display information when data in A is
> updated.
> I know cutom events in wxpython may work. But I found no material
> paricularly
> helpful :(
>
> can anyone write me some demo code to show how to do this ...


This example works for me:


import wx

class MyCustomEvent(wx.PyCommandEvent): #or wx.PyEvent
def __init__(self, event_type, id):
wx.PyCommandEvent.__init__(self, event_type, id)

class A(object):  #Data Processing class
def __init__(self, widget_to_update):
self.widget_to_update = widget_to_update

#create the custom event:
self.my_event_type = wx.NewEventType()
self.EVT_MY_CUSTOM_EVENT =
wx.PyEventBinder(self.my_event_type, 1)
#Note: you need to make EVT_MY_CUSTOM_EVENT persist so that you
#can refer to it in a later call to Bind()

def process_data(self): #create thread here
finished = True

if finished:
self.update_gui()


def update_gui(self):
#create a custom event object and enter it in the event queue:
my_evt_obj = MyCustomEvent(self.my_event_type,
self.widget_to_update.GetId() )
 
self.widget_to_update.GetEventHandler().ProcessEvent(my_evt_obj)


class B(object):  #Gui class
def __init__(self):
frame = wx.Frame(None, -1, "My Window")

panel = wx.Panel(frame, -1)
button = wx.Button(panel, -1, "Start Data Processing",
pos=(100, 10))
button.Bind(wx.EVT_BUTTON, self.onclick)

self.text_ctrl = wx.TextCtrl(panel, -1, "Hello World",
pos=(100, 50), size=(200, 20))

self.a = A(self.text_ctrl)
frame.Bind(self.a.EVT_MY_CUSTOM_EVENT,
self.on_my_custom_event)

frame.Show()

def onclick(self, event):
self.a.process_data()

def on_my_custom_event(self, event):
self.text_ctrl.SetValue("Finished Processing Data")


app = wx.PySimpleApp(redirect=False)
b = B()
app.MainLoop()




However, I couldn't get similar code to work when I derived the event
class from wx.PyEvent and used Bind() directly on the TextCtrl
(command events propagate up the container hierarchy while regular
events don't):

import wx

class MyCustomEvent(wx.PyEvent): #or wx.PyEvent
def __init__(self, event_type, id):
wx.PyEvent.__init__(self, event_type, id)

class A(object):  #Data Processing class
def __init__(self, widget_to_update):
self.widget_to_update = widget_to_update

#create the custom event:
self.my_event_type = wx.NewEventType()
self.EVT_MY_CUSTOM_EVENT =
wx.PyEventBinder(self.my_event_type, 1)

def process_data(self): #create thread here
finished = True
if finished:
self.update_gui()


def update_gui(self):
#create a custom event object and enter it in the event queue:
my_evt_obj = MyCustomEvent(self.my_event_type,
self.widget_to_update.GetId() )
 
self.widget_to_update.GetEventHandler().ProcessEvent(my_evt_obj)


class B(object):  #Gui class
def __init__(self):
frame = wx.Frame(None, -1, "My Window")

panel = wx.Panel(frame, -1)
button = wx.Button(panel, -1, "Start Data Processing",
pos=(100, 10))
button.Bind(wx.EVT_BUTTON, self.onclick)

self.text_ctrl = wx.TextCtrl(panel, -1, "Hello World",
pos=(100, 50), size=(200, 20))

self.a = A(self.text_ctrl)
self.text_ctrl.Bind(self.a.EVT_MY_CUSTOM_EVENT,
self.on_my_custom_event)

frame.Show()

def onclick(self, event):
self.a.process_data()

def on_my_custom_event(self, event):
self.text_ctrl.SetValue("Finished Processing Data")

app = wx.PySimpleApp(redirect=False)
b = B()
app.MainLoop()
--
http://mail.python.org/mailman/listinfo/python-list


frameword vs application server?

2008-05-11 Thread walterbyrd
Can somebody help me understand the difference? Not just where Python
is concerned, but in general?

As I understand it, an application server is supposed to be a great
help in developing apps, because most of the business logic is already
there. It seems to me that, usually when applications servers are
discussed, people are talking about Java.

I suppose most popular Python frameworks incorporate an application
server, but I get the idea that those app servers are not nearly as
sophisticed as something like JBoss.

I am not sure if a Python app server, that works like a Java app
server would make sense.
--
http://mail.python.org/mailman/listinfo/python-list


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread bc90021
> It's difficult to know what's wrong with the code you posted because:
> 
> * it is not self-contained: otherFile, fileName, pattern are names
>   which you do not define;
> 
> * the IOError you reported earlier can't arise as a result of running
>   this code.
> 
> * you claim it works unless you put it in a subclass of
>   threading.Thread.  Why don't you post this instead, and show us the
>   traceback?
> 
> HTH
> 
> FWIW, my crystal ball (whose predictions I don't usually report!) tells
> me the same as Garry Herron's.

Here's the thread class:

#single file is the file we're working on, whose name is passed into the class 
and which does exist
#matrix is a list of lists that contains info about the files - for this 
example, [c][0] contains a string, [c][2] contains true or false, and [c][3] 
contains a pattern to match
#tfValue is another true or false value


class FileProcThread(threading.Thread):
def __init__(self, singleFile, matrix, tfValue):
self.singleFile = singleFile
self.matrix = matrix
self.tfValue = tfValue
threading.Thread.__init__(self)
def run(self):
(dirName, fileName) = os.path.split(self.singleFile)
f = open(self.singleFile).readlines()
copying = False
for i in range(len(f)):
for c in range (len(self.matrix)):
if (re.search(self.matrix[c][3], f[i])):
if (self.matrix[c][2] == True):
copying = True
if os.name == "posix":
if (self.tfValue == 
False):
tempfileName = 
"\"proctemp/" + self.matrix[c][0] + "_tmp_" + fileName + 
".txt\""
else:
tempfileName = 
"\"proctemp/" + self.matrix[c][0] + "_other.txt\""
else:
if (self.tfValue == 
False):
tempfileName = 
"\"proctemp\\" + self.matrix[c][0] + "_tmp_" + fileName + ".txt\""
else:
tempfileName = 
"\"proctemp\\" + self.matrix[c][0] + "_other.txt\""
else:
copying = False
if (re.search(self.matrix[c][4], f[i])):
copying = False
if (copying):
print "We're in copying, and tempfileName is: 
%s...\n" % tempfileName
#The above line correctly prints the temporary 
file name every time!  The directory exists, too!
g = open(tempfileName, 'a')  #This does not 
work.  Notice I do NOT have quotes around tempfileName, as I said.
g.write(f[i])
g.close()

Like I said, this works FINE outside the thread class.  I hope that the 
formatting comes through...
--
http://mail.python.org/mailman/listinfo/python-list


Re: File Creation Not Working In A Thread Class?

2008-05-11 Thread Arnaud Delobelle
Arnaud Delobelle <[EMAIL PROTECTED]> writes:

> bc90021 <[EMAIL PROTECTED]> writes:
>
>> On Sun, 11 May 2008 18:36:25 +0100, Arnaud Delobelle wrote:
>>
>>> bc90021 <[EMAIL PROTECTED]> writes:
>>> 
 Hi All,

 Thanks in advance for any and all help!

 I have this code:

 g = open(fileName, 'a')

 where fileName is defined before the line it's used in.  It works fine
 when I use it outside a thread class.

 When I put the same line in a thread class, it no longer works, and I
 get an error:

 IOError: [Errno 2] no such file u'fileName'


>>> It's telling you that you haven't got a file called 'fileName'. Posting
>>> the code that triggers this error would allow people to diagnose the
>>> error accurately rather than guessing.
>>
>> f = open(otherFile).readlines()
>> for i in len(f):
>>  for c in range(0,24,1):
>>  if os.name == "posix":
>>  tempfileName = "\"proctemp/" + self.matrix[c][0] 
>> + "_tmp_" + fileName + ".txt\""
>>  if re.search(f[i], pattern):
>>  g = open(tempfileName, 'a')
>>  g.write(f[i])
>>
>>
>> This code works *perfectly* unless I put it in a class that inherits from 
>> threading.Thread.  In the thread class, everything works (I can see the 
>> "c" value, and I can print out each line in "f[i]", it's just that the g 
>> = open line doesn't work.
>
> It's difficult to know what's wrong with the code you posted because:
>
> * it is not self-contained: otherFile, fileName, pattern are names
>   which you do not define;
>
> * the IOError you reported earlier can't arise as a result of running
>   this code.

Correction: it can, if otherFile == u'fileName'

So I put 1000 rupees on this being the cause of the error :)

-- 
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list


  1   2   >