Floating Number format problem

2007-06-12 Thread 人言落日是天涯,望极天涯不见家

How could I format the float number like this: (keep 2 digit
precision)
1.002 => 1
1.12  => 1.12
1.00  => 1
1.567 => 1.57
2324.012 => 2324.01

I can not find any Formatting Operations is able to meet my
requirement.
Any suggestion will be appreciated.

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

Adding a DB regs to a wx listbox

2007-06-12 Thread Marcpp
Hi, I need add to a listbox a list of items extracted from a database.
This is that I've do:

class tasques(wx.Frame):
def __init__(self, *args, **kwds):

self.list_box_1_copy = wx.ListBox(self, -1, choices=[],
style=wx.LB_SINGLE|wx.LB_ALWAYS_SB)
...

How I add the list to choices?

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


Re: Floating Number format problem

2007-06-12 Thread ici
On Jun 12, 10:10 am, <[EMAIL PROTECTED]> wrote:
> How could I format the float number like this: (keep 2 digit
> precision)
> 1.002 => 1
> 1.12  => 1.12
> 1.00  => 1
> 1.567 => 1.57
> 2324.012 => 2324.01
>
> I can not find any Formatting Operations is able to meet my
> requirement.
> Any suggestion will be appreciated.

>>> print "%.02f" % (2324.012)
2324.01
>>>

http://docs.python.org/tut/node9.html#SECTION00910

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


Calling for Python Writers/Authors

2007-06-12 Thread Jeff Rush
For those who write books and articles, I've established a wiki page just as
we already have a page for those who offer training services for Python.  If
you would like to be reachable by those needing writing services of various
kinds, please add yourself to the list, along with some indication of what you
prefer to work on, your portfolio of work and your experience level:

  http://wiki.python.org/moin/PythonWriters

I'm open to creative ideas on how to format the information.  A link to the
page has been added to the sidebar menu under "Community".

Jeff Rush
Advocacy Coordinator
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations

2007-06-12 Thread Joachim Durchholz
Twisted schrieb:
> On Jun 11, 5:36 pm, Tim Bradshaw <[EMAIL PROTECTED]> wrote:
>> I think it's just obvious that this is the case.  What would *stop*
>> you writing maintainable Perl?
> 
> For starters, the fact that there are about six zillion obscure
> operators represented by punctuation marks, instead of a dozen or so.
> More generally, the fact that it comes out looking like modem barf,
> and modem barf is unmaintainable. ;)

You can write Perl that uses just a dozen or so punctuation marks, so 
that doesn't stop you (or anybody else) from writing maintainable Perl.
You haven't looked into the Webmin code that I gave for an example, have 
you? You'd have seen code that's quite far from line noise. (But 
sticking with prejudice can be more fun, I know...)

If anything, the real criticism is that it's easy to write 
unmaintainable Perl, so there's too much of unmaintainable Perl around.

The other criticism is that Perl's learning curve is needlessly 
prolonged because you need time to pick up all those idioms that are 
possible - nice for those who're doing Perl and just Perl, horror for 
those who usually work in other languages.

I don't know of any other serious design flaws in the language, given 
its design goals. (When designing a scripting/glue language today, I'd 
set up slightly different design goals, of course. Perl is far from the 
optimum that should be used today, its main merits are its ubiquity and 
completeness, not the language qualities.)

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


Re: A gotcha: Python pain point?

2007-06-12 Thread Terry Reedy

"Beorn" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Consider this example:
|
|  >>> def funcs(x):
|  ... for i in range(5):
|  ... def g(): return x + i
|  ... yield g
|
| I would expect the value of x used in g to be that at the function
| declaration time, as if you've pass g a (x=x) argument,

Since x is constant during the funcs call, does not matter.  Perhaps you 
meant i, which does vary?  If so, put i=i in the header -- or perhaps ii=i 
to give two different names to two things which are made to have the same 
value.

In any case, the simple rule is that default argument expressions in the 
*header* are evaluated at definition time while the *body* (past the doc 
string, if any) is executed after a call.

Some people expect defaults to be executed every call;  others expect part 
of the body to be executed once.  Both get in trouble.  For nested 
functions, outer call time is inner definition time and this can confuses. 
Defining (but delaying the call of) multiple identical inner functions, as 
you do in the first example below, also confuses.

| especially
| after reading this post: http://lua-users.org/wiki/LuaScopingDiscussion

Lua is not Python.

| But:
|
|  >>> [ fun() for fun in list(funcs(1)) ]
|  [5, 5, 5, 5, 5]
|
| Whereas:
|
|  >>> [ fun() for fun in funcs(1) ]
|  [1, 2, 3, 4, 5]

As Calderone explained, the simple rule works as long as one keeps track of 
what is called when.

Terry Jan Reedy



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


How can I parse False from c extension?

2007-06-12 Thread Allen
>From python command, I call C extension method
>>> import PyRPC
>>> PyRPC.addBool(False)

In C extension, I know parse integer value like this:
PyArg_ParseTuple(args, "i", &nValue);

But, how can I parse the False value?

Regards,
Allen Chen

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

Re: The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations

2007-06-12 Thread Thomas F. Burdick
On Jun 11, 11:36 pm, Tim Bradshaw <[EMAIL PROTECTED]> wrote:
> On Jun 11, 8:02 am, Twisted <[EMAIL PROTECTED]> wrote:
>
> > On Jun 11, 2:42 am, Joachim Durchholz <[EMAIL PROTECTED]> wrote:
>
> > > It is possible to write maintainable Perl.
>
> > Interesting (spoken in the tone of someone hearing about a purported
> > sighting of Bigfoot, or maybe a UFO).
>
> I think it's just obvious that this is the case.  What would *stop*
> you writing maintainable Perl?

The constantly shifting target of a language.  Hell, even the parser
has changed over time.  Fortunately this seems to have been solved by
Perl 6 [*].

[*] Stopping work on Perl 5 to focus on the probably never-to-be Perl
6 brought a surprising stability to the language.

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


Re: python-ldap for Python 2.5 on Windows?

2007-06-12 Thread Benedict Verheyen
Waldemar Osuch schreef:

> 
> I have also build it on XP SP2.
> 
> I have wrapped the files from "setup.py build" and all required .dll
> using Inno Setup.
> Maybe Vista does not like the executable produced by Inno.
> 
> If you still want to try then unzip the following:
> http://www.osuch.org/python-ldap.zip
> into your "site-packages" and see how far you can get.
> 
> The detailed instructions on how to build would be quite long and I'm
> sure I have forgotten some of the steps already but if you know about
> "./configure make make install" dance and know how to use Google you
> should be OK.
> 
> 1. First install MinGW, Msys and msysDTK.
> 2. Then you need to compile openldap.  See:
>
> http://mail.gnome.org/archives/gnomemeeting-devel-list/2005-September/msg00019.html
>for reference.  You will need regex but you can skip Berkley DB
> before you start.
> 3. I have compiled openssl too but I have seen ready made libraries
> for download.
>I do not have link handy at the moment.
> 4. The last step would be to run "setup.py build" for python-ldap.
> Remove sasl2 from setup.cfg
>since cyrus-sasl does not seem to be available for MinGW.
> 
> See how far you can get with the above instructions.  If you get stuck
> send me a private email and I will try to help you.
> If you could keep track of the steps and came up with better
> instructions than my pitiful attempt above that would be great.
> 
> Waldemar

Hi Waldemar,

thanks for the instructions.
I will try to build it one of these days and see how far i get.

As for the zip, i installed it and it works, i can use the ldap lib now.
So as you said, it indeed seems to be a problem with the Inno setup.
Anyway, if the zip works, i'm happy :)

If i get around to building it and if i succeed, i will post a more 
detailed report on how to do it.

Thanks,
Benedict

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-12 Thread Antoon Pardon
On 2007-06-11, Terry Reedy <[EMAIL PROTECTED]> wrote:
>
> "Antoon Pardon" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>| On 2007-06-09, Terry Reedy <[EMAIL PROTECTED]> wrote:
>| > For him to imply that Python is anti-flexibility is wrong.  Very 
> wrong..
>| > He should look in a mirror.  See below.
>|
>| My impression is that python supporters often enough show
>| some anti-flexibility attitude.
>
> More so than supporters of most other languages, in particular Scheme?

Well to my knowledge (which could be vastly improved), scheme doesn't
have some Zen-rules that include something like this.

I tried to google for similar remarks in relation to scheme but I
got no results. Maybe your google skills are better.

> Here's the situation.  Python is making inroads at MIT, Scheme home turf. 
> The co-developer of Scheme, while writing about some other subject, tosses 
> in an off-the-wall slam against Python.  Someone asks what we here think. 
> I think that the comment is a crock and the slam better directed, for 
> instance, at Scheme itself.  Hence 'he should look in a mirror'.
>
>| Yes science is different. The difference is the following. Should
>| science only know the Newtonian vectoral mechanics and someone
>| would come up with the Lagrangian approach, nobody would protest
>| against this new approach by remarking that there should only be
>| one obvious approach,
>
> The history of science is a history of innovation and resistance to 
> innovation.  Do you have information that the introduction of the 
> Lagrangian approach was exceptional?  Do you really think that no college 
> student has ever groused about having to learn another approach that is 
> only equivalent to what he already knows?

Yes the history of science is a history of innovation and resistance.
But the resistance to my knowledge has never used the argument that
there should (preferably) be only one obvious way to do things.

The student example is IMO not appropiate. There is a difference between
prefering not having to learn something yourself and argueing something
shouldn't be available in general.

>| Yet these kind of remarks are made often enough when someone suggest a
>| change to python.
>
> So?  Tim wrote 'There should be one-- and preferably only one --obvious way 
> to do it'.  The primary clause is that there should at least one.  The 
> secondary clause is that once there is a good and obvious way to do 
> something, we take a hard look before adding another.  As it is, there are 
> already multiple ways to do many things.  And there are probably at least 
> 10 suggested innovations for everyone accepted.

Yes I know that. But that doesn't stop a lot of python supporters in this news
group to come with a variation that suggests once there is an obvious way to do
something in python, there really is no need any more to look at ways
that do it differently. And if my memory doesn't betray me, corrections
from others to such variations are a rather recent occurence.

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


Re: Autocompletion in interactive mode doesn't work in 2.5.1

2007-06-12 Thread jitudon
On Jun 12, 9:36 am, "Papalagi Pakeha" <[EMAIL PROTECTED]>
wrote:
> Hi all,
>
> How can I turn on autocompletion when I push  in python 2.5.1
> interactive mode? E.g. to give me a list of all methods and attributes
> of a given object.
>
> It works great on my Linux / Ubuntu 7.04 installation but doesn't work
> on Solaris 10 (x86). I have libreadline.so and libncurses.so installed
> and "import readline" is executed during startup, but  still
> doesn't work. ArrowUp and ArrowDown however work and I can browse the
> history of commands so I believe readline is installed and loaded
> correctly.
>
> Any hints?
>
> Thanks
>
> PaPa

http://docs.python.org/lib/module-rlcompleter.html

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


Re: Floating Number format problem

2007-06-12 Thread kelvin.you
On 6 12 ,   3 16 , ici <[EMAIL PROTECTED]> wrote:
> On Jun 12, 10:10 am, <[EMAIL PROTECTED]> wrote:
>
>
>
> > How could I format the float number like this: (keep 2 digit
> > precision)
> > 1.002 => 1
> > 1.12  => 1.12
> > 1.00  => 1
> > 1.567 => 1.57
> > 2324.012 => 2324.01
>
> > I can not find any Formatting Operations is able to meet my
> > requirement.
> > Any suggestion will be appreciated.
> >>> print "%.02f" % (2324.012)
> 2324.01
>
> http://docs.python.org/tut/node9.html#SECTION00910

thank you !
But in these case:

>>> print '%.02f'%1.002
1.00
>>> print '%.02f'%1.00
1.00

I just expect it to output "1" , but these way will output 1.00

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


Re: New mailing list mirrors

2007-06-12 Thread Clement
In proejct i need a program having two thread. One is server thread
will listen on a port. and aniother one is to controll some opertion
in the system.. The server therad will get the comment and the and the
another thread will do some opertion based on the commend..


How to implemten it.. I have no idea of implement this..
Pelase help

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


Re: A gotcha: Python pain point?

2007-06-12 Thread Diez B. Roggisch
James Stroud wrote:

> Beorn wrote:
>> Consider this example:
>> 
>>   >>> def funcs(x):
>>   ... for i in range(5):
>>   ... def g(): return x + i
>>   ... yield g
>> 
>> I would expect the value of x used in g to be that at the function
>> declaration time, as if you've pass g a (x=x) argument, especially
>> after reading this post: http://lua-users.org/wiki/LuaScopingDiscussion
>> 
>> But:
>> 
>>   >>> [ fun() for fun in list(funcs(1)) ]
>>   [5, 5, 5, 5, 5]
>> 
>> Whereas:
>> 
>>   >>> [ fun() for fun in funcs(1) ]
>>   [1, 2, 3, 4, 5]
>> 
>> This came up while discussing Python pain points at
>> http://intertwingly.net/blog/2007/06/04/Python-Pain-Points#c1181602242
>> 
>> I can see how it works now, but I haven't found an easy-to-read
>> documentation on this.
>> 
>> I guess it's debatable if perhaps every i used in the loop shouldn't
>> be a different i.  It had me fooled, anyways.
>> 
>> Rgds,
>> Bjorn
>> 
> 
> If this isn't classified as a bug, then someone has some serious
> explaining to do. Why would it be desirable for a generator to behave
> differently in two different contexts. Should I import this to see how
> many principles this behavior violates?

It's no bug. The generator behaves the same way in both cases. What is
different is the calling time of the function.

Certainly a surprising outcome. But no bug.

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


Re: A gotcha: Python pain point?

2007-06-12 Thread Terry Reedy

"James Stroud" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Beorn wrote:
| > Consider this example:
| >
| >   >>> def funcs(x):
| >   ... for i in range(5):
| >   ... def g(): return x + i
| >   ... yield g
| >
| >   >>> [ fun() for fun in list(funcs(1)) ]
| >   [5, 5, 5, 5, 5]
| >
| > Whereas:
| >
| >   >>> [ fun() for fun in funcs(1) ]
| >   [1, 2, 3, 4, 5]

| If this isn't classified as a bug,

It is not, it is well-documented behavior.  Still, suggestions for 
improvement might be considered.

| Why would it be desirable for a generator to behave
| differently in two different contexts.

I have no idea.

Each call of the generator function funcs behaves the same.  It returns a 
generator that yields 5 identical copies of the inner function g.  The 
multiple copies are not needed and only serve to confuse the issue. 
Changing funcs to return a generator that yields the *same* function (five 
times) gives the same behavior.

def funcs(x):
def g(): return x + i
for i in range(5):
yield g

print [ fun() for fun in list(funcs(1)) ]
print [ fun() for fun in funcs(1) ]

>>> # when run
[5, 5, 5, 5, 5]
[1, 2, 3, 4, 5]

What matters is the value of g's nonlocal var i (funcs' local var i) when 
the yielded function g is *called*.

The difference between returning versus yielding an inner closure such as g 
is this.  If g is returned, the outer function has terminated and the 
enclosed variable(s), i in this case, is frozen at its final value.  If g 
is yielded, the enclosed i is *live* as long as the generator is, and its 
values can change between calls, as in the second print statement.

| Should I import this to see how
| many principles this behavior violates?

???

If you meant 'report' (on SF), please do not.

Terry Jan Reedy



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


Re: A gotcha: Python pain point?

2007-06-12 Thread Diez B. Roggisch
Beorn wrote:

> Consider this example:
> 
>   >>> def funcs(x):
>   ... for i in range(5):
>   ... def g(): return x + i
>   ... yield g
> 
> I would expect the value of x used in g to be that at the function

You mean i here, don't you?
> declaration time, as if you've pass g a (x=x) argument, especially
> after reading this post: http://lua-users.org/wiki/LuaScopingDiscussion
> 
> But:
> 
>   >>> [ fun() for fun in list(funcs(1)) ]
>   [5, 5, 5, 5, 5]
> 
> Whereas:
> 
>   >>> [ fun() for fun in funcs(1) ]
>   [1, 2, 3, 4, 5]
> 
> This came up while discussing Python pain points at
> http://intertwingly.net/blog/2007/06/04/Python-Pain-Points#c1181602242
> 
> I can see how it works now, but I haven't found an easy-to-read
> documentation on this.

This has been discussed here very often. Python closures do capture the
names, not the values. If you want a value at a certain point, you need to
bind in the generated function scope by passing it as parameter. Like this:

def funcs(x):
for i in xrange(5):
def g(i=i): return x + i
yield g

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


Re: Adding a DB regs to a wx listbox

2007-06-12 Thread Jorgen Bodde
self.list_box_1_copy.Append( your_item )

In the wxWidgets help:

http://www.wxwidgets.org/manuals/2.8.0/wx_wxcontrolwithitems.html#wxcontrolwithitems

And in the wxPython help:

http://www.wxpython.org/docs/api/wx.ItemContainer-class.html

Regards,
- Jorgen

On 6/12/07, Marcpp <[EMAIL PROTECTED]> wrote:
> Hi, I need add to a listbox a list of items extracted from a database.
> This is that I've do:
>
> class tasques(wx.Frame):
> def __init__(self, *args, **kwds):
> 
> self.list_box_1_copy = wx.ListBox(self, -1, choices=[],
> style=wx.LB_SINGLE|wx.LB_ALWAYS_SB)
> ...
>
> How I add the list to choices?
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Fight Stopping AIDS, Let's Do it...

2007-06-12 Thread a . kaur11
Hi Friends,

Let's Stop AIDS, it's increasing like a forest fire...

See the page below and learn more about it.


www.chulbul.com/aids.htm


Let's Know more about stopping AIDS today !!

---

Join the Revolution !!

http://www.orkut.com/Community.aspx?cmm=27495757

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


Re: How can I parse False from c extension?

2007-06-12 Thread Gabriel Genellina
En Tue, 12 Jun 2007 05:07:13 -0300, Allen <[EMAIL PROTECTED]>  
escribió:

>> From python command, I call C extension method
 import PyRPC
 PyRPC.addBool(False)
>
> In C extension, I know parse integer value like this:
> PyArg_ParseTuple(args, "i", &nValue);
>
> But, how can I parse the False value?

Parse them as integers, with False==0 and True==1.

-- 
Gabriel Genellina

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


Re: Pasting an image from clipboard in Tkinter?

2007-06-12 Thread Eric Brunel
On Mon, 11 Jun 2007 14:23:48 +0200, exhuma.twn <[EMAIL PROTECTED]> wrote:
> As many might know, windows allows to copy an image into the clipboard
> by pressing the "Print Screen" button on the keyboard. Is it possible
> to paste such an image from the clipboard into a "Text" widget in
> Tkinter? Here is my first attempt with just trying to print out the
> image data:
>
> -
> def pasteImg(tgt):
>global clipboardEnabled
>if not clipboardEnabled: return
>
>win32clipboard.OpenClipboard(0)
>print win32clipboard.GetClipboardData()
>win32clipboard.CloseClipboard()
> -
>
> This works fine with selecting text, but comes up with the following
> error when trying to paste an image:
>
> -
> Exception in Tkinter callback
> Traceback (most recent call last):
>   File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
> return self.func(*args)
>   File "X:\development\testing\tkwiki\tkwiki.py", line 52, in 
> Button( root, command=lambda: pasteImg(txt) ).pack()
>   File "X:\development\testing\tkwiki\tkwiki.py", line 38, in pasteImg
> print win32clipboard.GetClipboardData()
> TypeError: Specified clipboard format is not available
> -
>
> Obviously the clipboard does not know about that format. Does that
> mean I have to wait until it's implemented or are there other ways to
> access the image data?

According to http://msdn2.microsoft.com/en-us/library/ms649039.aspx, there  
is format that you should pass to GetClipboardData telling the data type  
you expect to get. The format you should specify to get a bitmap image is  
named CF_BITMAP in the Windows API. AFAIK, this constant is not exposed in  
the Python world, so you have to pass directly the numeric value, which is  
2.

But even if you do get the clipboard contents, you'll get it in BMP  
format, that tk/Tkinter does not understand by default. So you'll need a  
means to convert it to the only format known to tk/Tkinter by default,  
which is GIF. PIL is certainly able to do that (I don't use it myself);  
you may also rely on an external conversion utility.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Thunderbird access to this newsgroup

2007-06-12 Thread Rostfrei
Hello!

I'm writing this message over Google web access. I'm trying to access
to the comp.lang.python newsgroup trough the Thunderbird, but I just
can't configure it properly. What is the news server for this
newsgroup. If I ping comp.lang.python it is not resolved. For instance
I had no problem configuring Eclipse news server. I just entered
news.eclipse.org as a news server address and after it I can browse
available groups.

Your help will be much appreciated!

Regards,
Marko Kukovec

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


Re: Multiline lamba implementation in python.

2007-06-12 Thread exhuma.twn
On Jun 12, 5:57 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Tue, 12 Jun 2007 00:02:37 -0300, Josh Gilbert
> <[EMAIL PROTECTED]> escribió:
>
> > I don't expect multiline lambdas to be added to Python. I'm not so sure
> > that
> > that's a bad thing. Regardless, isn't it possible to write your own
> > implementation of multiline lambdas as functions? Wouldn't that be a
> > win-win
> > for everyone?
>
> If you want to "implement multiline lambdas as functions"... why don't you
> use a plain old function?
>
> --
> Gabriel Genellina

I agree. lambdas are useful for simple things like "lambda x: x^2" or
so. Once you need more than that, you should consider refactoring
things into a "plain old function" ;)

In general I suppose that is a good idea anyhow to ensure future
compatibility. lambdas are to be removed in Py3k IIRC.

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


Re: Floating Number format problem

2007-06-12 Thread Gabriel Genellina
En Tue, 12 Jun 2007 05:46:25 -0300, <[EMAIL PROTECTED]> escribió:

> On 6 12 ,   3 16 , ici <[EMAIL PROTECTED]> wrote:
>> On Jun 12, 10:10 am, <[EMAIL PROTECTED]> wrote:
>>
>> > How could I format the float number like this: (keep 2 digit
>> > precision)
>> > 1.002 => 1
>> > 1.12  => 1.12
>> >>> print "%.02f" % (2324.012)
>> 2324.01
>>
> But in these case:
>
 print '%.02f'%1.002
> 1.00
 print '%.02f'%1.00
> 1.00
>
> I just expect it to output "1" , but these way will output 1.00

def my_formatter_ommitting_trailing_zeroes(value):
   result = '%.2f' % value
   if result[-3:]=='.00': result = result[:-3]
   return result

for f in [1.0, 1.002, 1.12, 1.567, 2324.012]:
   print "%g -> %s" % (f, my_formatter_ommitting_trailing_zeroes(f))

-- 
Gabriel Genellina

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


for ... else ?

2007-06-12 Thread exhuma.twn
On Jun 12, 6:57 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> [...]
>
> for number in range(10,100):
>  is_prime = True
>  for divisor in range(2,number):
>  if number % divisor == 0:
>  is_prime = False
>  break
>  if is_prime:
>  print number,
>
> Next step: for loops have an optional "else" clause, that gets executed
> whenever the loop exits normally (in this case, when divisor goes up to
> number, and the break statement is never executed). So you don't need
> is_prime:
>
> for number in range(10,100):
>  for divisor in range(2,number):
>  if number % divisor == 0:
>  break
>  else:
>  print number,
>

Oh my. Would it not be an idea to rename this "else" into a "finally"?
As Gabriel points out, the else-block gets executed after the for loop
exits *normally*. In that case, is the "else" not semantically
misleading? I would surely misunderstand it if I saw it the first time.

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


Accessing attributes

2007-06-12 Thread Jeff Rollin
Hi there.

I'm working with the Python Tutorial "Byte of Python" at swaroopch.info.

I have created the attached file, but when I execute:

% objvar.py

I get the error message:

(Initializing Calamity Jane)
Traceback (most recent call last):
  File "/home/jef/bin/objvar.py", line 49, in 
Person.how_many()
AttributeError: class Person has no attribute 'how_many'

Where am I going wrong?

Many TIA for any help.

Jeff


objvar.py
Description: application/python
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Pasting an image from clipboard in Tkinter?

2007-06-12 Thread exhuma.twn
On Jun 12, 11:24 am, "Eric Brunel" <[EMAIL PROTECTED]> wrote:
> On Mon, 11 Jun 2007 14:23:48 +0200,exhuma.twn <[EMAIL PROTECTED]> wrote:
> > As many might know, windows allows to copy an image into the clipboard
> > by pressing the "Print Screen" button on the keyboard. Is it possible
> > to paste such an image from the clipboard into a "Text" widget in
> > Tkinter? Here is my first attempt with just trying to print out the
> > image data:
>
> > -
> > def pasteImg(tgt):
> >global clipboardEnabled
> >if not clipboardEnabled: return
>
> >win32clipboard.OpenClipboard(0)
> >print win32clipboard.GetClipboardData()
> >win32clipboard.CloseClipboard()
> > -
>
> > This works fine with selecting text, but comes up with the following
> > error when trying to paste an image:
>
> > -
> > Exception in Tkinter callback
> > Traceback (most recent call last):
> >   File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
> > return self.func(*args)
> >   File "X:\development\testing\tkwiki\tkwiki.py", line 52, in 
> > Button( root, command=lambda: pasteImg(txt) ).pack()
> >   File "X:\development\testing\tkwiki\tkwiki.py", line 38, in pasteImg
> > print win32clipboard.GetClipboardData()
> > TypeError: Specified clipboard format is not available
> > -
>
> > Obviously the clipboard does not know about that format. Does that
> > mean I have to wait until it's implemented or are there other ways to
> > access the image data?
>
> According tohttp://msdn2.microsoft.com/en-us/library/ms649039.aspx, there
> is format that you should pass to GetClipboardData telling the data type
> you expect to get. The format you should specify to get a bitmap image is
> named CF_BITMAP in the Windows API. AFAIK, this constant is not exposed in
> the Python world, so you have to pass directly the numeric value, which is
> 2.
>
> But even if you do get the clipboard contents, you'll get it in BMP
> format, that tk/Tkinter does not understand by default. So you'll need a
> means to convert it to the only format known to tk/Tkinter by default,
> which is GIF. PIL is certainly able to do that (I don't use it myself);
> you may also rely on an external conversion utility.
>
> HTH
> --
> python -c "print ''.join([chr(154 - ord(c)) for c in
> 'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

Well, by inspecting the clipboard contents, I already suspected it
might be "2". So I did a getData with the format set to "2".
So, when I try to paste simple text, it does complain that the
requested format is not on the clipboard. So far, correct. So I press
the print screen button, which loads an image into th clipboard. When
pasting I get this:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
return self.func(*args)
  File "X:\development\testing\tkwiki\tkwiki.py", line 55, in 
Button( root, command=lambda: pasteImg(txt) ).pack()
  File "X:\development\testing\tkwiki\tkwiki.py", line 39, in pasteImg
print win32clipboard.GetClipboardData(2)
error: (6, 'GetClipboardData:GlobalLock', 'The handle is invalid.')

I'm not sure what this means.


... Ah... bugger. It won't work (yet):
http://mail.python.org/pipermail/python-win32/2001-May/56.html

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


Re: How can I parse False from c extension?

2007-06-12 Thread Allen
On 6 12 ,   5 21 , "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Tue, 12 Jun 2007 05:07:13 -0300, Allen <[EMAIL PROTECTED]>
> escribió:
>
> >> From python command, I call C extension method
>  import PyRPC
>  PyRPC.addBool(False)
>
> > In C extension, I know parse integer value like this:
> > PyArg_ParseTuple(args, "i", &nValue);
>
> > But, how can I parse the False value?
>
> Parse them as integers, with False==0 and True==1.
>
> --
> Gabriel Genellina

Thanks!
It does work.

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

Re: Floating Number format problem

2007-06-12 Thread Marc Christiansen
Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> En Tue, 12 Jun 2007 05:46:25 -0300, <[EMAIL PROTECTED]> escribió:
> 
>> On 6 12 ,   3 16 , ici <[EMAIL PROTECTED]> wrote:
>>> On Jun 12, 10:10 am, <[EMAIL PROTECTED]> wrote:
>>>
>>> > How could I format the float number like this: (keep 2 digit
>>> > precision)
>>> > 1.002 => 1
>>> > 1.12  => 1.12
>>> >>> print "%.02f" % (2324.012)
>>> 2324.01
>>>
>> But in these case:
>>
> print '%.02f'%1.002
>> 1.00
> print '%.02f'%1.00
>> 1.00
>>
>> I just expect it to output "1" , but these way will output 1.00
> 
> def my_formatter_ommitting_trailing_zeroes(value):
>   result = '%.2f' % value
>   if result[-3:]=='.00': result = result[:-3]
>   return result
> 
> for f in [1.0, 1.002, 1.12, 1.567, 2324.012]:
>   print "%g -> %s" % (f, my_formatter_ommitting_trailing_zeroes(f))

Or:

def my_other_formatter_ommitting_trailing_zeroes(value):
result = '%.2f' % value
return result.rstrip('0.')

my_other_formatter_ommitting_trailing_zeroes(1.102) == "1.1"
-- 
http://mail.python.org/mailman/listinfo/python-list

Accessing attributes?

2007-06-12 Thread Jeff Rollin
Hi there.

I'm working with the Python Tutorial "Byte of Python" at swaroopch.info.

I have created the following file:


#!/usr/bin/env python
# Filename: objvar.py

class Person:
"""Represents a person."""
population = 0# class variable

def __init__(self,name):
"""Initializes the person's data."""
self.name = name # object variable
print '(Initializing %s)' % self.name

# When this person is created, he/she adds to the population
Person.population += 1

def __del__(self):
"""I am dying."""
print '%s says bye.' % self.name

Person.population -= 1

if Person.population == 0:
print 'I am the last one.'
else:
print 'There are still %d people left.' % Person.population

def say_hi(self):
"""Greeting by the person.

Really, that's all it does."""
print 'Hi, my name is %s.' % self.name

def how_many(cls):
"""Prints the current population."""
if Person.population == 0:
print 'Nobody is alive as of now.'
elif Person.population == 1:
print 'There is just one person here.'
else:
print 'We have %d persons here.' % Person.population
how_many = classmethod(how_many)

#jeff = Person('Jeff')

#jeff.say_hi()

cj = Person('Calamity Jane')
#cj.say_hi()
Person.how_many()

#jeff.say_hi()
Person.how_many()
-

 but when I execute:

% objvar.py

I get the error message:

(Initializing Calamity Jane)
Traceback (most recent call last):
  File "/home/jef/bin/objvar.py", line 49, in 
    Person.how_many()
AttributeError: class Person has no attribute 'how_many'

Where am I going wrong?

Many TIA for any help.
-- 
http://mail.python.org/mailman/listinfo/python-list

In C extension .pyd, sizeof INT64 = 4?

2007-06-12 Thread Allen
My C extension works wrong, and debug it, found that sizeof (INT64) =
4, not 8.
I compile on Windows XP platform.
Please tell me how to fix it to support INT64?
Thanks.

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

Re: pyExcelerator and multiple worksheets

2007-06-12 Thread John Machin
On Jun 12, 10:58 am, [EMAIL PROTECTED] wrote:
> I'm using pyExcelerator to take a folder of CSV files and create Excel
> workbooks for all of them, then generate an Excel workbook with the
> data from all of them.
>
> Everything up until here works great; next, I make a second worksheet
> on the last workbook which has summary details regarding the previous
> worksheet.  Here I run into a problem.  The Excel form
>
> AVERAGE(Data!E5:E3053)
>
> where Data is the name of the worksheet being referenced (Summary is
> the name of the worksheet where the formula is entered) isn't
> recognized when I call Formula().

See my reply to your post on
http://groups.google.com/group/python-excel

Cheers,
John

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


Re: Accessing attributes

2007-06-12 Thread Marc Christiansen
Jeff Rollin <[EMAIL PROTECTED]> wrote:
> I'm working with the Python Tutorial "Byte of Python" at swaroopch.info.
> 
> I have created the attached file, but when I execute:
> 
> % objvar.py
> 
> I get the error message:
> 
> (Initializing Calamity Jane)
> Traceback (most recent call last):
>  File "/home/jef/bin/objvar.py", line 49, in 
>Person.how_many()
> AttributeError: class Person has no attribute 'how_many'
> 
> Where am I going wrong?

The indentation of __del__, say_hi and how_many is wrong. You define
them inside __init__. Move them to the same indentation level as
__init__ and all should work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Newsgroup query

2007-06-12 Thread Jeff Rollin
Hi.

You may have just seen that I posted a more-or-less identical message to the
group. This was because the message w/ the attached file didn't show up for
me - but I also just got a reply which references the message with the
attached file.

Why do I not see my messages with attached files in the newsgroup, and is
there any way to configure this?

TIA.

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


Re: Accessing attributes

2007-06-12 Thread Jeff Rollin
In the last episode, on Tuesday 26 Sivan 5767 11:09, Marc Christiansen
wrote:


> 
> The indentation of __del__, say_hi and how_many is wrong. You define
> them inside __init__. Move them to the same indentation level as
> __init__ and all should work.

Thanks very much.

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


Re: for ... else ?

2007-06-12 Thread Nis Jørgensen
exhuma.twn skrev:

>> for number in range(10,100):
>>  for divisor in range(2,number):
>>  if number % divisor == 0:
>>  break
>>  else:
>>  print number,
>>
> 
> Oh my. Would it not be an idea to rename this "else" into a "finally"?
> As Gabriel points out, the else-block gets executed after the for loop
> exits *normally*. In that case, is the "else" not semantically
> misleading? I would surely misunderstand it if I saw it the first time.

"finally" would be at least equally confusing IMO, indicating that the
code is always called (although this would of course make it a
ridiculous construct).

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


Re: Newsgroup query

2007-06-12 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Jeff Rollin wrote:

> Why do I not see my messages with attached files in the newsgroup, and is
> there any way to configure this?

No, most news servers strip attachments from postings in non-binary
groups.  It's a plain text medium.

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


Re: Newsgroup query

2007-06-12 Thread Jeff Rollin
In the last episode, on Tuesday 26 Sivan 5767 11:21, Marc 'BlackJack'
Rintsch wrote:

> In <[EMAIL PROTECTED]>, Jeff Rollin wrote:
> 
>> Why do I not see my messages with attached files in the newsgroup, and is
>> there any way to configure this?
> 
> No, most news servers strip attachments from postings in non-binary
> groups.  It's a plain text medium.
> 
> Ciao,
> Marc 'BlackJack' Rintsch

OK, I'll keep that in mind.

TVM.

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


Re: Thunderbird access to this newsgroup

2007-06-12 Thread Nis Jørgensen
Rostfrei skrev:
> Hello!
> 
> I'm writing this message over Google web access. I'm trying to access
> to the comp.lang.python newsgroup trough the Thunderbird, but I just
> can't configure it properly. What is the news server for this
> newsgroup. If I ping comp.lang.python it is not resolved. For instance
> I had no problem configuring Eclipse news server. I just entered
> news.eclipse.org as a news server address and after it I can browse
> available groups.

Newsgroups are not specific to one server, they can be "carried" by any
number of servers. Most ISP's make a news server available to their
customers which carries the "standard" newsgroup hierarchy - which
comp.lang.python is part of. Try using news. as the server
name, or look at their help pages for the correct server name/setup.
There used to be quite a few free and open servers available, but I
don't know the situation today.

Many organizations keep their own newsgroup servers, which carry only
their own groups (and possibly a few relevant ones from the standard
hierarchy) - news.eclipse.org is probably such a server.

Hope this helps.

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


Re: Accessing attributes?

2007-06-12 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Jeff Rollin wrote:

> (Initializing Calamity Jane)
> Traceback (most recent call last):
>   File "/home/jef/bin/objvar.py", line 49, in 
>     Person.how_many()
> AttributeError: class Person has no attribute 'how_many'
> 
> Where am I going wrong?

Looking at the indention of the code I would say you just have an
`__init__()` and all other ``def``\s are local functions to that method.

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

Re: A gotcha: Python pain point?

2007-06-12 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Terry Reedy
wrote:

> | Should I import this to see how
> | many principles this behavior violates?
> 
> ???
> 
> If you meant 'report' (on SF), please do not.

I think he meant ``import this`` at the Python interpreter.

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


Re: Floating Number format problem

2007-06-12 Thread Peter Otten
Marc Christiansen wrote:

> Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>> En Tue, 12 Jun 2007 05:46:25 -0300, <[EMAIL PROTECTED]> escribió:
>> 
>>> On 6 12 ,   3 16 , ici <[EMAIL PROTECTED]> wrote:
 On Jun 12, 10:10 am, <[EMAIL PROTECTED]> wrote:

 > How could I format the float number like this: (keep 2 digit
 > precision)
 > 1.002 => 1
 > 1.12  => 1.12
 >>> print "%.02f" % (2324.012)
 2324.01
> Or:
> 
> def my_other_formatter_ommitting_trailing_zeroes(value):
> result = '%.2f' % value
> return result.rstrip('0.')

Make that result.rstrip("0").rstrip("."), or it may fail:

>>> ("%.2f" % 100.0).rstrip(".0") 
'1' # wrong
>>> ("%.2f" % 100.0).rstrip("0").rstrip(".")
'100'

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


Re: Floating Number format problem

2007-06-12 Thread John Machin
On Jun 12, 8:04 pm, Marc Christiansen <[EMAIL PROTECTED]> wrote:
> Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> > En Tue, 12 Jun 2007 05:46:25 -0300, <[EMAIL PROTECTED]> escribió:
>
> >> On 6 12 ,   3 16 , ici <[EMAIL PROTECTED]> wrote:
> >>> On Jun 12, 10:10 am, <[EMAIL PROTECTED]> wrote:
>
> >>> > How could I format the float number like this: (keep 2 digit
> >>> > precision)
> >>> > 1.002 => 1
> >>> > 1.12  => 1.12
> >>> >>> print "%.02f" % (2324.012)
> >>> 2324.01
>
> >> But in these case:
>
> > print '%.02f'%1.002
> >> 1.00
> > print '%.02f'%1.00
> >> 1.00
>
> >> I just expect it to output "1" , but these way will output 1.00
>
> > def my_formatter_ommitting_trailing_zeroes(value):
> >   result = '%.2f' % value
> >   if result[-3:]=='.00': result = result[:-3]
> >   return result
>
> > for f in [1.0, 1.002, 1.12, 1.567, 2324.012]:
> >   print "%g -> %s" % (f, my_formatter_ommitting_trailing_zeroes(f))
>
> Or:
>
> def my_other_formatter_ommitting_trailing_zeroes(value):
> result = '%.2f' % value
> return result.rstrip('0.')
>
> my_other_formatter_ommitting_trailing_zeroes(1.102) == "1.1"

Marc, thanks for coming, but:

>>> my_other_formatter_ommitting_trailing_zeroes(100.00)
'1'
>>>

What does the OP want to happen with 1.2? I suspect he wants '1.2',
not '1.20'

Looks like a variation of Marc's idea will do the business:
>>> values = [100.0, 1.0, 1.2, 1.002, 1.12, 1.567, 2324.012]
>>> [('%.02f' % x).rstrip('0').rstrip('.') for x in values]
['100', '1', '1.2', '1', '1.12', '1.57', '2324.01']

Howzat?

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

Re: Autocompletion in interactive mode doesn't work in 2.5.1

2007-06-12 Thread Papalagi Pakeha
On 6/12/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> On Jun 12, 9:36 am, "Papalagi Pakeha" wrote:
> > Hi all,
> >
> > How can I turn on autocompletion when I push  in python 2.5.1
> > interactive mode? E.g. to give me a list of all methods and attributes
> > of a given object.
>
> http://docs.python.org/lib/module-rlcompleter.html

That's it! Thanks heaps :-)

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


Re: Postpone creation of attributes until needed

2007-06-12 Thread Steven D'Aprano
On Mon, 11 Jun 2007 22:35:46 -0700, Frank Millman wrote:

> On Jun 12, 1:46 am, Steven D'Aprano
> <[EMAIL PROTECTED]> wrote:
>>
>> >> You haven't told us what the 'compute' method is.
>>
>> >> Or if you have, I missed it.
>>
>> > Sorry - I made it more explicit above. It is the method that sets up
>> > all the missing attributes. No matter which attribute is referenced
>> > first, 'compute' sets up all of them, so they are all available for
>> > any future reference.
>>
>> If you're going to do that, why not call compute() from your __init__ code
>> so that initializing an instance sets up all the attributes?
> 
> Because, as I have tried to explain elsewhere (probably not very
> clearly), not all the information required to perform compute() is
> available at __init__ time.

I'm sorry, but this explanation doesn't make sense to me.

Currently, something like this happens:

(1) the caller initializes an instance
=>  instance.x = some known value
=>  instance.y is undefined
(2) the caller tries to retrieve instance.y
(3) which calls instance.__getattr__('y')
(4) which calls instance.compute()
=>  which forces the necessary information to be available
=>  instance.__dict__['y'] = some value
(5) finally returns a value for instance.y

Since, as far as I can tell, there is no minimum time between creating the
instance at (1) and trying to access instance.y at (2), there is no
minimum time between (1) and calling compute() at (4), except for the
execution time of the steps between them. So why not just make compute()
the very last thing that __init__ does?



> I have gained a lot of valuable advice from this thread, but I do have
> a final question.
> 
> Every respondent has tried to nudge me away from __getattr__() and
> towards property(), but no-one has explained why. 

Not me! I'm trying to nudge you away from the entire approach!



> What is the downside of my approach? 

It is hard to do at all, harder to do right, more lines of code, more bugs
to fix, slower to write and slower to execute.


> And if this is not a good case for using
> __getattr__(), what is? What kind of situation is it intended to
> address?


Delegation is probably the poster-child for the use of __getattr__. Here's
a toy example: a list-like object that returns itself when you append to
it, without sub-classing.

class MyList:
def __init__(self, *args):
self.__dict__['data'] = list(args)
def __getattr__(self, attr):
return getattr(self.data, attr)
def __setattr__(self, attr, value):
return setattr(self.data, attr, value)
def append(self, value):
self.data.append(value)
return self




-- 
Steven.

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


Re: Python's "only one way to do it" philosophy isn't good?

2007-06-12 Thread Neil Cerutti
On 2007-06-12, Antoon Pardon <[EMAIL PROTECTED]> wrote:
> On 2007-06-11, Terry Reedy <[EMAIL PROTECTED]> wrote:
>> More so than supporters of most other languages, in particular
>> Scheme?
>
> Well to my knowledge (which could be vastly improved), scheme
> doesn't have some Zen-rules that include something like this.
>
> I tried to google for similar remarks in relation to scheme but
> I got no results. Maybe your google skills are better.

It's in _The Revised^%d Report on Scheme_, Introduction:

  Programming languages should be designed not by piling feature
  on top of feature, but by removing the weaknesses and
  restrictions that make additional features appear necessary.

Of course, that was written well before Scheme had most of its
current features.

-- 
Neil Cerutti
These people haven't seen the last of my face. If I go down, I'm going down
standing up. --Chuck Person
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Floating Number format problem

2007-06-12 Thread Marc Christiansen
Peter Otten <[EMAIL PROTECTED]> wrote:
> Marc Christiansen wrote:
> 
>> Gabriel Genellina <[EMAIL PROTECTED]> wrote:
>>> En Tue, 12 Jun 2007 05:46:25 -0300, <[EMAIL PROTECTED]> escribió:
>>> 
 On 6 12 ,   3 16 , ici <[EMAIL PROTECTED]> wrote:
> On Jun 12, 10:10 am, <[EMAIL PROTECTED]> wrote:
>
> > How could I format the float number like this: (keep 2 digit
> > precision)
> > 1.002 => 1
> > 1.12  => 1.12
> >>> print "%.02f" % (2324.012)
> 2324.01
>> Or:
>> 
>> def my_other_formatter_ommitting_trailing_zeroes(value):
>> result = '%.2f' % value
>> return result.rstrip('0.')
> 
> Make that result.rstrip("0").rstrip("."), or it may fail:
> 
 ("%.2f" % 100.0).rstrip(".0") 
> '1' # wrong
 ("%.2f" % 100.0).rstrip("0").rstrip(".")
> '100'

Oops, didn't think of what happens if the value is a multiple of 10.
Thanks for correcting me. And thanks to John, who found it too.

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

Re: for ... else ?

2007-06-12 Thread kaens
On 6/12/07, Nis Jørgensen <[EMAIL PROTECTED]> wrote:
> exhuma.twn skrev:
>
> >> for number in range(10,100):
> >>  for divisor in range(2,number):
> >>  if number % divisor == 0:
> >>  break
> >>  else:
> >>  print number,
> >>
> >
> > Oh my. Would it not be an idea to rename this "else" into a "finally"?
> > As Gabriel points out, the else-block gets executed after the for loop
> > exits *normally*. In that case, is the "else" not semantically
> > misleading? I would surely misunderstand it if I saw it the first time.
>
> "finally" would be at least equally confusing IMO, indicating that the
> code is always called (although this would of course make it a
> ridiculous construct).
>
> /Nis
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I think finally would be semantically nicer than else. . . maybe
something like "andthen" instead (yeah that's ugly).

I mean, else works (so would herbivore), but the terminology is a bit weird.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: In C extension .pyd, sizeof INT64 = 4?

2007-06-12 Thread Allen
On 6 12 ,   6 03 , Allen <[EMAIL PROTECTED]> wrote:
> My C extension works wrong, and debug it, found that sizeof (INT64) =
> 4, not 8.
> I compile on Windows XP platform.
> Please tell me how to fix it to support INT64?
> Thanks.

I find it is strange. In an exe win32 console project, sizeof(INT64) =
8.

My code is just like this:

/* my.h header file */

#ifdef __cplusplus
extern "C" {
#endif

static PyObject* method(PyObject* self, PyObject *args);

#idef __cplusplus
}
#endif

/* my.cpp source file */
PyObject* method(PyObject* self, PyObject *args)
{
   INT64 nValue; /* LINE_HERE */
   INT32 nRet;
   nRet = DoSomeCOperations(nValue);
   return PyBuildValue("i", nRet);
}

If I changed INT64 nValue to be static INT64 nValue at LINE_HERE, it
is ok.
Why?


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


Re: for ... else ?

2007-06-12 Thread Gabriel Genellina
En Tue, 12 Jun 2007 06:34:49 -0300, exhuma.twn <[EMAIL PROTECTED]> escribió:

> On Jun 12, 6:57 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
> wrote:
>> for number in range(10,100):
>>  for divisor in range(2,number):
>>  if number % divisor == 0:
>>  break
>>  else:
>>  print number,
>>
>
> Oh my. Would it not be an idea to rename this "else" into a "finally"?
> As Gabriel points out, the else-block gets executed after the for loop
> exits *normally*. In that case, is the "else" not semantically
> misleading? I would surely misunderstand it if I saw it the first time.

No - finally already has a meaning, "do this always, even if an exception  
occurred before".
The "else" clause is fired when a condition is not met:

if condition:
   do something when condition is true
else:
   do something when condition is not true


while condition:
   do something when condition is true
else:
   do something when condition is not met


for x in iterable:
   do something with x
else:
   do something when there are no more x


You can think the above as:

while there are still values in iterable:
   do something with the next value
else:
   do something when there are no more items

-- 
Gabriel Genellina

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


Re: Multiline lamba implementation in python.

2007-06-12 Thread Carsten Haese
On Tue, 12 Jun 2007 02:29:31 -0700, exhuma.twn wrote
> lambdas are to be removed in Py3k IIRC.

No. From http://www.python.org/dev/peps/pep-3099/, "At one point lambda was
slated for removal in Python 3000. Unfortunately no one was able to come up
with a better way of providing anonymous functions. And so lambda is here to
stay."

--
Carsten Haese
http://informixdb.sourceforge.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Postpone creation of attributes until needed

2007-06-12 Thread Gabriel Genellina
En Tue, 12 Jun 2007 08:18:40 -0300, Steven D'Aprano  
<[EMAIL PROTECTED]> escribió:

> On Mon, 11 Jun 2007 22:35:46 -0700, Frank Millman wrote:
>
>> Because, as I have tried to explain elsewhere (probably not very
>> clearly), not all the information required to perform compute() is
>> available at __init__ time.
>
> I'm sorry, but this explanation doesn't make sense to me.
>
> Currently, something like this happens:
>
> (1) the caller initializes an instance
> =>  instance.x = some known value
> =>  instance.y is undefined
> (2) the caller tries to retrieve instance.y
> (3) which calls instance.__getattr__('y')
> (4) which calls instance.compute()
> =>  which forces the necessary information to be available
> =>  instance.__dict__['y'] = some value
> (5) finally returns a value for instance.y
>
> Since, as far as I can tell, there is no minimum time between creating  
> the
> instance at (1) and trying to access instance.y at (2), there is no
> minimum time between (1) and calling compute() at (4), except for the
> execution time of the steps between them. So why not just make compute()
> the very last thing that __init__ does?

As far as I understand what the OP said, (2) may never happen. And since  
(4) is expensive, it is avoided until it is actually required.

-- 
Gabriel Genellina

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


Re: lists - append - unique and sorted

2007-06-12 Thread rhXX
On Jun 8, 12:17 am, "Delaney, Timothy (Tim)" <[EMAIL PROTECTED]>
wrote:
> Terry Reedy wrote:
> > "Dan Bishop" <[EMAIL PROTECTED]> wrote in message
> >news:[EMAIL PROTECTED]
> >> If you don't need the list to be sorted until you're done building
> >> it, you can just use:
>
> >> lst = sorted(set(lst))
>
> > ?? looks same as
> > lst.sort()
>
> You missed that the OP wants only unique values from the original list.
>
> Tim Delaney

tks to all for comments!


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


Re: In C extension .pyd, sizeof INT64 = 4?

2007-06-12 Thread Gabriel Genellina
En Tue, 12 Jun 2007 08:39:43 -0300, Allen <[EMAIL PROTECTED]>  
escribió:

> PyObject* method(PyObject* self, PyObject *args)
> {
>INT64 nValue; /* LINE_HERE */
>INT32 nRet;
>nRet = DoSomeCOperations(nValue);
>return PyBuildValue("i", nRet);
> }
>
> If I changed INT64 nValue to be static INT64 nValue at LINE_HERE, it
> is ok.
> Why?

I don't know, but I don't see either where Python is involved... you don't  
use any argument and the returned Python object is not an INT64...

-- 
Gabriel Genellina

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


Re: SimplePrograms challenge

2007-06-12 Thread Rob Wolfe

Steve Howell wrote:
> Hi, I'm offering a challenge to extend the following
> page by one good example:
>
> http://wiki.python.org/moin/SimplePrograms

What about simple HTML parsing? As a matter of fact this is not
language concept, but shows the power of Python standard library.
Besides, that's very popular problem among newbies. This program
for example shows all the linked URLs in the HTML document:


from HTMLParser import HTMLParser

page = '''
URLs


http://domain1/page1";>some page1
http://domain2/page2";>some page2


'''

class URLLister(HTMLParser):
def reset(self):
HTMLParser.reset(self)
self.urls = []

def handle_starttag(self, tag, attrs):
try:
# get handler for tag and call it e.g. self.start_a
getattr(self, "start_%s" % tag)(attrs)
except AttributeError:
pass

def start_a(self, attrs):
href = [v for k, v in attrs if k == "href"]
if href:
self.urls.extend(href)

parser = URLLister()
parser.feed(page)
parser.close()
for url in parser.urls: print url


--
Regards,
Rob

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


httplib / connection

2007-06-12 Thread rhXX
hi all,

i'm using this tutorial example

import httplib

h = httplib.HTTP("www.python.org")
h.putrequest('GET','/index.html')
h.putheader('User-Agent','Lame Tutorial Code')
h.putheader('Accept','text/html')
h.endheaders()

errcode,errmsg, headers = h.getreply()
f = h.getfile() # Get file object for reading data
data = f.read()
f.close()

but always i get this tracing error, a timeout in h.endheaders()


  File "ejemplo.py", line 331, in testA
h.endheaders()

  File ".../lib/python2.4/httplib.py", line 795, in endheaders
self._send_output()

  File ".../lib/python2.4/httplib.py", line 676, in _send_output
self.send(msg)

  File ".../lib/python2.4/httplib.py", line 643, in send
self.connect()

  File ".../lib/python2.4/httplib.py", line 627, in connect
raise socket.error, msg

socket.error: (110, 'Connection timed out')

must i do something about network before

i would appreciate ur commenst

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


popen e pclose on python 2.3 question

2007-06-12 Thread Flyzone
I need to run a network program and return output in a variable name
without use temporany file.
So i tought to use popen (i'm using python 2.3, i can't upgrade).
RESULT = os.popen('command'+HOST, 'r')
I have a problem about it:
i need to kill the child if the program take more than 300 ms, but i
need also to wait this 300 ms to have the reply.
os.pclose(RESULT) give me:
AttributeError: 'module' object has no attribute 'pclose'
cause pclose doens't exist in 2.3.and a time.wait(0.3) is not a so
clean code.
Someone can give me some tricks? I would like a script portable on
python 2.3, i would not like
to compile on 2.5.

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


Build problem, pyopenssl on win32 vs2003.

2007-06-12 Thread Darrin Thompson
I've been trying to build pyOpenSSL on Windows with Visual Studio
2003. I've hit the message below:

building 'OpenSSL.SSL' extension
creating build\temp.win32-2.5\Release\src\ssl
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\cl.exe /c
/nologo /Ox /MD /W3 /GX /DNDEBUG -Ic:\OpenSSL\include
-Ic:\Python25\include -Ic:\Python25\PC /Tcsrc/ssl/connection.c
/Fobuild\temp.win32-2.5\Release\src/ssl/connection.obj
connection.c
c:\cygwin\home\pandora\build-toolchain\build\pyOpenSSL-0.6\src\crypto\x509name.h(27)
: error C2059: syntax error : '('
c:\cygwin\home\pandora\build-toolchain\build\pyOpenSSL-0.6\src\crypto\x509name.h(30)
: error C2059: syntax error : '}'
c:\OpenSSL\include\openssl\x509v3.h(185) : error C2059: syntax error : '('
c:\OpenSSL\include\openssl\x509v3.h(193) : error C2059: syntax error : 'type'
c:\OpenSSL\include\openssl\x509v3.h(197) : error C2059: syntax error : '}'

I dug in and looked at preprocessor output. For some reason, after
winsock.h is included, X509_NAME is replaced with ((LPCSTR) 7).

Oh, And I'm building against the windows binaries build by "shining
light productions".

Any ideas on how to fix this?

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


Re: Python optimization (was Python's "only one way to do it" philosophy isn't good?)

2007-06-12 Thread Diez B. Roggisch
John Nagle wrote:

> Diez B. Roggisch wrote:
>> Regardless of the possibility of speeding it up - why should one want
>> this? Coding speed is more important than speed of coding in 90%+ of all
>> cases.
> 
>  When you have to start buying more servers for the server farm,
> it's a real pain.  I'm actually facing that because Python's HTML
> parsing is so slow.

I can't believe that this is a general "python is to slow"-issue. After all,
lxml and cElementTree are _really_ fast - and written in C.

For example in TurboGears, there are two python-only templating systems -
KID & genshi (apart from others). The latter is a magnitude faster than the
former. After all, O(n^3) is O(n^3), regardless of the language...

And if only the html-parsing is slow, you might consider creating an
extension for that. Using e.g. Pyrex.

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


Re: httplib / connection

2007-06-12 Thread rhXX
On Jun 12, 2:09 pm, rhXX <[EMAIL PROTECTED]> wrote:
> hi all,
>
> i'm using this tutorial example
>
> import httplib
>
> h = httplib.HTTP("www.python.org")
> h.putrequest('GET','/index.html')
> h.putheader('User-Agent','Lame Tutorial Code')
> h.putheader('Accept','text/html')
> h.endheaders()
>
> errcode,errmsg, headers = h.getreply()
> f = h.getfile() # Get file object for reading data
> data = f.read()
> f.close()
>
> but always i get this tracing error, a timeout in h.endheaders()
>
>   File "ejemplo.py", line 331, in testA
> h.endheaders()
>
>   File ".../lib/python2.4/httplib.py", line 795, in endheaders
> self._send_output()
>
>   File ".../lib/python2.4/httplib.py", line 676, in _send_output
> self.send(msg)
>
>   File ".../lib/python2.4/httplib.py", line 643, in send
> self.connect()
>
>   File ".../lib/python2.4/httplib.py", line 627, in connect
> raise socket.error, msg
>
> socket.error: (110, 'Connection timed out')
>
> must i do something about network before
>
> i would appreciate ur commenst


sorry, the timeout induced me to think about proxy connection
(evident ). i found this example and worked fine!
import httplib, getpass, base64

print "Proxy Authentication Required:"
user = raw_input("Username: ")
passwd = getpass.getpass()
auth = base64.encodestring(user + ":" + passwd)

proxy_domain = "proxy.toto.com"
proxy_port = 8000

host = "www.tata.com"
url = "/"

h = httplib.HTTPConnection(proxy_domain, proxy_port)
h.putrequest('GET', "http://%s%s"%(host,url))
h.putheader('Host', host)
h.putheader('Proxy-Authorization', '''Basic %s''' % auth)
h.endheaders()
r = h.getresponse()
z = r.read()

print z

sorry by disturb 


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


Re: popen e pclose on python 2.3 question

2007-06-12 Thread Flyzone
> i need to kill the child if the program take more than 300 ms, but i
> need also to wait this 300 ms to have the reply.

I reply by myself:

from popen2 import Popen3
cmd = Popen3('command','r')
waiting=0
while (cmd.poll()==-1):
   time.sleep(0.1)
   waiting+=1
   if (waiting>3): os.kill(RESULT.pid,0)

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


Re: Multiline lamba implementation in python.

2007-06-12 Thread Facundo Batista
Josh Gilbert wrote:

> I don't expect multiline lambdas to be added to Python. I'm not so sure that
> that's a bad thing. Regardless, isn't it possible to write your own

Yes, it is a bad thing.

Why? Because it would another way to do something you can do in other
way.

The *only* big value of lambda is than you can code a function in a
small place, like:

  bt = Button(...,...,..., lambda evt: None)

If you want to grow that in multiline, just use a named function:

  def multilinefunct(...):
  ...

Remember that the *only* difference between the two functions is that
one is anonymous, and for other you have to came up with a name (name
that if is well thought, actually adds readibility to your code).

Regards,

-- 
.   Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


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


Excel file interface for Python 2.3?

2007-06-12 Thread Hamilton, William
I'm in need of a module that will let me create Excel workbooks from within
Python.  Something like PyExcelerator, but it needs to work with Python 2.3.
(A third-party limitation that I have no control over.)  Can anyone point me
to what I need?  All my searches keep leading back to PyExcelerator.

--
-Bill Hamilton
 

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


Re: In C extension .pyd, sizeof INT64 = 4?

2007-06-12 Thread Allen
On 6 12 ,   8 08 , "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Tue, 12 Jun 2007 08:39:43 -0300, Allen <[EMAIL PROTECTED]>
> escribió:
>
> > PyObject* method(PyObject* self, PyObject *args)
> > {
> >INT64 nValue; /* LINE_HERE */
> >INT32 nRet;
> >nRet = DoSomeCOperations(nValue);
> >return PyBuildValue("i", nRet);
> > }
>
> > If I changed INT64 nValue to be static INT64 nValue at LINE_HERE, it
> > is ok.
> > Why?
>
> I don't know, but I don't see either where Python is involved... you don't
> use any argument and the returned Python object is not an INT64...
>
> --
> Gabriel Genellina

The problem is obviously compiler involved.
But I don't know why the sizeof INT64 is changed to be 4.

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

Re: Excel file interface for Python 2.3?

2007-06-12 Thread John Machin
On Jun 12, 11:01 pm, "Hamilton, William " <[EMAIL PROTECTED]> wrote:
> I'm in need of a module that will let me create Excel workbooks from within
> Python.  Something like PyExcelerator, but it needs to work with Python 2.3.
> (A third-party limitation that I have no control over.)  Can anyone point me
> to what I need?  All my searches keep leading back to PyExcelerator.
>

xlwt is a fork of pyExcelerator that I'm maintaining. It works with
Python 2.3 and later.

https://secure.simplistix.co.uk/svn/xlwt/trunk



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


Re: How to get inputs for a python program that run from another python program

2007-06-12 Thread pyscottishguy
On Jun 11, 7:47 am, pradeep nair <[EMAIL PROTECTED]> wrote:
> I would like to know how to pass keyboard input for a python script
> which is ran by another script.
>
> for eg:
>
> hello1.py:
>
> import os
>
> if __name__=='__main__':
>
>  print "I will call this other program called hello.py"
>  os.system("python hello.py")
>  print "hello1.py"
>
> hello.py:
>
> import os
>
> if __name__=='__main__':
>
>  print "press ENTER to display"
>  #code wer if the user hits enter
>  print "hello"
>  #else the user hits any other keyboard button:
>  sys.exit()
>
> now wen i run hello1.py,i want the  some function or utility in
> hello1.py that can pass the keyboard i/p  to hello.py .

Using pexpect: http://pexpect.sourceforge.net/

hello1.py:

import pexpect

if __name__=='__main__':

 print "I will call this other program called hello.py"

 child = pexpect.spawn('python hello.py')
 child.expect ('\n')

 print "Received from hello.py: ", child.before

 entered = raw_input("> ")
 child.sendline (entered)
 child.expect ('\n')

 print "Received from hello.py: ", child.before


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


Re: Accessing attributes?

2007-06-12 Thread BartlebyScrivener
On Jun 12, 5:04 am, Jeff Rollin <[EMAIL PROTECTED]> wrote:
> Where am I going wrong?
>
> Many TIA for any help.

Look at your code, then look at swaroop's

http://tinyurl.com/2v5zze

Line up all your defs at the same indent and they should work.


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


Re: Excel file interface for Python 2.3?

2007-06-12 Thread kyosohma
On Jun 12, 8:01 am, "Hamilton, William " <[EMAIL PROTECTED]> wrote:
> I'm in need of a module that will let me create Excel workbooks from within
> Python.  Something like PyExcelerator, but it needs to work with Python 2.3.
> (A third-party limitation that I have no control over.)  Can anyone point me
> to what I need?  All my searches keep leading back to PyExcelerator.
>
> --
> -Bill Hamilton

You can also use COM if you're on Windows, via PyWin32. Hammond's book
talks about it a little here: 
http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html

I also saw some information about this in Core Python Programming by
Chun.

Example code follows:



import win32com.client as win32
def excel():
app = 'Excel'
xl = win32.gencache.EnsureDispatch('%s.Application' % app)
ss = xl.Workbooks.Add()
sh = ss.ActiveSheet
xl.Visible = True
sleep(1)

sh.Cells(1,1).Value = 'Python-to-%s Demo' % app
sleep(1)
for i in RANGE:
sh.Cells(i,1).Value = 'Line %d' % i
sleep(1)
sh.Cells(i+2,1).Value = "Th-th-th-that's all folks!"


ss.Close(False)
xl.Application.Quit()



Admittedly, COM is kind of confusing. But it's there if you need it.

Mike

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


Re: Excel file interface for Python 2.3?

2007-06-12 Thread kyosohma
On Jun 12, 8:38 am, [EMAIL PROTECTED] wrote:
> On Jun 12, 8:01 am, "Hamilton, William " <[EMAIL PROTECTED]> wrote:
>
> > I'm in need of a module that will let me create Excel workbooks from within
> > Python.  Something like PyExcelerator, but it needs to work with Python 2.3.
> > (A third-party limitation that I have no control over.)  Can anyone point me
> > to what I need?  All my searches keep leading back to PyExcelerator.
>
> > --
> > -Bill Hamilton
>
> You can also use COM if you're on Windows, via PyWin32. Hammond's book
> talks about it a little 
> here:http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html
>
> I also saw some information about this in Core Python Programming by
> Chun.
>
> Example code follows:
>
> 
>
> import win32com.client as win32
> def excel():
> app = 'Excel'
> xl = win32.gencache.EnsureDispatch('%s.Application' % app)
> ss = xl.Workbooks.Add()
> sh = ss.ActiveSheet
> xl.Visible = True
> sleep(1)
>
> sh.Cells(1,1).Value = 'Python-to-%s Demo' % app
> sleep(1)
> for i in RANGE:
> sh.Cells(i,1).Value = 'Line %d' % i
> sleep(1)
> sh.Cells(i+2,1).Value = "Th-th-th-that's all folks!"
>
> ss.Close(False)
> xl.Application.Quit()
>
> 
>
> Admittedly, COM is kind of confusing. But it's there if you need it.
>
> Mike

Oops...forgot that to mention that I import the sleep function from
the time module in the above code. Sorry about that.

Mike

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


Re: for ... else ?

2007-06-12 Thread Chris Mellon
On 6/12/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> En Tue, 12 Jun 2007 06:34:49 -0300, exhuma.twn <[EMAIL PROTECTED]> escribió:
>
> > On Jun 12, 6:57 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
> > wrote:
> >> for number in range(10,100):
> >>  for divisor in range(2,number):
> >>  if number % divisor == 0:
> >>  break
> >>  else:
> >>  print number,
> >>
> >
> > Oh my. Would it not be an idea to rename this "else" into a "finally"?
> > As Gabriel points out, the else-block gets executed after the for loop
> > exits *normally*. In that case, is the "else" not semantically
> > misleading? I would surely misunderstand it if I saw it the first time.
>
> No - finally already has a meaning, "do this always, even if an exception
> occurred before".
> The "else" clause is fired when a condition is not met:
>
> if condition:
>do something when condition is true
> else:
>do something when condition is not true
>
>
> while condition:
>do something when condition is true
> else:
>do something when condition is not met
>
>
> for x in iterable:
>do something with x
> else:
>do something when there are no more x
>
>
> You can think the above as:
>
> while there are still values in iterable:
>do something with the next value
> else:
>do something when there are no more items
>

This is a good way of phrasing it and I hope I can remember it,
because for..else always gives me trouble. To me, "else" indicates the
negative condition and I intuitively associate it with executing the
loop early, not normal exit. Personally, I think a different keyword
(maybe "after"?) would have done a better job of clarifying this.
-- 
http://mail.python.org/mailman/listinfo/python-list


file open default location

2007-06-12 Thread T. Crane
Hi,

How is the default path chosen in this instance:

myFile = file('test.txt','w')

Here I'm opening/creating a file but I have not specified the exact path, so 
how does Python determine where to 'put' this file?  More to the point, how 
do I change what the default path is?  Right now it's a networked drive that 
should not be getting my Python clutter.

Interestingly, this network drive is also where I can find my _ipython 
folder from my ipython install as well as my .matplotlib folder.  Can anyone 
tell me how to change where these folders and files go by default?

thanks for any help,
trevis 


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


Re: file open default location

2007-06-12 Thread kyosohma
On Jun 12, 8:42 am, "T. Crane" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> How is the default path chosen in this instance:
>
> myFile = file('test.txt','w')
>
> Here I'm opening/creating a file but I have not specified the exact path, so
> how does Python determine where to 'put' this file?  More to the point, how
> do I change what the default path is?  Right now it's a networked drive that
> should not be getting my Python clutter.
>
> Interestingly, this network drive is also where I can find my _ipython
> folder from my ipython install as well as my .matplotlib folder.  Can anyone
> tell me how to change where these folders and files go by default?
>
> thanks for any help,
> trevis

When you don't specify where you want to save a file, it saves the
file to the directory the script itself is run from. As far as I know,
you have to specify where you want the file saved if you don't want it
with the script.py

Mike

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


Re: file open default location

2007-06-12 Thread T. Crane

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Jun 12, 8:42 am, "T. Crane" <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> How is the default path chosen in this instance:
>>
>> myFile = file('test.txt','w')
>>
>> Here I'm opening/creating a file but I have not specified the exact path, 
>> so
>> how does Python determine where to 'put' this file?  More to the point, 
>> how
>> do I change what the default path is?  Right now it's a networked drive 
>> that
>> should not be getting my Python clutter.
>>
>> Interestingly, this network drive is also where I can find my _ipython
>> folder from my ipython install as well as my .matplotlib folder.  Can 
>> anyone
>> tell me how to change where these folders and files go by default?
>>
>> thanks for any help,
>> trevis
>
> When you don't specify where you want to save a file, it saves the
> file to the directory the script itself is run from. As far as I know,
> you have to specify where you want the file saved if you don't want it
> with the script.py

Unfortunately, this is not the case.  My module's path is this:

C:\documents and setting\t_crane\my documents\python modules\script.py

Python is in the directory C:\Python25

The file is being saved in this path:

K:\myFile.txt  (this is the networked drive mentioned above)

As an aside, I forgot to mention above that I'm using Windows XP.  Any other 
ideas or possible reasons that it would not choose my script location as the 
default location to save something?

thanks,
trevis 


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


Re: Thunderbird access to this newsgroup

2007-06-12 Thread Ben Finney
Rostfrei <[EMAIL PROTECTED]> writes:

> What is the news server for this
> newsgroup.

Usenet newsgroups are redistributed over many servers worldwide.

http://en.wikipedia.org/wiki/Usenet>

> If I ping comp.lang.python it is not resolved.

That's right. It's the name of a Usenet newsgroup, not a host name.

news:comp.lang.python>

> For instance I had no problem configuring Eclipse news server. I
> just entered news.eclipse.org as a news server address and after it
> I can browse available groups.

You can browse the groups available on that server, yes. To browse
this group, you need to find a server that carries comp.lang.python.

http://dmoz.org/Computers/Usenet/Public_News_Servers/>

-- 
 \   "The man who is denied the opportunity of taking decisions of |
  `\  importance begins to regard as important the decisions he is |
_o__) allowed to take."  -- C. Northcote Parkinson |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file open default location

2007-06-12 Thread Richard Brodie

"T. Crane" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

> As an aside, I forgot to mention above that I'm using Windows XP.  Any other 
> ideas or 
> possible reasons that it would not choose my script location as the default 
> location to 
> save something?

If you open a DOS window and run Python from there, it will write the files
in whatever directory you were in when you typed the command.

If you are running Python directly from Windows, or from an IDE, it's up
to the OS or the IDE to decide what your default directory is. Often it
will be the home directory from your user profile. 


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


Re: Multiline lamba implementation in python.

2007-06-12 Thread Kay Schluehr
On 12 Jun., 14:57, Facundo Batista <[EMAIL PROTECTED]> wrote:

> Remember that the *only* difference between the two functions is that
> one is anonymous, and for other you have to came up with a name (name
> that if is well thought, actually adds readibility to your code).

The difference is that one can be inlined since it is an expression
and the other has to be a statement and a reusable ( named )
abstraction even when you don't need one. I have a very hard time to
defend this as a good design decision even when it is just a minor
pain point in almost all my practical purposes.

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


Re: file open default location

2007-06-12 Thread T. Crane
>> As an aside, I forgot to mention above that I'm using Windows XP.  Any 
>> other ideas or possible reasons that it would not choose my script 
>> location as the default location to save something?
>
> If you open a DOS window and run Python from there, it will write the 
> files
> in whatever directory you were in when you typed the command.
>
> If you are running Python directly from Windows, or from an IDE, it's up
> to the OS or the IDE to decide what your default directory is. Often it
> will be the home directory from your user profile.

I'm using ipython and running everything from there.  On my wife's laptop 
the default save location is the home directory of her user profile, but on 
my work computer this is not the case.  Therefore I assume that there's some 
setting somewhere that's causing ipython to send stuff to such a weird 
location.

trevis 


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


Leo 4.4.3 beta 2 released

2007-06-12 Thread Edward K Ream
Leo 4.4.3 beta 2 is available at:
http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106

Leo is a text editor, data organizer, project manager and much more. See:
http://webpages.charter.net/edreamleo/intro.html

The highlights of Leo 4.4.3:

- Added support for chapters in Leo's core.
- Added support for zipped .leo files.
- Added a leoBridge module that allows full access to all of Leo's
capabilities
  from programs running outside of Leo.
- Removed all gui-dependent code from Leo's core.
- Better support for the winpdb debugger.
- Added support for @enabled-plugins nodes in settings files.
- Added support for @open-with nodes in settings files.
- Added support for @bool write_strips_blank_lines setting.
- The__wx_gui plugin is now functional.
- Leo can use aspell on Linux when using Python 2.5 or later.
- Many minor improvements, new settings, commands and bug fixes.

Links:
--
Leo:  http://webpages.charter.net/edreamleo/front.html
Home: http://sourceforge.net/projects/leo/
Download: http://sourceforge.net/project/showfiles.php?group_id=3458
CVS:  http://leo.tigris.org/source/browse/leo/
Quotes:   http://webpages.charter.net/edreamleo/testimonials.html

Edward

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html




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


Re: file open default location

2007-06-12 Thread Tim Golden
T. Crane wrote:
> myFile = file('test.txt','w')
> 
> Here I'm opening/creating a file but I have not specified the exact path, so 
> how does Python determine where to 'put' this file?  More to the point, how 
> do I change what the default path is?  Right now it's a networked drive that 
> should not be getting my Python clutter.

Python doesn't choose anything. Whatever your
Operating System deems the current drive when
you start Python is the one which will contain
any other unqualified files. You can find out
what it is by running a script which just does:

import os
print os.getcwd ()

and you can change it by doing this:

import os
os.chdir ("new-path-of-my-choosing")

> Interestingly, this network drive is also where I can find my _ipython 
> folder from my ipython install as well as my .matplotlib folder.  Can anyone 
> tell me how to change where these folders and files go by default?

Different question. (And, I'm afraid, a more complicated one). You
haven't said, but I'm going to guess you're running on Windows,
not least because any *nix setup I know of will place the user in
a well-known "Home" directory (typically /home/username).

The trouble is that applications like ipython, and maybe
matplotlib, were developed under *nix where you can rely
on getting hold of a user's "Home" directory either by
expanding the "~" shell variable -- or whatever it's called --
or by examining the HOME shell variable. Windows doesn't
traditionally have either of these things, and has over
the years had several locations with legitimate claim to
be "Home".

Python's own os.expanduser, for example, uses this approach:
"""
On Windows, only "~" is supported; it is replaced by the
environment variable HOME or by a combination of
HOMEDRIVE and HOMEPATH
"""

I think IPython now uses expandvar. Maybe it always did;
I've an idea its current behaviour was a more recent
addition to Python under Windows. But IPython used to
fall back to C:\ if it couldn't do anything else.
Don't know about matplotlib. You'll need to check the
docs (or the source).

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


Convert String to Int and Arithmetic

2007-06-12 Thread tereglow
Hello,

I am a complete newbie to Python and am accustomed to coding in PHP/
Perl/Shell.  I am trying to do the following:

I have a string:

cpuSpeed = 'Speed: 10'

What I would like to do is extract the '10' from the string,
and divide that by 1000 twice to get the speed of a processor in MHz.

My understanding is that I need to 'import re' and then use re.split
to get the first part done.  The second part confuses me because I'm
unable to convert the '10' to an integer to run division
against it.

Basically, I want to come out with 1000 for the above string.  Any
help would be appreciated.
Tom

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


Re: Convert String to Int and Arithmetic

2007-06-12 Thread kyosohma
On Jun 12, 9:32 am, tereglow <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am a complete newbie to Python and am accustomed to coding in PHP/
> Perl/Shell.  I am trying to do the following:
>
> I have a string:
>
> cpuSpeed = 'Speed: 10'
>
> What I would like to do is extract the '10' from the string,
> and divide that by 1000 twice to get the speed of a processor in MHz.
>
> My understanding is that I need to 'import re' and then use re.split
> to get the first part done.  The second part confuses me because I'm
> unable to convert the '10' to an integer to run division
> against it.
>
> Basically, I want to come out with 1000 for the above string.  Any
> help would be appreciated.
> Tom

You don't need to use the "re" module. I'd just do something like
this:

>>> temp = cpuSpeed.split(' ')
>>> temp
['Speed:', '10']
# grab the 2nd element from the list and cast it as an integer
>>> cpuSpeed = int(temp [1])
>>> cpuSpeed = (cpuSpeed / 1000) / 1000
>>> cpuSpeed
1000

Basically, you just use the split command and cast it as an integer
using the reserved word "int".

Then you can divide it twice.

Mike

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


Re: Convert String to Int and Arithmetic

2007-06-12 Thread Kay Schluehr
On 12 Jun., 16:32, tereglow <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am a complete newbie to Python and am accustomed to coding in PHP/
> Perl/Shell.  I am trying to do the following:
>
> I have a string:
>
> cpuSpeed = 'Speed: 10'
>
> What I would like to do is extract the '10' from the string,
> and divide that by 1000 twice to get the speed of a processor in MHz.
>
> My understanding is that I need to 'import re' and then use re.split
> to get the first part done.  

It shall suffice to use string methods in this case:

>>> int(cpuSpeed.split(":")[1].strip())
10

Finally you might trim the numerical value by division just as you
wish.


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


Re: file open default location

2007-06-12 Thread kyosohma
On Jun 12, 9:09 am, "Richard Brodie" <[EMAIL PROTECTED]> wrote:
> "T. Crane" <[EMAIL PROTECTED]> wrote in message
>
> news:[EMAIL PROTECTED]
>
> > As an aside, I forgot to mention above that I'm using Windows XP.  Any 
> > other ideas or
> > possible reasons that it would not choose my script location as the default 
> > location to
> > save something?
>
> If you open a DOS window and run Python from there, it will write the files
> in whatever directory you were in when you typed the command.
>
> If you are running Python directly from Windows, or from an IDE, it's up
> to the OS or the IDE to decide what your default directory is. Often it
> will be the home directory from your user profile.

Oops. My bad. I didn't know that the IDE behaved differently than the
DOS window.

Mike

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


Re: Multiline lamba implementation in python.

2007-06-12 Thread George Sakkis
On Jun 12, 10:12 am, Kay Schluehr <[EMAIL PROTECTED]> wrote:
> On 12 Jun., 14:57, Facundo Batista <[EMAIL PROTECTED]> wrote:
>
> > Remember that the *only* difference between the two functions is that
> > one is anonymous, and for other you have to came up with a name (name
> > that if is well thought, actually adds readibility to your code).
>
> The difference is that one can be inlined since it is an expression
> and the other has to be a statement and a reusable ( named )
> abstraction even when you don't need one. I have a very hard time to
> defend this as a good design decision even when it is just a minor
> pain point in almost all my practical purposes.

I think of it more as a "necessary evil" rather than a conscious
design choice. IIRC the "official" justification is that nobody came
up with an acceptable syntax for multiline lambdas; TOOWTDI is a
secondary reason (as one can easily come up with a dozen TOOWTDI
violations in other parts of the language). I agree though that in
practice it's a very small limitation.

George

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


Pattern Classification Frameworks?

2007-06-12 Thread Evan Klitzke
Hi all,

What frameworks are there available for doing pattern classification?
I'm generally interested in the problem of mapping some sort of input
to one or more categories. For example, I want to be able to solve
problems like taking text and applying one or more tags to it like
"romance", "horror", "poetry", etc. This isn't really my research
specialty, but my understanding is that Bayesian classifiers are
generally used for problems like this. I've had CRM114 recommended to
me, but as far as I can tell there aren't any python bindings for
this. From a few searches online, I've come across the Open Bayes
project which is a Python library for working with Bayesian networks,
and it also appears that DSPAM has some Python bindings, but from the
cursory look I gave it it's hard to tell how general purpose the DSPAM
engine is. Has anyone worked with any of these frameworks? Are there
any other frameworks I should be aware of?

Also, as a sidenote, are there any texts that anyone can recommend to
me for learning more about this area? I'm a mathematician by training,
so I'm not afraid to jump into reasonably advanced statistics
papers/books if necessary.

-- 
Evan Klitzke <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert String to Int and Arithmetic

2007-06-12 Thread tereglow
On Jun 12, 10:46 am, Kay Schluehr <[EMAIL PROTECTED]> wrote:
> On 12 Jun., 16:32, tereglow <[EMAIL PROTECTED]> wrote:
>
> > Hello,
>
> > I am a complete newbie to Python and am accustomed to coding in PHP/
> > Perl/Shell.  I am trying to do the following:
>
> > I have a string:
>
> > cpuSpeed = 'Speed: 10'
>
> > What I would like to do is extract the '10' from the string,
> > and divide that by 1000 twice to get the speed of a processor in MHz.
>
> > My understanding is that I need to 'import re' and then use re.split
> > to get the first part done.
>
> It shall suffice to use string methods in this case:
>
> >>> int(cpuSpeed.split(":")[1].strip())
>
> 10
>
> Finally you might trim the numerical value by division just as you
> wish.

Thanks guys.  The biggest problem I'm having with Python is that it
makes things too easy to do!

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


cgi.FieldStorage() not working on Windows

2007-06-12 Thread arorap
I've mod_php installed with Apache 2.2. In one of my folders, I'm
using the cgihandler as the PythonHandler as my target host runs
python only as CGI. Here cgi.FieldStorage() doesn't seem to work. I
can see the form data in sys.stdin but cgi.FieldStorage() returns an
empty dictionary. Here's the code for the test script I am posting to
-

--
#!/usr/bin/python

import os
import cgi
import sys

print "Content Type: text/plain\n\n"
print "Hello CGI World !\n"

for key in os.environ:
  print key + "= " + os.environ[key]

print cgi.FieldStorage()

print sys.stdin.read()
--

And here's the output I see ..

--
Hello CGI World !

HTTP_REFERER= http://learnpython/form.htm
SERVER_SOFTWARE= Apache/2.2.4 (Win32) mod_python/3.3.1 Python/2.5.1
SCRIPT_NAME= /mptest.py
SERVER_SIGNATURE=
REQUEST_METHOD= POST
SERVER_PROTOCOL= HTTP/1.1
QUERY_STRING= abc=ayz
PATH= C:\Program Files\Internet Explorer;;C:\WINDOWS\system32;C:
\WINDOWS;C:\WINDOWS\System32\Wbem;q:\bin;m:\cm\clearcase\bin;M:\PERL\NT
\EXEC\BIN;m:\cm\clearcase\bin\nt;M:\Perl\NT\EXEC\BIN;m:\perl\nt\exec
\bin;m:\cm\clearcase\utils;q:\bin;m:\opus;m:\tvcs;C:\highc331\bin;C:
\Program Files\Rational\ClearCase\bin;C:\Program Files\Rational\common
CONTENT_LENGTH= 86
HTTP_USER_AGENT= Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
HTTP_CONNECTION= Keep-Alive
SERVER_NAME= learnpython
REMOTE_ADDR= 127.0.0.1
PATHEXT= .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
SERVER_PORT= 80
SERVER_ADDR= 127.0.0.1
DOCUMENT_ROOT= D:/Projects/LearnPython/www
COMSPEC= C:\WINDOWS\system32\cmd.exe
SCRIPT_FILENAME= D:/Projects/LearnPython/www/mptest.py
SERVER_ADMIN= [EMAIL PROTECTED]
HTTP_HOST= learnpython
SystemRoot= C:\WINDOWS
HTTP_CACHE_CONTROL= no-cache
REQUEST_URI= /mptest.py?abc=ayz
HTTP_ACCEPT= */*
WINDIR= C:\WINDOWS
GATEWAY_INTERFACE= Python-CGI/1.1
REMOTE_PORT= 1081
HTTP_ACCEPT_LANGUAGE= en-us
CONTENT_TYPE= application/x-www-form-urlencoded
HTTP_ACCEPT_ENCODING= gzip, deflate

FieldStorage(None, None, [])

firstName=puneet&address=hawaii
--

I am posting to this script using a form with two text fields named
firstName and address.

any clue where am I going wrong ?

thanks,

regards,
-Puneet.

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


Re: Convert String to Int and Arithmetic

2007-06-12 Thread Evan Klitzke
On 6/12/07, tereglow <[EMAIL PROTECTED]> wrote:
> Basically, I want to come out with 1000 for the above string.  Any
> help would be appreciated.
> Tom

There are any number of techniques you can use to parse out the
integer part of the string -- the most generic is to use the re module
to match regular expressions, but you may not have to use that module
if you know the exact form of the strings you are parsing. Once you
parse out the number into a string such as '100' you can just cast
it as an integer using some code like
x = int('100')


-- 
Evan Klitzke <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pattern Classification Frameworks?

2007-06-12 Thread Diez B. Roggisch
Evan Klitzke wrote:

> Hi all,
> 
> What frameworks are there available for doing pattern classification?
> I'm generally interested in the problem of mapping some sort of input
> to one or more categories. For example, I want to be able to solve
> problems like taking text and applying one or more tags to it like
> "romance", "horror", "poetry", etc. This isn't really my research
> specialty, but my understanding is that Bayesian classifiers are
> generally used for problems like this. I've had CRM114 recommended to
> me, but as far as I can tell there aren't any python bindings for
> this.

I've utilized the CRM114 classifier from python. It wasn't too hard to come
up with a simple wrapping that only needs the crm114 binary somewhere. The
rest was dealt with in python.

So if CRM114 fits you needs functionalitywise, you should go for it.

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


Re: Multiline lamba implementation in python.

2007-06-12 Thread Kay Schluehr
On 12 Jun., 16:54, George Sakkis <[EMAIL PROTECTED]> wrote:
> On Jun 12, 10:12 am, Kay Schluehr <[EMAIL PROTECTED]> wrote:
>
> > On 12 Jun., 14:57, Facundo Batista <[EMAIL PROTECTED]> wrote:
>
> > > Remember that the *only* difference between the two functions is that
> > > one is anonymous, and for other you have to came up with a name (name
> > > that if is well thought, actually adds readibility to your code).
>
> > The difference is that one can be inlined since it is an expression
> > and the other has to be a statement and a reusable ( named )
> > abstraction even when you don't need one. I have a very hard time to
> > defend this as a good design decision even when it is just a minor
> > pain point in almost all my practical purposes.
>
> I think of it more as a "necessary evil" rather than a conscious
> design choice. IIRC the "official" justification is that nobody came
> up with an acceptable syntax for multiline lambdas;

Translating this into unofficial language: Guido just didn't care a
lot about lambda and found no one of the alternative proposals
compelling. If he's actually interested in a language feature he fixes
syntax quite fast.

> TOOWTDI is a
> secondary reason (as one can easily come up with a dozen TOOWTDI
> violations in other parts of the language). I agree though that in
> practice it's a very small limitation.
>
> George

But in the case we are discussing here it is really not obvious.
That's why the community as well as the public opinion when discussing
Python returns to the topic every once in a while. We agree about this
issue being a minor limitation but I'd vote nevertheless +1 for either
removing lambda or liberating it from the restriction of containing an
expressions only. When Guido decided to use @ to prefix a decorator
half of the Python community screamed in Perl Angst. Nothing
particularly happened. Same thing with Lisp Angst and putting a
statement into parens. Nothing special will happen either. A few hurt
souls initially and Python-as-usual after the first excitements.

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


a question about unicode in python

2007-06-12 Thread hzqij
i have a python source code test.py

# -*- coding: UTF-8 -*-

# s is a unicode string, include chinese
s = u'张三'

then i run

$ python test.py
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-1:
invalid data

by in python interactive, it is right

>>> s = u'张三'

why?

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

Re: Postpone creation of attributes until needed

2007-06-12 Thread Frank Millman
On Jun 12, 1:18 pm, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Mon, 11 Jun 2007 22:35:46 -0700, Frank Millman wrote:
> > On Jun 12, 1:46 am, Steven D'Aprano
> > <[EMAIL PROTECTED]> wrote:
>
> >> >> You haven't told us what the 'compute' method is.
>
> >> >> Or if you have, I missed it.
>
> >> > Sorry - I made it more explicit above. It is the method that sets up
> >> > all the missing attributes. No matter which attribute is referenced
> >> > first, 'compute' sets up all of them, so they are all available for
> >> > any future reference.
>
> >> If you're going to do that, why not call compute() from your __init__ code
> >> so that initializing an instance sets up all the attributes?
>
> > Because, as I have tried to explain elsewhere (probably not very
> > clearly), not all the information required to perform compute() is
> > available at __init__ time.
>
> I'm sorry, but this explanation doesn't make sense to me.
>
> Currently, something like this happens:
>
> (1) the caller initializes an instance
> =>  instance.x = some known value
> =>  instance.y is undefined
> (2) the caller tries to retrieve instance.y
> (3) which calls instance.__getattr__('y')
> (4) which calls instance.compute()
> =>  which forces the necessary information to be available
> =>  instance.__dict__['y'] = some value
> (5) finally returns a value for instance.y
>
> Since, as far as I can tell, there is no minimum time between creating the
> instance at (1) and trying to access instance.y at (2), there is no
> minimum time between (1) and calling compute() at (4), except for the
> execution time of the steps between them. So why not just make compute()
> the very last thing that __init__ does?
>

I wrote a long reply to this about an hour ago, but Google Groups
seems to have eaten it. I hope I can remember what I wrote.

This is more like what I am doing -

(t=table, c=column, p=pseudo column)

(1) the caller initializes table t1 and columns c1-c10
(2) the caller initializes table t2 and columns c11-c20
(3) t2.__init__() creates a link to t1, and updates t1 with a link to
t2
(4) t2.__init__() creates a link from c12 to c3, and updates c3 with a
link to c12
(5) t2.__init__() creates pseudo column p1 on table t1, creates a link
from c14 to p1, updates p1 with a link to c14

This all works well, and has been working for some time.

You can already see a difference between your scenario and mine.
Various attributes are set up *after* the original __init__() method
has completed.

I have now added a complication.

I want to create a t3 instance, with columns c21-c30, and I want to
create a pseudo column p2 on table t2, exactly as I did in steps 2 to
5 above. I also want to change step 5 so that instead of linking p1 on
table 1 to c14 on table 2, I link it to p2 on table 2. However, at
that point, p2 does not exist.

I hope that describes the problem a bit better. I'm going to leave it
at that for now, as I am getting a glimmer of an idea as to how I can
refactor this. I will tackle it again in the morning when I am feeling
fresh, and will report back then.

Frank

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


how to kill a process

2007-06-12 Thread Richard Rossel
Hi Fellows,
I have a problem with process termination. I have a python code that
apache runs through a django interface.
The code is very simple, first, it creates a process with the
subprocess.Popen call, and afterwards, (using a web request) the
python code uses the PID of the previously created process(stored in a
db) and kills it with an os.kill call using the SIGKILL signal.

The creation of the process is ok, apache calls the python code, this
code creates the process and exits leaving the process up and
running :)
But when the python code is called to kill the created process, the
process is left in a zombie state.

The kill code that I'm using is:
os.kill(pid, signal.SIGKILL)

and I also tried:
 kill_proc = Popen("kill -9 " + pid, shell=true)
but with no success.

I suppose that the reason maybe that the python code exits before the
kill call has finished,
so I tried with a while loop until kill_proc.poll() != None, but
without success too :(

do you know what is what I'm doing wrong?

thanks very much.-

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


Re: a question about unicode in python

2007-06-12 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, hzqij wrote:

> i have a python source code test.py
> 
> # -*- coding: UTF-8 -*-
> 
> # s is a unicode string, include chinese
> s = u'张三'
> 
> then i run
> 
> $ python test.py
> UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-1:
> invalid data
> 
> by in python interactive, it is right
> 
 s = u'张三'
> 
> why?

Does the "coding comment" match the actual encoding of the source file?

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

Forgetting an import

2007-06-12 Thread HMS Surprise
I imported a set of functions from a file I wrote to interpreter
shell:

from myFile import *

Now if I change functions in this file how can I make python forget it
so I can force a fresh import?

thanx,

jh

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


Re: Article on wxPython ToolKit for Mac OS X

2007-06-12 Thread miah_gbg
On May 3, 9:46 pm, James Stroud <[EMAIL PROTECTED]> wrote:
> miah_gbg wrote:
> > Hi there!
>
> > Just wanted to let people know in this group that I have recently
> > (April 24th) published an introductory article on wxPython and Mac OS
> > X. It is available here:http://www.macdevcenter.com/
>
> > Hope someone finds it useful.
>
> > Regards,
>
> > Jeremiah
>
> Nice article, but it has an inaccuracy:
>
> "The first thing we need to do is download wxPython so we can begin
> creating applications."
>
> This is not entirely correct. The stock 10.4 that came in a G5 bought in
> June has wx built-in:
>
>   cabin % /usr/bin/python
>   Python 2.3.5 (#1, Oct  5 2005, 11:07:27)
>   [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin
>   Type "help", "copyright", "credits" or "license" for more information.
>   >>> import wx
>   >>>
>
> Of course the stock python is 2.3, but its very cool that one can depend
> on wx being present on 10.4+ machines. So there is no need to bundle
> python/wx with your app when developing for Macs. (Yes, I noticed the
> author is running OS X 10.3.)
>
> James

Wow. That is cool. I didn't know that.

   Jeremiah

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


Re: a question about unicode in python

2007-06-12 Thread WolfgangZ
hzqij schrieb:
> i have a python source code test.py
> 
> # -*- coding: UTF-8 -*-
> 
> # s is a unicode string, include chinese
> s = u'张三'
> 
> then i run
> 
> $ python test.py
> UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-1:
> invalid data
> 
> by in python interactive, it is right
> 
 s = u'张三'
> 
> why?
> 
> 

just an idea: is your text editor really supporting utf-8? In the mail
it is only displayed as '??' which looks for me as the mail editor did
not send the mail as utf. Try to attach a correct text file.

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

Re: Forgetting an import

2007-06-12 Thread Larry Bates
HMS Surprise wrote:
> I imported a set of functions from a file I wrote to interpreter
> shell:
> 
> from myFile import *
> 
> Now if I change functions in this file how can I make python forget it
> so I can force a fresh import?
> 
> thanx,
> 
> jh
> 
While there may be ways of doing this, I have found that you are much
better off opening another window and run your script from the bare
OS.  It will help you catch problems that you may miss in the
interpreter shell.  It also solves this problem completely.

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


Re: how to kill a process

2007-06-12 Thread Larry Bates
Richard Rossel wrote:
> Hi Fellows,
> I have a problem with process termination. I have a python code that
> apache runs through a django interface.
> The code is very simple, first, it creates a process with the
> subprocess.Popen call, and afterwards, (using a web request) the
> python code uses the PID of the previously created process(stored in a
> db) and kills it with an os.kill call using the SIGKILL signal.
> 
> The creation of the process is ok, apache calls the python code, this
> code creates the process and exits leaving the process up and
> running :)
> But when the python code is called to kill the created process, the
> process is left in a zombie state.
> 
> The kill code that I'm using is:
> os.kill(pid, signal.SIGKILL)
> 
> and I also tried:
>  kill_proc = Popen("kill -9 " + pid, shell=true)
> but with no success.
> 
> I suppose that the reason maybe that the python code exits before the
> kill call has finished,
> so I tried with a while loop until kill_proc.poll() != None, but
> without success too :(
> 
> do you know what is what I'm doing wrong?
> 
> thanks very much.-
> 
Wouldn't it be better to make the process that you start respond gracefully
to some signal?  Either a command over a socket or some other signal?

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


Re: how to kill a process

2007-06-12 Thread Evan Klitzke
On 6/12/07, Richard Rossel <[EMAIL PROTECTED]> wrote:
> But when the python code is called to kill the created process, the
> process is left in a zombie state.

If the process is left in a zombie state, it's because the parent
process isn't calling wait(2). If the parent process is your own
python script, you might try a call to os.wait after the kill
statement.

-- 
Evan Klitzke <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Forgetting an import

2007-06-12 Thread René Fleschenberg
HMS Surprise schrieb:
> I imported a set of functions from a file I wrote to interpreter
> shell:
> 
> from myFile import *
> 
> Now if I change functions in this file how can I make python forget it
> so I can force a fresh import?

I think you are looking for reload(). But don't forget to check its
documentation, there may be some caveats.


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

  1   2   3   >