Invitation to connect on LinkedIn

2009-09-12 Thread suhail shaik
LinkedIn


suhail shaik requested to add you as a connection on LinkedIn:
--

Jaime,

I'd like to add you to my professional network on LinkedIn.

- suhail

Accept invitation from suhail shaik
http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/blk/I325701776_3/6lColZJrmZznQNdhjRQnOpBtn9QfmhBt71BoSd1p65Lr6lOfPdvdzsTcj0Tdj8PiiZ7jklHomoUpiYPd3ANcz0QcPsLrCBxbOYWrSlI/EML_comm_afe/

View invitation from suhail shaik
http://www.linkedin.com/e/I2LlXdLlWUhFABKmxVOlgGLlWUhFAfhMPPF/blk/I325701776_3/0PnPoTdP4MdPkOcQALqnpPbOYWrSlI/svi/

--

Why might connecting with suhail shaik be a good idea?

People suhail shaik knows can discover your profile:
Connecting to suhail shaik will attract the attention of LinkedIn users. See 
who's been viewing your profile:

http://www.linkedin.com/e/wvp/inv18_wvmp/

 
--
(c) 2009, LinkedIn Corporation

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


Re: Which version of python I should use if I just start programming in python?

2009-09-12 Thread John Nagle

Kee Nethery wrote:
I am in 2.x because the IDE I am using does not support stepping through 
my code when in 3.x. As soon as the IDE I use supports debugging in 3.x, 
I'm moving up to 3.x.


I would prefer to be in 3.x because all the inconsistencies of how you 
do things in 2.x make it harder than it needs to be to learn the language.


   So would I.  But the infrastructure isn't there yet.  Realistically,
2.5 is the "production stable" version of CPython.  Almost all important
modules work with CPython 2.5.  Some work with 2.6.  3.x support remains
spotty.  Give it a year.  Or two.

   I've tried using 3.1, but had to back down.

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


Re: Declaring array of Variables ?

2009-09-12 Thread Lie Ryan

Lennyboi wrote:

Can I declare an array of variables in python like in C

int p[10];

I looked everywhere, but I don't find any mention of it.



p = []

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


Re: Declaring array of Variables ?

2009-09-12 Thread Chris Rebert
On Sat, Sep 12, 2009 at 9:51 PM, Lennyboi  wrote:
> Can I declare an array of variables in python like in C
>
> int p[10];
>
> I looked everywhere, but I don't find any mention of it.

Python doesn't have C-like variable declarations, and it does not have
arrays of static length.
The closest you can get is a list prefilled with certain number of
duplicates of a certain value.

p = [0] * 10

or for non-numbers:

p = [None] * 10

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finite state machine in python

2009-09-12 Thread CTO
On Sep 12, 4:39 pm, Peng Yu  wrote:
> Hi,
>
> I have see some discussion on the implementation of finite state
> machine in python. Can somebody point to me the best way in implenting
> an FSM in python?
>
> http://code.activestate.com/recipes/146262/
>
> Regards,
> Peng

I wrote an example of how to do it using Graphine a while back.
Probably not the most efficient in the world, but pretty easy
to read, and it allows you to add and remove states and transitions
easily.

URL: http://gitorious.org/graphine/pages/GraphineForPythonistas

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


Declaring array of Variables ?

2009-09-12 Thread Lennyboi
Can I declare an array of variables in python like in C

int p[10];

I looked everywhere, but I don't find any mention of it.

Thanks,
Lenny
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to define a function with an empty body?

2009-09-12 Thread Mel
Peng Yu wrote:

> Hi,
> 
> I want to define a function without anything in it body. In C++, I can
> do something like the following because I can use "{}" to denote an
> empty function body. Since python use indentation, I am not sure how
> to do it. Can somebody let me know how to do it in python?
> 
> void f() {
> }

Syntactically, there has to be something in the function definition.  It can 
be a `pass` statement, or a doc string, though:


Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def f():
...   "empty function"
... 
>>> f()
>>> print f()
None
>>> def g():
... 
  File "", line 2

^
IndentationError: expected an indented block
>>> def h():
...   pass
... 
>>> print h()
None
>>> 



Cheers, Mel.

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


Re: How to define a function with an empty body?

2009-09-12 Thread Chris Rebert
On Sat, Sep 12, 2009 at 8:37 PM, Peng Yu  wrote:
> Hi,
>
> I want to define a function without anything in it body. In C++, I can
> do something like the following because I can use "{}" to denote an
> empty function body. Since python use indentation, I am not sure how
> to do it. Can somebody let me know how to do it in python?
>
> void f() {
> }

Use the no-op `pass` keyword:

def f():
pass

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


How to define a function with an empty body?

2009-09-12 Thread Peng Yu
Hi,

I want to define a function without anything in it body. In C++, I can
do something like the following because I can use "{}" to denote an
empty function body. Since python use indentation, I am not sure how
to do it. Can somebody let me know how to do it in python?

void f() {
}

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


Re: list as an instance attribute

2009-09-12 Thread Chris Rebert
Cheers,
Chris
--
http://blog.rebertia.com



On Sat, Sep 12, 2009 at 8:22 PM, André  wrote:
> On Sep 12, 11:48 pm, Daniel Luis dos Santos 
> wrote:
>> Hello,
>>
>> I have an object definition :
>>
>> class primitive:
>>
>>         def __init__(self)
>>                 self.name = ""
>>                 self.transforms = []
>>
>>         def copy(self, copyName)
>>
>>                 copy = self.copyInternalState(copyName)  # method defined 
>> elsewhere
>> in derived class
>>
>>                 if self.transforms != []
>>                         for transf in self.transforms
>>                                 copy.transforms.append(transf.copy())
>>
>> In short, what I want to is to have the transforms list as an instance
>> attribute of the class. I will add objects to it. When I call the copy
>> method on the object the list is to be copied to the new object.
>>
>> Problem is that the python interpreter is complaining that it doesn't
>> know any self.transforms in the if statement.
>>
>> Help
>
> 1. Always post the actual code - the code you posted is not valid
> Python as many colons (:) are missing.
> 2. You appear to be attempting to use the same name (copy) both as a
> method name AND as a local variable of that method.  This definitely
> look wrong.
>
> Perhaps if you could post the actual offending code (the smallest
> example showing the problem you observe) others might be able to help
> you.

The full, exact error message and exception traceback would also be helpful.

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


Re: Which version of python I should use if I just start programming in python?

2009-09-12 Thread Kee Nethery
I am in 2.x because the IDE I am using does not support stepping  
through my code when in 3.x. As soon as the IDE I use supports  
debugging in 3.x, I'm moving up to 3.x.


I would prefer to be in 3.x because all the inconsistencies of how you  
do things in 2.x make it harder than it needs to be to learn the  
language.


People who have been coding in 2.x for along time don't notice how the  
syntax is wonky in places. Their fingers type the right stuff. As a  
newbie I assume that everything works the same way and I am frequently  
surprised. One of the goals of 3.x was to make the language more  
consistent and that would make it easier for us newbies.


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


Re: list as an instance attribute

2009-09-12 Thread André
On Sep 12, 11:48 pm, Daniel Luis dos Santos 
wrote:
> Hello,
>
> I have an object definition :
>
> class primitive:
>
>         def __init__(self)
>                 self.name = ""
>                 self.transforms = []
>
>         def copy(self, copyName)
>
>                 copy = self.copyInternalState(copyName)  # method defined 
> elsewhere
> in derived class
>
>                 if self.transforms != []
>                         for transf in self.transforms
>                                 copy.transforms.append(transf.copy())
>
> In short, what I want to is to have the transforms list as an instance
> attribute of the class. I will add objects to it. When I call the copy
> method on the object the list is to be copied to the new object.
>
> Problem is that the python interpreter is complaining that it doesn't
> know any self.transforms in the if statement.
>
> Help

1. Always post the actual code - the code you posted is not valid
Python as many colons (:) are missing.
2. You appear to be attempting to use the same name (copy) both as a
method name AND as a local variable of that method.  This definitely
look wrong.

Perhaps if you could post the actual offending code (the smallest
example showing the problem you observe) others might be able to help
you.

Cheers,

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


list as an instance attribute

2009-09-12 Thread Daniel Luis dos Santos

Hello,

I have an object definition :

class primitive:

def __init__(self)
self.name = ""
self.transforms = []

def copy(self, copyName)

		copy = self.copyInternalState(copyName)  # method defined elsewhere 
in derived class


if self.transforms != []
for transf in self.transforms
copy.transforms.append(transf.copy())


In short, what I want to is to have the transforms list as an instance 
attribute of the class. I will add objects to it. When I call the copy 
method on the object the list is to be copied to the new object.


Problem is that the python interpreter is complaining that it doesn't 
know any self.transforms in the if statement.


Help

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


Re: Finite state machine in python

2009-09-12 Thread Tim Chase

I have see some discussion on the implementation of finite
state machine in python. Can somebody point to me the best way
in implenting an FSM in python?


To offer a "best way" requires knowing more about what you're 
trying to accomplish.  Are you looking for just some fixed 
states?  are you looking to dynamically adjust the available 
states?  Is this workflow for a single user, or is it for 
multiple users?  A FSM merely involves a list of states and the 
transitions between them.  You can augment the states and/or the 
transitions with additional metadata.  You can store your states 
in fixed internal hard-coded structures, or you can store them in 
a file/database that can grow external.


I posted information on doing this with a SQL-ish database 
(whether sqlite or whatever) a while back, so you can see a more 
"complex" version of tracking this info:


http://article.gmane.org/gmane.comp.python.general/624448


Hope this gives you some ideas from which to choose an option 
that's "best" for your needs.


-tkc





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


Re: platform-specific overrides of functions and class methods (expanding on imputils demo code)

2009-09-12 Thread Aahz
In article ,
Terry Reedy   wrote:
>lkcl wrote:
>> On Aug 21, 12:58 am, a...@pythoncraft.com (Aahz) wrote:
>>> In article 
>>> <77715735-2668-43e7-95da-c91d175b3...@z31g2000yqd.googlegroups.com>,
>>> lkcl   wrote:

 if somebody would like to add this to the python bugtracker, as a
 contribution, that would be great.  alternatively, you might like to
 have a word with the python developers to get them to remove the
 censorship on my contributions.
>>>
>>> Excuse me?  What censorship?
>> 
>>  i was ordered to cease contributing to python.
>
>As I remember from the public discussion, you were asked to cease using 
>the bugtracker as a progress blog ...
>
>> the cause was the
>> provision of a port of python to run under mingw32, which passed all
>> but eight of the regression tests.
>
>and wait until you had a complete patch to submit. 

That matches my memory as well.  Luke, your contributions would
definitely be welcome, but contributions must follow some process.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"It's 106 miles to Chicago.  We have a full tank of gas, a half-pack of
cigarettes, it's dark, and we're wearing sunglasses."  "Hit it."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which version of python I should use if I just start programming in python?

2009-09-12 Thread Terry Reedy

Peng Yu wrote:

On Sep 12, 4:10 pm, Terry Reedy  wrote:

Peng Yu wrote:

Hi,
I just start python programming. That is, I don't have any legacy
code. I notice that there are different versions of python. I would
guess that older version of python has the more libraries than newer
versions. But the code developed in newer versions might be better
supported in the future. Can somebody give a guideline on which
version of python a new python developer shall choose?

My own view is start with 3.1 and move back to 2.6 or even 2.5 when you
need a library not available with 3.1. Others will say start with 2.6 or
2.5. This has been discussed previously on this list.


Would you please point me where the previous discussion is?


http://groups.google.com/group/comp.lang.python/topics

type question in search box and click 'search this group'

and see what you get


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


Re: Podcast catcher in Python

2009-09-12 Thread Someone Something
C shouldn't be very hard.
You just get the url of the file you want to connect to, then just use the
normal connect sequence and read the file and print it out to the UNIX
shell, then at the unix shell, just pipe it to an MP3. Or you could just do
it with FILE *.
On Sat, Sep 12, 2009 at 4:37 PM, Chuck  wrote:

> On Sep 11, 9:54 pm, Chris Rebert  wrote:
> > On Fri, Sep 11, 2009 at 7:43 PM, Chuck  wrote:
> > > Does anyone know how I should read/download the mp3 file, and how I
> > > should write/save it so that I can play it on a media player such as
> > > Windoze media player?  Excuse my ignorance, but I am a complete noob
> > > at this.  I downloaded the mp3, and I got a ton of hex, I think, but
> > > it could've been unicode.
> >
> > urllib.urlretrieve():
> http://docs.python.org/library/urllib.html#urllib.urlretrieve
> >
> > Cheers,
> > Chris
>
> Thanks Chris!  I will play around with this.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string interpolation mystery in Python 2.6

2009-09-12 Thread Alan G Isaac

On 9/11/2009 9:42 PM, Steven D'Aprano wrote:

However, I must admit I'm perplexed why the original example is calling
__unicode__() in the first place! Given the line:

raise self.severe('Problems with "%s" directive path:\n%s: %s.'
 % (self.name, error.__class__.__name__, error))

it looks to me like it should be calling error.__str__() not
error.__unicode(). Making the suggested edit:

raise self.severe('Problems with "%s" directive path:\n%s: %s.'
 % (self.name, error.__class__.__name__, str(error)))

should have no effect. But it (apparently) does. This brings us back to
Alan's original question:

"MYSTERY: how can "%s"%error be different from "%s"%str(error) in Python
2.6?"



George Brandl explained it to me this way:

It's probably best explained with a bit of code:

>>> >>> class C(object):
...  def __str__(self): return '[str]'
...  def __unicode__(self): return '[unicode]'
...
>>> "%s %s" % ('foo', C())
'foo [str]'
>>> "%s %s" % (u'foo', C())
u'foo [unicode]'

I.e., as soon as a Unicode element is interpolated into a string, further

interpolations automatically request Unicode via __unicode__, if it 
exists.

Pretty subtle ...

Cheers,
Alan Isaac

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


Re: Where regexs listed for Python language's tokenizer/lexer?

2009-09-12 Thread Robert Kern

Dennis Lee Bieber wrote:

On Fri, 11 Sep 2009 23:10:39 -0700 (PDT), Chris Seberino
 declaimed the following in
gmane.comp.python.general:


Where regexs listed for Python language's tokenizer/lexer?

If I'm not mistaken, the grammar is not sufficient to specify the
language
you also need to specify the regexs that define the tokens
right?..where is that?


Pardon... I've been out of the "market", but I don't recall EVER
seeing a "regex" used in a textbook for compiler/interpreter design.

BNF (or Pascal's bubble diagram equivalent) has always been used to
define the syntactical components in those books in my possession, and
parsers (tokenizers) were written using those implied algorithms (if the
first character is numeric or "." it starts a number, otherwise treat it
as an identifier, etc.),


In actual implementations of lexers and the lexical analysis components of 
parsers, regexes are fairly common. For example, from ply:


  http://www.dabeaz.com/ply/ply.html#ply_nn6

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: Which version of python I should use if I just start programming in python?

2009-09-12 Thread Peng Yu
On Sep 12, 4:10 pm, Terry Reedy  wrote:
> Peng Yu wrote:
> > Hi,
>
> > I just start python programming. That is, I don't have any legacy
> > code. I notice that there are different versions of python. I would
> > guess that older version of python has the more libraries than newer
> > versions. But the code developed in newer versions might be better
> > supported in the future. Can somebody give a guideline on which
> > version of python a new python developer shall choose?
>
> My own view is start with 3.1 and move back to 2.6 or even 2.5 when you
> need a library not available with 3.1. Others will say start with 2.6 or
> 2.5. This has been discussed previously on this list.

Would you please point me where the previous discussion is?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which version of python I should use if I just start programming in python?

2009-09-12 Thread r
On Sep 12, 3:47 pm, Peng Yu  wrote:
> Hi,
>
> I just start python programming. That is, I don't have any legacy
> code. I notice that there are different versions of python. I would
> guess that older version of python has the more libraries than newer
> versions. But the code developed in newer versions might be better
> supported in the future. Can somebody give a guideline on which
> version of python a new python developer shall choose?
>
> Regards,
> Peng

Boxers or briefs? ;-)

Well both have pros and cons. As for myself i am using 2.x until it
expires, but that is because i already have much code in 2.x line. If
you are starting from scratch i would say 3.x. The only bad aspect of
2.x right now is that eventually (if you want to keep current) you
will have to make the change to 3.0 and since backwards compatabiltity
is broken you will need to do more than just download the new
version!

At the very least you should learn the 2.x just to see why such
changes were made. But in the end keep all *real* projects in the
Python 3.0. So just lean with 3.0 and if you find some need for 2.x
(3rd party modules) use it for christs sake!

At this point in time with 3rd party modules still converting i would
say 3.0 may feel like a pair of tight briefs and your "boys" might
start to feel "confined" shall we say. With 2.x you will feel the free-
ballin' freedom of more choices at your disposal. But eventually the
tides will shift!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question regarding handling of Unicode data in Devnagari

2009-09-12 Thread Mark Tolonen


"joy99"  wrote in message 
news:fade868b-6a69-4b74-a8e8-9c28a1617...@p10g2000prm.googlegroups.com...

Dear Group,

As per the standard posted by the UNICODE for the Devnagari script
used for Hindi and some other languages of India, we have a standard
set, like from the range of 0900-097F.
Where, we have numbers for each character:
like 0904 for Devnagari letter short a, etc.
Now, if write a program,

where
ch="0904"
and I like to see the Devnagari letter short a as output then how
should I proceed? Can codecs help me or should I use unicodedata?


Here are a number of ways to generate a Unicode character.  Displaying them 
is another matter.  My newsreader program could display them properly but my 
the interactive window in my Python editor could not.


c = unichr(0x904)
print c,unicodedata.name(c)
print u'\N{DEVANAGARI LETTER SHORT A}'
print u'\u0904'
print u''.join(unichr(c) for c in range(0x900,0x980))

OUTPUT
ऄ DEVANAGARI LETTER SHORT A
ऄ
ऄ
ऀँंःऄअआइईउऊऋऌऍऎएऐऑऒओऔकखगघङचछजझञटठडढणतथदधनऩपफबभमयरऱलळऴवशषसहऺऻ़ऽािीुूृॄॅॆेैॉॊोौ्ॎॏॐ॒॑॓॔ॕॖॗक़ख़ग़ज़ड़ढ़फ़य़ॠॡॢॣ।॥०१२३४५६७८९॰ॱॲॳॴॵॶॷॸॹॺॻॼॽॾॿ

If you use an editor that can write Devnagari and save in an encoding such 
as UTF-8, you can write Devnagari directly in the editor.  You only need to 
tell Python what encoding the source code is in.  You'll also need a 
terminal and know the encoding it uses for display of characters to actually 
see the correct character.  For example, below is a program written using 
Pythonwin from the pywin32 extensions (version 214).  It can write programs 
in most encodings and its interactive window supports UTF-8.


I can type Chinese and my fonts support it so I'll use that in this example. 
This message is sent in UTF-8 so hopefully it displays properly for you.


# coding: gbk
encoded_text = '你好!你在干什么?'
Unicode_text = u'你好!你在干什么?'
print encoded_text
print encoded_text.decode('gbk')
print Unicode_text
print Unicode_text.encode('utf-8')

OUTPUT:
ţۃáţ՚ىʲôÿ
你好!你在干什么?
你好!你在干什么?
你好!你在干什么?

'encoded_text' is a byte string encoded in the encoding the file is saved in 
(*not*what the #coding line declares...*you* have to make sure they agree!). 
Since my terminal is UTF-8, The gbk-encoded line is garbage.


The 2nd line should be correct because it decoded the byte string to 
Unicode.  'print' will automatically encode Unicode text in the terminal's 
encoding.  As long as the terminal's encoding and font supports the Unicode 
characters used (which in Pythonwin it does), the line will be correct.


The 3rd line works for the same reason the 2nd line does...The string is 
already Unicode.


The 4th line works because it was explicitly encoded into UTF-8, and the 
terminal supports it.


I hope this is useful to you.
-Mark 



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


Re: Where regexs listed for Python language's tokenizer/lexer?

2009-09-12 Thread Duncan Booth
Paul McGuire  wrote:

> On Sep 12, 1:10 am, Chris Seberino  wrote:
>> Where regexs listed for Python language's tokenizer/lexer?
>>
>> If I'm not mistaken, the grammar is not sufficient to specify the
>> language
>> you also need to specify the regexs that define the tokens
>> right?..where is that?
> 
> I think the OP is asking for the regexs that define the terminals
> referenced in the Python grammar, similar to those found in yacc token
> definitions.  He's not implying that there are regexs that implement
> the whole grammar.
> 

The OP should read 
http://www.python.org/doc/current/reference/lexical_analysis.html

That has the BNF for those tokens that can be defined by BNF 
such as identifiers, numbers and strings. The tricky bit is that INDENT and 
DEDENT tokens depend on the context: see section 2.1.8.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Which version of python I should use if I just start programming in python?

2009-09-12 Thread Terry Reedy

Peng Yu wrote:

Hi,

I just start python programming. That is, I don't have any legacy
code. I notice that there are different versions of python. I would
guess that older version of python has the more libraries than newer
versions. But the code developed in newer versions might be better
supported in the future. Can somebody give a guideline on which
version of python a new python developer shall choose?


My own view is start with 3.1 and move back to 2.6 or even 2.5 when you 
need a library not available with 3.1. Others will say start with 2.6 or 
2.5. This has been discussed previously on this list.


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


Re: Where regexs listed for Python language's tokenizer/lexer?

2009-09-12 Thread Paul McGuire
On Sep 12, 1:10 am, Chris Seberino  wrote:
> Where regexs listed for Python language's tokenizer/lexer?
>
> If I'm not mistaken, the grammar is not sufficient to specify the
> language
> you also need to specify the regexs that define the tokens
> right?..where is that?

I think the OP is asking for the regexs that define the terminals
referenced in the Python grammar, similar to those found in yacc token
definitions.  He's not implying that there are regexs that implement
the whole grammar.

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


Which version of python I should use if I just start programming in python?

2009-09-12 Thread Peng Yu
Hi,

I just start python programming. That is, I don't have any legacy
code. I notice that there are different versions of python. I would
guess that older version of python has the more libraries than newer
versions. But the code developed in newer versions might be better
supported in the future. Can somebody give a guideline on which
version of python a new python developer shall choose?

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


Re: Podcast catcher in Python

2009-09-12 Thread Chuck
On Sep 11, 9:54 pm, Chris Rebert  wrote:
> On Fri, Sep 11, 2009 at 7:43 PM, Chuck  wrote:
> > Does anyone know how I should read/download the mp3 file, and how I
> > should write/save it so that I can play it on a media player such as
> > Windoze media player?  Excuse my ignorance, but I am a complete noob
> > at this.  I downloaded the mp3, and I got a ton of hex, I think, but
> > it could've been unicode.
>
> urllib.urlretrieve():http://docs.python.org/library/urllib.html#urllib.urlretrieve
>
> Cheers,
> Chris

Thanks Chris!  I will play around with this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Finite state machine in python

2009-09-12 Thread Peng Yu
Hi,

I have see some discussion on the implementation of finite state
machine in python. Can somebody point to me the best way in implenting
an FSM in python?

http://code.activestate.com/recipes/146262/

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


Re: is there a "strawberry python"?

2009-09-12 Thread Daniel Fetchinson
> the reason I like strawberry perl is that I don't need to have admin right
> to install it. i can just unzip it and start the game.
> i am wondering if there is something similar in python community.
>
> any insight will be appreciated!

As far as I remember there are python installations on USB sticks
which you can run without any privileges.

http://www.portablepython.com/

HTH,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming ideas?

2009-09-12 Thread Daniel Fetchinson
> I know you've probably had this question a million and one times but here it
> is again. I'm intermediate at C, pretty good at Java (though I really don't
> want to program in this), okay at perl and I've just learned python. But, I
> have no more ideas to write programs/scripts for! Any ideas will be helpful?


Take a look at,

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

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CPU usage while reading a named pipe

2009-09-12 Thread Miguel P
On Sep 12, 2:54 pm, Ned Deily  wrote:
> In article
> ,
>  Miguel P  wrote:
>
>
>
> > I've been working on parsing (tailing) a named pipe which is the
> > syslog output of the traffic for a rather busy haproxy instance. It's
> > a fair bit of traffic (upto 3k hits/s per server), but I am finding
> > that simply tailing the file  in python, without any processing, is
> > taking up 15% of a CPU core. In contrast HAProxy takes 25% and syslogd
> > takes 5% with the same load. `cat < /named.pipe` takes 0-2%
>
> > Am I just doing things horribly wrong or is this normal?
>
> > Here is my code:
>
> > from collections import deque
> > import io, sys
>
> > WATCHED_PIPE = '/var/log/haproxy.pipe'
>
> > if __name__ == '__main__':
> >     try:
> >         log_pool = deque([],1)
> >         fd = io.open(WATCHED_PIPE)
> >         for line in fd:
> >             log_pool.append(line)
> >     except KeyboardInterrupt:
> >         sys.exit()
>
> > Deque appends are O(1) so that's not it. And I am using 2.6's io
> > module because it's supposed to handle named pipes better. I have
> > commented the deque appending line and it still takes about the same
> > CPU.
>
> Be aware that the io module in Python 2.6 is written in Python and was
> viewed as a prototype.  In the current svn trunk, what will be Python
> 2.7 has a much faster C implementation of the io module backported from
> Python 3.1.
>
> --
>  Ned Deily,
>  n...@acm.org

Aha, I will test with trunk and see if the performance is better, if
so I'll use 2.6 in production until 2.7 comes out. I will report back
when I have made the tests.

Thanks,
Miguel Pilar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question regarding handling of Unicode data in Devnagari

2009-09-12 Thread Stephen Hansen
>
> As per the standard posted by the UNICODE for the Devnagari script
> used for Hindi and some other languages of India, we have a standard
> set, like from the range of 0900-097F.
> Where, we have numbers for each character:
> like 0904 for Devnagari letter short a, etc.
> Now, if write a program,
>
> where
> ch="0904"
> and I like to see the Devnagari letter short a as output then how
> should I proceed? Can codecs help me or should I use unicodedata?


If you're writing a program, you can include that character with u"\u0904";
the \u escape inside a unicode string is a how you write any arbitrary
unicode literal in python. In Python 2, u"string" is a unicode string, and
"string" is a regular byte string. In Python 3, you don't need that 'u' on
front because "string" is a unicode string. You didn't specify your version,
so whichever is appropriate.

So first, use a unicode string, and second directly write the actual
character with \u instead of just writing the number into a string. That'll
result in a string with a single real character in it, and if you are on a
terminal which is set up to display unicode (with a proper font and such),
you should be able to "print ch" and see the devnagari character that way.

The statement:

print u"\u0904"

should print your character. If you want to look up characters by name
instead of number, you can use unicodedata, and do:

print unicodedata.lookup("DEVANAGARI LETTER SHORT A")

HTH,

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


Re: CPU usage while reading a named pipe

2009-09-12 Thread Ned Deily
In article 
,
 Miguel P  wrote:
> I've been working on parsing (tailing) a named pipe which is the
> syslog output of the traffic for a rather busy haproxy instance. It's
> a fair bit of traffic (upto 3k hits/s per server), but I am finding
> that simply tailing the file  in python, without any processing, is
> taking up 15% of a CPU core. In contrast HAProxy takes 25% and syslogd
> takes 5% with the same load. `cat < /named.pipe` takes 0-2%
> 
> Am I just doing things horribly wrong or is this normal?
> 
> Here is my code:
> 
> from collections import deque
> import io, sys
> 
> WATCHED_PIPE = '/var/log/haproxy.pipe'
> 
> if __name__ == '__main__':
> try:
> log_pool = deque([],1)
> fd = io.open(WATCHED_PIPE)
> for line in fd:
> log_pool.append(line)
> except KeyboardInterrupt:
> sys.exit()
> 
> Deque appends are O(1) so that's not it. And I am using 2.6's io
> module because it's supposed to handle named pipes better. I have
> commented the deque appending line and it still takes about the same
> CPU.

Be aware that the io module in Python 2.6 is written in Python and was 
viewed as a prototype.  In the current svn trunk, what will be Python 
2.7 has a much faster C implementation of the io module backported from 
Python 3.1.

-- 
 Ned Deily,
 n...@acm.org

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


Re: Project euler no. 3

2009-09-12 Thread Dave Angel

Kee Nethery wrote:
in 
checkPrime what do you return when "x" is less than 2?


On Sep 12, 2009, at 8:46 AM, Someone Something wrote:


But, I'm returning true or false right?

On Sat, Sep 12, 2009 at 11:32 AM, MRAB  
wrote:

Someone Something wrote:
Project euler (in case you don't know: projecteuler.net 
)



I'm trying to do the third one and here's my current code:

 1 def checkPrime (x):
 2 factors=2;
 3 while factors<=x:
 4 if x==factors:
 5 return True;
 6 elif x%factors==0:
 7 return False;
 8 elif x%factors!=0:
 9 factors=factors+1;

You're not returning 'factors', so the function will return None.


 10
 11 factorl=[];
 12 factors=600851475142;
 13
 14 while factors != 1:
 15 if 600851475143%factors==0:
 16 if checkPrime(factors)==True:
 17 print factors;
 18 else:
 19 factors=factors-1;
 20
 21 else:
 22 factors=factors-1;
 23

And it just gets frozen when I run it. I put a

print "Loop completed"

in one of the loops and it showed up just fine. So, there are two 
possibilities:

1. Its looping in the trillions and taking a while
2. I have a forever loop somewhere


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

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


It's a rather minor point that it returns None for values less than 2.  
If/when somebody writes documentation, one might just specify the 
precondition that x >=2.  After all, there aren't too many primes below 
that value.  And actually, when one does an if-test, None is pretty 
close to False.  And this program won't call it with a value less than 2.


To the OP:

The original Euler problem asked   "What is the largest prime factor of 
the number 600851475143 "


This program could get that answer, but very slowly.  The problem is 
it's starting its guessing at 600 billion, and counting down by ones.  
That's going to take a very long time.  The OP needs to study the nature 
of factoring, to pick a better starting point.  There are other 
inefficiencies, but this one fix gets the run time down to a couple of 
seconds (if you don't count the fact that it then repeatedly prints the 
answer, ad-infinitum.)


Another piece of advice - pick symbol names that represent their purpose 
in some way.  An integer shouldn't be called factors, since that's 
plural.  When I see a name like that, I expect to see a list of integers.


Please don't include line numbers;  it makes it quite difficult to 
copy/paste the code into an editor to try it.  And lose the semicolons.  
They're a leftover from other languages.


DaveA

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


Re: Question regarding handling of Unicode data in Devnagari

2009-09-12 Thread MRAB

joy99 wrote:

Dear Group,

As per the standard posted by the UNICODE for the Devnagari script
used for Hindi and some other languages of India, we have a standard
set, like from the range of 0900-097F.
Where, we have numbers for each character:
like 0904 for Devnagari letter short a, etc.
Now, if write a program,

where
ch="0904"
and I like to see the Devnagari letter short a as output then how
should I proceed? Can codecs help me or should I use unicodedata?

If you can kindly help me.

That number is hexadecimal, so the character/codepoint is unichr(int(ch, 
16)) in Python 2.x.

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


Question regarding handling of Unicode data in Devnagari

2009-09-12 Thread joy99
Dear Group,

As per the standard posted by the UNICODE for the Devnagari script
used for Hindi and some other languages of India, we have a standard
set, like from the range of 0900-097F.
Where, we have numbers for each character:
like 0904 for Devnagari letter short a, etc.
Now, if write a program,

where
ch="0904"
and I like to see the Devnagari letter short a as output then how
should I proceed? Can codecs help me or should I use unicodedata?

If you can kindly help me.

Best Regards,
Subhabrata.

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


Re: CPU usage while reading a named pipe

2009-09-12 Thread MRAB

Miguel P wrote:

Hey everyone,

I've been working on parsing (tailing) a named pipe which is the
syslog output of the traffic for a rather busy haproxy instance. It's
a fair bit of traffic (upto 3k hits/s per server), but I am finding
that simply tailing the file  in python, without any processing, is
taking up 15% of a CPU core. In contrast HAProxy takes 25% and syslogd
takes 5% with the same load. `cat < /named.pipe` takes 0-2%

Am I just doing things horribly wrong or is this normal?

Here is my code:

from collections import deque
import io, sys

WATCHED_PIPE = '/var/log/haproxy.pipe'

if __name__ == '__main__':
try:
log_pool = deque([],1)
fd = io.open(WATCHED_PIPE)
for line in fd:
log_pool.append(line)
except KeyboardInterrupt:
sys.exit()

Deque appends are O(1) so that's not it. And I am using 2.6's io
module because it's supposed to handle named pipes better. I have
commented the deque appending line and it still takes about the same
CPU.

The system is running Ubuntu 9.04 with kernel 2.6.28 and ext4 (not
sure the FS is relevant).

Any help bringing down the CPU usage would be really appreciated, and
if it can't be done I guess that's ok too, server has 6 cores not
doing much.


Is this any faster?

log_pool.extend(fd)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Project euler no. 3

2009-09-12 Thread Someone Something
Anyone?

On Sat, Sep 12, 2009 at 11:46 AM, Someone Something wrote:

> But, I'm returning true or false right?
>
> On Sat, Sep 12, 2009 at 11:32 AM, MRAB  wrote:
>
>> Someone Something wrote:
>>
>>> Project euler (in case you don't know: projecteuler.net <
>>> http://projecteuler.net>)
>>>
>>> I'm trying to do the third one and here's my current code:
>>>
>>>  1 def checkPrime (x):
>>>  2 factors=2;
>>>  3 while factors<=x:
>>>  4 if x==factors:
>>>  5 return True;
>>>  6 elif x%factors==0:
>>>  7 return False;
>>>  8 elif x%factors!=0:
>>>  9 factors=factors+1;
>>>
>>
>> You're not returning 'factors', so the function will return None.
>>
>>
>>   10
>>>  11 factorl=[];
>>>  12 factors=600851475142;
>>>  13
>>>  14 while factors != 1:
>>>  15 if 600851475143%factors==0:
>>>  16 if checkPrime(factors)==True:
>>>  17 print factors;
>>>  18 else:
>>>  19 factors=factors-1;
>>>  20
>>>  21 else:
>>>  22 factors=factors-1;
>>>  23
>>>
>>> And it just gets frozen when I run it. I put a
>>>
>>> print "Loop completed"
>>>
>>> in one of the loops and it showed up just fine. So, there are two
>>> possibilities:
>>> 1. Its looping in the trillions and taking a while
>>> 2. I have a forever loop somewhere
>>>
>>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with the inclusion of new files like lxml, django, numpy, etc.

2009-09-12 Thread joy99
On Sep 11, 10:19 pm, Robert Kern  wrote:
> On 2009-09-11 11:39 AM,joy99wrote:
>
>
>
>
>
> > Dear Group,
>
> > I am trying to download the following files,
> > a) lxml,
> > b) numpy,
> > c) scipy, and
> > d) django.
>
> > I am trying to include them in C\python26\Lib
>
> > But they are giving error report, as I am trying to use them by
> > importing.
>
> > I am using IDLE as GUI, my OS is WinXP SP2, and my Python version 2.6.
>
> > If any one suggest what is the problem, I am doing?
>
> Exactly what steps are you doing? Are you following the detailed installation
> instructions for each package? You cannot just download the packages and drop
> them into Lib. Exactly what errors are you seeing? Please copy-and-paste
> complete error messages; do not paraphrase.
>
> Do one package at a time, and write to each package's mailing list if you need
> help installing that package.
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
>   that is made terrible by our own mad attempt to interpret it as though it 
> had
>   an underlying truth."
>    -- Umberto Eco- Hide quoted text -
>
> - Show quoted text -

Dear Group,

The case for Django:

As I read the note for Django it says:

“How to install Django
This document will get you up and running with Django.
Install Python
Being a Python Web framework, Django requires Python.
It works with any Python version from 2.3 to 2.6….”
As Python is a prerequisite, I have already installed it and
successfully running.
The document further says, it needs a DBMS and as I am running
Python2.6 Sqllite is already installed.
It is said for the Windows system, “
1.  On Windows systems, the same result can be achieved by copying the
file django-trunk/django/bin/django-admin.py to somewhere on your
system path, for example C:\Python24\Scripts.
You don't have to run python setup.py install, because you've already
carried out the equivalent actions in steps 3 and 4.”
Now , there is a word about installing apache. Should I have to
install apache as Django is a web server.

Now, what I did.
i)  I have downloaded Django and it is a winrar file.
ii) I have extracted it to C\Python26\Lib\site-packages.
iii)I tried C\Python26\Scripts from command prompt it is coming upto
c:\python26> but as I am giving dir command or writing cd Scripts it
is giving a message “The system can not find path specified” and in
giving dir I am not seeing any Django file
iv) In IDLE when I am giving the input
IDLE 2.6
>>> from django.db import models

I am getting the following error message.

Traceback (most recent call last):
  File "", line 1, in 
from django.db import models
ImportError: No module named django.db
>>>
What is the problem I am doing?
2) lxml:
I went to the site: http://codespeak.net/lxml/installation.html and
tried to read the paragraph >>MS WINDOWS. I have run the binary
distribution for Python2.6 from the site : 
http://users.skynet.be/sbi/libxml-python/
and tried the following command on IDLE
IDLE 2.6
>>> from lxml import etree
but it is giving me the error message
Traceback (most recent call last):
  File "", line 1, in 
from lxml import etree
  File "C:\Python26\lib\lxml\etree.py", line 7, in 
__bootstrap__()
  File "C:\Python26\lib\lxml\etree.py", line 3, in __bootstrap__
import sys, pkg_resources, imp
ImportError: No module named pkg_resources
But as I give
>>> from lxml import*
it is showing no error.

Is lxml inbuilt or got installed? But why etree command is not getting
executed, then?

I am trying to send the numpy and scipy problem in detail, soon.

Best Regards,
Subhabrata.









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


Re: Project euler no. 3

2009-09-12 Thread Kee Nethery

in checkPrime what do you return when "x" is less than 2?

On Sep 12, 2009, at 8:46 AM, Someone Something wrote:


But, I'm returning true or false right?

On Sat, Sep 12, 2009 at 11:32 AM, MRAB   
wrote:

Someone Something wrote:
Project euler (in case you don't know: projecteuler.net )



I'm trying to do the third one and here's my current code:

 1 def checkPrime (x):
 2 factors=2;
 3 while factors<=x:
 4 if x==factors:
 5 return True;
 6 elif x%factors==0:
 7 return False;
 8 elif x%factors!=0:
 9 factors=factors+1;

You're not returning 'factors', so the function will return None.


 10
 11 factorl=[];
 12 factors=600851475142;
 13
 14 while factors != 1:
 15 if 600851475143%factors==0:
 16 if checkPrime(factors)==True:
 17 print factors;
 18 else:
 19 factors=factors-1;
 20
 21 else:
 22 factors=factors-1;
 23

And it just gets frozen when I run it. I put a

print "Loop completed"

in one of the loops and it showed up just fine. So, there are two  
possibilities:

1. Its looping in the trillions and taking a while
2. I have a forever loop somewhere


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

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





-
I check email roughly 2 to 3 times per business day.
Kagi main office: +1 (510) 550-1336


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


Re: Project euler no. 3

2009-09-12 Thread MRAB

Someone Something wrote:

But, I'm returning true or false right?


No. If you don't explicitly return a value then None will be returned.

On Sat, Sep 12, 2009 at 11:32 AM, MRAB > wrote:


Someone Something wrote:

Project euler (in case you don't know: projecteuler.net
 )


I'm trying to do the third one and here's my current code:

 1 def checkPrime (x):
 2 factors=2;
 3 while factors<=x:
 4 if x==factors:
 5 return True;
 6 elif x%factors==0:
 7 return False;
 8 elif x%factors!=0:
 9 factors=factors+1;


You're not returning 'factors', so the function will return None.


 10
 11 factorl=[];
 12 factors=600851475142;
 13
 14 while factors != 1:
 15 if 600851475143%factors==0:
 16 if checkPrime(factors)==True:
 17 print factors;
 18 else:
 19 factors=factors-1;
 20
 21 else:
 22 factors=factors-1;
 23

And it just gets frozen when I run it. I put a

print "Loop completed"

in one of the loops and it showed up just fine. So, there are
two possibilities:
1. Its looping in the trillions and taking a while
2. I have a forever loop somewhere


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


Re: ImageFont family mojibake

2009-09-12 Thread Donn
On Saturday 12 September 2009 17:30:19 garabik-
news-2005...@kassiopeia.juls.savba.sk wrote:
> apt-get install unicode
> unicode 0100..
Nice tip, thanks.

> if you see a lot of accented letters (and not squares or question marks), 
> you can be sure
I see the accented chars -- so now I am more certain that the problem is in 
the font.family function. Something deep in the C code...

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


Re: Writing a thread-safe class

2009-09-12 Thread sturlamolden
On 12 Sep, 15:54, Timothy Madden  wrote:

> I find that hard to believe, but I will look into it.

Carl Banks is correct.

There is a mutex called "the global interpreter lock" that takes care
of this. You can have multiple threads running, but access to the
Python interpreter is serialized.



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


Re: Project euler no. 3

2009-09-12 Thread Someone Something
But, I'm returning true or false right?

On Sat, Sep 12, 2009 at 11:32 AM, MRAB  wrote:

> Someone Something wrote:
>
>> Project euler (in case you don't know: projecteuler.net <
>> http://projecteuler.net>)
>>
>> I'm trying to do the third one and here's my current code:
>>
>>  1 def checkPrime (x):
>>  2 factors=2;
>>  3 while factors<=x:
>>  4 if x==factors:
>>  5 return True;
>>  6 elif x%factors==0:
>>  7 return False;
>>  8 elif x%factors!=0:
>>  9 factors=factors+1;
>>
>
> You're not returning 'factors', so the function will return None.
>
>
>   10
>>  11 factorl=[];
>>  12 factors=600851475142;
>>  13
>>  14 while factors != 1:
>>  15 if 600851475143%factors==0:
>>  16 if checkPrime(factors)==True:
>>  17 print factors;
>>  18 else:
>>  19 factors=factors-1;
>>  20
>>  21 else:
>>  22 factors=factors-1;
>>  23
>>
>> And it just gets frozen when I run it. I put a
>>
>> print "Loop completed"
>>
>> in one of the loops and it showed up just fine. So, there are two
>> possibilities:
>> 1. Its looping in the trillions and taking a while
>> 2. I have a forever loop somewhere
>>
>>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ImageFont family mojibake

2009-09-12 Thread garabik-news-2005-05
Donn  wrote:
> On Saturday 12 September 2009 07:55:14 Lie Ryan wrote:
>> > f=ImageFont.truetype("FGTshgyo.TTF",1,encoding="utf-8")
>> > print f.font.family
>> > '?s'
>> Are you sure that your terminal (Command Prompt/bash/IDLE/etc) supports
>> utf-8 and that it is properly set up to display utf-8?
> Fairly sure... It's konsole under Kubuntu Jaunty. My locale it utf-8. To tell 
> the truth I am not sure how to be sure.

apt-get install unicode
unicode 0100..

if you see a lot of accented letters (and not squares or question marks), 
you can be sure

-- 
 ---
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Project euler no. 3

2009-09-12 Thread MRAB

Someone Something wrote:
Project euler (in case you don't know: projecteuler.net 
)


I'm trying to do the third one and here's my current code:

  1 def checkPrime (x):
  2 factors=2;
  3 while factors<=x:
  4 if x==factors:
  5 return True;
  6 elif x%factors==0:
  7 return False;
  8 elif x%factors!=0:
  9 factors=factors+1;


You're not returning 'factors', so the function will return None.


 10
 11 factorl=[];
 12 factors=600851475142;
 13
 14 while factors != 1:
 15 if 600851475143%factors==0:
 16 if checkPrime(factors)==True:
 17 print factors;
 18 else:
 19 factors=factors-1;
 20
 21 else:
 22 factors=factors-1;
 23

And it just gets frozen when I run it. I put a

print "Loop completed"

in one of the loops and it showed up just fine. So, there are two 
possibilities:

1. Its looping in the trillions and taking a while
2. I have a forever loop somewhere



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


Project euler no. 3

2009-09-12 Thread Someone Something
Project euler (in case you don't know: projecteuler.net)

I'm trying to do the third one and here's my current code:

  1 def checkPrime (x):
  2 factors=2;
  3 while factors<=x:
  4 if x==factors:
  5 return True;
  6 elif x%factors==0:
  7 return False;
  8 elif x%factors!=0:
  9 factors=factors+1;
 10
 11 factorl=[];
 12 factors=600851475142;
 13
 14 while factors != 1:
 15 if 600851475143%factors==0:
 16 if checkPrime(factors)==True:
 17 print factors;
 18 else:
 19 factors=factors-1;
 20
 21 else:
 22 factors=factors-1;
 23

And it just gets frozen when I run it. I put a

print "Loop completed"

in one of the loops and it showed up just fine. So, there are two
possibilities:
1. Its looping in the trillions and taking a while
2. I have a forever loop somewhere
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming ideas?

2009-09-12 Thread Dave Angel

Someone Something wrote:

I know you've probably had this question a million and one times but here it
is again. I'm intermediate at C, pretty good at Java (though I really don't
want to program in this), okay at perl and I've just learned python. But, I
have no more ideas to write programs/scripts for! Any ideas will be helpful?

  

Try Euler, a website full of puzzles:

http://projecteuler.net/index.php?section=problems

255 problems there so far, and once you solve one, you can see how 
others have also solved it, in various languages.  Python is one of the 
languages commonly used by posters there.



DaveA

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


Re: Creating a local variable scope.

2009-09-12 Thread Daniel Stutzbach
On Sat, Sep 12, 2009 at 10:02 AM, Ethan Furman  wrote:

> That's probably why he called it as:
> with do_nothing() as *imaginary*_local_scope:
>...
>del spam, eggs, imaginary_local_scope
>
> and then as the last item deleted all the variables, except the one he
> wanted to keep.
>

You're absolutely right.  My apologies.  I need to learn not to post to
mailing lists first thing in the morning! ;-)

--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC 
-- 
http://mail.python.org/mailman/listinfo/python-list


is there a "strawberry python"?

2009-09-12 Thread Wensui Liu
the reason I like strawberry perl is that I don't need to have admin right
to install it. i can just unzip it and start the game.
i am wondering if there is something similar in python community.

any insight will be appreciated!

-- 
==
WenSui Liu
Blog   : statcompute.spaces.live.com
Tough Times Never Last. But Tough People Do.  - Robert Schuller
==
-- 
http://mail.python.org/mailman/listinfo/python-list


CPU usage while reading a named pipe

2009-09-12 Thread Miguel P
Hey everyone,

I've been working on parsing (tailing) a named pipe which is the
syslog output of the traffic for a rather busy haproxy instance. It's
a fair bit of traffic (upto 3k hits/s per server), but I am finding
that simply tailing the file  in python, without any processing, is
taking up 15% of a CPU core. In contrast HAProxy takes 25% and syslogd
takes 5% with the same load. `cat < /named.pipe` takes 0-2%

Am I just doing things horribly wrong or is this normal?

Here is my code:

from collections import deque
import io, sys

WATCHED_PIPE = '/var/log/haproxy.pipe'

if __name__ == '__main__':
try:
log_pool = deque([],1)
fd = io.open(WATCHED_PIPE)
for line in fd:
log_pool.append(line)
except KeyboardInterrupt:
sys.exit()

Deque appends are O(1) so that's not it. And I am using 2.6's io
module because it's supposed to handle named pipes better. I have
commented the deque appending line and it still takes about the same
CPU.

The system is running Ubuntu 9.04 with kernel 2.6.28 and ext4 (not
sure the FS is relevant).

Any help bringing down the CPU usage would be really appreciated, and
if it can't be done I guess that's ok too, server has 6 cores not
doing much.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Variables vs attributes

2009-09-12 Thread Steven D'Aprano
On Sat, 12 Sep 2009 00:39:17 -0700, Miles Kaufmann wrote:

> On Apr 17, 2009, at 8:56 PM, Steven D'Aprano wrote:
>> If an integer variable is an integer, and a string variable is a
>> string,
>> and float variable is a float, and a list variable is a list (there's a
>> pattern here), shouldn't a class variable be a class and an instance
>> variable be an instance?
>>
>> I had never noticed the usage of "variable" to mean attribute until a
>> few
>> months ago. What's going on? Why did people decide that confusing
>> variables and attributes of variables was a good thing? What's next,
>> describing dictionary keys as "dictionary variables"?
> 
> (Replying to this old message because I've seen you make this point in
> several threads recently)
> 
> Let me prefix this by saying: I don't like to use the word "variable"
> when being specific about Python, because its meaning isn't well
> established like "name" or "object".  Personally, I think most people
> use "variable" when they're thinking about Python in terms of C-style
> assignment semantics (which isn't accurate, but as a newbie you can get
> away with it for a little while), or when they're conflating a name with
> the object it refers to.  But I don't think there's a well- established
> definition in Python (because it implies a storage model that Python
> doesn't use), and it certainly isn't synonymous with "object".

Agreed, but you can make a fuzzy definition of "variable" as "object 
bound to a name" in some sense. It's imprecise when used to discuss 
Python, but not so imprecise as to be useless, and it has the advantage 
that it is easier to talk about "variables" than name binding semantics. 
Often the differences are unimportant, but beware that it can sometimes 
be misleading.



> As far as "class variable" and "instance variable" go:
> 
> They're used across many object-oriented languages:
> http://en.wikipedia.org/wiki/Class_variable

The Wikipedia article doesn't support that assertion. The only examples 
it gives are C++ and C#, and see the comments in the talk page. But 
perhaps you're right, and it is widespread across many OO languages -- if 
so that's another example of the pernicious influence the C family of 
languages have had on programming. Just because something is common 
doesn't make it sensible.


> The Python language reference uses that terminology:
> http://docs.python.org/reference/datamodel.html
> 
> As does Guido himself:
> http://people.csail.mit.edu/rudolph/Teaching/Lectures/guido-intro-2.pdf
> 
> We're blessed with a variety of object-oriented almost-synonyms to
> choose from, some of which are more Pythonic than others.  


It is difficult to avoid using the word "variable" when discussing 
Python. I've tried to use "name binding" and "object", and frequently it 
makes the discussion unnecessarily complicated while not communicating 
any additional meaning. (On the other hand, there are times when using 
"name binding" is absolutely essential and "variable" must be avoided.) 
Consequently, a little bit of sloppiness can be forgiven, if being 
technically correct gets in the way of communication.

But the same is not true for the terms "class/instance variable": there 
is never any reason to prefer them over the synonyms "attribute" (as 
commonly used in Python), "property" (as used in, say, Hypertalk), or 
even "member" (although member tends to be more general, in languages 
where methods and attributes are different types of things). At best, it 
is a pointless redefinition of "variable" in languages that don't have 
first-class classes (and therefore can't assign a class to a variable). 
At worst, in languages like Python that do have first-class classes, it 
is actively confusing.


> But I don't
> think it's worth "correcting" everyone who uses the phrase "class
> variable", especially when their use of it causes no confusion.

But it does cause confusion. Python has an exception AttributeError, not 
VariableError. Sloppiness can be forgiven when it makes no difference, 
but that's not the case here. When I read "class variable", I actively 
have to force myself to remember that the writer isn't talking about 
storing a class in a variable (that is, bind a class object to a name) in 
the same way that you would bind an int to a variable, but that they're 
talking about a class attribute.

This is Python, and we treat classes as first-class objects. I don't know 
what people do in other languages, but I often write code like this:


classes = [int, long, MyInt, SpecialInt, SomethingElse]
for cls in classes:
do_something_with(cls)

We even do this:

class Parrot:
# whatever
Parrot = class_decorator(Parrot)

(or use decorator syntax in Python 2.6 or better). This drives home the 
message that if class variable has any meaning in Python at all, it is of 
the names Parrot and cls.

The problem is even worse when people talk about "instance variables". In 
languages like ObjectPascal (Delphi) that require d

Re: Creating a local variable scope.

2009-09-12 Thread Ethan Furman

Daniel Stutzbach wrote:
On Fri, Sep 11, 2009 at 8:29 PM, Steven D'Aprano 
> wrote:


(4) Create a "do nothing" context manager allowing you to visually
indent
the block, but otherwise have no effect:


"with" doesn't create a new scope.


That's probably why he called it as:

with do_nothing() as *imaginary*_local_scope:
...
del spam, eggs, imaginary_local_scope

and then as the last item deleted all the variables, except the one he 
wanted to keep.


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


Re: Modifying a row in a textfile

2009-09-12 Thread Dave Angel

Jorgen Grahn wrote:

On Tue, 08 Sep 2009 14:21:59 +0200, Diez B. Roggisch  
wrote:
  

Olli Virta wrote:



Hi!

I got a textfile made out of database records. Is there an easy way to
modify rows in that file in case you have to take away some items here
and there from each rows.
  

for line in inf.readlines():
if matches_criteria(line):
   line = modify_line(line)
outf.write(line)



In other words, no. You need to put the results in another file.

/Jorgen

  
If it is important that this ends up in the same file, you can simplify 
the code by using fileinput.input() with the "inplace" paramater.  It 
renames the input file, redirects stdout to a new file with the original 
name, and deletes the renamed file, all at appropriate times.  There are 
a few caveats, so be careful.  The main caveat is to make sure you close 
the file.


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


Re: Programming ideas?

2009-09-12 Thread exarkun

On 02:30 pm, fordhai...@gmail.com wrote:

Thanks a lot!

Also, can someone suggest some ideas for a medium sized or small sized
project?


Here are some things you could do to contribute to an existing project:

 http://bit.ly/easy-twisted-tickets

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


Re: Programming ideas?

2009-09-12 Thread Someone Something
Thanks a lot!

Also, can someone suggest some ideas for a medium sized or small sized
project?

On Sat, Sep 12, 2009 at 10:25 AM, Mark Tolonen

> wrote:

>
> "Someone Something"  wrote in message
> news:e196a4050909120713m76592252r9e89fb24fdaae...@mail.gmail.com...
>
>  I know you've probably had this question a million and one times but here
>> it
>> is again. I'm intermediate at C, pretty good at Java (though I really
>> don't
>> want to program in this), okay at perl and I've just learned python. But,
>> I
>> have no more ideas to write programs/scripts for! Any ideas will be
>> helpful?
>>
>
> Here's a couple I've used if you like math and puzzles.
>
> http://projecteuler.net
> http://www.pythonchallenge.com
>
> -Mark
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming ideas?

2009-09-12 Thread Mark Tolonen


"Someone Something"  wrote in message 
news:e196a4050909120713m76592252r9e89fb24fdaae...@mail.gmail.com...
I know you've probably had this question a million and one times but here 
it
is again. I'm intermediate at C, pretty good at Java (though I really 
don't
want to program in this), okay at perl and I've just learned python. But, 
I
have no more ideas to write programs/scripts for! Any ideas will be 
helpful?


Here's a couple I've used if you like math and puzzles.

http://projecteuler.net
http://www.pythonchallenge.com

-Mark


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


Programming ideas?

2009-09-12 Thread Someone Something
I know you've probably had this question a million and one times but here it
is again. I'm intermediate at C, pretty good at Java (though I really don't
want to program in this), okay at perl and I've just learned python. But, I
have no more ideas to write programs/scripts for! Any ideas will be helpful?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyWin editor modification

2009-09-12 Thread Mark Tolonen


"C or L Smith"  wrote in message 
news:0bfe194edbb6410cb3b319cdda601...@kisc.edu.np...
The PyWin editor that comes with the Windows distribution is a great 
little workhorse. If you have used it you perhaps notice how it 
intelligently works with spaces and indentation, e.g. after typing the 
word 'pass' and pressing enter it dedents one level as you would probably 
desire. It also strips trailing space from every line that you 
enter...unless that line contains ONLY space.


The following modification to the AutoIndent.py file in the 
pythonwin\pywin\idle directory makes the editor strip all trailing space, 
even if that's all a line contains. With this modification, no line that 
you enter with the PyWin editor will ever contain trailing space (unless 
you purposely add it to the end of a line but then don't press ).


Search for the word "inject" which appears only once in the file and add 
the line as indicated below:


if i == n:
   # the cursor is in or at leading indentation; just inject
   # an empty line at the start
   text.delete("insert - %d chars" % i, "insert")  <== add this line
   text.insert("insert linestart", '\n')
   return "break"


I like it!  You should post it to pywin32 sourceforge patches.

Here's one I did.  I like to clear the interactive window with CTRL-A, DEL 
before running a script.  However, if the script is run its output uses the 
blue, proportional font that the banner in that window uses when Pythonwin 
is first opened.  This happens whenever the cursor is on the first line of 
the interactive window.  So I would type CTRL-A,DEL, 2xEnter, 4xbackspace to 
move the cursor to the 2nd line and delete the prompt instead.  The diff 
patch below adds four lines to pythonwin\pywin\framework\interact.py to 
correct this problem and use the fixed font used for script output.


(Also posted to pywin32 Patches @ 
http://sourceforge.net/tracker/?func=detail&aid=2813056&group_id=78018&atid=551956).


diff -r 108cdf7a1232 interact.py
--- a/interact.py Fri Jun 26 08:34:29 2009 -0700
+++ b/interact.py Fri Jun 26 08:36:48 2009 -0700
@@ -94,6 +94,7 @@
class InteractiveFormatter(FormatterParent):
 def __init__(self, scintilla):
  FormatterParent.__init__(self, scintilla)
+  self.bannerDisplayed = False

 def SetStyles(self):
  FormatterParent.SetStyles(self)
@@ -233,8 +234,11 @@
  if start > 0:
   stylenum = self.scintilla.SCIGetStyleAt(start - 1)
   styleStart = self.GetStyleByNum(stylenum).name
+  elif self.bannerDisplayed:
+   styleStart = STYLE_INTERACTIVE_EOL
  else:
   styleStart = STYLE_INTERACTIVE_BANNER
+   self.bannerDisplayed = True
  self.scintilla.SCIStartStyling(start, 31)
  self.style_buffer = array.array("b", (0,)*len(stringVal))
  self.ColorizeInteractiveCode(stringVal, styleStart, stylePyStart)

-Mark


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


Re: Writing a thread-safe class

2009-09-12 Thread Timothy Madden

Carl Banks wrote:
[...]


You are not correct.  Dictionary operation (like getting and setting
items) are atomic and limited to one thread at a time, thus thread-
safe.

>

(In fact, in CPython only one thread can execute Python code at a
time, in most cases.  This is called the Global Interpreter Lock, or

[...]

I find that hard to believe, but I will look into it.

Thank you,
Timothy Madden
--
http://mail.python.org/mailman/listinfo/python-list


Re: Modifying a row in a textfile

2009-09-12 Thread Jorgen Grahn
On Tue, 08 Sep 2009 14:21:59 +0200, Diez B. Roggisch  
wrote:
> Olli Virta wrote:
>
>> Hi!
>> 
>> I got a textfile made out of database records. Is there an easy way to
>> modify rows in that file in case you have to take away some items here
>> and there from each rows.
>
> for line in inf.readlines():
> if matches_criteria(line):
>line = modify_line(line)
> outf.write(line)

In other words, no. You need to put the results in another file.

/Jorgen

-- 
  // Jorgen GrahnO  o   .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Distutils - can user designate install directory for windows installer?

2009-09-12 Thread Jorgen Grahn
On Wed, 09 Sep 2009 09:10:38 +1000, Mark Hammond
 wrote:
> On 9/09/2009 1:57 AM, Timothy W. Grove wrote:
>> I have successfully built a windows installer for my python program
>> using distutils, (python setup.py bdist_wininst), but is there a way to
>> do it that will allow a user ('user' == 'boss', in this case!) to
>> designate the installation directory, rather than being forced to
>> install into /Python/Lib/site-packages ? Thanks for any help.
>
> bdist_wininst is for packaging python modules or packages and so depends 
> on Python itself being installed.  As a result, it only installs into 
> where Python libs and modules are generally installed.
>
> It sounds like you are looking for something to create a stand-alone 
> version of your program - in that case you are probably looking for 
> py2exe to create the application itself [...]

No, that does not follow from what he writes.  To me it seems he wants
a windows installer which can be run by a non-administrator,
installing probably to that guy's home directory.  Or maybe to a
networked disk -- anywhere but the standard place.

I don't know how that works.  I *do* know that you can do "setup.py
install --prefix somewhere" but the guy who does that needs to have
the actual source code, not a windows installer.

/Jorgen

-- 
  // Jorgen GrahnO  o   .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a local variable scope.

2009-09-12 Thread Daniel Stutzbach
On Fri, Sep 11, 2009 at 8:29 PM, Steven D'Aprano <
st...@remove-this-cybersource.com.au> wrote:

> (4) Create a "do nothing" context manager allowing you to visually indent
> the block, but otherwise have no effect:
>

"with" doesn't create a new scope.  Observe:

Python 2.6.2 (r262:71600, Apr 15 2009, 07:20:39)
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> with open('/dev/null') as f:
...   x = 5
...
>>> x
5

--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to return value from button clicked by python

2009-09-12 Thread Hendrik van Rooyen
On Saturday 12 September 2009 06:57:26 Tim Roberts wrote:
> chen tao  wrote:
> > I have several buttons, I want to realize: when I click first
> >button, the button will call a function, and the function should
> >return some parameter value, because I need this value for the other
> >buttons.

As Tim said - you cannot return anything, as the button command is called by 
the main GUI loop.

If you really want to, you can set a variable global to the class, (Like 
self.my_passed_param) and use it in the second button - however then you have 
to handle cases where the user does not click the buttons in the sequence you 
expect.

> >I tried the button.invoke() function, it almost got it...however,
> >I only want it returns value when the button clicked, but because the
> >program is in the class _ini_ function, so it always runs once before
> >I click the button...
> >Any one can give me some suggestions?
>
> You're thinking of your program in the wrong way.  When you write a GUI,
> things don't happen in order.  Your __init__ function merely sets up your
> window structure.  The window has not actually been created or displayed at
> that time.
>
> Later, when you call the "mainloop" function, it will start to process
> messages.  Your window will be displayed, and then you'll go idle while
> waiting for user input.  When you click a button, the mainloop will call
> your handler, do a little processing, and return.
>
> So, your button function can't really return anything.  There's nothing to
> return it TO.  If there is some action you need to take when the button is
> clicked, then you DO that function in the button handler.

This is perfectly right.

- Hendrik

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


Re: Dataflow programming in Python

2009-09-12 Thread Anh Hai Trinh
> Does it have any advantage to generator comprehension?
>
> import re
> mm = mapmethod('strip')        # Is mapmethod something in the stdlib?
> pat = re.compile('[Pp]attern')
> result = (mm(line) for line in open('log') if pat.search(line))
>
> which is also lazy

Generator expression accomplishes the same thing, the main advantage I
think is that of better notation. You can clearly see each of the
processing steps which is usually lost in the syntaxes. This is the
simplest example here.

And strip is a method of string, so you would say `(line.strip() for
line in open('log') if pat.search(line))`.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a local variable scope.

2009-09-12 Thread Jorgen Grahn
On Fri, 11 Sep 2009 19:07:55 -0700 (PDT), Bearophile  
wrote:
...
> No need to add other things to the
> language as the OP suggests.

He didn't suggest that (although he did give examples from other
languages).

Personally ... yes, I sometimes feel like the OP, but usually if I
want that kind of subtle improvements, I am also willing to
restructure my code so the natural scopes become short enough.

/Jorgen

-- 
  // Jorgen GrahnO  o   .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python C/API Problem

2009-09-12 Thread Gianfranco Murador
Ok, I solved the previous error changing the second argument , but i
have another question. Does PyNode_Compile function store the object
code in the file passed as argument? And it will be execute by python?
I mean, it works if i type 'python prova.pyc'?
Thank.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mapping in python? Transforming shapefile so that basemap can read them?

2009-09-12 Thread Andrew MacIntyre

C Barr Leigh wrote:

I'm trying to get started with plotting maps in python. I need to read
"shape files" (.shp) and make maps. There seem to be many efforts but
none is complete? I'm looking for suggestions and troubleshooting.

The basemap package is obviously at an impressive stage and comes with
some data:
http://www.scipy.org/Cookbook/Matplotlib/Maps

but it cannot read shapefiles when their coordinates are not in
geographic projection. min are in a lambert, so the readshapefile
fails.

Apparently there is a utility that can convert a .shp file to lat/lon
coordinates, but it fails for me. “You can convert the shapefile to
geographic - coordinates using the shpproj utility from the shapelib
tools - (http://shapelib.maptools.org/shapelib-tools.html)"
 For me, this gives:
“unable to process projection, exiting...”


Someone else has already mentioned GDAL which is actually the raster
part of the GDAL/OGR duo; OGR is the vector toolset which understands
shapefiles.  There are a couple of other packages possibly worth exploring:
- Thuban   (http://thuban.intevation.org)
- GRASS(http://grass.itc.it/)
- Shapelib (http://shapelib.maptools.org/)
- FWTools  (http://fwtools.maptools.org/)

Shapefiles, except for the coordinate system support included in ESRI's
more recent products, are documented in a publicly accessible PDF which
googling for "ESRI shapefile" should find.

--
-
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: andy...@bullseye.apana.org.au  (pref) | Snail: PO Box 370
   andy...@pcug.org.au (alt) |Belconnen ACT 2616
Web:http://www.andymac.org/   |Australia

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


Re: ImageFont family mojibake

2009-09-12 Thread Donn
On Saturday 12 September 2009 07:55:14 Lie Ryan wrote:
> > f=ImageFont.truetype("FGTshgyo.TTF",1,encoding="utf-8")
> > print f.font.family
> > '?s'
> Are you sure that your terminal (Command Prompt/bash/IDLE/etc) supports
> utf-8 and that it is properly set up to display utf-8?
Fairly sure... It's konsole under Kubuntu Jaunty. My locale it utf-8. To tell 
the truth I am not sure how to be sure.
OTOH - when I pass that family name string to wxPython (unicode version) to be 
drawn to a DC it displays the exact same string that I see in Python's 
console. So even if my console is misconfigured, the string is still looking 
flawed.

> Try:
> print repr(f.font.family)
Same result. Also same for print unicode(...)

I wonder about the return result from f.font.family. If it was a unicode 
object should I not see u"s???" which would show that my terminal can't 
draw the glyphs, but it knows it's a unicode?

print type(f.font.family)


Hmmm. This seems wrong.But I could be making a mistake.
 
> > I hope there's some simple encoding="voodoo" that might fix this. The
> > problem is, I guess, knowing *what* that voodoo is for arbitrary fonts
> > (which can come from any source).
> If all else fails, you can simply compare the byte string representation
> of the font family name. 
I don't follow this. What would I compare it to?

Thanks for helping.
\d
-- 
home: http://otherwise.relics.co.za/
2D vector animation : https://savannah.nongnu.org/projects/things/
Font manager : https://savannah.nongnu.org/projects/fontypython/
-- 
http://mail.python.org/mailman/listinfo/python-list


PyWin editor modification

2009-09-12 Thread C or L Smith
The PyWin editor that comes with the Windows distribution is a great little 
workhorse. If you have used it you perhaps notice how it intelligently works 
with spaces and indentation, e.g. after typing the word 'pass' and pressing 
enter it dedents one level as you would probably desire. It also strips 
trailing space from every line that you enter...unless that line contains ONLY 
space.

The following modification to the AutoIndent.py file in the 
pythonwin\pywin\idle directory makes the editor strip all trailing space, even 
if that's all a line contains. With this modification, no line that you enter 
with the PyWin editor will ever contain trailing space (unless you purposely 
add it to the end of a line but then don't press ).

Search for the word "inject" which appears only once in the file and add the 
line as indicated below:

if i == n:
# the cursor is in or at leading indentation; just inject
# an empty line at the start
text.delete("insert - %d chars" % i, "insert")  <== add this line
text.insert("insert linestart", '\n')
return "break"

This little modification is going to make my editing life less error prone as I 
work on a project that checks for trailing whitespace. Maybe it will be useful 
to someone else.

/c

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


Re: string interpolation mystery in Python 2.6

2009-09-12 Thread Vlastimil Brom
2009/9/12 Steven D'Aprano :
> On Fri, 11 Sep 2009 15:19:05 -0700, Chris Rebert wrote:
>
>> Sounds like IOError or one of its ancestors defines both __str__() and
>> __unicode__ () special methods but has them produce different output.
>
>
> That's what it looks like to me too, which I wouldn't call either a bug
> or a feature. I don't think Python makes any promises regarding exception
> messages.
>
>

There are some report about the apparently same issue in the bug tracker.
http://bugs.python.org/issue5274
http://bugs.python.org/issue6108

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


Re: Python C/API Problem

2009-09-12 Thread Gianfranco Murador
Yes, i've done some debugging and the error is on
PyParser_SimpleParseString(..) call. I'll try to change the second
arguments..
Thank to all.

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


Re: Variables vs attributes

2009-09-12 Thread Miles Kaufmann

On Apr 17, 2009, at 8:56 PM, Steven D'Aprano wrote:
If an integer variable is an integer, and a string variable is a  
string,
and float variable is a float, and a list variable is a list  
(there's a

pattern here), shouldn't a class variable be a class and an instance
variable be an instance?

I had never noticed the usage of "variable" to mean attribute until  
a few

months ago. What's going on? Why did people decide that confusing
variables and attributes of variables was a good thing? What's next,
describing dictionary keys as "dictionary variables"?


(Replying to this old message because I've seen you make this point in  
several threads recently)


Let me prefix this by saying: I don't like to use the word "variable"  
when being specific about Python, because its meaning isn't well  
established like "name" or "object".  Personally, I think most people  
use "variable" when they're thinking about Python in terms of C-style  
assignment semantics (which isn't accurate, but as a newbie you can  
get away with it for a little while), or when they're conflating a  
name with the object it refers to.  But I don't think there's a well- 
established definition in Python (because it implies a storage model  
that Python doesn't use), and it certainly isn't synonymous with  
"object".


As far as "class variable" and "instance variable" go:

They're used across many object-oriented languages:
http://en.wikipedia.org/wiki/Class_variable

The Python language reference uses that terminology:
http://docs.python.org/reference/datamodel.html

As does Guido himself:
http://people.csail.mit.edu/rudolph/Teaching/Lectures/guido-intro-2.pdf

We're blessed with a variety of object-oriented almost-synonyms to  
choose from, some of which are more Pythonic than others.  But I don't  
think it's worth "correcting" everyone who uses the phrase "class  
variable", especially when their use of it causes no confusion.


-Miles

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