Re: py2exe problem

2009-04-03 Thread Wolfgang Forstmeier

On 03.04.2009 05:29, Gabriel Genellina wrote:

En Thu, 02 Apr 2009 08:06:22 -0300, Wolfgang Forstmeier
 escribió:

On 02.04.2009 11:34, Gabriel Genellina wrote:

En Wed, 01 Apr 2009 17:51:52 -0300, Wolfgang Forstmeier
 escribió:


what kind of error do I have with getting this error at starting my
app.
Im am not using IdleConf.GetOption right now.

Warning: configHandler.py - IdleConf.GetOption -
problem retrieving configration option 'name'
from section 'Keys'.
returning default value: ''








Ok, but do you really use idlelib for something? Or it's just some
random code you found somewhere and drop into your application?


Ah yes, I really use this. I create some message boxes for a little GUI 
application that controls some other program with COM.
Running my app without py2exe, just with python, there is no warning at 
all. This comes in with py2exe first.


Here some piece of code that I use for tkMessageBox.

from idlelib.OutputWindow import tkMessageBox

...
# Define about message box
def about(self):
tkMessageBox.showinfo("About", "My little about text box.")
# --
...

There is some more GUI programming arround that def in my class, but 
that uses only Tkinter, should not be interesting for that error.



Also, note that you got just a warning, not an error; chances are your
program may still work.


That is right, but there is an annoying message box at closing my 
program that tells me the error above.


BTW, what's your program for?

Connecting a MFC COM application with an old FORTRAN program.

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


HTML Generation

2009-04-03 Thread Mike
Hello all,

I'm writing a web app and wanted to do some html generation (I really do not
like to maintain or write html).

I'm thinking of writing a dsl based on the following:

def html():
return

def a():
return

def body():
return
(html,
...(head, (style, "id", {"font-color":"black"}))
...(body,
.. (a, "id", {"title":"bla"}, ("link title","http://www.link.com";)),
..(p, "paragraph text")
.. )
...)
)

And then parsing the resulting list. (the specification of sorts is as far
as I've got) I'd have to create the list as a string and then call a method
which executes the contents as the methods would not be in the local scope.

The reason I'm posting is I'm curious what people think, I've been starting
to perfer this style and am curious if a similar solution exists or if this
is a good idea :)

I'll proberly finish it as a learning experience regardless.

I appreciate any responses :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: interacting with an updatedb generated data file within python

2009-04-03 Thread John Machin
On Apr 3, 1:07 pm, birdsong  wrote:
> Does anybody have any recommendations on how to interact with the data
> file that updatedb generates?  I'm running through a file list in
> sqlite that I want to check against the file system. updatedb is
> pretty optimized for building an index and storing it, but I see no
> way to query the db file other than calling locate itself.  This would
> require me to fork and exec for every single file I want to verify -
> I'd be better off doing the stat myself in that case, but I'd really
> rather let updatedb build the index for me.
>
> I searched high and low for any sort of library that is well suited
> for reading these data files, but I've found nothing for any language
> other than the source for locate and updatedb itself.

Disclaimer: I had to google to find out what "updatedb" is so don't
take me as any authority on this :-)

The format appears to be documented e.g.
http://www.delorie.com/gnu/docs/findutils/locatedb.5.html
and thus should be found on the locatedb(5) man page on your system.

Assuming that you don't have the old version, it should take about 20
lines of Python to loop around extracting the file names, plus some
more to open the file, read it in as one big string (how big is it?),
and check the dummy "LOCATE02" entry up the front -- it's a bit hard
to be sure how the prefix length of the first non-dummy entry is
determined without seeing an actual example, but my guess is that the
file will start like this:

"\x00LOCATE02\x00\xF8name-of-first-file-in-full\x00."
where the "\xF8" is -8 meaning ignore the 8-character previous name
"LOCATE02" i.e. previous name can be regarded as "".

Anyway, I reckon utter max 50 lines of Python to produce a module with
a generator that yields one file name at a time, or a function
returning a list or a set.

HTH ... feel free to ask more if the above is a little obscure. But do
accompany any questions with the result of doing this:
   print repr(open('the_locatedb_file').read(400))
plus what you believe the full name of the first non-dummy file should
be.

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


Re: HTML Generation

2009-04-03 Thread Tino Wildenhain

Hi Mike,


Mike wrote:

Hello all,

I'm writing a web app and wanted to do some html generation (I really do 
not like to maintain or write html).


I'm thinking of writing a dsl based on the following:

def html():
return

def a():
return

def body():
return


That would be writing HTML just another way and also
mixing code and representation, this is generally not a
good idea.

If you really don't want to maintain HTML along with
your code, I'd suggest an approach like

Zope Page Templates

http://en.wikipedia.org/wiki/Zope_Page_Templates#Zope_Page_Templates

which can be used outside Zope as well, (even with many other languages)

For example: http://zpt.sourceforge.net/

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


Re: Iteratoration question

2009-04-03 Thread Diez B. Roggisch


while what you are doing is interesting, it is not the same as Python's
iterators, which use "yield" from a function and don't require storing a
value in a class.  look for "yield" in the python docs.  this comment may
be irrelevant; i am just worried you are confusing the above (which apart
from the mistake about instances is perfectly ok) and python's iterators
(which use next(), yield, etc).


You are confusing generators with the iterator-protocol. Iteration has 
been part of python long before generators appeared on the scene.


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


Re: interacting with an updatedb generated data file within python

2009-04-03 Thread John Machin
On Apr 3, 6:25 pm, John Machin  wrote:

> The format appears to be documented 
> e.g.http://www.delorie.com/gnu/docs/findutils/locatedb.5.html
> and thus should be found on the locatedb(5) man page on your system.

More comprehensive:
http://www.gnu.org/software/findutils/manual/html_node/find_html/Database-Formats.html#Database-Formats

> Assuming that you don't have the old version, it should take about 20
> lines of Python to loop around extracting the file names, plus some
> more to open the file, read it in as one big string (how big is it?),
> and check the dummy "LOCATE02" entry up the front -- it's a bit hard
> to be sure how the prefix length of the first non-dummy entry is
> determined without seeing an actual example, but my guess is that the
> file will start like this:
>
> "\x00LOCATE02\x00\xF8name-of-first-file-in-full\x00."
> where the "\xF8" is -8 meaning ignore the 8-character previous name
> "LOCATE02" i.e. previous name can be regarded as "".

After noticing there was in fact an example, make that:
"\x00LOCATE02\x00\x00name-of-first-file-in-full\x00."

i.e. you can assert that buffer[:10] == "\x00LOCATE02\x00" and start
the loop from offset 10 with the previous name set to "".

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


pyreadline, InteractiveConsole, and tab completion on Windows

2009-04-03 Thread Thomas Heller
I have installed pyreadline, and get nice tab completion in
the normal interactive interpreter:


Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import rlcompleter
>>> import readline
>>> readline.parse_and_bind("tab: complete")
>>> 
and   oct   UserWarning   
ArithmeticError
assertSystemExitfilter
str
break StandardError range 
property
[...]
>>> import sys
>>> sys.   
sys.__displayhook__   sys.call_tracing  sys.getfilesystemencoding 
sys.ps1
sys.__doc__   sys.callstats sys.getrecursionlimit 
sys.ps2
[...]
>>> sys.


However, in 'code.interact()', the behaviour is different.  Hitting TAB
at the top level works as before, but hitting TAB after entering 'sys.' for 
example
doesn't show any completions:


Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import rlcompleter
>>> import readline
>>> readline.parse_and_bind("tab: complete")
>>> import code
>>> code.interact()
Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> 
and   oct   UserWarning   
ArithmeticError
assertSystemExitfilter
str
break StandardError range 
property
[...]
>>> import sys
>>> sys.  


How can I get the same tab-completion?

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


Re: Python Goes Mercurial

2009-04-03 Thread Jeremiah Dodds
On Thu, Apr 2, 2009 at 9:02 PM, andrew cooke  wrote:

> Echo wrote:
> > 2009/4/2 Jeremiah Dodds 
> >
> >> The one thing that makes me want to use git more than any other dvcs is
> >> that you don't have to create a new directory for branches. This may be
> >> possible in other dvcs's , but git is the only one I've seen advertise
> >> the
> >> capability.
> [...]
> > That is the main reason why I switched to git at my work.
> > As for the git rebase, I don't ever plan on using that 'feature'. Even
> > though I would rather have had GvR pick git, I think he did a good job
> > deciding.
>
> please can you explain this?  i can think of a couple of things you could
> mean, but neither of them seem to make much sense to me.
>
>
> one is that hg only allows you one branch per repository.  i checked the
> docs and that's not true - see 2/3 way down
>
> http://hgbook.red-bean.com/read/managing-releases-and-branchy-development.html
> - which describes how you can branch in the repository and then swap your
> working copy between them.
>

It looks like basically the same thing is accomplishable in hg, but is a bit
discouraged (I am not experienced with hg, and haven't read the docs
thoroughly, so I could be off base here). In most (d)vcs's , there is
normally a one-to-one relationship between project branches and directories
on your filesystem. In git, there is normally a many-to-on relationship
between project branches and directories on your filesystem - branching is
cheap and easy, and you can branch for every little fix or feature you want
to do, keeping one directory with multiple logical development paths with
basically no pain.
--
http://mail.python.org/mailman/listinfo/python-list


dictionary and list

2009-04-03 Thread abakarmukhtar
 

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


Re: "Pythoner",Wish me luck!

2009-04-03 Thread Matteo
On Apr 3, 9:05 am, Linuxwell  wrote:
> Starting today I would like to study Python,Wish me luck!

Good luck!

Don't forget to...

>>> print 'Hello World!'



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


"Pythoner",Wish me luck!

2009-04-03 Thread Linuxwell
Starting today I would like to study Python,Wish me luck!
--
http://mail.python.org/mailman/listinfo/python-list


Re: HTML Generation

2009-04-03 Thread Daniel Fetchinson
> Hello all,
>
> I'm writing a web app and wanted to do some html generation (I really do not
> like to maintain or write html).
>
> I'm thinking of writing a dsl based on the following:
>
> def html():
> return
>
> def a():
> return
>
> def body():
> return
> (html,
> ...(head, (style, "id", {"font-color":"black"}))
> ...(body,
> .. (a, "id", {"title":"bla"}, ("link title","http://www.link.com";)),
> ..(p, "paragraph text")
> .. )
> ...)
> )
>
> And then parsing the resulting list. (the specification of sorts is as far
> as I've got) I'd have to create the list as a string and then call a method
> which executes the contents as the methods would not be in the local scope.
>
> The reason I'm posting is I'm curious what people think, I've been starting
> to perfer this style and am curious if a similar solution exists or if this
> is a good idea :)
>
> I'll proberly finish it as a learning experience regardless.
>
> I appreciate any responses :)

You might find the following helpful:

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

HTH,
Daniel



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


config parser -help

2009-04-03 Thread Murali kumar
hi all,

i want to all my configuration file names in current/user/home directory..

for that i came across following function in configparser class..
Is it must to specify file names? or only directories enough..
if there anyway to read conf filenames in current/user directory...

config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')])
--
http://mail.python.org/mailman/listinfo/python-list


Re: "Pythoner",Wish me luck!

2009-04-03 Thread Hendrik van Rooyen
"Matteo"  wrote:


On Apr 3, 9:05 am, Linuxwell  wrote:
>> Starting today I would like to study Python,Wish me luck!
>
>Good luck!
>
>Don't forget to...
>
 print 'Hello World!'

This is better advice than what you may think,
because the interactive interpreter is your very 
best friend when studying the language.

You get there by typing "python" at the command
line, and pressing enter.

Using it, you will save yourself many hours of
misunderstanding.

- Hendrik


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


Re: Python Goes Mercurial

2009-04-03 Thread Patrick Mullen
2009/4/3 Jeremiah Dodds :
>
>
> On Thu, Apr 2, 2009 at 9:02 PM, andrew cooke  wrote:
>>
>> Echo wrote:
>> > 2009/4/2 Jeremiah Dodds 
>> >
>> >> The one thing that makes me want to use git more than any other dvcs is
>> >> that you don't have to create a new directory for branches. This may be
>> >> possible in other dvcs's , but git is the only one I've seen advertise
>> >> the
>> >> capability.
>> [...]
>> > That is the main reason why I switched to git at my work.
>> > As for the git rebase, I don't ever plan on using that 'feature'. Even
>> > though I would rather have had GvR pick git, I think he did a good job
>> > deciding.
> It looks like basically the same thing is accomplishable in hg, but is a bit
> discouraged (I am not experienced with hg, and haven't read the docs
> thoroughly, so I could be off base here). In most (d)vcs's , there is
> normally a one-to-one relationship between project branches and directories
> on your filesystem. In git, there is normally a many-to-on relationship
> between project branches and directories on your filesystem - branching is
> cheap and easy, and you can branch for every little fix or feature you want
> to do, keeping one directory with multiple logical development paths with
> basically no pain.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>

I don't think it's discouraged at all.  There are several ways to
accomplish a similar workflow if you want a quick, short-lived branch.
 The ones I know of, are named branches, bookmarks, and mercurial
queues.  I have a hard time wrapping my head around what all of these
(and git branching) mean, since a quick branch is something I rarely
need in my personal development.  The differences between each
approach is very difficult for me to see.  But they all let you have
one set of files and work on disparate things at once to merge later.

Queues (which is a patch stack) seem useful but also dangerous, since
you can do a lot of switching back and forth without actually
commiting.  Since you can apply any of the queues to your working
directory, they might work well for a short lived feature that you
potentially put into a real branch or into the main if the feature is
more complete and less experimental.

Named branches work off of a changeset I believe.  At any time you can
rename the current branch, commit new stuff from that point in
history, and you have a new branch; using the name to keep track of
where you are.  If you want to switch branches, you just update the
working copy to be the new branch you want to work from.

There are probably some advantages to how git handles things,
considering this is the main feature I hear cited at something git
does certifiably better, but I wouldn't know what that would be.

Oh, and merc recently got a rebase as well, for good or ill.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Iteratoration question

2009-04-03 Thread Steven D'Aprano
On Thu, 02 Apr 2009 18:07:38 -0700, grocery_stocker wrote:

> Okay, I was thinking more about this. I think this is also what is
> irking me. Say I have the following..
> 
 a = [1,2,3,4]
 for x in a:
> ... print x
> ...
> 1
> 2
> 3
> 4


> Would 'a' somehow call __iter__ and next()? If so, does python just
> perform this magically?

Not necessarily.

For loops will call __iter__ automatically if it exists, but that isn't 
the only way that for loops can work. There is an older sequence protocol 
that the for loop will use as well:

>>> class D(object):
... def __getitem__(self, i):
... if i < 5: return i
... raise IndexError
...
>>> d = D()
>>> for i in d:
... print i
...
0
1
2
3
4


-- 
Steven

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


Re: config parser -help

2009-04-03 Thread Murali kumar
Is there anyway to read all my configuration filenames with extension
(.cfg)?

Advanced thanks..

On Fri, Apr 3, 2009 at 3:15 PM, Murali kumar  wrote:

> hi all,
>
> i want to all my configuration file names in current/user/home directory..
>
> for that i came across following function in configparser class..
> Is it must to specify file names? or only directories enough..
> if there anyway to read conf filenames in current/user directory...
>
> config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')])
>
>
>
>
>
>
--
http://mail.python.org/mailman/listinfo/python-list


SOAPpy serious problem

2009-04-03 Thread ozgur vatansever
Hi, I have a problem about soappy.

I have a wsdl file located at 
http://212.175.81.30:/importWebService/services/ShippingOrderDispatcher?wsdl

I want to call the function "dispatch" but that function takes an
array of ShippingOrder objects. I couldn't manage to define that array
of ShippingOrder structs. I tried SOAPpy.structType,
SOAPpy.typedArrayType. I'm missing something. Any suggestions? Here is
the code:

# -*- coding: utf-8 -*-
import SOAPpy

WSDLFILE = "http://212.175.81.30:/importWebService/services/
ShippingOrderDispatcher?wsdl"

server = SOAPpy.WSDL.Proxy(WSDLFILE)

stl = SOAPpy.typedArrayType(name="ArrayOfShippingOrder")

st = SOAPpy.structType(name="ShippingOrder")
st._addItem("invoiceKey","213123")
st._addItem("cargoKey","12312312")
st._addItem("receiverCustName","asdasdasd")
st._addItem("receiverAddress","asdasdasdasdas")
st._addItem("receiverPhone1","21")
st._addItem("receiverPhone2","")
st._addItem("receiverPhone3","")
st._addItem("cityName","ANKARA")
st._addItem("townName", "")
st._addItem("custProdId", "1")
st._addItem("desi", 4.67)
st._addItem("kg", 0.0)
st._addItem("cargoCount", 1)
st._addItem("waybillNo", "")
st._addItem("specialField1", "")
st._addItem("specialField2", "")
st._addItem("specialField3", "")
st._addItem("ttCollectionType", "")
st._addItem("ttDocumentId", long(1.0))
st._addItem("ttDocumentSaveType", "")
st._addItem("ttInvoiceAmount", "")
st._addItem("orgReceiverCustId", "")
st._addItem("description", "")
st._addItem("taxOfficeId", long(-1))
st._addItem("taxNumber", "")


stl.append(st)
server.soapproxy.config.dumpSOAPOut = 1
print server.dispatch(stl,"USER","PASSWD")

I got the following error:
SOAPpy.Types.faultType: http://mail.python.org/mailman/listinfo/python-list


Re: A design problem I met again and again.

2009-04-03 Thread Steven D'Aprano
On Thu, 02 Apr 2009 22:18:02 -0700, Emile van Sebille wrote:

> Steven D'Aprano wrote:
>> On Thu, 02 Apr 2009 16:51:24 -0700, Emile van Sebille wrote:
> 
>>> I refactor constantly during development to avoid code reuse through
>>> cut-n-paste, but once I've got it going, whether it's 1000 or 6000
>>> lines, it doesn't matter as long as it works.
>> 
>> If you've been refactoring during development, and gotten to the point
>> where it is working,
> 
> yes, but
> 
>> clear and maintainable,
> 
> not necessarily

If it's not clear and maintainable, then there *is* refactoring left to 
do. Whether you (generic you) choose to do so or not is a separate issue.



>> then there's very little refactoring left to do.
> 
> Again, not necessarily.  I often find it easier to refactor old code
> when I'm maintaining it to better understand how to best implement the
> change I'm incorporating at the moment.  The refactoring certainly may
> have been done when the code was originally written, but at that time
> refactoring would have only served to pretty it up as it already worked.
> 
>> I don't think anyone suggests that you refactor code that doesn't need
>> refactoring.
> 
> That's exactly what I read the OP as wanting to do. That's why I was
> asking why.  So, I think the question becomes, when does code need
> refactoring?

(1) When the code isn't clear and maintainable.

(2) When you need to add or subtract functionality which would leave the 
code unclear or unmaintainable.

(3) When refactoring would make the code faster, more efficient, or 
otherwise better in some way.

(4) When you're changing the API.



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


Re: config parser -help - anybody please immediately help for me...

2009-04-03 Thread Murali kumar
On Fri, Apr 3, 2009 at 3:59 PM, Murali kumar  wrote:

> Is there anyway to read all my configuration filenames with extension
> (.cfg)?
>
> Advanced thanks..
>
>
> On Fri, Apr 3, 2009 at 3:15 PM, Murali kumar  wrote:
>
>> hi all,
>>
>> i want to all my configuration file names in current/user/home directory..
>>
>>
>> for that i came across following function in configparser class..
>> Is it must to specify file names? or only directories enough..
>> if there anyway to read conf filenames in current/user directory...
>>
>> config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')])
>>
>>
>>
>>
>>
>>
>>
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: python for loop

2009-04-03 Thread Lou Pecora
In article 
<5c92e9bd-1fb4-4c01-a928-04d7f6733...@e21g2000yqb.googlegroups.com>,
 Aaron Brady  wrote:

> On Apr 2, 6:34 pm, Tim Wintle  wrote:
> > On Thu, 2009-04-02 at 15:16 -0700, Emile van Sebille wrote:
> > > Lou Pecora wrote:
> > > > Confusion only comes when you try to force the
> > > > defintion of one of them on the other and then say it's illogical or not
> > > > natural.  Both are natural.
> >
> > > Consider the French 'Premiere etage' vs the American 'First Floor'
> >
> > or even in the same language - "first floor" in English (UK) is very
> > different from "first floor" in English (US).
> 
> Did I tell you guys that 'natural' has 38 definitions at
> dictionary.com?


Amazing.  I suggest you pick the one that fits best.

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


mmap regex search replace

2009-04-03 Thread David Pratt
Hi. I have a circumstance where I have to search and replace a block  
of text in a very large file. I have written some psuedo code to  
locate the text and print the span of text to be removed and replaced  
by new block. Can someone advise what to do to remove the text span  
and insert with the new text. the match.span() provides a tuple of the  
starting and ending position. Many thanks.


Regards,
David


import mmap
import re

text_to_insert = 'the block to insert'

pattern = re.compile(my regex here)

f = open('my_large_file.dat', 'r+')
try:
m = mmap.mmap(f.fileno(), 0)
try:
match = chart_re.search(m)
print match.span()
finally:
m.close()
finally:
f.close()


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


Re: py2exe problem

2009-04-03 Thread Gabriel Genellina
En Fri, 03 Apr 2009 03:55:20 -0300, Wolfgang Forstmeier   
escribió:

On 03.04.2009 05:29, Gabriel Genellina wrote:

En Thu, 02 Apr 2009 08:06:22 -0300, Wolfgang Forstmeier
 escribió:

On 02.04.2009 11:34, Gabriel Genellina wrote:

En Wed, 01 Apr 2009 17:51:52 -0300, Wolfgang Forstmeier
 escribió:


what kind of error do I have with getting this error at starting my
app.
Im am not using IdleConf.GetOption right now.


from idlelib.OutputWindow import tkMessageBox

...
 # Define about message box
 def about(self):
 tkMessageBox.showinfo("About", "My little about text box.")
 # --
...

There is some more GUI programming arround that def in my class, but  
that uses only Tkinter, should not be interesting for that error.


The above doesn't use idlelib either; tkMessageBox comes with Tkinter.
import tkMessageBox
is enough, and doesn't carry idlelib as a dependency.

If you remove all idlelib remaining references -if any- that annoying  
warning should go away too (and your program should be smaller and load  
faster).


--
Gabriel Genellina

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


Re: Regression test

2009-04-03 Thread Gabriel Genellina

En Mon, 23 Mar 2009 21:04:35 -0300, Colin J. Williams 
escribió:

I am running a regression test, mainly because I wish to explore  
subprocess, and get a number of errors before crashing.  Is this to be  
expected?  The run output is below.


C:\Documents and Settings\cjw\Desktop>C:\python26\python.exe
Python 2.6 (r26:66721, Oct  2 2008, 11:35:03) [MSC v.1500 32 bit  
(Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.

from test import regrtest
regrtest.main()


Not sure about 2.6, but 2.6.1 fails some tests too -- I assume they were
considered minor issues...

--
Gabriel Genellina

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


Re: config parser -help - anybody please immediately help for me...

2009-04-03 Thread Gabriel Genellina
En Fri, 03 Apr 2009 08:46:17 -0300, Murali kumar   
escribió:



Is there anyway to read all my configuration filenames with extension
(.cfg)?


See the glob module
http://docs.python.org/library/glob.html

glob.glob(os.path.expanduser('~/*.cfg'))

--
Gabriel Genellina

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


Re: Class methods read-only by default?

2009-04-03 Thread Emanuele D'Arrigo
Thank you both, Steven and Andrew, for the insightful explanation. I
shall keep it in mind when thinking about classes methods and
instances. Thank you again.

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


Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-04-03 Thread srepmub
On Mar 30, 4:36 pm, Michele Simionato 
wrote:
> On Mar 30, 3:31 pm, srepmub  wrote:
>
> > for the record, the input forShedskinis pure Python, so there is no
> > added syntax or optional type declaration system. that said, I can
> > understand it not being on some list for not being production-ready.
>
> > thanks,
> > mark dufour.
>
> But doesShedSkinaccepts all valid Python constructs?
> I thought there were restrictions.

there are certainly several important restrictions, but what I meant
was that if it works with Shedskin it is also valid Python code, and
there are no hidden type declarations or hints hidden in docstrings
and such.


thanks,
mark dufour.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python for loop

2009-04-03 Thread MRAB

Lie wrote:
[snip]

Alternatively:
"One friend of mine half-seriously advanced the following thesis: We
should count from zero. But "first" is, etymologically, a diminution
of "foremost", and (as TomStambaugh says) should mean "0th" when we
count from 0. And "second" is from the Latin "secundus", meaning
"following", so it should mean "1th" when we count from 0. Obviously
the ordinals from "third" onwards get their names from the numbers.
So... we need a new word for "2th". He proposed "twifth". Thus: first,
second, twifth, third, fourth, ..."


I propose "twoth" (sounds like "tooth"). :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: "Pythoner",Wish me luck!

2009-04-03 Thread MRAB

Matteo wrote:

On Apr 3, 9:05 am, Linuxwell  wrote:

Starting today I would like to study Python,Wish me luck!


Good luck!

Don't forget to...


print 'Hello World!'



Or:

>>> print('Hello World!')

if using Python 3.
--
http://mail.python.org/mailman/listinfo/python-list


Re: A design problem I met again and again.

2009-04-03 Thread Emile van Sebille

Steven D'Aprano wrote:

On Thu, 02 Apr 2009 22:18:02 -0700, Emile van Sebille wrote:


Steven D'Aprano wrote:

On Thu, 02 Apr 2009 16:51:24 -0700, Emile van Sebille wrote:



I refactor constantly during development to avoid code reuse through
cut-n-paste, but once I've got it going, whether it's 1000 or 6000
lines, it doesn't matter as long as it works.

If you've been refactoring during development, and gotten to the point
where it is working,

yes, but


clear and maintainable,

not necessarily


If it's not clear and maintainable, then there *is* refactoring left to 
do. 


Agreed.


Whether you (generic you) choose to do so or not is a separate issue.


Also agreed - and that is really my point.  Doing so feels to me like 
continuing to look for a lost object once you've found it.





So, I think the question becomes, when does code need refactoring?

(1) When the code isn't clear and maintainable.

(2) When you need to add or subtract functionality which would leave the 
code unclear or unmaintainable.


(3) When refactoring would make the code faster, more efficient, or 
otherwise better in some way.


(4) When you're changing the API.


Certainly agreed on (2) and (4).  (1) follows directly from (3). And (3) 
only after an issue has been observed.


Emile

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


Re: with open('com1', 'r') as f:

2009-04-03 Thread Gabriel Genellina

En Thu, 02 Apr 2009 20:04:14 -0300, gert  escribió:

On Apr 2, 8:53 pm, Kushal Kumaran  wrote:

On Thu, 2 Apr 2009 10:01:02 -0700 (PDT)
gert  wrote:



> from subprocess import *
> check_call(['mode', 'COM1:9600,N,8,1,P'],shell=True)
> while True:
>     with open('com1', 'r') as f:
>         for line in f:
>              print('line')

> This works very well except for one thing. After a reboot I have to
> launch 1 time any windows serial exe application no mater with one,
> that just opens an closes the com port, before i can launch this
> script. The script keeps on working even after closing and reopening
> it, until i reboot the pc. Then again I have to launch one time a
> serial.exe and close it again. The exe does not run anything in the
> background it just does something in windows python does not do when
> it reads from the com port after a fresh reboot.

> And i really appreciate it if somebody knew what it was.

I don't know why you're getting this behaviour, but have you tried using
a python library for accessing the serial port?  
Seehttp://pyserial.wiki.sourceforge.net/pySerial.


I am sorry but I don't think pyserial will work on python3.x and I
also like to know whats going on before I consider it.


A real Windows program accessing the serial port is likely to use  
SetupComm, SetCommState, and other functions in addition to CreateFile.

See http://msdn.microsoft.com/en-us/library/aa363196(VS.85).aspx

pySerial takes care of all those details, as suggested.


Maybe its a bug in open() on windows?


open() doesn't care about the file name; it's the OS that interprets  
"com1" as a serial port.


--
Gabriel Genellina

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


Re: A design problem I met again and again.

2009-04-03 Thread andrew cooke
Emile van Sebille wrote:
>>> Whether you (generic you) choose to do so or not is a separate issue.
>
> Also agreed - and that is really my point.  Doing so feels to me like
> continuing to look for a lost object once you've found it.

i can see your point here, but there's two things more to consider:

1 - if you do need to refactor it later, because there is a bug say, it
will be harder to do so because you will have forgotten much about the
code.  so if it is likely that you will need to refactor in the future, it
may pay to do some of that work now.

2 - if someone else needs to work with the code then the worse state it is
in - even if it works - the harder time they will have understanding it. 
which could lead to them using or extending it incorrectly, for example.

both of the above fall under the idea that code isn't just a machine that
produces a result, but also serves as documentation.  and working code
isn't necessarily good documentation.

i don't think there's a clear, fixed answer to this (i don't think "stop
refactoring as soon as all tests work" can be a reliable general rule any
more than "refactor until it is the most beautiful code in the world" can
be).  you need to use your judgement on a case-by-case basis.

in fact, the thing i am most sure of in this thread is that 15000 lines of
code in one module is a disaster.  the likelihood of that being ok seems
so small, compared to all the other uncertainties in software development,
that i cannot see why people are even discussing it (well, i can
understand, because human nature is what it is, and software development
seems to attract a certain kind of pedantic, rigid mind, but even so...)

andrew


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


Re: py2exe problem

2009-04-03 Thread Dave Angel



Wolfgang Forstmeier wrote:






Ok, but do you really use idlelib for something? Or it's just some
random code you found somewhere and drop into your application?


Ah yes, I really use this. I create some message boxes for a little 
GUI application that controls some other program with COM.
Running my app without py2exe, just with python, there is no warning 
at all. This comes in with py2exe first.


Here some piece of code that I use for tkMessageBox.

from idlelib.OutputWindow import tkMessageBox

...
# Define about message box
def about(self):
tkMessageBox.showinfo("About", "My little about text box.")
# --
...

There is some more GUI programming arround that def in my class, but 
that uses only Tkinter, should not be interesting for that error.




So why not use tkMessageBox directly, and skip Idle's namespace wrapping?

import tkMessageBox

tkMessageBox.showinfo("About", "My little about text box.")


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


Re: HTML Generation

2009-04-03 Thread J Kenneth King
Tino Wildenhain  writes:

> Hi Mike,
>
>
> Mike wrote:
>> Hello all,
>>
>> I'm writing a web app and wanted to do some html generation (I
>> really do not like to maintain or write html).
>>
>> I'm thinking of writing a dsl based on the following:
>>
>> def html():
>> return
>>
>> def a():
>> return
>>
>> def body():
>> return
>
> That would be writing HTML just another way and also
> mixing code and representation, this is generally not a
> good idea.
>
> If you really don't want to maintain HTML along with
> your code, I'd suggest an approach like
>
> Zope Page Templates
>
> http://en.wikipedia.org/wiki/Zope_Page_Templates#Zope_Page_Templates
>
> which can be used outside Zope as well, (even with many other languages)
>
> For example: http://zpt.sourceforge.net/
>
> Regards
> Tino

You could also look at CL-WHO for inspiration.

I feel the same way about templates -- the seperation is unnecessary
complexity. One knowledge domain for everything please. We're not
building the tower of Babel here.

I use Python through all of my desktop application development without
switching to markup languages and stylesheets and other scripting
languages (at least VERY rarely).

Why is the web any different?

It's rather somewhat trivial to implement a simple grammar in Python for
describing a page using Python data structures and Pythonic idioms.

I've toyed with it using a base "Tag" metaclass which creates the
__str__() representation for a Tag-metaclassed object based on the name
of the class.

It would look something like this:

code:


from tags import html, head, meta, title, body, div, p, a

mypage = html(
 head(
 meta(attrs={'http-equiv': "Content-Type",
 'content': "text/html;"}),
 title("My Page")),
 body(attrs={'background': "#ff;"},
 div(attrs={'id': "article-content"},
 p(a(attrs={'href': "http://python.org"},
"Python.org")

tabbed_file(mypage, open('myfile.html', 'w'))


Unfortunately Python isn't as malleable when it comes to syntax as Lisp,
but I don't think it's a lost endeavour.

Having to know a template language, markup, stylesheets, CSS, plus all
of Python and good web application design is a huge headache and puts
too many cooks in the kitchen. I'd rather 95% of the work be in pure
Python and keep the team small.

Just 0.02 monetary units.
--
http://mail.python.org/mailman/listinfo/python-list


Re: HTML Generation

2009-04-03 Thread Stefan Behnel
J Kenneth King wrote:
> from tags import html, head, meta, title, body, div, p, a
> 
> mypage = html(
>  head(
>  meta(attrs={'http-equiv': "Content-Type",
>  'content': "text/html;"}),
>  title("My Page")),
>  body(attrs={'background': "#ff;"},
>  div(attrs={'id': "article-content"},
>  p(a(attrs={'href': "http://python.org"},
> "Python.org")
> 
> tabbed_file(mypage, open('myfile.html', 'w'))

See here for another example that uses lxml.html:

http://codespeak.net/lxml/lxmlhtml.html#creating-html-with-the-e-factory

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


Re: config parser -help - anybody please immediately help for me...

2009-04-03 Thread Tim Chase
1) Posting the same question multiple times in a 3 hour span 
isn't likely to get you anything more than people who get peeved 
at your impatience.  Take a moment to realize that you posted at 
4:00am for my local (CST/CDT) time.  That means that, at least 
for those of us in the US, you posted between 2:00am and 5:00am. 
 Most of us in this swath of the globe are asleep at that hour. 
 Our good brothers & sisters across the pond have been awake for 
a while, but remember you're only addressing a portion of the 
newsgroup until you've let at least 16-24 hours pass.


2) Post the question clearly the first time, to the best of your 
ability.  With verbs:  "i want to all my configuration file 
names..."  You want to WHAT all your configuration file names? 
Your second post hints that you want to automatically tack on the 
extension, an aspect that you *totally* omitted in the initial 
posting.  To answer what I believe you're asking, yes, you do 
have to supply the full filename (not just the directory).  You 
can use a list-comprehension to tack on extensions if you want, 
but for only 2 file-names, it's a bit of overkill:


  ["%s.cfg" % path for path in lst_of_filenames_without_ext]

If you, for some crazy reason, want to match all the filenames in 
a directory matching the pattern "*.cfg", you can use the "glob" 
module.  However, a lot of files with .cfg extensions don't need 
to be in "INI" format (the format read by configparser), so 
trying to use configparser to read them may fail.


3) "anybody please immediately help for me".  whine, whine.  You 
already have a working solution.  You're only looking to tweak 
the code for some unfathomable reason.  There's no apparent need 
for urgency unless you're taking an exam or have a homework 
problem due that you haven't been able to figure out.  Give it a 
break.



Waiting-for-an-hour-or-two-to-hit-Send-to-teach-patience'ly yours,

-tkc




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


Re: config parser -help

2009-04-03 Thread Chris Rebert
> On Fri, Apr 3, 2009 at 3:15 PM, Murali kumar  wrote:
>>
>> hi all,
>>
>> i want to all my configuration file names in current/user/home directory..
>>
>> for that i came across following function in configparser class..
>> Is it must to specify file names? or only directories enough..
>> if there anyway to read conf filenames in current/user directory...
>>
>> config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')])

2009/4/3 Murali kumar :
> Is there anyway to read all my configuration filenames with extension
> (.cfg)?
>
> Advanced thanks..
>

Not directly, but you can get a list of all such files using
glob.glob() [http://docs.python.org/library/glob.html] and then easily
write such logic yourself from there.

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: python needs leaning stuff from other language

2009-04-03 Thread Zamnedix
On Apr 2, 3:25 pm, [email protected] wrote:
> python's list needs a thing  list.clear()  like c# arraylist
> and
> python needs a writeline() method

Please don't post things like list before you do any research.
You don't know what you are talking about.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Sending SMS using python script

2009-04-03 Thread Craig
There's a Python wrapper to the Skype API here:
http://sourceforge.net/projects/skype4py/
On Linux I've used the PyGTK GUI that uses this. It's called
SkySentials here:
http://www.kolmann.at/philipp/linux/skysentials/

Craig

On Apr 3, 6:50 am, "ISF (Computer Scientists without Frontiers,
Italy)"  wrote:
> On 2 Apr, 06:41, guptha  wrote:
>
>
>
> > hi group,
> > my application needs to sendSMSoccasionally to all the clients  .Is
> > there any library in python that supports in sendingSMS.
> > I like to conform few information i gathered in this regard.
>
> > I can sendSMSby two ways
>
> > 1. SendingSMSusing Email clients
> > 2. Usingsmsgateway to send message(we can implementSMSGateway API
> > 's ,provided by vendor and ,sendSMS-- we will be charged
> > accordingly )
>
> > In case of First approach
> > 1. We can make use of libgamil library to sendSMSusing gmail ( I
> > ref :http://blog.datasingularity.com/?p=63)
> > i suppose sendingsmsthrough gmail is not supported in India
> >  2. Can we use Skype4py library,
>
> > In case of second approach
> > 1. Is there any way to sendSMSfor free inside India ,or ,Any freeSMSgateway 
> > providers in India
> > Any information regarding this is appreciable
> >   Thanks
>
> A friend from India sent me this hint:
>
> the following link can be explored further for sending SMS on pyS60
> (python for symbian OS)http://mobilenin.com/pys60/menu.htm
>
> wkr,
> Aldo

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


Re: python needs leaning stuff from other language

2009-04-03 Thread Mel
Ben Finney wrote:

> I think it would also be better to have One (and prefereably Only One)
> Obvious Way To Do It. That obvious way, for those who work with
> Python's ‘set’ and ‘dict’, is a ‘clear’ method. It seems best to have
> ‘list’ conform with this also.

Does that mean a one-off special case rule to forbid slices having a 
default?

Mel.


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


Re: python for loop

2009-04-03 Thread alex23
On Apr 3, 10:36 pm, Lou Pecora  wrote:
>  Aaron Brady  wrote:
> > Did I tell you guys that 'natural' has 38 definitions at
> > dictionary.com?
>
> Amazing.  I suggest you pick the one that fits best.

You mean the one that feels most natural?
--
http://mail.python.org/mailman/listinfo/python-list


Re: python needs leaning stuff from other language

2009-04-03 Thread Steven D'Aprano
On Fri, 03 Apr 2009 08:23:22 -0700, Zamnedix wrote:

> On Apr 2, 3:25 pm, [email protected] wrote:
>> python's list needs a thing  list.clear()  like c# arraylist and
>> python needs a writeline() method
> 
> Please don't post things like list before you do any research. You don't
> know what you are talking about.

The original poster may or may not know what he is talking about, but 
adding a clear() method to lists seems to be very much in demand. I'd 
vote Yes for one.

Besides, this news group is for people to ask questions about Python, 
even stupid questions. It's not just for experts only.



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


Re: python needs leaning stuff from other language

2009-04-03 Thread Steven D'Aprano
On Fri, 03 Apr 2009 11:41:10 -0400, Mel wrote:

> Ben Finney wrote:
> 
>> I think it would also be better to have One (and prefereably Only One)
>> Obvious Way To Do It. That obvious way, for those who work with
>> Python's ‘set’ and ‘dict’, is a ‘clear’ method. It seems best to have
>> ‘list’ conform with this also.
> 
> Does that mean a one-off special case rule to forbid slices having a
> default?

Why would it do that?


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


django model problem

2009-04-03 Thread Mark
Hi,

Say I have these simple models:

class Musician(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)

class Album(models.Model):
artist = models.ForeignKey(Musician)
name = models.CharField(max_length=100)


Now in `Musician` I want to add a field "last_album". 
How can I do that? I'd like to be able to write:

m = Musician(pk=1)
print m.last_album.name

When I try:
last_album = models.OneToOneField(Album)
it somehow works but creates a (useless) unique index for last_album.
And I don't need additional related field in the Album model (it's also
created now).


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


Best way to pickle functions

2009-04-03 Thread Aaron Scott
I have a number of functions that I need to pickle without necessarily
knowing their names in advance. My first thought was to put all the
functions in a class, then pickle the class, but it doesn't really
work like I expected it to.

import cPickle
class PickleClass:
def Awesome(self):
pass
stored = cPickle.dumps(PickleClass)
del PickleClass
restored = cPickle.loads(stored)

Results:

Traceback (most recent call last):
  File "pickletest.py", line 7, in 
restored = cPickle.loads(stored)
AttributeError: 'module' object has no attribute 'PickleClass'

So, the class itself isn't being pickled, just an instance of it.

This being the case, what's the best way to store these functions?
Maybe dump the class to a string and pull them back with an exec
statement when I need them?
--
http://mail.python.org/mailman/listinfo/python-list


Re: A design problem I met again and again.

2009-04-03 Thread Emile van Sebille

andrew cooke wrote:

Emile van Sebille wrote:

Whether you (generic you) choose to do so or not is a separate issue.

Also agreed - and that is really my point.  Doing so feels to me like
continuing to look for a lost object once you've found it.


i can see your point here, but there's two things more to consider:

1 - if you do need to refactor it later, because there is a bug say, it
will be harder to do so because you will have forgotten much about the
code.  


Yes, I generally count on it.  Refactoring at that time is precisely 
when you get the most benefit, as it will concisely focus your 
attentions on the sections of code that need to be clearer to support 
the debugging changes.  Face it, you'll have to get your head around the 
code anyway, be it 1, 5, or 10k lines and all beautifully structured or 
not.  Remember, proper refactoring by definition does not change 
functionality -- so that bug in the code will be there regardless.



so if it is likely that you will need to refactor in the future, it
may pay to do some of that work now.


Certainly -- and I envy those who know which sections to apply their 
attentions to and when to stop.  Personally, I stop when it works and 
wait for feedback.



2 - if someone else needs to work with the code then the worse state it is
in - even if it works - the harder time they will have understanding it. 
which could lead to them using or extending it incorrectly, for example.


Assuming you're talking about non-refactored code when you say worse, 
consider Zope vs Django.  I have no doubt that both meet an acceptable 
level of organization and structure intended in part to facilitate 
maintenance.  I've got multiple deployed projects of each. But I'll hack 
on Django if it doesn't do what I want and I find that easy, while 
hacking on Zope ranks somewhere behind having my mother-in-law come for 
a three-week stay on my favorite-things-to-do list.  Refactored code 
doesn't necessarily relate to easier understanding.



both of the above fall under the idea that code isn't just a machine that
produces a result, but also serves as documentation.  and working code
isn't necessarily good documentation.


Here I agree.  Once I've got it working and I have the time I will add 
minor clean up and some notes to help me the next time I'm in there. 
Clean up typically consists of dumping unused cruft, relocating imports 
to the top, and adding a couple lines of overview comments.  On the 
other hand, I do agree with Aahz's sometimes tag line quote accepting 
all comments in code as lies.  It's akin to believing a user -- do so 
only at your own peril.  They're really bad witnesses.



i don't think there's a clear, fixed answer to this (i don't think "stop
refactoring as soon as all tests work" can be a reliable general rule any
more than "refactor until it is the most beautiful code in the world" can
be).  you need to use your judgement on a case-by-case basis.


Well said.


in fact, the thing i am most sure of in this thread is that 15000 lines of
code in one module is a disaster.  


Agreed.  I took a quick scan and the largest modules I'm working with 
look to be closer to 1500 lines.  Except tiddlywiki of course, which 
comes in at 9425 lines in the current download before adding anything to 
it.  I bet I'd prefer even hacking that to zope though.


One programmer's disaster is another programmer's refactoring dream :)

Emile


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


Re: Best way to pickle functions

2009-04-03 Thread Aaron Brady
On Apr 3, 11:04 am, Aaron Scott  wrote:
> I have a number of functions that I need to pickle without necessarily
> knowing their names in advance. My first thought was to put all the
> functions in a class, then pickle the class, but it doesn't really
> work like I expected it to.
>
>         import cPickle
>         class PickleClass:
>                 def Awesome(self):
>                         pass
>         stored = cPickle.dumps(PickleClass)
snip
> So, the class itself isn't being pickled, just an instance of it.
>
> This being the case, what's the best way to store these functions?
> Maybe dump the class to a string and pull them back with an exec
> statement when I need them?

All pickling a class does is pickle its module and name.  You can't
pickle functions in principle because byte-code is sensitive and
volatile, and is least likely to run consistently later on.  'pickle'
is not just for serialization, it's for persistence.

Pickling the source code is much sturdier.  It's very unlikely that
the same code runs differently in different interpreters.  It's much
more likely that the same code runs the same, or not at all.

It's better yet to just get the source from the original place every
time: instead, pickle a file name and open the file.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python for loop

2009-04-03 Thread Aaron Brady
On Apr 3, 10:43 am, alex23  wrote:
> On Apr 3, 10:36 pm, Lou Pecora  wrote:
>
> >  Aaron Brady  wrote:
> > > Did I tell you guys that 'natural' has 38 definitions at
> > > dictionary.com?
>
> > Amazing.  I suggest you pick the one that fits best.
>
> You mean the one that feels most natural?

No, not feels.  *Is*.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python needs leaning stuff from other language

2009-04-03 Thread Mel
Steven D'Aprano wrote:

> On Fri, 03 Apr 2009 11:41:10 -0400, Mel wrote:
> 
>> Ben Finney wrote:
>> 
>>> I think it would also be better to have One (and prefereably Only One)
>>> Obvious Way To Do It. That obvious way, for those who work with
>>> Python's ‘set’ and ‘dict’, is a ‘clear’ method. It seems best to have
>>> ‘list’ conform with this also.
>> 
>> Does that mean a one-off special case rule to forbid slices having a
>> default?
> 
> Why would it do that?

Well, if list.clear were truly and strictly to be the only way to clear the 
contents of a list, then assigning nothing via the default slice would have 
to be ruled out.  `somelist[:] = []` is just a special case of assignment to 
a slice generally.

Mel.


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


Re: with open('com1', 'r') as f:

2009-04-03 Thread gert
On Apr 3, 3:44 pm, "Gabriel Genellina"  wrote:
> En Thu, 02 Apr 2009 20:04:14 -0300, gert  escribió:
>
> > On Apr 2, 8:53 pm, Kushal Kumaran  wrote:
> >> On Thu, 2 Apr 2009 10:01:02 -0700 (PDT)
> >> gert  wrote:
> >> > from subprocess import *
> >> > check_call(['mode', 'COM1:9600,N,8,1,P'],shell=True)
> >> > while True:
> >> >     with open('com1', 'r') as f:
> >> >         for line in f:
> >> >              print(line)
>
> >> > This works very well except for one thing. After a reboot I have to
> >> > launch 1 time any windows serial exe application no mater with one,
> >> > that just opens an closes the com port, before i can launch this
> >> > script. The script keeps on working even after closing and reopening
> >> > it, until i reboot the pc. Then again I have to launch one time a
> >> > serial.exe and close it again. The exe does not run anything in the
> >> > background it just does something in windows python does not do when
> >> > it reads from the com port after a fresh reboot.
>
> >> > And i really appreciate it if somebody knew what it was.
>
> >> I don't know why you're getting this behaviour, but have you tried using
> >> a python library for accessing the serial port?  
> >> Seehttp://pyserial.wiki.sourceforge.net/pySerial.
>
> > I am sorry but I don't think pyserial will work on python3.x and I
> > also like to know whats going on before I consider it.
>
> A real Windows program accessing the serial port is likely to use  
> SetupComm, SetCommState, and other functions in addition to CreateFile.
> Seehttp://msdn.microsoft.com/en-us/library/aa363196(VS.85).aspx
>
> pySerial takes care of all those details, as suggested.
>
> > Maybe its a bug in open() on windows?
>
> open() doesn't care about the file name; it's the OS that interprets  
> "com1" as a serial port.

I do understand, and I went looking into pySerial, but it is a long
way from getting compatible with python3.x and involves other libs
that are big and non pyhton3.x compatible.

Also I can not imaging activating a com port wouldn't be possible with
a check_call dos instruction. I can already configure com with mode.

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


User or UserManager ? Problems of Observer Pattern

2009-04-03 Thread 一首诗
#This is a real world problem I met.
#
#We have a database containing serveral tables, like : user, role,
organization.  Each 2 of them has m:n relationships.  These relations
are stored in association tables.
#
#Not we have to load all these data in memory to gain higher
performances.  We create 3 classes , User, Role, Organization, to hold
these data.
#
#The question is : should I implement "add/delete/update" as methods
of User, or should I add another class UserManager?


#
# Choice 1
#

user_dict = {}
role_dict = {}

class User:
on_del_funcs = []
roles = []

def del(self):
user_dict.pop(self.name)

for f in self.on_del_funcs:
f(self)

# Using Observer Pattern to notify this user is deleted.
def addUserDelListener(self, on_del_func):
on_del_funcs.append(on_del_funcs)

def delUserDelListener(self, on_del_func):
on_del_funcs.remove(on_del_func)

class Role:

users = []

def addUsser(self, user):
self.users.append(user)
user.roles.append(self)
users.addUserDelListener(self.onUserDel)

def onUserDel(self, user):
self.users.remove(user)
user.delUserDelListener(self.onUserDel)

#
# Choice 2
#

class UserManager:

users = []

@classmethod
def delUser(cls, user):
cls.users.remove(user)

RoleManager.onUserDel(user)

class RoleManager:

roles = []

@classmethod
def onUserDel(cls, user):
for r in cls.roles.items():
r.users.remove(user)


# These codes are not complete, but that's enough to show my question.
# The first choice, which use Observer Pattern, has a very big
problem.
# When calling addUserDelListener, user got not only a callback
function, it
# also add reference count of role.  So when we want to delete a
role.  We have
# to carefully remove all *listener* hold by other objects, otherwise
this role
# will never be garbage collected.

# Not a big problem for only 2 classes.  But when there are 10
*subject* classes which
# Role want to *observe*, 10 listeners has to be removed when delete a
role.
# And if these *subject* have 5 different types of events, then 50
listeners has
# to be removed.

# Actually I tried this approach once, and it is still a big headache
for 10
# programmers. ( The company I worked at that time hate any change to
so-called
# working code )



# The second choice, which I am using right now, actually has nothing
to do with
# Object Oriented Designing.   The manager classes are not real
classes, just
# container of methods.   These User/Role classes are only container
of data,
# not behavior.
#
# For many times, I asked my self, "Is it too hard for me to see the
power of
# OO, or I have just never met a problem suitable for a OO resolution?"
--
http://mail.python.org/mailman/listinfo/python-list


Hash of None varies per-machine

2009-04-03 Thread ben . taylor
Found this while trying to do something unrelated and was curious...

If you hash an integer (eg. hash(3)) you get the same integer out. If
you hash a string you also get an integer. If you hash None you get an
integer again, but the integer you get varies depending on which
machine you're running python on (which isn't true for numbers and
strings).

This raises the following questions:
1. Is it correct that if you hash two things that are not equal they
might give you the same hash value? Like, for instance, None and the
number 261862182320 (which is what my machine gives me if I hash
None). Note this is just an example, I'm aware hashing integers is
probably daft. I'm guessing that's fine, since you can't hash
something to a number without colliding with that number (or at least
without hashing the number to something else, like hashing every
number to itself * 2, which would then mean you couldn't hash very
large numbers)
2. Should the hash of None vary per-machine? I can't think why you'd
write code that would rely on the value of the hash of None, but you
might I guess.
3. Given that presumably not all things can be hashed (since the
documentation description of hash() says it gives you the hash of the
object "if it can be hashed"), should None be hashable?

Bit esoteric perhaps, but like I said, I'm curious. ;-)

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


Re: Best way to pickle functions

2009-04-03 Thread Aaron Scott
> Pickling the source code is much sturdier.  It's very unlikely that
> the same code runs differently in different interpreters.  It's much
> more likely that the same code runs the same, or not at all.

Okay, I've run into another problem. I've saved the code to a string,
so I can call it up when I need it. I want to keep these functions all
together, though, so I'm pushing them into a dictionary when I execute
it. It seems like when I put it in a dictionary, though, it messes up
the scope of the functions contained within. For example:

import cPickle
def Main():
holder = {}
functiontest = "def PickleTest():\n\tprint cPickle"
exec functiontest in holder
print holder["PickleTest"]()
Main()

... produces:

Traceback (most recent call last):
  File "pickletest.py", line 11, in 
Main()
  File "pickletest.py", line 9, in Main
print holder["PickleTest"]()
  File "", line 2, in PickleTest
NameError: global name 'cPickle' is not defined

Is there any way to do this so that the functions have access to the
higher scope?

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


platform.architecture, __path__, PYTHONPATH, and dist.utils

2009-04-03 Thread szager
Howdy,

I need to support both 32-bit and 64-bit versions of compiled python
modules that cannot be installed into the default search path of the
python interpreter(s).  I use PYTHONPATH to point to the module
installations, but I have a problem: I don't know, a priori, whether
the user will be running a 32-bit or 64-bit python interpreter.  So, I
would like to set up a hybrid installation that will be able to load
either version, based on the architecture of the currently-running
interpreter.

** How can I use dist.utils to create a hybrid installation of an
extension module? **

Currently, I'm manually hacking the build results, but my method is
very platform-dependent.  It would be nicer to have an automated,
platform-agnostic way to do this.

Here's what I'm doing now:

/path/to/foo/32bit/libfoo.so
/path/to/foo/64bit/libfoo.so

In /path/to/foo/__init__.py:

import os
import platform

# Note that I can't use platform.architecture(),
#   because that doesn't work when using embedded python
exe_arch = platform.architecture('/proc/self/exe')

__path__[0] = os.path.join(__path[0]__, exe_arch[0])

from libfoo import *



Thanks in advance,

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


Re: Hash of None varies per-machine

2009-04-03 Thread Paul Rubin
[email protected] writes:
> 1. Is it correct that if you hash two things that are not equal they
> might give you the same hash value?

Yes, hashes are 32 bit numbers and there are far more than 2**32
possible Python values (think of long ints), so obviously there must
be multiple values that hash to the same slot.

> 2. Should the hash of None vary per-machine? 

If the docs say this shouldn't happen, then it's a bug.  Otherwise,
it should probably be considered ok.

> 3. Given that presumably not all things can be hashed (since the
> documentation description of hash() says it gives you the hash of the
> object "if it can be hashed"), should None be hashable?

Yes, anything that can be used as a dict key (basically all immutable
values with equality comparison) should be hashable.
--
http://mail.python.org/mailman/listinfo/python-list


Re: A design problem I met again and again.

2009-04-03 Thread paul
一首诗 schrieb:
> Consolidate existing functions?
> 
> I've thought about it.
> 
> For example, I have two functions:
> 
> #=
> 
> def startXXX(id):
> pass
> 
> def startYYY(id):
> pass
> #=
> 
> I could turn it into one:
> 
> #=
> def start(type, id):
> if(type == "XXX"):
> pass
> else if(type == "YYY"):
> pass
> #=
> 
> But isn't the first style more clear for my code's user?
Depends ;)

There are more ways to structure code than using classes. To avoid the
if-elif-elif-elif-else problem you could start using a dispatch table
which maps types to functions (fex using a dict)

start_methods = {
 'type1': startXX,
 'type2': startYY,
}

def start(type, id):
  func = start_methods.get(type, None)
  if func:
func(id)
  else:
raise ...

Or maybe look at trac's (http://trac.edgewall.com) use of Components and
Interfaces. Very lightweight and modular. You can start reading here:
http://trac.edgewall.org/browser/trunk/trac/core.py

cheers
 Paul

> 
> That's one reason why my interfaces grow fast.
> 
> On Apr 3, 1:51 am, Carl Banks  wrote:
>> On Apr 2, 8:02 am, 一首诗  wrote:
>>
>>> You get it.  Sometimes I feel that my head is trained to work in a
>>> procedural way.  I use a big class just as a container of functions.
>>> About the "data-based" approach, what if these functions all shares a
>>> little data, e.g. a socket, but nothing else?
>> Then perhaps your problem is that you are too loose with the
>> interface.  Do you write new functions that are very similar to
>> existing functions all the time?  Perhaps you should consolidate, or
>> think about how existing functions could do the job.
>>
>> Or perhaps you don't have a problem.  There's nothing wrong with large
>> classes per se, it's just a red flag.  If you have all these functions
>> that really all operate on only one piece of data, and really all do
>> different things, then a large class is fine.
>>
>> Carl Banks
> 
> --
> http://mail.python.org/mailman/listinfo/python-list

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


Re: Best way to pickle functions

2009-04-03 Thread Aaron Scott
Never mind. Solved the problem by putting the functions in a class and
dumping that into a string. Then, when I need it, I executed the
string to get myself the class, then created an instance of that class
which gave me access to those functions along with the correct scope.
Probably not the smartest solution, but it works for now.
--
http://mail.python.org/mailman/listinfo/python-list


Re: django model problem

2009-04-03 Thread Dave Angel

Mark wrote:

Hi,

Say I have these simple models:

class Musician(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)

class Album(models.Model):
artist = models.ForeignKey(Musician)
name = models.CharField(max_length=100)

  
I think the first thing you need to do is decide if there is going to be 
more than one Musician object. and more than one Album object.  
Presently you are giving all musicians the same first_name and 
last_name.  I suggest you look up the documentation for the special 
method __init__()


Then you need to realize that assigning new attributes to an instance 
object needs to be done inside an instance method, either __init__() or 
some other method with a self parameter.



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


Re: Hash of None varies per-machine

2009-04-03 Thread Joshua Judson Rosen
Paul Rubin  writes:
>
> [email protected] writes:
> > 1. Is it correct that if you hash two things that are not equal they
> > might give you the same hash value?
> 
> Yes, hashes are 32 bit numbers and there are far more than 2**32
> possible Python values (think of long ints), so obviously there must
> be multiple values that hash to the same slot.

This is not true. CPython integers, at least up through the 2.x
series, are implemented as C *long integers*; on some platforms, this
means that they're 32 bits long. But on an increasing number of
platforms, long integes are 64 bits long.

But, more specifically, consider the following:

> > 2. Should the hash of None vary per-machine? 
> 
> If the docs say this shouldn't happen, then it's a bug.  Otherwise,
> it should probably be considered ok.
> 
> > 3. Given that presumably not all things can be hashed (since the
> > documentation description of hash() says it gives you the hash of the
> > object "if it can be hashed"), should None be hashable?
> 
> Yes, anything that can be used as a dict key (basically all immutable
> values with equality comparison) should be hashable.

My recollection is that what you're seeing here is that, when hash()
doesn't have any `proper value' to use other than object-identity, it
just returns the result of id(). And id() is documented as:

 Return the "identity" of an object. This is an integer (or long
 integer) which is guaranteed to be unique and constant for this
 object during its lifetime. Two objects with non-overlapping
 lifetimes may have the same id() value. (Implementation note:
 this is the address of the object.)

So, not only is the return-value from id() (and hash(), if there's not
actually a __hash__ method defined) non-portable between different
machines, it's not even necessarily portable between two *runs* on the
*same* machine.

In practice, your OS will probably start each new process with the
same virtual memory-address range, and a given *build* of Python will
probably initialise the portion of its memory-segment leading up to
the None-object the same way each time, but

-- 
Don't be afraid to ask (Lf.((Lx.xx) (Lr.f(rr.
--
http://mail.python.org/mailman/listinfo/python-list


Re: "Pythoner",Wish me luck!

2009-04-03 Thread barisa
On Apr 3, 11:39 am, "Hendrik van Rooyen"  wrote:
> "Matteo"  wrote:
>
> On Apr 3, 9:05 am, Linuxwell  wrote:
>
> >> Starting today I would like to study Python,Wish me luck!
>
> >Good luck!
>
> >Don't forget to...
>
>  print 'Hello World!'
>
> This is better advice than what you may think,
> because the interactive interpreter is your very
> best friend when studying the language.
>
> You get there by typing "python" at the command
> line, and pressing enter.
>
> Using it, you will save yourself many hours of
> misunderstanding.
>
> - Hendrik

Hi,
I'm also begginer in python;
i did few basic programs about graph etc..

my question is : what benefit is using interactive intrepreter ?

i come from java backround, so I use eclipse for python as well.
I start my program, it does it's job, and that's it.  (after some
debugging ofc)
--
http://mail.python.org/mailman/listinfo/python-list


Re: HTML Generation

2009-04-03 Thread J Kenneth King
Stefan Behnel  writes:

> J Kenneth King wrote:
>> from tags import html, head, meta, title, body, div, p, a
>> 
>> mypage = html(
>>  head(
>>  meta(attrs={'http-equiv': "Content-Type",
>>  'content': "text/html;"}),
>>  title("My Page")),
>>  body(attrs={'background': "#ff;"},
>>  div(attrs={'id': "article-content"},
>>  p(a(attrs={'href': "http://python.org"},
>> "Python.org")
>> 
>> tabbed_file(mypage, open('myfile.html', 'w'))
>
> See here for another example that uses lxml.html:
>
> http://codespeak.net/lxml/lxmlhtml.html#creating-html-with-the-e-factory
>
> Stefan

Ah, looks good. Have never used nor finished the example I had given --
only meant as inspiration. I'm not surprised it has been done by someone
else.

I've been thinking about the co-routines presentation recently given at
Pycon and have been thinking about ways they could be used to extend the
grammar a bit.

At present, it looks like in my example and the lxml.html example that
the HTML structures created are declarative. Scripting the generation of
child elements for example would break up the flow...

code:


E.HTML(
E.HEAD(
E.TITLE("Best Page Evar!")
),
E.BODY(
E.H1(E.CLASS("best-articles-heading"), "Best Articles"),
E.UL(E.CLASS("articles"))
)
)

for article in articles:
E.HTML.BODY.UL.append(E.LI(article['title]))


... at least that's how I assume it would work.

I think in my prototype you could use list-comprehensions in-line to add
the elements, but it was quite an eyesore.

code:


my_html = html(
  head(
  title("Best Page Evar!")
  ),
  body(
  ul(
  [li(article['title']) for article in articles]
  )
  )
  )


I guess it's not that bad, but I had a feeling it could look prettier
like how naturally CL-WHO reads in Lisp. It's just that the list
comprehension doesn't read well in this context; it'd be more natural to
read it as "for each article in article, create a list element with the
article title" instead.

I get the impression that creating a chain of co-routines would reveal a
grammar for talking about generating web pages. Something like...

code:


html_to_file(
html(
head(
title("Best page evar")
),
body(
h1({'class': "underline-heading"},
   "Newest Articles"),
unordered_list(
articles,
['title', 'href'],
'%-10s: %s')
)
),
file=sys.stdout
)


Where `unordered_list` would walk the elements in its first argument,
extract the values from the keys specified by its second argument, and
format the results using the string from its third argument and simply
return a ul() object with nested li() objects with all the data inserted
into them.

Of course, this is very off-the-cuff; I only started picking up interest
in this old subject this morning. ;) I could be talking way out of my
ass here. No idea if any of it's even practical.

Anyway -- OP: there are many ways to approach HTML generation and it's a
good pursuit. If you come up with something new and unique, please
share! Down with templates! :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: minor revision encoded in SONAME in libpython.so

2009-04-03 Thread Martin v. Löwis
>> So no, no minor revision gets encoded into the SONAME.
> 
> Then what's the significance of the .1.0 at the end of the SONAME?  Is
> it just nipples for men?  (I hope no one objects to my extending the
> Monty Python theme to Time Bandits).

Some systems require that shared libraries have a version in their
SONAME, so we provide a version.

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


Re: Re: Best way to pickle functions

2009-04-03 Thread Dave Angel

Aaron Scott wrote:

Pickling the source code is much sturdier.  It's very unlikely that
the same code runs differently in different interpreters.  It's much
more likely that the same code runs the same, or not at all.



Okay, I've run into another problem. I've saved the code to a string,
so I can call it up when I need it. I want to keep these functions all
together, though, so I'm pushing them into a dictionary when I execute
it. It seems like when I put it in a dictionary, though, it messes up
the scope of the functions contained within. For example:

import cPickle
def Main():
holder =}
functiontest =def PickleTest():\n\tprint cPickle"
exec functiontest in holder
print holder["PickleTest"]()
Main()

... produces:

Traceback (most recent call last):
  File "pickletest.py", line 11, in 
Main()
  File "pickletest.py", line 9, in Main
print holder["PickleTest"]()
  File "", line 2, in PickleTest
NameError: global name 'cPickle' is not defined

Is there any way to do this so that the functions have access to the
higher scope?

Thanks.

  
Why not use import ?  Simply recreate the source file, if necessary, and 
import it again.


If you must import without it being in a clear text file, check out the 
deprecated imputil module, standard in 2.x, but removed in Python 3.0.  
And if you find some way to get __import__ or one of its relatives to 
work from a stream instead of a file, please let us know.



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


Re: Python Goes Mercurial

2009-04-03 Thread Martin v. Löwis
 So what were these "strong antipathies" towards Git, exactly?
>>> i haven't read the article you link to, but compared to what i've read
>>> on
>>> dev "strong antipathies" sounds a bit over-hyped.
>> That was the phrase used by GvR.
> 
> well if you find any, please do report back.

I don't like git because it is too difficult for me. In many cases,
git would refuse to do operations like updating or local committing,
producing error messages I was not able to understand (most of the
time including long sequences of hexdigits which I did not recognize,
or complaining about conflicts in long lists of files I knew I hadn't
touched at all). In some cases, I lost all my changes, and had to
do them all over again.

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


Re: "Pythoner",Wish me luck!

2009-04-03 Thread nrballard
On Apr 3, 12:33 pm, barisa  wrote:
> On Apr 3, 11:39 am, "Hendrik van Rooyen"  wrote:
>
>
>
> > "Matteo"  wrote:
>
> > On Apr 3, 9:05 am, Linuxwell  wrote:
>
> > >> Starting today I would like to study Python,Wish me luck!
>
> > >Good luck!
>
> > >Don't forget to...
>
> >  print 'Hello World!'
>
> > This is better advice than what you may think,
> > because the interactive interpreter is your very
> > best friend when studying the language.
>
> > You get there by typing "python" at the command
> > line, and pressing enter.
>
> > Using it, you will save yourself many hours of
> > misunderstanding.
>
> > - Hendrik
>
> Hi,
> I'm also begginer in python;
> i did few basic programs about graph etc..
>
> my question is : what benefit is using interactive intrepreter ?
>
> i come from java backround, so I use eclipse for python as well.
> I start my program, it does it's job, and that's it.  (after some
> debugging ofc)

I'm also a beginner in Python, but from my own experience the
interactive interpreter is great for experimenting with new modules
and output formatting because it allows you to see the immediate
output of a function before you write it into your program.  The
immediate result is that you'll see any errors and be able to fix them
before they end up in your script.

Nick Ballard
http://90daysofpython.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: "Pythoner",Wish me luck!

2009-04-03 Thread Ravi Kumar
>
> Hi,
> I'm also begginer in python;
> i did few basic programs about graph etc..
>
> my question is : what benefit is using interactive intrepreter ?
>
>

the IDLE interractive python IDE is best comparing to any other most
advanced IDE available in world. Really, if you are learning the python at
any level, go for IDLE.

What you do, you write every step of statements and that is executed as soon
as you finish the block. So you have chance to understand the things step by
step. Just like learning by debugging..

Try it self, no one's review can satisfy you.

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


IIS python web application mapping issue - resolved

2009-04-03 Thread davidj411
i searched the internet for an hour , never found this info, and
figured it out myself.
posting this so that others won't have to look so hard.

ran across this issue and it seems that nobody really documented this
correctly on http://support.microsoft.com/kb/276494

in IIS i could not add the "python mapping" to the web mappings like
this:
"c:\\python.exe -u %s %s"


windows said the file does not exist, even when i unchecked the option
to make sure it exists (and it does exist!).

it would not allow the arguments, i.e. it allowed the mapping when i
just used "c:\\python.exe".

solution was to do it like this:
c:\\python.exe -u "%s %s"

making the arguments have there own set of quotes.


remember to also do the following
have web service extensions enabled for cgi.
register python using pyscript.py.

thanks!

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


Re: Hash of None varies per-machine

2009-04-03 Thread Dave Angel

[email protected] wrote:

Found this while trying to do something unrelated and was curious...

If you hash an integer (eg. hash(3)) you get the same integer out. If
you hash a string you also get an integer. If you hash None you get an
integer again, but the integer you get varies depending on which
machine you're running python on (which isn't true for numbers and
strings).

This raises the following questions:
1. Is it correct that if you hash two things that are not equal they
might give you the same hash value? Like, for instance, None and the
number 261862182320 (which is what my machine gives me if I hash
None). Note this is just an example, I'm aware hashing integers is
probably daft. I'm guessing that's fine, since you can't hash
something to a number without colliding with that number (or at least
without hashing the number to something else, like hashing every
number to itself * 2, which would then mean you couldn't hash very
large numbers)
2. Should the hash of None vary per-machine? I can't think why you'd
write code that would rely on the value of the hash of None, but you
might I guess.
3. Given that presumably not all things can be hashed (since the
documentation description of hash() says it gives you the hash of the
object "if it can be hashed"), should None be hashable?

Bit esoteric perhaps, but like I said, I'm curious. ;-)

Ben

  
1. Most definitely.  Every definition of hash (except for "perfect 
hash") makes it a many-to-one mapping.  Its only intent is to reduce the 
likelihood of collision between dissimilar objects.  And Python's spec 
that says that integers, longs and floats that are equal are guaranteed 
the same hash value is a new one for me.  Thanks for making me look it up.


2. Nothing guarantees that the Python hash() will return the same value 
for the same object between implementations, or even between multiple 
runs with the same version on the same machine.  In fact, the default 
hash for user-defined classes is the id() of the object, which will 
definitely vary between program runs.  Currently, id() is implemented to 
just return the address of the object.


3. Normally, it's just mutable objects that are unhashable.  Since None 
is definitely immutable, it should have a hash.  Besides, if it weren't 
hashable, it couldn't be usable as a key in a dictionary.


All my opinions, of course.
DaveA

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


Python-URL! - weekly Python news and links (Apr 3)

2009-04-03 Thread Gabriel Genellina
QOTW:  "A programmer has to know the name of many data structures." - bearophile


Code organization: how to split a project into modules

http://groups.google.com/group/comp.lang.python/browse_thread/thread/56c320cea02796cc/

A speech generator, expert in leading-edge Web-based technologies:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/cc8013d5399dd65d/

Unladen-Swallow: a new runtime for Python based on LLVM

http://groups.google.com/group/comp.lang.python/browse_thread/thread/15f4f9bec82c80b9/

http://groups.google.com/group/comp.lang.python/browse_thread/thread/ec66471ebe5948c6/

Why indexes start at 0, and ranges are semi-open?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/ba73814384f7c0ef/

Advanced generator usage, a talk by David Beazley at PyCon2009:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/aacd809829d6b6ce/

Mercurial to be the new distributed version control system for Python

http://groups.google.com/group/comp.lang.python/browse_thread/thread/1f99be59ea13bd22/

How to split a string at commas respecting quotes

http://groups.google.com/group/comp.lang.python/browse_thread/thread/aacac2d2a5c192e9/

Some tkinter design questions: why things are the way they are?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/75d3ce79c919b76d/

PEP 382: A proposal to add namespace packages

http://groups.google.com/group/comp.lang.python/browse_thread/thread/aebfb3311a2f5eb6/

Still discussing an ordered set implementation

http://groups.google.com/group/comp.lang.python/browse_thread/thread/90d818e016632a2c/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish "the efforts of Python enthusiats":
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the "Planet" sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance.
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donations/

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions. 

http://search.gmane.org/?author=status%40bugs.python.org&group=gmane.comp.python.devel&sort=date

Although unmaintained since 2002, the Cetus collection of Python
hyperlinks retains a few gems.
http://www.cetus-links.org/oo_python.html

Python FAQTS
http://python.faqts.com/

The Cookbook is a collaborative effort to capture useful and
interesting recipes.
http://code.activestate.com/recipes/langs/python/

Many Python conferences around the world are in preparation.
Watch this space for links to them.

Among several Python-oriented RSS/RDF feeds available, see:
http://www.python.org/channews.rdf
For more, see:
http://www.syndic8.com/feedlist.php?ShowMatch=python&ShowStatus=all
The old Python "To-Do List" now lives principally i

Re: "Pythoner",Wish me luck!

2009-04-03 Thread barisa
On Apr 3, 8:58 pm, [email protected] wrote:
> On Apr 3, 12:33 pm, barisa  wrote:
>
>
>
> > On Apr 3, 11:39 am, "Hendrik van Rooyen"  wrote:
>
> > > "Matteo"  wrote:
>
> > > On Apr 3, 9:05 am, Linuxwell  wrote:
>
> > > >> Starting today I would like to study Python,Wish me luck!
>
> > > >Good luck!
>
> > > >Don't forget to...
>
> > >  print 'Hello World!'
>
> > > This is better advice than what you may think,
> > > because the interactive interpreter is your very
> > > best friend when studying the language.
>
> > > You get there by typing "python" at the command
> > > line, and pressing enter.
>
> > > Using it, you will save yourself many hours of
> > > misunderstanding.
>
> > > - Hendrik
>
> > Hi,
> > I'm also begginer in python;
> > i did few basic programs about graph etc..
>
> > my question is : what benefit is using interactive intrepreter ?
>
> > i come from java backround, so I use eclipse for python as well.
> > I start my program, it does it's job, and that's it.  (after some
> > debugging ofc)
>
> I'm also a beginner in Python, but from my own experience the
> interactive interpreter is great for experimenting with new modules
> and output formatting because it allows you to see the immediate
> output of a function before you write it into your program.  The
> immediate result is that you'll see any errors and be able to fix them
> before they end up in your script.
>
> Nick Ballardhttp://90daysofpython.blogspot.com

thanks, i'll give it a try
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] PEP 382: Namespace Packages

2009-04-03 Thread Martin v. Löwis
> Perhaps we could add something like a sys.namespace_packages that would
> be updated by this mechanism?  Then, pkg_resources could check both that
> and its internal registry to be both backward and forward compatible.

I could see no problem with that, so I have added this to the PEP.

Thanks for the feedback,

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


confused with creating doctest in xmlrpc server

2009-04-03 Thread Krishnakant
hello all,
I am thinking of using the doctest module for my unit testing code in
python.
I have no problems doing this in usual classes but I am a bit confused
with my twisted based rpc classes.

given that I directly take the output of running functions on a python
prompt for the dockstrings, how do I get them for my twisted class which
has a published object?

What I mean is that in normal classes I would just start the python
prompt, import the module, create the object and run the methods to get
the output.

Then I take the output and put it into a file and then use those
dockstrings for my tests.
As you all know an rpc server app can't be run like this.  To my
knowledge an rpc server is a service that listens on a port on the given
ip address.

So how do I extract the dockstrings from the functions inside my xmlrpc
class?
obviously it is not run on a python prompt, so what is the solution?

happy hacking.
Krishnakant.




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


Re: [Python-Dev] PEP 382: Namespace Packages

2009-04-03 Thread Martin v. Löwis
Chris Withers wrote:
> Martin v. Löwis wrote:
>> I propose the following PEP for inclusion to Python 3.1.
>> Please comment.
> 
> Would this support the following case:
> 
> I have a package called mortar, which defines useful stuff:
> 
> from mortar import content, ...
> 
> I now want to distribute large optional chunks separately, but ideally
> so that the following will will work:
> 
> from mortar.rbd import ...
> from mortar.zodb import ...
> from mortar.wsgi import ...
> 
> Does the PEP support this? 

That's the primary purpose of the PEP. You can do this today already
(see the zope package, and the reference to current techniques in the
PEP), but the PEP provides a cleaner way.

In each chunk (which the PEP calls portion), you had a structure like
this:

mortar/
mortar/rbd.pkg (contains just "*")
mortar/rbd.py

or

mortar/
mortar/zobd.pkg
mortar/zobd/
mortar/zobd/__init__.py
mortar/zobd/backends.py

As a site effect, you can also do "import mortar", but that would just
give you the (nearly) empty namespace package, whose only significant
contents is the variable __path__.

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


Re: django model problem

2009-04-03 Thread Mark
> I think the first thing you need to do is decide if there is going to be 
> more than one Musician object. and more than one Album object.  
> Presently you are giving all musicians the same first_name and 
> last_name.  I suggest you look up the documentation for the special 
> method __init__()
> 
> Then you need to realize that assigning new attributes to an instance 
> object needs to be done inside an instance method, either __init__() or 
> some other method with a self parameter.


What you say would normally make sense, but it's Django and it works that
way here. See:
http://docs.djangoproject.com/en/dev/topics/db/models/#fields


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


Re: [Python-Dev] PEP 382: Namespace Packages

2009-04-03 Thread Martin v. Löwis
> I'd like to extend the proposal to Python 2.7 and later.

I don't object, but I also don't want to propose this, so
I added it to the discussion.

My (and perhaps other people's) concern is that 2.7 might
well be the last release of the 2.x series. If so, adding
this feature to it would make 2.7 an odd special case for
users and providers of third party tools.

> That's going to slow down Python package detection a lot - you'd
> replace an O(1) test with an O(n) scan.

I question that claim. In traditional Unix systems, the file system
driver performs a linear search of the directory, so it's rather
O(n)-in-kernel vs. O(n)-in-Python. Even for advanced file systems,
you need at least O(log n) to determine whether a specific file is
in a directory. For all practical purposes, the package directory
will fit in a single disk block (containing a single .pkg file, and
one or few subpackages), making listdir complete as fast as stat.

> Wouldn't it be better to stick with a simpler approach and look for
> "__pkg__.py" files to detect namespace packages using that O(1) check ?

Again - this wouldn't be O(1). More importantly, it breaks system
packages, which now again have to deal with the conflicting file names
if they want to install all portions into a single location.

> This would also avoid any issues you'd otherwise run into if you want
> to maintain this scheme in an importer that doesn't have access to a list
> of files in a package directory, but is well capable for the checking
> the existence of a file.

Do you have a specific mechanism in mind?

Regards,
Martin

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


Re: Hash of None varies per-machine

2009-04-03 Thread Christian Heimes
Paul Rubin wrote:
> Yes, hashes are 32 bit numbers and there are far more than 2**32
> possible Python values (think of long ints), so obviously there must
> be multiple values that hash to the same slot.

No, hashs are C longs. On most 64bit platforms a C long has 64bits. As
far as I know only 64bit Windows has a 32bit long type.

> If the docs say this shouldn't happen, then it's a bug.  Otherwise,
> it should probably be considered ok.

Can you show me the exact place in the docs? The NoneType code uses
_Py_HashPointer which returns the address of the PyObject* as hash. The
value may vary between platforms and compilers.

> Yes, anything that can be used as a dict key (basically all immutable
> values with equality comparison) should be hashable.

The __eq__ equality method is not related to the hash functions. But
__eq__ is very import to resolve hash collisions.

Christian

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


Re: with open('com1', 'r') as f:

2009-04-03 Thread Christian Heimes
gert wrote:
> I do understand, and I went looking into pySerial, but it is a long
> way from getting compatible with python3.x and involves other libs
> that are big and non pyhton3.x compatible.

So don't use Python 3.0. Most people are still using Python 2.5 or 2.6.

Christian

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


Re: [Python-Dev] PEP 382: Namespace Packages

2009-04-03 Thread Martin v. Löwis
> Note that there is no such thing as a "defining namespace package" --
> namespace package contents are symmetrical peers.

With the PEP, a "defining package" becomes possible - at most one
portion can define an __init__.py.

I know that the current mechanisms don't support it, and it might
not be useful in general, but now there is a clean way of doing it,
so I wouldn't exclude it. Distribution-wise, all distributions
relying on the defining package would need to require (or
install_require, or depend on) it.

> The above are also true for using only a '*' in .pkg files -- in that
> event there are no sys.path changes.  (Frankly, I'm doubtful that
> anybody is using extend_path and .pkg files to begin with, so I'd be
> fine with a proposal that instead used something like '.nsp' files that
> didn't even need to be opened and read -- which would let the directory
> scan stop at the first .nsp file found.

That would work for me as well. Nobody at PyCon could remember where
.pkg files came from.

> I believe the PEP does this as well, IIUC.

Correct.

>> * It's possible to have a defining package dir and add-one package
>> dirs.
> 
> Also possible in the PEP, although the __init__.py must be in the first
> such directory on sys.path.

I should make it clear that this is not the case. I envision it to work
this way: import zope
- searches sys.path, until finding either a directory zope, or a file
  zope.{py,pyc,pyd,...}
- if it is a directory, it checks for .pkg files. If it finds any,
  it processes them, extending __path__.
- it *then* checks for __init__.py, taking the first hit anywhere
  on __path__ (just like any module import would)
- if no .pkg was found, nor an __init__.py, it proceeds with the next
  sys.path item (skipping the directory entirely)

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


Re: Best way to pickle functions

2009-04-03 Thread Aaron Scott
> Why not use import ?  Simply recreate the source file, if necessary, and
> import it again.
>

Ah, you'd think it would be that easy :P

The problem with just importing a module is that the module is then
cached in memory. Multiple copies of the program are running on a
server, and each of them have something akin to a "randomfunctions"
module. When the first program is accessed, it loads
"randomfunctions". When the second program is accessed, it uses the
"randomfunctions" module already in memory, even though it doesn't
contain the right functions. So, I have to pull in these functions
dynamically.
--
http://mail.python.org/mailman/listinfo/python-list


Re: is there a way to collect twitts with python?

2009-04-03 Thread Michael Torrie
'2+ wrote:
> i found a guy twittin supercollider code
> this means his followers can listen to a noiz by activating that 1 line
> (well if he has sc installed)
> if lots of sc users start twittin ... it would be no good to follow each
> 
> collecting a sc related twitt can be done with python?
> if there's a lib already any good pointers to start learnin thangs at?
> 
> maybe someday
> jython or pyjamas can be used to launch a
> sctwitt strreaming radio?
> (this should be the one listeners can mix his favorite sctwittists)

Oh wow.  If this is what Twitter does to one's ability to articulate
clearly, I hope Twitter dies a horrible death and any APIs and Python
bindings with it!
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] PEP 382: Namespace Packages

2009-04-03 Thread glyph

On 08:15 pm, [email protected] wrote:

Note that there is no such thing as a "defining namespace package" --
namespace package contents are symmetrical peers.


With the PEP, a "defining package" becomes possible - at most one
portion can define an __init__.py.


For what it's worth, this is a _super_ useful feature for Twisted.  We 
have one "defining package" for the "twisted" package (twisted core) and 
then a bunch of other things which want to put things into twisted.* 
(twisted.web, twisted.conch, et. al.).


For debian we already have separate packages, but such a definition of 
namespace packages would allow us to actually have things separated out 
on the cheeseshop as well.

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


SFTP libraries in pure Python?

2009-04-03 Thread hirudo #1







Hi, I am looking for SFTP libraries that are written in pure Python. I already 
checked out paramiko, but as far as I can see, it requires pycrypto, which is 
not pure Python. Another candidate, Twisted, isn't pure Python either. I don't 
really care about speed as much as about portability.

I'm hoping for some pointers here.

-Peter-


_
What can you do with the new Windows Live? Find out
http://www.microsoft.com/windows/windowslive/default.aspx--
http://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] PEP 382: Namespace Packages

2009-04-03 Thread P.J. Eby

At 10:15 PM 4/3/2009 +0200, Martin v. Löwis wrote:

I should make it clear that this is not the case. I envision it to work
this way: import zope
- searches sys.path, until finding either a directory zope, or a file
  zope.{py,pyc,pyd,...}
- if it is a directory, it checks for .pkg files. If it finds any,
  it processes them, extending __path__.
- it *then* checks for __init__.py, taking the first hit anywhere
  on __path__ (just like any module import would)
- if no .pkg was found, nor an __init__.py, it proceeds with the next
  sys.path item (skipping the directory entirely)


Ah, I missed that.  Maybe the above should be added to the PEP to clarify.

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


Module caching

2009-04-03 Thread Aaron Scott
Is there a way to make a Python app running in mod_python with zero
persistence? I have an app that should be resetting its variables
every time you access it, but sometimes -- and only sometimes -- the
variables persist through a couple refreshes. They'll even persist
through multiple browsers, so I know it's a Python issue and not a
browser caching issue.

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


Re: IIS python web application mapping issue - resolved

2009-04-03 Thread davidj411
I thought i was being clever but not only did i typo , but it does not
work with the "-u" for unbuffered option.

remove the "-u" to avoid the ugly message:

CGI Error
The specified CGI application misbehaved by not returning a complete
set of HTTP headers.

I am going to use the CGI script to upload files (.exe and .zip files)
and had read that "-u" would be needed.

i am going to need to research how this is done now that "-u" is a
known issue with IIS.
i think that i will need to baseencode64 the data before writing it to
a file. not sure really...
any thoughts are appreciated.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python needs leaning stuff from other language

2009-04-03 Thread Tim Wintle
On Fri, 2009-04-03 at 13:12 -0400, Mel wrote:
> >>> I think it would also be better to have One (and prefereably Only One)
> >>> Obvious Way To Do It. That obvious way, for those who work with
> >>> Python's ‘set’ and ‘dict’, is a ‘clear’ method. It seems best to have
> >>> ‘list’ conform with this also.
> >> 
> >> Does that mean a one-off special case rule to forbid slices having a
> >> default?
> > 
> > Why would it do that?
> 
> Well, if list.clear were truly and strictly to be the only way to clear the 
> contents of a list, then assigning nothing via the default slice would have 
> to be ruled out.  `somelist[:] = []` is just a special case of assignment to 
> a slice generally.

agreed. If .clear was to be added then really assignments to slices
should be entirely removed. 

Tim W

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


Let-expressions

2009-04-03 Thread sloisel
Dear All,

I searched this group and found that there have been discussions about
introducing a let expression to the language so that you can define
local variables in a lambda. I.e., something like f=lambda x: let
y=x^2 in sin(y). (My syntax is unpythonic, but I hope you get it).

Can someone tell me what eventually happened?

Thanks,

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


Re: Module caching

2009-04-03 Thread Aaron Scott
Okay, I'm at my wit's end. I have a Python app, running via
mod_python. There are variables in this app that, when changed, save
their changes to a pickled file tied to a session ID. Then, when the
page is accessed again, the variables are loaded from the respective
file.

But, when one user uses the page and a number of variables are
changed, these changes persist, even if I try to load the saved values
over them. So, if my Python file has a value of "5", the "custom
values" file has a value of "10", but a user does something that
changes the variable to "20", the next user who accesses the page with
see the value as "20", even if their "custom values" file tries to set
it differently.

If anyone has experience with mod_python, either drop me a message
here or e-mail me at aaron(at)manlab.com. I'd really appreciate some
help with this.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Module caching

2009-04-03 Thread Aaron Scott
Huzzah, another post.

I just discovered that even physically deleting the variable doesn't
work.

The module storylab.game has the class InitGame, which contains
"daemons = {}".

A user runs the code, resulting in some values in "daemons":
"{'berry2': , 'berry3': , 'berry1': }". These are pickled.

The next user runs the code. I put this in to make sure "daemons" is
getting reset:

req.write(str(lab.game.settings.daemons))
del lab.game.settings
req.write(str(lab.game.settings.daemons))
lab.game.settings = lab.game.InitGame()
req.write(str(lab.game.settings.daemons))

Okay, that should wipe out any of the values and leave us with a clean
slate, right?

{'berry2': , 'berry3': , 'berry1': }failed{'berry2': , 'berry3': ,
'berry1': }

Oh, you'd be so lucky.

Why? WHY? Why does these values persist? They persist if I change
them, they persist if I delete them.

Help... please :(
--
http://mail.python.org/mailman/listinfo/python-list


Re: Module caching

2009-04-03 Thread andrew cooke

are you an experienced python programmer?

a lot of newbies post here with problems related to unexpected results
because they make "the usual" mistakes about list mutability and default
function arguments.

i suspect that's not the case here, but it seemed worth mentioning, just
in case.

andrew


Aaron Scott wrote:
> Huzzah, another post.
>
> I just discovered that even physically deleting the variable doesn't
> work.
>
> The module storylab.game has the class InitGame, which contains
> "daemons = {}".
>
> A user runs the code, resulting in some values in "daemons":
> "{'berry2': , 'berry3': , 'berry1': }". These are pickled.
>
> The next user runs the code. I put this in to make sure "daemons" is
> getting reset:
>
>   req.write(str(lab.game.settings.daemons))
>   del lab.game.settings
>   req.write(str(lab.game.settings.daemons))
>   lab.game.settings = lab.game.InitGame()
>   req.write(str(lab.game.settings.daemons))
>
> Okay, that should wipe out any of the values and leave us with a clean
> slate, right?
>
>   {'berry2': , 'berry3': , 'berry1': }failed{'berry2': , 'berry3': ,
> 'berry1': }
>
> Oh, you'd be so lucky.
>
> Why? WHY? Why does these values persist? They persist if I change
> them, they persist if I delete them.
>
> Help... please :(
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


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


Re: Class methods read-only by default?

2009-04-03 Thread Piet van Oostrum
> "Emanuele D'Arrigo"  (ED) wrote:

>ED> Hi Everybody!
>ED> I just tried this:

> class C(object):
>ED> ...def method(self):
>ED> ...pass
>ED> ...
> c = C()
> delattr(c, "method")

>ED> Traceback (most recent call last):
>ED>   File "", line 1, in 
>ED> AttributeError: 'C' object attribute 'method' is read-only

>ED> How come? Who told the class to make the method read-only? I didn't!

Methods in a class are done with the descriptor protocol. All access to
the method through an instance is executed via the descriptor. The
delete calls the __delete__ method of the descriptor which isn't
implemented for functions. See
http://docs.python.org/reference/datamodel.html?highlight=descriptor#implementing-descriptors
(Actually, IIRC, the function object is its own descriptor)

>>> class C(object):
...   def method(self):
... pass
... 
>>> c=C()
>>> C.__dict__['method']

>>> C.__dict__['method'].__get__

>>> C.__dict__['method'].__delete__
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'function' object has no attribute '__delete__'
>>> 

-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: [email protected]
--
http://mail.python.org/mailman/listinfo/python-list


Re: python needs leaning stuff from other language

2009-04-03 Thread MRAB

Tim Wintle wrote:

On Fri, 2009-04-03 at 13:12 -0400, Mel wrote:

I think it would also be better to have One (and prefereably Only One)
Obvious Way To Do It. That obvious way, for those who work with
Python's ‘set’ and ‘dict’, is a ‘clear’ method. It seems best to have
‘list’ conform with this also.

Does that mean a one-off special case rule to forbid slices having a
default?

Why would it do that?
Well, if list.clear were truly and strictly to be the only way to clear the 
contents of a list, then assigning nothing via the default slice would have 
to be ruled out.  `somelist[:] = []` is just a special case of assignment to 
a slice generally.


agreed. If .clear was to be added then really assignments to slices
should be entirely removed. 


Should we also remove .update from dict?

I see no problem in collections having a .clear method. Saying that "if
c is a collection then c.clear() clears that collection" seems to be a
very duck-typy(?) thing to me.

Assignments to slices is just a feature of ordered collections (well,
lists), and clearing a list by assigning an empty list is just a special
case of that.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Goes Mercurial

2009-04-03 Thread Lawrence D'Oliveiro
In message <[email protected]>, "Martin v. Löwis" 
wrote:

> I don't like git because it is too difficult for me. In many cases,
> git would refuse to do operations like updating or local committing,
> producing error messages I was not able to understand ...

Post an example of what you were trying to do, with the exact messages, and 
we can walk you through it.

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


Re: with open('com1', 'r') as f:

2009-04-03 Thread Lawrence D'Oliveiro
In message <8bc55c05-19da-41c4-
[email protected]>, gert wrote:

> with open('com1', 'r') as f:
> for line in f:
>  print('line')

Why bother, why not just

for line in open('com1', 'r') :
print line


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


Re: Module caching

2009-04-03 Thread Aaron Scott
> are you an experienced python programmer?
>

Yeah, I'd link to think I'm fairly experienced and not making any
stupid mistakes. That said, I'm fairly new to working with mod_python.

All I really want is to have mod_python stop caching variables. This
seems like it should be easy enough to do, but I can't for the life of
me find information on how to do it.

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


Re: Unix programmers and Idle

2009-04-03 Thread MRAB

Dale Amon wrote:

On Mon, Mar 30, 2009 at 08:11:10PM -0500, Dave Angel wrote:
I don't know what Idle has to do with it.  sys.args contains the command  
line arguments used to start a script.


Dale Amon wrote:
I wonder if someone could point me at documentation on how to debug 
some of the standard Unix type things

in Idle. I cannot seem to figure out how to set my
argument line for the program I am debugging in an Idle
window. for example:

vlmdeckcheck.py --strict --debug file.dat

There must be a way to tell it what the command line args
are for the test run but I can't find it so far.



The line above represent what I want to emulate within idle.
If you run idle, select File->Open; then select the program name
as above to open; select Debug->Debugger; then start the program
with F5... which is lovely but I cannot find a way to tell idle
what the args are.

idle is really nice but I am stuck doing my debugging in pdb
because of this.


FYI I've just submitted a patch which adds a dialog for entering
command-line arguments in IDLE (issue #5680).
--
http://mail.python.org/mailman/listinfo/python-list


Re: python needs leaning stuff from other language

2009-04-03 Thread Ben Finney
Mel  writes:

> Well, if list.clear were truly and strictly to be the only way to
> clear the contents of a list

Who ever suggested that?

Note that the “OOW” in OOWTDI does *not* mean “Only One Way”. It
means “One Obvious Way”. Having other Ways To Do It is only mildly
deprecated, not forbidden.

-- 
 \   “It ain't so much the things we don't know that get us in |
  `\trouble. It's the things we know that ain't so.” —Artemus Ward |
_o__)   (1834-67), U.S. journalist |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Goes Mercurial

2009-04-03 Thread Ben Finney
Lawrence D'Oliveiro  writes:

> In message <[email protected]>, "Martin v. Löwis" 
> wrote:
> 
> > I don't like git because it is too difficult for me. In many
> > cases, git would refuse to do operations like updating or local
> > committing, producing error messages I was not able to understand
> > ...
> 
> Post an example of what you were trying to do, with the exact
> messages, and we can walk you through it.

No, please, not in this forum. It would be quite off-topic, and Git
has its own discussion forums; please use those.

-- 
 \   Eccles: “I just saw the Earth through the clouds!”  Lew: “Did |
  `\  it look round?”  Eccles: “Yes, but I don't think it saw me.” |
_o__)—The Goon Show, _Wings Over Dagenham_ |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: Let-expressions

2009-04-03 Thread Terry Reedy

sloisel wrote:

Dear All,

I searched this group and found that there have been discussions about
introducing a let expression to the language so that you can define
local variables in a lambda. I.e., something like f=lambda x: let
y=x^2 in sin(y). (My syntax is unpythonic, but I hope you get it).

Can someone tell me what eventually happened?


The discussions ended.
Proposals for assignment expressions have been rejected.

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


Re: python needs leaning stuff from other language

2009-04-03 Thread Robert Kern

On 2009-04-03 16:42, Tim Wintle wrote:

On Fri, 2009-04-03 at 13:12 -0400, Mel wrote:

I think it would also be better to have One (and prefereably Only One)
Obvious Way To Do It. That obvious way, for those who work with
Python's ‘set’ and ‘dict’, is a ‘clear’ method. It seems best to have
‘list’ conform with this also.

Does that mean a one-off special case rule to forbid slices having a
default?

Why would it do that?

Well, if list.clear were truly and strictly to be the only way to clear the
contents of a list, then assigning nothing via the default slice would have
to be ruled out.  `somelist[:] = []` is just a special case of assignment to
a slice generally.


agreed. If .clear was to be added then really assignments to slices
should be entirely removed.


Please tell me you are joking.

--
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


  1   2   >