ANN: easygconf 0.02

2009-11-16 Thread Florian Diesch


I'm happy to announce easygconf 0.02.
Get it at http://www.florian-diesch.de/software/easygconf


easygconf provids an easy, pythonic way to access GConf
through a dict-like interface.

Example
---

from easygconf import GConfDict
import gtk


key = 'test
gc=GConfDict('/apps/easygconftest')

print %s is %s%(key, gc[key])
gc[key] = 'foo'
print Now %s is %s%(key, gc[key])
 
def callback (key, value, gconfdict, id, args):
print %s changed to %s%(key, value)

gc.add_listner('test', callback)
try:
gtk.main()
except KeyboardInterrupt:
pass
gc.unset('test')




   Florian
-- 
http://www.florian-diesch.de/
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Elixir 0.7.1 released

2009-11-16 Thread Gaetan de Menten
I am very pleased to announce that version 0.7.1 of Elixir
(http://elixir.ematia.de) is now
available. As always, feedback is very welcome, preferably on Elixir
mailing list.

This release packs a few interesting new features (abstract classes
and a new collection
type providing explicit relative resolution of target entities) and
some bug fixes. It is a safe
upgrade from the 0.7.0 release.

The full list of changes can be seen at:
http://elixir.ematia.de/trac/browser/elixir/tags/0.7.1/CHANGES

What is Elixir?
-

Elixir is a declarative layer on top of the SQLAlchemy library. It is
a fairly thin wrapper, which provides the ability to create simple
Python classes that map directly to relational database tables (this
pattern is often referred to as the Active Record design pattern),
providing many of the benefits of traditional databases without losing
the convenience of Python objects.

Elixir does not intend to replace SQLAlchemy's core features, and
instead focuses on providing a simpler syntax for defining model
objects when you do not need the full expressiveness of
SQLAlchemy's manual mapper definitions.

Mailing list


http://groups.google.com/group/sqlelixir/about

-- 
Gaëtan de Menten
http://openhex.org
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: python simply not scaleable enough for google?

2009-11-16 Thread sturlamolden
On 14 Nov, 02:42, Robert Brown bbr...@speakeasy.net wrote:

 If you want to know why Python *the language* is slow, look at the Lisp code
 CLPython generates and at the code implementing the run time.  Simple
 operations end up being very expensive.

You can also see this by looking at the C that Cython or Pyrex
generates.

You can also see the dramatic effect by a handful of strategically
placed type declarations.


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


The ol' [[]] * 500 bug...

2009-11-16 Thread kj



...just bit me in the fuzzy posterior.  The best I can come up with
is the hideous

  lol = [[] for _ in xrange(500)]

Is there something better?  What did one do before comprehensions
were available?  I suppose in that case one would have to go all
the way with

  lol = [None] * 500
  for i in xrange(len(lol)):
  lol[i] = []

Yikes.  10 miles uphill, both ways...

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


Re: The ol' [[]] * 500 bug...

2009-11-16 Thread kj
In 6e20a31b-2218-49c5-a32c-5f0147db3...@k19g2000yqc.googlegroups.com Jon 
Clements jon...@googlemail.com writes:

 lol =3D map(lambda L: [], xrange(5))
 [id(i) for i in lol]
[167614956, 167605004, 167738060, 167737996, 167613036]

Oh yeah, map!  I'd forgotten all about it.  Thanks!

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


Re: A terminators' club for clp

2009-11-16 Thread kj

In 7x3a4i56u7@ruckus.brouhaha.com Paul Rubin 
http://phr...@nospam.invalid writes:

kj no.em...@please.post writes:
 frequent* clp posters the ability to *easily* delete spam from the
 comp.lang.python server?

Um, this is usenet; there is no comp.lang.python server.  Are you
saying you want a moderated newsgroup?  Hmm, maybe this group is busy
enough that there is some merit to that idea.

Sorry, I had a mistaken view of how usenet was implemented.  But
yeah, I guess I'm thinking of a moderated newsgroup, but with a
large number of moderators working in parallel, and a very lax
acceptance policy.  The goal is to filter out only the obvious
spam, and let through all the other non-spam traffic as quickly as
possible...  What do I mean by obvious spam?  Well, among the
most recent messages (that have survived my killfile policies) I
see the following subject lines:

* Top 10 US mp3 songs.Cheers
* www.find68.com cheaper nike shoes g-satr kidrobot hoodies ed hardy star red 
monkey gino green global true religion ed-hardy kidrobot jeans hoodies china 
supplier wholesaler exporters,manufacture
* jobs in france jobs in france for english people jobs in france for 
foreigners jobs in france for australians jobs in france for foreigners  
jobs in france for new zealanders jobs paris jobs http://jobs-in-fr 
ance.blogspot.com/
* germany jobs germany job sites germany job search jobs in germany 
german jobs germany jobs it germany jobs for foreigners germany jobsite 
germany jobs in english on http://jobs-germany.blogspot.com/

Those look pretty obvious to me.

But, as I already showed, I'm out of my depth here,
so I'd better shut up.

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


Re: Python Go

2009-11-16 Thread Terry Reedy

Simon Forman wrote:

On Sat, Nov 14, 2009 at 5:10 PM, Terry Reedy tjre...@udel.edu wrote:

Paul Rubin wrote:


Mark Chu-Carroll has a new post about Go:


 http://scienceblogs.com/goodmath/2009/11/the_go_i_forgot_concurrency_an.php

In a couple of minutes, I wrote his toy prime filter example in Python,
mostly from the text rather than the code, which I can barely stand to read.
It ran the first time without error.

def plurals():
 i = 2
 while True:
   yield i
   i += 1

def primefilter(src, prime):
 for i in src:
   if i % prime:
 yield i

src = plurals()
while True:
 i = next(src)
 print(i)
 src = primefilter(src, i)

As I commented there
It stopped at 7877 when it hit the default recursion limit of 1000, which
could easily be increased to get out-of-memory error instead.

I think Google is making a blunder if it moves to another old-fashioned
language whose code is bloated with junky boilerplate that doubles the size.
It would be much better, for instance, to tweak Python, which it has had
great success with, to better run on multiple cores.

Terry Jan Reedy


FWIW,

def plurals():
 i = 3
 while True:
   yield i
   i += 2


Of course, in fact, I thought of at the time

def plurals():
  i = 6
  while True:
yield i-1
yield i+1
i += 6

5,7, 11,13, 17,19, 23,(25-first miss), 29,31, (35-2nd miss),37, 41,43, 
47,(49 erd)...Reduced the base cases by another 1/3. I *think* without 
measuring, that that compensates for the extra -1,+1. But I was 
implementing *Mark's* toy example, and first posted it on his blog, so I 
copied his naive version.


Even better, to avoid extra -1, +1

def plurals():
  yield 2
  yield 3
  i = 5
  while True:
yield i
i += 2
yield i
i += 4

Of course, testing with primes greater that square root(candidate) is 
wasteful, and recusion should be converted to iteration to avoid 
recursion limit.


Terry Jan Reedy

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


Re: IDE for python

2009-11-16 Thread Jonathan Hartley
On Nov 16, 5:09 am, sturlamolden sturlamol...@yahoo.no wrote:
 On 15 Nov, 18:09, Peng Yu pengyu...@gmail.com wrote:

  There had been some discussion on IDE. But I'm not sure what pros and
  cons of each choice. Current, I'm using vim and ctags.

  Could somebody give some advices on choosing the best IDE for me?

 There is a plug-in to develop (amd debug) Python using MS Visual
 Studio. It works with IronPython and CPython.

 There is the PyDev plug-in for Eclipse.

 There is Komodo from ActiveState.

 There is KDevelop in KDE4.

 Which is better? I don't know.

 My impression is that Python development does noe need an IDE like
 e.g. C++ development do. There is no build process, which takes the
 major advantage of the IDE away. I am fine with a editor like IDLE or
 Kate.


I'd like to offer the group the anecdote of the great Resolver IDE
migration.

Developers at Resolver, where I work, choose their own IDE. Being
developers, that meant every single person chose a different one. We
had them all. Which turned out, slightly unexpectedly, to be just
fine.

We pair on all production code. So this meant we all spent a lot of
time sitting at each other's desks. We soon all became pretty familiar
with each other's environments - there's nothing like 8 hours a day of
hands-on usage, coupled with sitting right next to a bone-fide expert
to get you up to speed pretty quick. I even learned a little Emacs,
holy cow!

Occasionally, after seeing the details of how well some other IDE
worked, developers would switch from one to another.

Then, after about a year, a curious thing happened. One by one, in
entirely independent decisions, almost all developers decided to
migrate to either Emacs or Vi.*

Each person decided that the fancy features of their IDE wasn't as
useful to them as having a flexible, powerful and lightweight editor
which can easily be scripted to provide whatever ad-hoc features they
need.

I regard this as an example of the way pairing spreads knowledge.

* I say 'most developers' - there were two notable exceptions: Michael
Foord, who's prodigious contributions are legend, who likes Wing, and
Will Reade, our tame brainiac, responsible for the exceedingly clever
'IronClad' open-source project, who likes the uncomplicated simplicity
of TextPad.

As far as I can make out, TextPad has only two features, syntax
highlighting and the ability to define a 'make' command, and a regex
that is used to extract filenames and line-numbers from the resulting
output of that make command. These are, it turns out, sufficient to
transform a program that would otherwise simply be 'Notepad' into an
entirely credible development environment.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Go

2009-11-16 Thread Terry Reedy

sturlamolden wrote:

On 14 Nov, 23:10, Terry Reedy tjre...@udel.edu wrote:


It would be much better, for instance, to tweak Python, which it
has had great success with, to better run on multiple cores.


Python run well on multiple cores, you just have to use processes
instead of threads.


But not so trivially as to add one word to an existing function.
Hence by tweak, I meant, as explained in another post, to add a keyword 
or just a decorator that will do what the go keyword does in go.


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


C api question and determining PyObject type

2009-11-16 Thread lallous

Hello

I have an a class defined as:

   class __object(object):
   pass

Now, I call a C function that takes a PyObject* and checks its type:

if (PyString_Check(obj)) ...
if (PySequence_Check(obj)) 

Before doing the check, I print the passed object with PyObject_Str() and 
get:


passed object: __main__.__object object at 0x040E4050

However, the C code returns true on the:
if (PySequence_Check(obj)) 


Why? That is not a sequence?

Please advise.

--
Elias 


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


python gui builders

2009-11-16 Thread me

Good People

I do not write stuff for humans, as it has been my job to remove 
humans from the loop. But I have to make a front end to a 
component database where everything was built in Python.


I have looked at the Tk stuff that is built into Python - not 
acceptable. So looking at wxGlade, Boa Constructor, Python Card. 
Also looked at the frames/forms created with QtDesigner, which 
can be used by Python via pyuic. BlackAdder IDE seems to have 
this built-in, but am loathe to buy into another GUI tool for a 
single job.


I have not been able to find a decent Python gui builder. The 
last time I did gui garbage was with Borland C++ Builder which 
was ok because I was only using win boxen for that project. This 
time I am using both Linux and Win.


What Python gui builder is well supported, does not require me 
to learn another framework/library, and can crank out stuff for 
multiple platforms ?


thanks much,
me
--
http://mail.python.org/mailman/listinfo/python-list


Re: IDE for python

2009-11-16 Thread sturlamolden
On 16 Nov, 10:05, Jonathan Hartley tart...@tartley.com wrote:

 As far as I can make out, TextPad has only two features, syntax
 highlighting and the ability to define a 'make' command, and a regex
 that is used to extract filenames and line-numbers from the resulting
 output of that make command. These are, it turns out, sufficient to
 transform a program that would otherwise simply be 'Notepad' into an
 entirely credible development environment.

When working with Java or C++ I like and IDE like KDevelop because it
makes makefiles for me. And when debugging it is easier to insert
break points graphically than use gdb from the terminal.

But apart from that, I prefer a tiny editor like Kate (yes I know,
call me a heretic for not using emacs).






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


Re: overriding __getitem__ for a subclass of dict

2009-11-16 Thread Carl Banks
On Nov 15, 2:52 pm, Steve Howell showel...@yahoo.com wrote:
 Does anybody have any links that points to the rationale for ignoring
 instance definitions of __getitem__ when new-style classes are
 involved?  I assume it has something to do with performance or
 protecting us from our own mistakes?


Not important enough to justify complexity of implementation.

I doubt they would have left if out of new-style classes if it had
been straightforward to implement (if for no other reason than to
retain backwards compatibility), but it wasn't.  The way attribute
lookups work meant it would have required all kinds of double lookups
and edge cases.  Some regarded it as dubious to begin with.  And it's
easily worked around by simply having __getitem__ call another method,
as you've seen.  Given all this it made better sense to just leave it
out of new-style classes.

Unfortunately not all such decisions and justifications are collected
in a tidy place.


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


Re: python gui builders

2009-11-16 Thread sturlamolden
On 16 Nov, 11:06, me not_h...@nowhere.com wrote:

 What Python gui builder is well supported, does not require me
 to learn another framework/library, and can crank out stuff for
 multiple platforms ?

I use wxFormBuilder. The 3.1 beta can even create wxPython code, but
it still has some minor issues (e.g. not always creating correct code
due to missing self.).

wxFormBuilder 3.0 can create XRC files, which work excellently with
wxPython. The drawback is that you must bind event handlers manually,
instead of having it done automatically (as you can with Python code
generation in 3.1 beta).

If you are fine with GPL, or can afford the commercial license, there
is QtDesigner which works with PyQt. This is a fantastic cross-
platform GUI tool, if not hte best there is.

If you are fine with Microsoft only, you can use Windows Forms with MS
Visual Studio and IronPython.

If you can use Jython, there are many tools for working with Java
Swing or SWT.







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


Re: IDE for python

2009-11-16 Thread Carl Banks
On Nov 16, 1:05 am, Jonathan Hartley tart...@tartley.com wrote:
 Then, after about a year, a curious thing happened. One by one, in
 entirely independent decisions, almost all developers decided to
 migrate to either Emacs or Vi.*

 Each person decided that the fancy features of their IDE wasn't as
 useful to them as having a flexible, powerful and lightweight editor
 which can easily be scripted to provide whatever ad-hoc features they
 need.

 I regard this as an example of the way pairing spreads knowledge.

That's the best justification for pair programming I've seen yet.


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


Re: python gui builders

2009-11-16 Thread sturlamolden
On 16 Nov, 11:39, sturlamolden sturlamol...@yahoo.no wrote:

 If you are fine with Microsoft only, you can use Windows Forms with MS
 Visual Studio and IronPython.

I also forgot to mention:

If you can restrict yourself to Windows, you can always use Visual
Basic or Borland Delphi with pywin32. Either expose your GUI as an
ActiveX to pywin32 (you have e.g. an MFC binding) or expose your
Python as an ActiveX to VB/Delphi. The same approach should work (with
a little bit more work) for C# and VB.NET.





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


Re: C api question and determining PyObject type

2009-11-16 Thread lallous

Actually, the object class is defined as:
   class __object(object):
   def __getitem__(self, idx):
   return getattr(self, idx)

Anyway, now I check like this:

bool PyIsSequenceType(PyObject *obj)
{
 if (!PySequence_Check(obj))
   return false;
 Py_ssize_t sz = PySequence_Size(obj);
 if (sz == -1 || PyErr_Occurred() != NULL)
 {
   PyErr_Clear();
   return false;
 }
 return true;
}

I don't like it, any other suggestions?

--
Elias
lallous lall...@lgwm.org wrote in message news:hdr80a$vs...@aioe.org...

Hello

I have an a class defined as:

   class __object(object):
   pass

Now, I call a C function that takes a PyObject* and checks its type:

if (PyString_Check(obj)) ...
if (PySequence_Check(obj)) 

Before doing the check, I print the passed object with PyObject_Str() and 
get:


passed object: __main__.__object object at 0x040E4050

However, the C code returns true on the:
if (PySequence_Check(obj)) 


Why? That is not a sequence?



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


Re: Python Go

2009-11-16 Thread sturlamolden
On 16 Nov, 10:06, Terry Reedy tjre...@udel.edu wrote:

  Python run well on multiple cores, you just have to use processes
  instead of threads.

 But not so trivially as to add one word to an existing function.
 Hence by tweak, I meant, as explained in another post, to add a keyword
 or just a decorator that will do what the go keyword does in go.

A decorator function like @go could just call os.fork and run the
function in the child. We already have a between-process Queue in
multiprocessing to use as channels.

Or we could have a context manager that forks in __enter__ and
waitpids or exits in __exit__. The body of the with-statement would
then be executed in the child process, the parent would just raise an
exception to skip directly to __exit__.

Not rocket science as all. Yes that would give us a new isolated
process, but such isolation is present in Erlang as well.

(Windows is more tricky though, as there is no efficent fork.)






























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


SCGIServer and unusal termination

2009-11-16 Thread Eden Kirin

Hi there,

I'm playing with SCGIServer 
(http://vmlinux.org/cgi-bin/dwww/usr/share/doc/python-scgi/guide.html), 
everything works just fine, but one thing bothers me. All prints after 
try-except block are executed twice after the Ctrl+C is pressed!


test.py:
#-
from scgi.scgi_server import SCGIServer

n = 0
print Starting server.

try:
SCGIServer().serve()
except (KeyboardInterrupt, SystemExit):
print Exception!

# print lines are executed twice (?!)
n += 1
print Terminating server, attempt %d. % n
n += 1
print Check n: %d. % n
#-

This is the output:

e...@sunce:~/data/project/ScgiServer/src python test.py
Starting server.
^CException!
Exception!
Terminating server, attempt 1.
Check n: 2.
Terminating server, attempt 1.
Check n: 2.
e...@sunce:~/data/project/ScgiServer/src


If I put something else in try-except block, code after is executed 
normally:


try:
while 1:
pass
except (KeyboardInterrupt, SystemExit):
print Exception!

e...@sunce:~/data/project/ScgiServer/src python test.py
Starting server.
^CException!
Terminating server, attempt 1.
Check n: 2.
e...@sunce:~/data/project/ScgiServer/src

Environment is 64bit Ubuntu with Python v2.6.4.

Is there some reasonable explanation for this behaviour? Thanks in advance.

--
www.vikendi.net -/- www.supergrupa.com
--
http://mail.python.org/mailman/listinfo/python-list


import subprocess in python

2009-11-16 Thread Kuhl
I am a Linux user beginning to learn Python now. Below is the first
Python script that I copied from the text book. It works, so it
confirmed that there is python installed in my system:

#!/usr/bin/env python

for a in [1, 2]:
for b in ['a', 'b']:
print a, b


But when I continue to learn Python, I come across with issue. The
text book instructed me to use ipython, but ipython command is not
found in my system, so I have to use python instead. However, import
subprocess still failed, see below.

# which python
/usr/bin/python
# which ipython
ipython: Command not found.
# python
Python 2.2.3 (#1, Feb  2 2005, 12:22:48)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2
Type help, copyright, credits or license for more information.
 import subprocess
Traceback (most recent call last):
  File stdin, line 1, in ?
ImportError: No module named subprocess


So I guess that there should be a file named subprocess.py somewhere.
But there are too many files on the huge disk, I don't know where I
should start to search for  it. Then I tried to key in a function
file  python_func_00.py  by myself.

def pyfunc():
print Hello function


# python
Python 2.2.3 (#1, Feb  2 2005, 12:22:48)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2
Type help, copyright, credits or license for more information.
 import python_func_00
 pyfunc()
Traceback (most recent call last):
  File stdin, line 1, in ?
NameError: name 'pyfunc' is not defined



There's a binary file of 240 bytes created:python_func_00.pyc
But as we can see above, the function pyfunc() does not work.

I guess that I should add the following statement at first line of
python_func_00.py, then redo the import:
#!/usr/bin/env python

But after adding this line and redoing the import, pyfunc() still
failed like above.

What's the mistake that I am making? How to solve it?

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


Re: import subprocess in python

2009-11-16 Thread sturlamolden
On 16 Nov, 13:50, Kuhl chen_zhi...@yahoo.com wrote:

 Python 2.2.3 (#1, Feb  2 2005, 12:22:48)

 What's the mistake that I am making? How to solve it?

Your Python version is too old.

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


Re: import subprocess in python

2009-11-16 Thread Chris Rebert
On Mon, Nov 16, 2009 at 4:50 AM, Kuhl chen_zhi...@yahoo.com wrote:
snip
 found in my system, so I have to use python instead. However, import
 subprocess still failed, see below.

 # which python
 /usr/bin/python
 # which ipython
 ipython: Command not found.
 # python
 Python 2.2.3 (#1, Feb  2 2005, 12:22:48)
 [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2
 Type help, copyright, credits or license for more information.
 import subprocess
 Traceback (most recent call last):
  File stdin, line 1, in ?
 ImportError: No module named subprocess


The `subprocess` modules was added in Python 2.4. You're using Python
2.2.3; you need to update.

 should start to search for  it. Then I tried to key in a function
 file  python_func_00.py  by myself.

 def pyfunc():
        print Hello function


 # python
 Python 2.2.3 (#1, Feb  2 2005, 12:22:48)
 [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-49)] on linux2
 Type help, copyright, credits or license for more information.
 import python_func_00
 pyfunc()
 Traceback (most recent call last):
  File stdin, line 1, in ?
 NameError: name 'pyfunc' is not defined
snip
 What's the mistake that I am making? How to solve it?

The `import foo` statement only adds the name of the module itself to
your namespace, so you need to refer to pyfunc by way of the module
name. To wit:

import python_func_00
python_func_00.pyfunc()

Alternatively, you can specify a set of names to import from the
module namespace into your own using the `from foo import bar` syntax:

from python_func_00 import pyfunc
pyfunc()


Regarding ipython, it's a third-party package that is not part of
Python itself and must be installed separately. Exactly how you do so
will obviously depend on which distro you're using.

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


Let python call a C function pointer passed from the C Python API

2009-11-16 Thread hvictor
I have C++ a void function pointer stored in a variable call. The
pointed function takes an int and a char* as arguments.

I have a python module containing this function:

def yeah(x):
x(int(0),text argument)
return pointer called

As you can see I'm trying to use the argument x of the function like a
method object.
In the C++ side I'm doing following (note that I only paste relevant
parts of code because this system is working fine, C++ is able to call
function yeah and get its return value, but only with a string-
oriented test):
...
PyObject *pValue; // the argument for python

pValue = PyCObject_FromVoidPtr(call,destr); // destr is a void fctn
ptr, required from the api.

PyObject *pFunc = PyObject_GetAttrString(pModule, yeah);

...
PyTuple_SetItem(pArgs, 0, pValue); // pArgs is a pyobject, the
arguments, I insert pValue in it.

pValue = PyObject_CallObject(pFunc, pArgs);

...

It does not work. can anyone help me please? I just want python to
call this function pointer.

Thank you


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


Re: Psyco on 64-bit machines

2009-11-16 Thread Robin Becker

Russ P. wrote:


I just stumbled across unladen swallow, a faster implementation of
Python. Is it ready for operational usage? How does it compare to
Psyco? I poked around their website a bit, but I don't see answers to
those questions. Thanks.


I've tried a few things with it. It mostly works, but it isn't actually faster 
at normal programs. I've been told their target is for long running processes 
where JIT and similar can speed up the inner loops etc etc. Certainly makes 
sense for google apps in python so perhaps that's the intended end use.

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


Re: Let python call a C function pointer passed from the C Python API

2009-11-16 Thread Carl Banks
On Nov 16, 5:04 am, hvictor hvic...@bluewin.ch wrote:
 I have C++ a void function pointer stored in a variable call. The
 pointed function takes an int and a char* as arguments.

 I have a python module containing this function:

 def yeah(x):
         x(int(0),text argument)
         return pointer called

 As you can see I'm trying to use the argument x of the function like a
 method object.
 In the C++ side I'm doing following (note that I only paste relevant
 parts of code because this system is working fine, C++ is able to call
 function yeah and get its return value, but only with a string-
 oriented test):
 ...
 PyObject *pValue; // the argument for python

 pValue = PyCObject_FromVoidPtr(call,destr); // destr is a void fctn
 ptr, required from the api.

 PyObject *pFunc = PyObject_GetAttrString(pModule, yeah);

 ...
 PyTuple_SetItem(pArgs, 0, pValue); // pArgs is a pyobject, the
 arguments, I insert pValue in it.

 pValue = PyObject_CallObject(pFunc, pArgs);

 ...

 It does not work. can anyone help me please? I just want python to
 call this function pointer.

Python can't call C function pointers.  You have to write a function
in C that accepts a CObject and some arguments, unpacks the arguments,
retrieves the function pointer from the CObject, and calls it.  Quick
and dirty function that might do that (untested, not robust).


static PyObject* call_user_void_ptr(PyObject* self, PyObject* args) {
PyObject* cobj;
int ival;
char* sval;
void (*func)(int,char*);
if (!PyArg_ParseTuple(O!is,PyCObject_Type,cobj,ival,sval))
return 0;
func = PyCObject_AsVoidPtr(cobj);
func(ival,sval);
Py_RETURN_NONE;
}


def yeah(x):
call_user_void_ptr(x,int(i),text_argument)
print pointer called


In a pinch, you could call the function pointer from ctypes.  Since
you're already writing a C extension I wouldn't recommend it as a
final solution, though.


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


Re: Let python call a C function pointer passed from the C Python API

2009-11-16 Thread sturlamolden
On 16 Nov, 14:25, Carl Banks pavlovevide...@gmail.com wrote:

 Python can't call C function pointers.  

Yes it can, use ctypes...





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


Re: object serialization as python scripts

2009-11-16 Thread J Kenneth King
King animator...@gmail.com writes:

 Why is it easier than the above mentioned - they are *there* (except the
 custom xml), and just can be used. What don't they do you want to do?

 Other than that, and even security issues put aside, I don't see much
 difference between pickle and python code, except the latter being more
 verbose. Which suits humans, but other than that has no advantage.

 Diez

 My application is PyQt based and objects that I am trying to save are
 couple of QGraphicsItem instances. You can't save instances of
 QGraphicsItem
 using pickle or shelve.
 Custom xml format would be a real pain as you have to write code for
 writing/reading both.

 I am aware of security issue but over all there are only 5 statements
 I have to use to get the entire
 information back. I can do syntax checking and other stuff before I
 should execute the script.

 Another reason is that data should be in human readable form.

 Prashant

 Python 2.6.2
 Win XP 32

Pickling should work just fine.  If you cannot pickle the class with the
default pickler, you can hook into the pickler protocol to tell pickle
how to pickle instances of the class.  Failing that you can write your
own pickler class for handling the special case.

Python scripts aren't really a good data format.  They're not structured
in a way that would be easy to parse and extract information from in a
non-python context without a lot of work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling Python functions from Excel

2009-11-16 Thread Darcy Mason
On Nov 15, 2:20 am, Cannonbiker lusve...@gmail.com wrote:

 Please I need Calling Python functions from Excel and receive result
 back in Excel. Can me somebody advise simplest solution please? I am
 more VBA programmer than Python.

A couple of years ago I used MSScriptControl for this. Couldn't find a
great reference just now, but here is a discussion which should give
enough information:
http://www.velocityreviews.com/forums/t319222-re-python-in-excel.html

Check from around message 3 on.
-- 
http://mail.python.org/mailman/listinfo/python-list


Logic operators with in statement

2009-11-16 Thread Mr.SpOOn
Hi,
I'm trying to use logical operators (or, and) with the in statement,
but I'm having some problems to understand their behavior.

In [1]: l = ['3', 'no3', 'b3']

In [2]: '3' in l
Out[2]: True

In [3]: '3' and '4' in l
Out[3]: False

In [4]: '3' and 'no3' in l
Out[4]: True

This seems to work as I expected.


In [5]: '3' and 'no3' or '3' and '4' in l
Out[5]: 'no3'

In [6]: ('3' and 'no3') or ('3' and '4') in l
Out[6]: 'no3'

I don't understand these outputs.
---

In [7]: (('3' and 'no3') or ('3' and '4')) in l
Out[7]: True

In [10]: (('b3' and '4') or ('3' and 'no3')) in l
Out[10]: False

Here I expected to get True in the second case too, so clearly I don't
really get how they work.

Can you help me?
What I really need is to create a sequence of if statements to check
the presence of elements in a list, because some of them are mutually
exclusive, so if for example there are both 3 and no3 it should
return an error.

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


Re: Code for finding the 1000th prime

2009-11-16 Thread mrholtsr
On Nov 15, 10:02 am, Diez B. Roggisch de...@nospam.web.de wrote:
 mrholtsr schrieb:

  I am absolutely new to python and barely past beginner in programming.
  Also I am not a mathematician. Can some one give me pointers for
  finding the 1000th. prime for a course I am taking over the internet
  on Introduction to Computer Science and Programming. Thanks, Ray

 Do you really think we are so retarded that we don't remember you posted
 the same question a week ago?

 Diez

Mea Culpa. I didn't realize at the time that this group was the same
as the newsletter. Won't do it again.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Psyco on 64-bit machines

2009-11-16 Thread Jeremy Sanders
Russ P. wrote:

 Would it make sense to compile Python in the 32-bit compatibility mode
 so I can use Psyco? What would I lose in that mode, if anything?
 Thanks.

You won't be able to access large amounts of memory in 32 bit mode. Also, 
the x86-64 mode has more CPU registers than x86 mode, so Python will 
typically run faster in 64 bit mode (this is more pronounced in AMD 
processors, in my experience).

It will depend on your application whether 32 bit mode plus Psyco is faster 
than 64 bit mode.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Newsgroup for beginners

2009-11-16 Thread mrholtsr
Is there a Python newsgroup for those who are strictly beginners at
programming and python?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Logic operators with in statement

2009-11-16 Thread Mr.SpOOn
Sorry for replying to myself, but I think I understood why I was wrong.

The correct statement should be something like this:

In [13]: ('b3' and '5') in l or ('3' and 'b3') in l
Out[13]: True
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code for finding the 1000th prime

2009-11-16 Thread sturlamolden
On 15 Nov, 15:30, mrholtsr mrhol...@gmail.com wrote:

 I am absolutely new to python and barely past beginner in programming.
 Also I am not a mathematician. Can some one give me pointers for
 finding the 1000th. prime for a course I am taking over the internet
 on Introduction to Computer Science and Programming. Thanks, Ray


print 7919



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


Re: Newsgroup for beginners

2009-11-16 Thread Diez B. Roggisch
mrholtsr wrote:

 Is there a Python newsgroup for those who are strictly beginners at
 programming and python?

Yes, the tutor-list. 

  http://mail.python.org/mailman/listinfo/tutor

Diez













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


Re: Logic operators with in statement

2009-11-16 Thread exarkun

On 02:02 pm, mr.spoo...@gmail.com wrote:

Hi,
I'm trying to use logical operators (or, and) with the in statement,
but I'm having some problems to understand their behavior.


and and or have no particular interaction with in.


In [1]: l = ['3', 'no3', 'b3']

In [2]: '3' in l
Out[2]: True

In [3]: '3' and '4' in l
Out[3]: False

In [4]: '3' and 'no3' in l
Out[4]: True

This seems to work as I expected.


What this actually does is '3' and ('no3' in l).  So it might have 
produced the result you expected, but it didn't work how you expected. 
:)


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


Re: Newsgroup for beginners

2009-11-16 Thread Chris Rebert
On Mon, Nov 16, 2009 at 6:01 AM, mrholtsr mrhol...@gmail.com wrote:
 Is there a Python newsgroup for those who are strictly beginners at
 programming and python?

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

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


Re: Logic operators with in statement

2009-11-16 Thread Chris Rebert
On Mon, Nov 16, 2009 at 6:02 AM, Mr.SpOOn mr.spoo...@gmail.com wrote:
 Hi,
 I'm trying to use logical operators (or, and) with the in statement,
 but I'm having some problems to understand their behavior.

 In [1]: l = ['3', 'no3', 'b3']

 In [2]: '3' in l
 Out[2]: True

 In [3]: '3' and '4' in l
 Out[3]: False

 In [4]: '3' and 'no3' in l
 Out[4]: True

 This seems to work as I expected.

No, it doesn't. You are misinterpreting. Membership tests via `in` do
NOT distribute over `and` and `or`.

'3' and '4' in l
is equivalent to:
('3') and ('4' in l)

Recall that non-empty sequences and containers are conventionally True
in Python, so your expression is logically equivalent to:
'4' in l
With '3' not being checked for membership at all.

To check multiple items for membership in a contains, you must write
each `in` test separately and then conjoin then by the appropriate
boolean operator:

'3' in l and '4' in l

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


Re: Logic operators with in statement

2009-11-16 Thread Xavier Ho
On Tue, Nov 17, 2009 at 12:02 AM, Mr.SpOOn mr.spoo...@gmail.com wrote:

 Hi,
 I'm trying to use logical operators (or, and) with the in statement,
 but I'm having some problems to understand their behavior.


Hey Carlo, I think your issue here is mistaking 'in' as a statement. It's
just another logic operator, much like 'and' and 'or'... it's not a
statement in itself. At least, I don't think that's how you'd call 'in'.

You have to remember that Python's logical operators (and, or) works
slightly different than most languages. It doesn't return True or False, if
the things compared aren't boolean values. Instead, it returns the first
thing that makes the decision.

For example a statement such as

'3' and '4'
'4'

returns the string literal 4.

1.
Python's AND operator returns the first element if the first one is False;
else, it returns the second element. That's all it does.

Python's OR operator returns the first element if the first one is True;
else, it returns the second element.

Think about it. It's a little strange, but they don't return a pure Boolean
value.

2.
Only the empty string is considered False. Any non-empty strings have True
values.

3.
The proper way of using the in operator is probably such: (There may be a
better way I'm not aware of.)

 '3' in l and '4' in l
False

 '3' in l and 'no3' in l
True

AND operator has a higher precedence, so you don't need any brackets here, I
think. But anyway, you have to use it like that. So that's something you'll
have to fix first.



 What I really need is to create a sequence of if statements to check
 the presence of elements in a list, because some of them are mutually
 exclusive, so if for example there are both 3 and no3 it should
 return an error


One idea I can think of is to have a presence count; assuming the input is
non-repeating, you increase this count by 1, starting at 0. If you get
anything above one, return this error you speak of, and that might be a good
start.

Good luck,
Xav
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Logic operators with in statement

2009-11-16 Thread Chris Rebert
On Mon, Nov 16, 2009 at 6:08 AM, Mr.SpOOn mr.spoo...@gmail.com wrote:
 Sorry for replying to myself, but I think I understood why I was wrong.

 The correct statement should be something like this:

 In [13]: ('b3' and '5') in l or ('3' and 'b3') in l
 Out[13]: True

No, you've just run into another misunderstanding.

Given the expression `X and Y`:
If bool(X) is False, it evaluates to X.
Otherwise, it evaluates to Y.

In other words, the subexpression which ends up determining the truth
of the conjunction is what the conjunction evaluates to. `or` works
similarly.
This allows for tricky tricks like:
foo = possiblyFalse or default # use default if given value is false

Thus, due to the parentheses, your expression is equivalent to:
'5' in l or 'b3' in l
Which I trust is not what you intended.

Again, you need to write separate `in`s for each item you need to
check the membership of:
('b3' in l and '5' in l) or ('3' in l and 'b3' in l)

Cheers,
Chris
--
Python language lawyer at your service
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Logic operators with in statement

2009-11-16 Thread Xavier Ho
On Tue, Nov 17, 2009 at 12:08 AM, Mr.SpOOn mr.spoo...@gmail.com wrote:

 Sorry for replying to myself, but I think I understood why I was wrong.

 The correct statement should be something like this:

 In [13]: ('b3' and '5') in l or ('3' and 'b3') in l
 Out[13]: True


Carlo, I'm not sure what that achieves. Care to enlighten me?

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


Re: Logic operators with in statement

2009-11-16 Thread Tim Chase

Here I expected to get True in the second case too, so clearly I don't
really get how they work.


You're seeing short-circuit evaluation:

   3 or 4  # true
  '3'
   '4' or '3'  # true
  '4'
   '4' in l# false
  False
   '3' or False  # true
  '3'
   '4' or '42' in l  # true: same as '4' or ('42' in l)
  '4'
   '4' or '42'
  '4'
   ('4' or '42') in l # true:  same as '4' in l
  '4'

It just happens that sometimes you get unexpected results that 
happen to be right because of how Python handles strings/numbers 
as booleans and order-of-operations.



What I really need is to create a sequence of if statements to check
the presence of elements in a list, because some of them are mutually
exclusive, so if for example there are both 3 and no3 it should
return an error.


The in operator only checks containment of one item, not 
multiples, so you have to manage the checking yourself.  This is 
fairly easy with the any()/all() functions added in 2.5:


  any(i in l for i in (3, 4))
  all(i in l for i in (3, 4))

For more complex containment testing, using sets will be more 
efficient and offers a richer family of batch operators 
(contains, intersection, union, difference, issubset, issuperset)


-tkc




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


Re: Newsgroup for beginners

2009-11-16 Thread Tim Chase

mrholtsr wrote:

Is there a Python newsgroup for those who are strictly beginners at
programming and python?


http://mail.python.org/mailman/listinfo/tutor

-tkc


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


Re: Logic operators with in statement

2009-11-16 Thread Chris Rebert
On Mon, Nov 16, 2009 at 6:23 AM, Xavier Ho cont...@xavierho.com wrote:
snip
 '3' in l and 'no3' in l
 True

 AND operator has a higher precedence, so you don't need any brackets here, I
 think. But anyway, you have to use it like that. So that's something you'll
 have to fix first.

Er, you mean lower precedence. Higher precedence means it would bind
tighter, thus the expression would mean:
'3' in (l and 'no3') in l
which is certainly incorrect.

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


Re: Python Go

2009-11-16 Thread Graham Breed

Terry Reedy wrote:

It seems to me that generators are already 'channels' that connect the 
calling code to the __next__ method, a semi-coroutine based on the body 
of the generator function. At present, the next method waits until an 
object is requested. Then it goes into action, yields an object, and 
rests again. For parallel operations, we need eager, anticipatory 
evaluation that produces things that *will* be needed rather than lazy 
evaluation of things that *are* needed and whose absence is holding up 
everything else.


Yes, generators look very much like channels.  The obvious 
thing, from where I'm sitting, is to have a function called 
channel that takes an iterator, runs it in a different 
thread/process/goroutine, and returns an iterator that reads 
from the channel.  A single threaded version would look very 
much like iter so let's use iter to get a working example:


#!/usr/bin/python2 -u

channel = iter # placeholder for missing feature

def generate():
i = 2
while True:
yield i
i += 1

def filter(input, prime):
for i in input:
if i%prime != 0:
yield i

ch = channel(generate())
try:
while True:
prime = ch.next()
print prime
ch = channel(filter(ch, prime))
except IOError:
pass

That works fine in a single thread.  It's close to the 
original go example, hence the evil shadowing of a builtin. 
 I don't think the channel function would present any 
problems given an appropriate library to wrap.  I got 
something like this working with Jython and the E language 
but, as I recall, had an accident and lost the code.  If 
somebody wants to implement it using multiprocessing, go to it!



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


Re: python simply not scaleable enough for google?

2009-11-16 Thread Paul Boddie
On 16 Nov, 05:51, sturlamolden sturlamol...@yahoo.no wrote:

 NASA can find money to build a space telescope and put it in orbit.
 They don't find money to create a faster Python, which they use for
 analyzing the data.

Is the analysis in Python really what slows it all down?

 Google is a multi-billion dollar business. They are using Python
 extensively. Yes I know about Unladen Swallow, but why can't they put
 1 mill dollar into making a fast Python?

Isn't this where we need those Ohloh figures on how much Unladen
Swallow is worth? ;-) I think Google is one of those organisations
where that Steve Jobs mentality of shaving time off a once-per-day
activity actually pays off. A few more cycles here and there is
arguably nothing to us, but it's a few kW when running on thousands of
Google nodes.

 And then there is IBM and Cern's Blue Brain project. They can set up
 the fastest supercomputer known to man, but finance a faster Python?
 No...

Businesses and organisations generally don't spend any more money than
they need to. And if choosing another technology is cheaper for future
work then they'll just do that instead. In a sense, Python's
extensibility using C, C++ and Fortran have helped adoption of the
language considerably, but it hasn't necessarily encouraged a focus on
performance.

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


Re: (unknown)

2009-11-16 Thread Tommy Grav

On Nov 15, 2009, at 11:08 AM, Gabriel Genellina wrote:

 En Fri, 13 Nov 2009 16:05:26 -0300, Ronn Ross ronn.r...@gmail.com escribió:
 
 I'm attempting to convert latitude and longitude coordinates from degrees
 minutes and second to decimal form. I would like to go from:
N39 42 36.3 W77 42 51.5
 to:
 -77.739855,39.70
 
 Does anyone know of a library or some existing out their to help with this
 conversion?
 
 Should be:
 
 decimal = degrees + minutes/60.0 + seconds/3600.0
 N,E are positive; S,W are negative.
 
 But the above numbers don't match.

It is more complicated than that. For negative numbers the value is degrees 
-minutes/60. - seconds/3600.
And people always trip up on numbers that start with -00 :)

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


Image to SVG conversion with Python

2009-11-16 Thread Carlo DiCelico
I need to convert JPEG and PNG files to SVG. I'm currently using PIL
to generate the JPEG/PNG files to begin with. However, I need to be
able to scale the generated images up in size without a loss of image
quality. Using SVG seems to be the best way to do this, other than
generating the images in the maximum size/resolution in the first
place, which would be too resource intensive.

I've looked around online and have found some tools for creating SVGs
but none for converting an image into SVG.

Does anyone have any experience doing this? What would be the best way
to go about this?

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


Re: C api question and determining PyObject type

2009-11-16 Thread Gabriel Genellina

En Mon, 16 Nov 2009 07:44:34 -0300, lallous lall...@lgwm.org escribió:


Actually, the object class is defined as:
class __object(object):
def __getitem__(self, idx):
return getattr(self, idx)

Anyway, now I check like this:

bool PyIsSequenceType(PyObject *obj)
{
  if (!PySequence_Check(obj))
return false;
  Py_ssize_t sz = PySequence_Size(obj);
  if (sz == -1 || PyErr_Occurred() != NULL)
  {
PyErr_Clear();
return false;
  }
  return true;
}

I don't like it, any other suggestions?


Yes: find another name for the thing you're checking for. It's not the  
same as a sequence in the Python sense.


Perhaps you want to consider your type a mapping? Sequences and mappings  
have a lot in common (mappings have length too.) In C you have separate  
slots tp_as_sequence, tp_as_mapping; but in Python code, __getitem__ is  
used for both meanings (and goes into both set of pointers.) tp_as_mapping  
takes precedence over tp_as_sequence.


--
Gabriel Genellina

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


Re: C api question and determining PyObject type

2009-11-16 Thread Gabriel Genellina

En Mon, 16 Nov 2009 07:44:34 -0300, lallous lall...@lgwm.org escribió:


Actually, the object class is defined as:
class __object(object):
def __getitem__(self, idx):
return getattr(self, idx)

Anyway, now I check like this:

bool PyIsSequenceType(PyObject *obj)
{
  if (!PySequence_Check(obj))
return false;
  Py_ssize_t sz = PySequence_Size(obj);
  if (sz == -1 || PyErr_Occurred() != NULL)
  {
PyErr_Clear();
return false;
  }
  return true;
}

I don't like it, any other suggestions?


Yes: find another name for the thing you're checking for. It's not the  
same as a sequence in the Python sense.


Perhaps you want to consider your type a mapping? Sequences and mappings  
have a lot in common (mappings have length too.) In C you have separate  
slots tp_as_sequence, tp_as_mapping; but in Python code, __getitem__ is  
used for both meanings (and goes into both set of pointers.) tp_as_mapping  
takes precedence over tp_as_sequence.


--
Gabriel Genellina

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


Python-URL! - weekly Python news and links (Nov 16)

2009-11-16 Thread Gabriel Genellina
QOTW:  The promise is 'batteries included.'  Nobody promised you a
nickel metal hydride battery that you can use as a replacement in your
Prius. - Stephen J. Turnbull
http://mail.python.org/pipermail/python-dev/2009-November/094014.html


Google's new language, Go, has similarities to Python:
http://groups.google.com/group/comp.lang.python/t/c1c4a8fe741c689a/

Is Python scalable enough for Google (or any other huge application)?
http://groups.google.com/group/comp.lang.python/t/ceef2ae6b4472b61/

Is it possible to get the physical memory address of a variable in python?
http://groups.google.com/group/comp.lang.python/t/969462b9a3b452/

Serialize objects as Python code:
http://groups.google.com/group/comp.lang.python/t/98536e7910e65256/

Overriding __getitem__ for a subclass of dict:
http://groups.google.com/group/comp.lang.python/t/d9b822119fc0917c/

Ensure a script is run with a certain range of Python versions:
http://groups.google.com/group/comp.lang.python/t/d21a492be99c90e8/

How to install applications when Python is not already present:
http://groups.google.com/group/comp.lang.python/t/495794a40d18fbc/

Turtle graphics are just for kids - or not? Its advantages when teaching
Python programming:
http://groups.google.com/group/comp.lang.python/t/d55388b0fdd9ed2f/

Using dynamic property names:
http://groups.google.com/group/comp.lang.python/t/f7b8829c97dcc3f9/

How can a module react differently when imported from one place or another?
http://groups.google.com/group/comp.lang.python/t/da162dc08f1c3550/

Sharing distributed objects between Python and C++:
http://groups.google.com/group/comp.lang.python/t/5a567a1a180511eb/

Beware: threads + import don't mix well!
http://groups.google.com/group/comp.lang.python/t/a60c83590a016528/

locals() and frame.f_locals return old data:
http://groups.google.com/group/comp.lang.python/t/fa17941218c6e89e/

Instantiate classes using names from the command line:
http://groups.google.com/group/comp.lang.python/t/d597a1a42b88c0d1/

New syntax proposal: if some_expression as x: do_something_with(x)
http://groups.google.com/group/comp.lang.python/t/55e7578903747dc4/



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 enthusiasts:
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the Planet site:
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/

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.orggroup=gmane.comp.python.develsort=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.

Re: (unknown)

2009-11-16 Thread Gabriel Genellina

En Mon, 16 Nov 2009 11:11:20 -0300, Tommy Grav tg...@me.com escribió:

On Nov 15, 2009, at 11:08 AM, Gabriel Genellina wrote:


En Fri, 13 Nov 2009 16:05:26 -0300, Ronn Ross ronn.r...@gmail.com  
escribió:


I'm attempting to convert latitude and longitude coordinates from  
degrees

minutes and second to decimal form. I would like to go from:
   N39 42 36.3 W77 42 51.5
to:
-77.739855,39.70


decimal = degrees + minutes/60.0 + seconds/3600.0
N,E are positive; S,W are negative.
But the above numbers don't match.


It is more complicated than that. For negative numbers the value is  
degrees -minutes/60. - seconds/3600.

And people always trip up on numbers that start with -00 :)


I set the sign of the result *after* computing it, so it doesn't matter.

py 39 + 42/60.0 + 36.3/3600
39.7100837
py 77 + 42/60.0 + 51.5/3600
77.7143055

Either the example above is incorrect, or there is another thing involved.

--
Gabriel Genellina

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


Re: A terminators' club for clp

2009-11-16 Thread Terry Reedy

kj wrote:

In 7x3a4i56u7@ruckus.brouhaha.com Paul Rubin 
http://phr...@nospam.invalid writes:


kj no.em...@please.post writes:

frequent* clp posters the ability to *easily* delete spam from the
comp.lang.python server?



Um, this is usenet; there is no comp.lang.python server.  Are you
saying you want a moderated newsgroup?  Hmm, maybe this group is busy
enough that there is some merit to that idea.


Sorry, I had a mistaken view of how usenet was implemented.  But
yeah, I guess I'm thinking of a moderated newsgroup, but with a
large number of moderators working in parallel, and a very lax
acceptance policy.  The goal is to filter out only the obvious
spam, and let through all the other non-spam traffic as quickly as
possible...  What do I mean by obvious spam?  Well, among the
most recent messages (that have survived my killfile policies) I
see the following subject lines:

* Top 10 US mp3 songs.Cheers
* www.find68.com cheaper nike shoes g-satr kidrobot hoodies ed hardy star red 
monkey gino green global true religion ed-hardy kidrobot jeans hoodies china 
supplier wholesaler exporters,manufacture
* jobs in france jobs in france for english people jobs in france for foreigners jobs in france for australians 
jobs in france for foreigners  jobs in france for new zealanders jobs paris jobs http://jobs-in-fr 
ance.blogspot.com/
* germany jobs germany job sites germany job search jobs in germany german jobs germany jobs it 
germany jobs for foreigners germany jobsite germany jobs in english on http://jobs-germany.blogspot.com/

Those look pretty obvious to me.

But, as I already showed, I'm out of my depth here,
so I'd better shut up.


Some usenet newsgroups were/are moderated either by a robot, a person, 
or a team (as you suggested). But a particular newsgroup has to be set 
up that way from the beginning. Last I knew, it wan/is? difficult to 
convert an unmoderated group to moderation.


Terry Jan Reedy

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


Re: Newsgroup for beginners

2009-11-16 Thread Terry Reedy

mrholtsr wrote:

Is there a Python newsgroup for those who are strictly beginners at
programming and python?


gmane.comp.python.tutor, which I believe mirrors the tutor-list

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


Re: Image to SVG conversion with Python

2009-11-16 Thread Dave Angel

Carlo DiCelico wrote:

I need to convert JPEG and PNG files to SVG. I'm currently using PIL
to generate the JPEG/PNG files to begin with. However, I need to be
able to scale the generated images up in size without a loss of image
quality. Using SVG seems to be the best way to do this, other than
generating the images in the maximum size/resolution in the first
place, which would be too resource intensive.

I've looked around online and have found some tools for creating SVGs
but none for converting an image into SVG.

Does anyone have any experience doing this? What would be the best way
to go about this?

Thanks,
Carlo

  
I have no direct experience with SVG, but have used and analyzed other 
formats.


I expect it's unreasonable to convert jpg or png files to SVG.  The 
latter is a vector format, and can't efficiently represent pixels, which 
is all you have in the jpg files.  And even if you did it brute force, 
it still wouldn't scale any better than the original jpg.  If the jpg 
file was generated from lines, and wasn't too crowded, it *might* be 
possible to analyze it to reconstruct the vectors, but it would be both 
very slow, and inaccurate.



In Photoshop PSD files, you can have vector layers and RGB layers (plus 
other kinds).  You convert a vector layer (such as text) to bits by 
rasterizing (or flattening).  And once you do, it no longer scales 
cleanly.  For instance, when I'm sending composite images to a printer, 
I get much better quality sending the raster portion separate from the 
text, either as layers in a PSD file, or in a PDF file, or even as two 
separate files that they will merge later.  (In that case, I usually 
send a low-res flattened file, so they can see how it's supposed to look)


I'd say you should change your python code to generate the svg files 
first (perhaps using http://code.activestate.com/recipes/325823/ )


Then you might want to use ( http://www.imagemagick.org/script/index.php 
) to convert it to jpg or other format.


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


Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-16 Thread Steve Ferg
This is a question for the language mavens that I know hang out here.
It is not Python related, except that recent comparisons of Python to
Google's new Go language brought it to mind.

NOTE that this is *not* a suggestion to change Python.  I like Python
just the way it is.  I'm just curious about language design.

For a long time I've wondered why languages still use blocks
(delimited by do/end, begin/end, { } , etc.) in ifThenElse statements.

I've often thought that a language with this kind of block-free syntax
would be nice and intuitive:

if condition then
do stuff
elif condition then
do stuff
else
do stuff
endif

Note that you do not need block delimiters.

Obviously, you could make a more Pythonesque syntax by using a colon
rather then then for the condition terminator.  You could make it
more PL/I-like by using do, etc.

You can write shell scripts using if ... fi, but other than that I
don't recall a language with this kind of syntax.

Does anybody know a language with this kind of syntax for
ifThenElseEndif?

Is there any particular reason why this might be a *bad* language-
design idea?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-16 Thread Robin Becker

Steve Ferg wrote:
.


if condition then
do stuff
elif condition then
do stuff
else
do stuff
endif

Note that you do not need block delimiters.

Obviously, you could make a more Pythonesque syntax by using a colon
rather then then for the condition terminator.  You could make it
more PL/I-like by using do, etc.

You can write shell scripts using if ... fi, but other than that I
don't recall a language with this kind of syntax.

Does anybody know a language with this kind of syntax for
ifThenElseEndif?

...

modern sh seems to use this with fi as endif eg

~:
$ if true; then
 echo true
 elif false; then
 echo false
 else
 echo hostile logic
 fi
true
~:
$

--
Robin Becker

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


Re: Image to SVG conversion with Python

2009-11-16 Thread Carlo DiCelico
On Nov 16, 11:48 am, Dave Angel da...@ieee.org wrote:
 Carlo DiCelico wrote:
  I need to convert JPEG and PNG files to SVG. I'm currently using PIL
  to generate the JPEG/PNG files to begin with. However, I need to be
  able to scale the generated images up in size without a loss of image
  quality. Using SVG seems to be the best way to do this, other than
  generating the images in the maximum size/resolution in the first
  place, which would be too resource intensive.

  I've looked around online and have found some tools for creating SVGs
  but none for converting an image into SVG.

  Does anyone have any experience doing this? What would be the best way
  to go about this?

  Thanks,
  Carlo

 I have no direct experience with SVG, but have used and analyzed other
 formats.

 I expect it's unreasonable to convert jpg or png files to SVG.  The
 latter is a vector format, and can't efficiently represent pixels, which
 is all you have in the jpg files.  And even if you did it brute force,
 it still wouldn't scale any better than the original jpg.  If the jpg
 file was generated from lines, and wasn't too crowded, it *might* be
 possible to analyze it to reconstruct the vectors, but it would be both
 very slow, and inaccurate.

 In Photoshop PSD files, you can have vector layers and RGB layers (plus
 other kinds).  You convert a vector layer (such as text) to bits by
 rasterizing (or flattening).  And once you do, it no longer scales
 cleanly.  For instance, when I'm sending composite images to a printer,
 I get much better quality sending the raster portion separate from the
 text, either as layers in a PSD file, or in a PDF file, or even as two
 separate files that they will merge later.  (In that case, I usually
 send a low-res flattened file, so they can see how it's supposed to look)

 I'd say you should change your python code to generate the svg files
 first (perhaps usinghttp://code.activestate.com/recipes/325823/)

 Then you might want to use (http://www.imagemagick.org/script/index.php
 ) to convert it to jpg or other format.

 DaveA

Thanks, this makes perfect sense.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-16 Thread James Harris
On 16 Nov, 16:54, Steve Ferg steve.ferg.bitbuc...@gmail.com wrote:
 This is a question for the language mavens that I know hang out here.
 It is not Python related, except that recent comparisons of Python to
 Google's new Go language brought it to mind.

 NOTE that this is *not* a suggestion to change Python.  I like Python
 just the way it is.  I'm just curious about language design.

 For a long time I've wondered why languages still use blocks
 (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements.

 I've often thought that a language with this kind of block-free syntax
 would be nice and intuitive:

     if condition then
         do stuff
     elif condition then
         do stuff
     else
         do stuff
     endif

 Note that you do not need block delimiters.

 Obviously, you could make a more Pythonesque syntax by using a colon
 rather then then for the condition terminator.  You could make it
 more PL/I-like by using do, etc.

 You can write shell scripts using if ... fi, but other than that I
 don't recall a language with this kind of syntax.

 Does anybody know a language with this kind of syntax for
 ifThenElseEndif?

 Is there any particular reason why this might be a *bad* language-
 design idea?

There are some. For example, Ada uses similar. See

  http://en.wikipedia.org/wiki/Ada_%28programming_language%29#Control_structures

These other newsgroups may be of interest:

  comp.programming
  comp.lang.misc

The latter is used by people designing programming languages where you
can find knowledgeable comments aplenty.

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


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-16 Thread Adrian Cherry
Steve Ferg steve.ferg.bitbuc...@gmail.com wrote in
news:ff92db5b-9cb0-4a72-b339-2c5ac02fb...@p36g2000vbn.googlegro
ups.com: 

 This is a question for the language mavens that I know hang
 out here. It is not Python related, except that recent
 comparisons of Python to Google's new Go language brought it
 to mind. 
 
 NOTE that this is *not* a suggestion to change Python.  I
 like Python just the way it is.  I'm just curious about
 language design. 
 
 For a long time I've wondered why languages still use blocks
 (delimited by do/end, begin/end, { } , etc.) in ifThenElse
 statements. 
 
 I've often thought that a language with this kind of
 block-free syntax would be nice and intuitive:
 
 if condition then
 do stuff
 elif condition then
 do stuff
 else
 do stuff
 endif
 
 Note that you do not need block delimiters.
 
 Obviously, you could make a more Pythonesque syntax by using
 a colon rather then then for the condition terminator. 
 You could make it more PL/I-like by using do, etc.
 
 You can write shell scripts using if ... fi, but other than
 that I don't recall a language with this kind of syntax.
 
 Does anybody know a language with this kind of syntax for
 ifThenElseEndif?
 
 Is there any particular reason why this might be a *bad*
 language- design idea?

I believe MATLAB has similar if syntax - please correct me if I'm 
wrong.

From

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/if.html

The if function can be used alone or with the else and elseif 
functions. When using elseif and/or else within an if statement, 
the general form of the statement is

if expression1
statements1
elseif expression2
statements2
else
statements3
end


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


Re: Redirect stdout to a buffer [Errno 9]

2009-11-16 Thread Ecir Hana
On Nov 15, 5:28 pm, Ecir Hana ecir.h...@gmail.com wrote:
 Hello,

 I'm trying to write a simple Win32 app, which may run some Python
 scripts. Since it is a Windows GUI app, I would like to redirect all
 output (Python print, C printf, fprinf stderr, ...) to a text area
 inside the app. In other words, I'm trying to log all the output from
 the app (C, Python) to a window. So far, this works for C printf():

 int fds[2];
 _pipe(fds, 1024, O_TEXT);
 _dup2(fds[1], 1);
 ...
 and then I read from pipe's read-end and append the text to the text
 area.

 But when I try to run:
 Py_Initialize();
 PyRun_SimpleString(print 'abc');
 Py_Finalize();

 I get an error:
 IOError: [Errno 9] Bad file descriptor

 What am I doing wrong? How to redirect standard IO, both for C and for
 Python?
 PS: Maybe I'm doind something wrong, but SetStdHandle() does not work
 at all

Also, maybe this matters: it's on WinXP, Python 2.6 and MinGW GCC.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newsgroup for beginners

2009-11-16 Thread George Oliver
On Nov 16, 8:35 am, Terry Reedy tjre...@udel.edu wrote:
 mrholtsr wrote:
  Is there a Python newsgroup for those who are strictly beginners at
  programming and python?

 gmane.comp.python.tutor, which I believe mirrors the tutor-list

There also is a beginner's forum at python-forum.org:

http://www.python-forum.org/pythonforum/viewforum.php?f=3
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-16 Thread MRAB

Steve Ferg wrote:

This is a question for the language mavens that I know hang out here.
It is not Python related, except that recent comparisons of Python to
Google's new Go language brought it to mind.

NOTE that this is *not* a suggestion to change Python.  I like Python
just the way it is.  I'm just curious about language design.

For a long time I've wondered why languages still use blocks
(delimited by do/end, begin/end, { } , etc.) in ifThenElse statements.

I've often thought that a language with this kind of block-free syntax
would be nice and intuitive:

if condition then
do stuff
elif condition then
do stuff
else
do stuff
endif

Note that you do not need block delimiters.

Obviously, you could make a more Pythonesque syntax by using a colon
rather then then for the condition terminator.  You could make it
more PL/I-like by using do, etc.

You can write shell scripts using if ... fi, but other than that I
don't recall a language with this kind of syntax.

Does anybody know a language with this kind of syntax for
ifThenElseEndif?

Is there any particular reason why this might be a *bad* language-
design idea?


Ada and Turing have:

if condition then
do stuff
elsif condition then
do stuff
else
do stuff
end if

Comal has:

if condition then
do stuff
elif condition then
do stuff
else
do stuff
end if

Modula-2 has:

if condition then
do stuff
elsif condition then
do stuff
else
do stuff
end
--
http://mail.python.org/mailman/listinfo/python-list


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-16 Thread Robin Becker

Robin Becker wrote:
...

modern sh seems to use this with fi as endif eg

~:
$ if true; then
  echo true
  elif false; then
  echo false
  else
  echo hostile logic
  fi
true
~:
$



I meant to say that since sh uses this construct it cannot be too bad as a 
language construct since the world is built with sh and bash and similar.


Of course that's a bad argument since there's more cobol than everything else 
put together (allegedly).

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


Re: import subprocess in python

2009-11-16 Thread Nobody
On Mon, 16 Nov 2009 04:58:00 -0800, sturlamolden wrote:

 On 16 Nov, 13:50, Kuhl chen_zhi...@yahoo.com wrote:
 
 Python 2.2.3 (#1, Feb  2 2005, 12:22:48)
 
 What's the mistake that I am making? How to solve it?
 
 Your Python version is too old.

Your Python version is *way* too old.

If you're lucky, people who use features of Python 2.5 or 2.6 will mention
that you need Python 2.5 or 2.6, but having at least Python 2.4 is
generally taken for granted.

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


Re: Image to SVG conversion with Python

2009-11-16 Thread Nobody
On Mon, 16 Nov 2009 07:19:49 -0800, Carlo DiCelico wrote:

 I need to convert JPEG and PNG files to SVG. I'm currently using PIL
 to generate the JPEG/PNG files to begin with. However, I need to be
 able to scale the generated images up in size without a loss of image
 quality. Using SVG seems to be the best way to do this, other than
 generating the images in the maximum size/resolution in the first
 place, which would be too resource intensive.
 
 I've looked around online and have found some tools for creating SVGs
 but none for converting an image into SVG.
 
 Does anyone have any experience doing this? What would be the best way
 to go about this?

JPEG/PNG are raster formats, SVG is a vector format.

To convert raster graphics to vector graphics, you need a tracing
program (aka image tracing, vector tracing, vectorizing), e.g.
potrace (this program is often bundled with InkScape):

http://potrace.sourceforge.net/

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


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-16 Thread Nobody
On Mon, 16 Nov 2009 08:54:28 -0800, Steve Ferg wrote:

 For a long time I've wondered why languages still use blocks
 (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements.
 
 I've often thought that a language with this kind of block-free syntax
 would be nice and intuitive:
 
 if condition then
 do stuff
 elif condition then
 do stuff
 else
 do stuff
 endif
 
 Note that you do not need block delimiters.

 Does anybody know a language with this kind of syntax for
 ifThenElseEndif? 

BBC BASIC V had if/then/else/endif (it didn't have elif).

make has if/else/else/endif (it doesn't have a dedicated elif, but
else if ... behaves like elif rather than starting a nested if).

 Is there any particular reason why this might be a *bad* language-
 design idea?

Blocks can be useful for other reasons (e.g. limiting variable scope), so
if you already have them, you don't need to provide dedicated blocks
for control constructs.

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


Re: Redirect stdout to a buffer [Errno 9]

2009-11-16 Thread Gabriel Genellina
En Mon, 16 Nov 2009 14:17:52 -0300, Ecir Hana ecir.h...@gmail.com  
escribió:



I'm trying to write a simple Win32 app, which may run some Python
scripts. Since it is a Windows GUI app, I would like to redirect all
output (Python print, C printf, fprinf stderr, ...) to a text area
inside the app. In other words, I'm trying to log all the output from
the app (C, Python) to a window. So far, this works for C printf():
[...]
PS: Maybe I'm doind something wrong, but SetStdHandle() does not work
at all


This worked for me:

#include windows.h
#include Python.h

int main()
{
  HANDLE hReadPipe, hWritePipe;
  DWORD nr, nw;
  char buffer[100];

  CreatePipe(
hReadPipe,
hWritePipe,
NULL,
1024);
  SetStdHandle(STD_OUTPUT_HANDLE, hWritePipe);

  Py_Initialize();
  PyRun_SimpleString(print 'from Python');
  Py_Finalize();

  puts(from C\n);

  CloseHandle(hWritePipe);
  ReadFile(hReadPipe, buffer, 19, nr, NULL);
  CloseHandle(hReadPipe);
  WriteFile(GetStdHandle(STD_ERROR_HANDLE), buffer, nr, nw, NULL);
}


Also, maybe this matters: it's on WinXP, Python 2.6 and MinGW GCC.


I'm using Visual Studio 2008 Express Edition.

--
Gabriel Genellina

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


RE: tkFileDialog question

2009-11-16 Thread Matt Mitchell



 
---
The information contained in this electronic message and any attached 
document(s) is intended only for the personal and confidential use of the 
designated recipients named above. This message may be confidential. If the 
reader of this message is not the intended recipient, you are hereby notified 
that you have received this document in error, and that any review, 
dissemination, distribution, or copying of this message is strictly prohibited. 
If you have received this communication in error, please notify sender 
immediately by telephone (603) 262-6300 or by electronic mail immediately. 
Thank you.
 
-Original Message-
From: python-list-bounces+mmitchell=transparent@python.org
[mailto:python-list-bounces+mmitchell=transparent@python.org] On
Behalf Of r
Sent: Monday, November 16, 2009 12:16 AM
To: python-list@python.org
Subject: Re: tkFileDialog question

Matt,

There is also a nice thing you need to know about Python if you
already do not know. That is the fact that all empty collections bool
to False. This makes Truth testing easier.

 bool([])
False
 bool('')
False
 bool({})
False
 bool([1])
True
 bool([[]])
True
 bool(' ')
True

any empty collection, string, or 0 always bools to False.
-- 
http://mail.python.org/mailman/listinfo/python-list



Thank you both for all the help.  Your suggestions have helped clean up
a bunch of my code.

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


Re: overriding __getitem__ for a subclass of dict

2009-11-16 Thread Steve Howell
On Nov 16, 2:35 am, Carl Banks pavlovevide...@gmail.com wrote:
 On Nov 15, 2:52 pm, Steve Howell showel...@yahoo.com wrote:

  Does anybody have any links that points to the rationale for ignoring
  instance definitions of __getitem__ when new-style classes are
  involved?  I assume it has something to do with performance or
  protecting us from our own mistakes?

 Not important enough to justify complexity of implementation.

 I doubt they would have left if out of new-style classes if it had
 been straightforward to implement (if for no other reason than to
 retain backwards compatibility), but it wasn't.  The way attribute
 lookups work meant it would have required all kinds of double lookups
 and edge cases.  Some regarded it as dubious to begin with.  And it's
 easily worked around by simply having __getitem__ call another method,
 as you've seen.  Given all this it made better sense to just leave it
 out of new-style classes.

Actually, the __getitem__ workaround that I proposed earlier only
works on subclasses of dict, not dict themselves.  So given a pure
dictionary object, it is impossible to hook into attribute lookups
after instantiation in debugging/tracing code.  I know it's not a
super common thing to do, but it is a legitimate use case from my
perspective.  But I understand the tradeoffs.  They seem kind of 20th
century to me, but with Moore's Law declining and all, maybe it's a
bad time to bring up the flexibility trumps performance
argument. ;)  The backward compatibility argument also seems a little
dubious, because if anybody *had* put __getitem__ on a dictionary
instance before, it would have already been broken code, and if they
hadn't done it, there would be no semantic change, just a performance
hit, albeit a pervasive one.

 Unfortunately not all such decisions and justifications are collected
 in a tidy place.


Yep, that's why I was asking here.  I figured somebody might remember
a thread on python-dev where this was discussed, or something like
that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-16 Thread MRAB

Nobody wrote:

On Mon, 16 Nov 2009 08:54:28 -0800, Steve Ferg wrote:


For a long time I've wondered why languages still use blocks
(delimited by do/end, begin/end, { } , etc.) in ifThenElse statements.

I've often thought that a language with this kind of block-free syntax
would be nice and intuitive:

if condition then
do stuff
elif condition then
do stuff
else
do stuff
endif

Note that you do not need block delimiters.



Does anybody know a language with this kind of syntax for
ifThenElseEndif? 


BBC BASIC V had if/then/else/endif (it didn't have elif).


I forgot about that one. :-(

I used to do this in order if I wanted to avoid a lot of indentation:

CASE TRUE OF
WHEN condition
do something
WHEN condition
do something
OTHERWISE
do something
ENDCASE


make has if/else/else/endif (it doesn't have a dedicated elif, but
else if ... behaves like elif rather than starting a nested if).


Is there any particular reason why this might be a *bad* language-
design idea?


Blocks can be useful for other reasons (e.g. limiting variable scope), so
if you already have them, you don't need to provide dedicated blocks
for control constructs.



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


Re: A terminators' club for clp

2009-11-16 Thread gil_johnson
On Nov 14, 12:08 pm, r rt8...@gmail.com wrote:
 On Nov 14, 7:28 am, gil_johnson x7-g5w...@earthlink.net wrote:

 Actually there is a rank this post (gotta be careful with that
 verbage!) AND a report this post as spam. Of course it only exists
 in GG's and not Usenet. I *do* know that the star system is used quite
 frequently, but i doubt anyone bothers to use the report as spam
 link since it seems have no effect whatsoever.

Heh. I should look around more before posting. It does prove your
point, though. The 'spam' button is ubiquitous, but so seldom used
it's forgotten.

Actually, my enthusiasm for my idea faded with a little thought. It is
an extra effort to open spam to get to the 'spam' button, and sends
the message to the spammer that people are, indeed opening their junk.
I'd use it if I opened a message with a deceptive subject.
Gil

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


Web servers

2009-11-16 Thread Virgil Stokes
Any suggestions on using Python to connect to Web servers (e.g. to 
access financial time series data)?


--V. Stokes

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


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-16 Thread Chris Rebert
On Mon, Nov 16, 2009 at 8:54 AM, Steve Ferg
steve.ferg.bitbuc...@gmail.com wrote:
 This is a question for the language mavens that I know hang out here.
 It is not Python related, except that recent comparisons of Python to
 Google's new Go language brought it to mind.

 NOTE that this is *not* a suggestion to change Python.  I like Python
 just the way it is.  I'm just curious about language design.

 For a long time I've wondered why languages still use blocks
 (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements.

 I've often thought that a language with this kind of block-free syntax
 would be nice and intuitive:

    if condition then
        do stuff
    elif condition then
        do stuff
    else
        do stuff
    endif

 Note that you do not need block delimiters.
snip
 Does anybody know a language with this kind of syntax for
 ifThenElseEndif?

Ruby:

if count  10
  puts Try again
elsif tries == 3
  puts You lose
else
  puts Enter a number
end

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


Re: Web servers

2009-11-16 Thread Chris Rebert
On Mon, Nov 16, 2009 at 11:17 AM, Virgil Stokes v...@it.uu.se wrote:
 Any suggestions on using Python to connect to Web servers (e.g. to access
 financial time series data)?

In what format? Using what protocol?
(*Insert other basic questions that need answering in order to answer
your question here*)

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


Re: Changing the current directory (full post)

2009-11-16 Thread vsoler
On Nov 16, 2:35 am, Gabriel Genellina gagsl-...@yahoo.com.ar
wrote:
 En Sun, 15 Nov 2009 09:04:06 -0300, vsoler vicente.so...@gmail.com
 escribió:

  Ever since I installed my Python 2.6 interpreter (I use IDLE), I've
  been saving my
  *.py files in the C:\Program Files\Python26 directory, which is the
  default directory for such files in my system.

  However, I have realised that the above is not the best practice.
  Therefore I created the C:\Program Files\Python26\test directory and I
  want it to be my default directory for saving *.py files, importing
  modules, etc.

 This is *not* a good place either. Non-privileged users should not have
 write permission in the C:\Program Files directory.

  I'd like to do something like the DOS equivalent of   CD test but I
  do not know kow to do it.

  I am currently doing something really awful: I open a *.py file in the
  test subdirectory, I run it with the F5 key and it works! but I am
  doing really something stupid.

 it works! What's the problem then?

  How should I proceed, if I want to proceed properly?

 Sorry but I don't even see your problem. You can save your .py files  
 anywhere you like...

 --
 Gabriel Genellina

Gabriel,

When I enter IDLE, I'd like to say at the prompt: my current
directory is...  ...test and then be able to run a module in that
directory. This is what my problem is!!!

Thank you if you can help
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing the current directory (full post)

2009-11-16 Thread Chris Rebert
On Mon, Nov 16, 2009 at 11:36 AM, vsoler vicente.so...@gmail.com wrote:
 On Nov 16, 2:35 am, Gabriel Genellina gagsl-...@yahoo.com.ar
 wrote:
 En Sun, 15 Nov 2009 09:04:06 -0300, vsoler vicente.so...@gmail.com
 escribió:

  Ever since I installed my Python 2.6 interpreter (I use IDLE), I've
  been saving my
  *.py files in the C:\Program Files\Python26 directory, which is the
  default directory for such files in my system.

  However, I have realised that the above is not the best practice.
  Therefore I created the C:\Program Files\Python26\test directory and I
  want it to be my default directory for saving *.py files, importing
  modules, etc.

 This is *not* a good place either. Non-privileged users should not have
 write permission in the C:\Program Files directory.

  I'd like to do something like the DOS equivalent of   CD test but I
  do not know kow to do it.

  I am currently doing something really awful: I open a *.py file in the
  test subdirectory, I run it with the F5 key and it works! but I am
  doing really something stupid.

 it works! What's the problem then?

  How should I proceed, if I want to proceed properly?

 Sorry but I don't even see your problem. You can save your .py files
 anywhere you like...

 --
 Gabriel Genellina

 Gabriel,

 When I enter IDLE, I'd like to say at the prompt: my current
 directory is...  ...test and then be able to run a module in that
 directory. This is what my problem is!!!

1. File - Open
2. Navigate to file and choose it
3. Press F5

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


Re: Changing the current directory (full post)

2009-11-16 Thread vsoler
On Nov 16, 8:45 pm, Chris Rebert c...@rebertia.com wrote:
 On Mon, Nov 16, 2009 at 11:36 AM, vsoler vicente.so...@gmail.com wrote:
  On Nov 16, 2:35 am, Gabriel Genellina gagsl-...@yahoo.com.ar
  wrote:
  En Sun, 15 Nov 2009 09:04:06 -0300, vsoler vicente.so...@gmail.com
  escribió:

   Ever since I installed my Python 2.6 interpreter (I use IDLE), I've
   been saving my
   *.py files in the C:\Program Files\Python26 directory, which is the
   default directory for such files in my system.

   However, I have realised that the above is not the best practice.
   Therefore I created the C:\Program Files\Python26\test directory and I
   want it to be my default directory for saving *.py files, importing
   modules, etc.

  This is *not* a good place either. Non-privileged users should not have
  write permission in the C:\Program Files directory.

   I'd like to do something like the DOS equivalent of   CD test but I
   do not know kow to do it.

   I am currently doing something really awful: I open a *.py file in the
   test subdirectory, I run it with the F5 key and it works! but I am
   doing really something stupid.

  it works! What's the problem then?

   How should I proceed, if I want to proceed properly?

  Sorry but I don't even see your problem. You can save your .py files
  anywhere you like...

  --
  Gabriel Genellina

  Gabriel,

  When I enter IDLE, I'd like to say at the prompt: my current
  directory is...  ...test and then be able to run a module in that
  directory. This is what my problem is!!!

 1. File - Open
 2. Navigate to file and choose it
 3. Press F5

 Cheers,
 Chris
 --http://blog.rebertia.com

Say that you wanted to import a file in the test directory after just
entering IDLE. How would you do it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing the current directory (full post)

2009-11-16 Thread Rami Chowdhury

On Mon, 16 Nov 2009 11:56:49 -0800, vsoler vicente.so...@gmail.com wrote:


On Nov 16, 8:45 pm, Chris Rebert c...@rebertia.com wrote:
On Mon, Nov 16, 2009 at 11:36 AM, vsoler vicente.so...@gmail.com  
wrote:

 On Nov 16, 2:35 am, Gabriel Genellina gagsl-...@yahoo.com.ar
 wrote:
 En Sun, 15 Nov 2009 09:04:06 -0300, vsoler vicente.so...@gmail.com
 escribió:

  Ever since I installed my Python 2.6 interpreter (I use IDLE), I've
  been saving my
  *.py files in the C:\Program Files\Python26 directory, which is the
  default directory for such files in my system.

  However, I have realised that the above is not the best practice.
  Therefore I created the C:\Program Files\Python26\test directory  
and I

  want it to be my default directory for saving *.py files, importing
  modules, etc.

 This is *not* a good place either. Non-privileged users should not  
have

 write permission in the C:\Program Files directory.

  I'd like to do something like the DOS equivalent of   CD test  
but I

  do not know kow to do it.

  I am currently doing something really awful: I open a *.py file in  
the

  test subdirectory, I run it with the F5 key and it works! but I am
  doing really something stupid.

 it works! What's the problem then?

  How should I proceed, if I want to proceed properly?

 Sorry but I don't even see your problem. You can save your .py files
 anywhere you like...

 --
 Gabriel Genellina

 Gabriel,

 When I enter IDLE, I'd like to say at the prompt: my current
 directory is...  ...test and then be able to run a module in that
 directory. This is what my problem is!!!

1. File - Open
2. Navigate to file and choose it
3. Press F5

Cheers,
Chris
--http://blog.rebertia.com


Say that you wanted to import a file in the test directory after just
entering IDLE. How would you do it?


http://docs.python.org/library/os.html#os.chdir and  
http://docs.python.org/library/sys.html#sys.path may be able to help you...




--
Rami Chowdhury
Never attribute to malice that which can be attributed to stupidity --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Changing the current directory (full post)

2009-11-16 Thread Chris Rebert
On Mon, Nov 16, 2009 at 11:56 AM, vsoler vicente.so...@gmail.com wrote:
 On Nov 16, 8:45 pm, Chris Rebert c...@rebertia.com wrote:
 On Mon, Nov 16, 2009 at 11:36 AM, vsoler vicente.so...@gmail.com wrote:
  On Nov 16, 2:35 am, Gabriel Genellina gagsl-...@yahoo.com.ar
  wrote:
  En Sun, 15 Nov 2009 09:04:06 -0300, vsoler vicente.so...@gmail.com
  escribió:

   Ever since I installed my Python 2.6 interpreter (I use IDLE), I've
   been saving my
   *.py files in the C:\Program Files\Python26 directory, which is the
   default directory for such files in my system.

   However, I have realised that the above is not the best practice.
   Therefore I created the C:\Program Files\Python26\test directory and I
   want it to be my default directory for saving *.py files, importing
   modules, etc.

  This is *not* a good place either. Non-privileged users should not have
  write permission in the C:\Program Files directory.

   I'd like to do something like the DOS equivalent of   CD test but I
   do not know kow to do it.

   I am currently doing something really awful: I open a *.py file in the
   test subdirectory, I run it with the F5 key and it works! but I am
   doing really something stupid.

  it works! What's the problem then?

   How should I proceed, if I want to proceed properly?

  Sorry but I don't even see your problem. You can save your .py files
  anywhere you like...

  When I enter IDLE, I'd like to say at the prompt: my current
  directory is...  ...test and then be able to run a module in that
  directory. This is what my problem is!!!

 1. File - Open
 2. Navigate to file and choose it
 3. Press F5

 Say that you wanted to import a file in the test directory after just
 entering IDLE. How would you do it?

import sys
sys.path.insert(0, C:/path/to/test/dir/here)
import something_in_test_dir

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


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-16 Thread r
On Nov 16, 10:54 am, Steve Ferg steve.ferg.bitbuc...@gmail.com
wrote:

 I've often thought that a language with this kind of block-free syntax
 would be nice and intuitive:

     if condition then
         do stuff
     elif condition then
         do stuff
     else
         do stuff
     endif

WHY? Python's syntax is by far the most elegant of all, no need to
show the end of a block. Python is the smartest kid on the block. And
are you saying you would rather type then instead of : and endif
instead of \n?

No thanks!

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


Re: Web servers

2009-11-16 Thread Dave Angel



Virgil Stokes wrote:
div class=moz-text-flowed style=font-family: -moz-fixedAny 
suggestions on using Python to connect to Web servers (e.g. to access 
financial time series data)?


--V. Stokes



You can open a web page for reading with  urllib2 module.  You can parse 
html with beautiful soup, or if it's clean xhtml, with the xml module.


But parsing raw html is error prone, and subject to change as the web 
designer reorganizes things.  So many web servers also have a protocol 
intended for data (as opposed to intended for a browser).  This is 
specific to each service, however.  If you want to get started in your 
reading, you could google for web services, which is one approach 
using SOAP  WSDL.


Note also that most servers have restrictions on the data you access 
this way.  They may or may not be enforceable, but if you access a lot 
of data from a server, you may be too big a drain on its resources, if 
it's configured for browser access only.


DaveA

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


directory wildcard

2009-11-16 Thread hong zhang
List,

I try to assign value to force_mcs sitting in a wildcard subdirectory 
/sys/kernel/debug/ieee80211/phy*, but python does not work for that such as:

os.system(echo %i  /sys/kernel/debug/ieee80211/phy*/iwlagn/data/force_mcs % 
mcs)

Any right way to do it?

Thanks.

--henry




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


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-16 Thread Edward A. Falk
In article ff92db5b-9cb0-4a72-b339-2c5ac02fb...@p36g2000vbn.googlegroups.com,
Steve Ferg  steve.ferg.bitbuc...@gmail.com wrote:
I've often thought that a language with this kind of block-free syntax
would be nice and intuitive:

if condition then
do stuff
elif condition then
do stuff
else
do stuff
endif

Note that you do not need block delimiters.

then, else, and endif *are* the block delimiters

-- 
-Ed Falk, f...@despams.r.us.com
http://thespamdiaries.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-16 Thread Robert Kern

On 2009-11-16 14:40 PM, Edward A. Falk wrote:

In articleff92db5b-9cb0-4a72-b339-2c5ac02fb...@p36g2000vbn.googlegroups.com,
Steve Fergsteve.ferg.bitbuc...@gmail.com  wrote:

I've often thought that a language with this kind of block-free syntax
would be nice and intuitive:

ifcondition  then
do stuff
elifcondition  then
do stuff
else
do stuff
endif

Note that you do not need block delimiters.


then, else, and endif *are* the block delimiters


I think he meant that you don't need *extra* block delimiters or generic block 
delimiters like {}.


--
Robert Kern

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

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


Re: directory wildcard

2009-11-16 Thread Diez B. Roggisch

hong zhang schrieb:

List,

I try to assign value to force_mcs sitting in a wildcard subdirectory 
/sys/kernel/debug/ieee80211/phy*, but python does not work for that such as:

os.system(echo %i  /sys/kernel/debug/ieee80211/phy*/iwlagn/data/force_mcs % 
mcs)

Any right way to do it?


Don't use os system. Use subprocess. Which incidentially is mentioned in 
the docs for os.system:


  http://docs.python.org/library/os.html#os.system

Then you can pass the use_shell=True parameter - which should work in 
your case.


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


Re: directory wildcard

2009-11-16 Thread Jeff McNeil
On Nov 16, 3:33 pm, hong zhang henryzhan...@yahoo.com wrote:
 List,

 I try to assign value to force_mcs sitting in a wildcard subdirectory 
 /sys/kernel/debug/ieee80211/phy*, but python does not work for that such as:

 os.system(echo %i  /sys/kernel/debug/ieee80211/phy*/iwlagn/data/force_mcs 
 % mcs)

 Any right way to do it?

 Thanks.

 --henry

I'd ditch the echo business altogether. 2.x. Not tested.

import glob

mcs = get_mcs_from_somewhere()
for i in glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/
force_mcs'):
with open(i, 'w') as f:
print f, mcs

Thanks,

Jeff
mcjeff.blogspot.com

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


Re: Redirect stdout to a buffer [Errno 9]

2009-11-16 Thread Ecir Hana
On Nov 16, 7:21 pm, Gabriel Genellina gagsl-...@yahoo.com.ar
wrote:
 En Mon, 16 Nov 2009 14:17:52 -0300, Ecir Hana ecir.h...@gmail.com  
 escribió:

  I'm trying to write a simple Win32 app, which may run some Python
  scripts. Since it is a Windows GUI app, I would like to redirect all
  output (Python print, C printf, fprinf stderr, ...) to a text area
  inside the app. In other words, I'm trying to log all the output from
  the app (C, Python) to a window. So far, this works for C printf():
  [...]
  PS: Maybe I'm doind something wrong, but SetStdHandle() does not work
  at all

 This worked for me:

 #include windows.h
 #include Python.h

 int main()
 {
    HANDLE hReadPipe, hWritePipe;
    DWORD nr, nw;
    char buffer[100];

    CreatePipe(
      hReadPipe,
      hWritePipe,
      NULL,
      1024);
    SetStdHandle(STD_OUTPUT_HANDLE, hWritePipe);

    Py_Initialize();
    PyRun_SimpleString(print 'from Python');
    Py_Finalize();

    puts(from C\n);

    CloseHandle(hWritePipe);
    ReadFile(hReadPipe, buffer, 19, nr, NULL);
    CloseHandle(hReadPipe);
    WriteFile(GetStdHandle(STD_ERROR_HANDLE), buffer, nr, nw, NULL);

 }
  Also, maybe this matters: it's on WinXP, Python 2.6 and MinGW GCC.

 I'm using Visual Studio 2008 Express Edition.

 --
 Gabriel Genellina

Hi,

thanks for the reply!

However, please, could you tell me how many bytes it read here:

ReadFile(hReadPipe, buffer, 19, nr, NULL);

because for me, it has read 0. When I run your code, it prints from
both C and Python, but it prints straight to the console, not to the
buffer. Could you also please try to add:

WriteFile(GetStdHandle(STD_ERROR_HANDLE), \n, 5, nw, NULL);

before:

WriteFile(GetStdHandle(STD_ERROR_HANDLE), buffer, nr, nw, NULL);

Does it print  before from Python and from C for you?
Because for me it comes afterwards (as nr is 0)...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing the current directory (full post)

2009-11-16 Thread Dave Angel



Chris Rebert wrote:

On Mon, Nov 16, 2009 at 11:56 AM, vsoler vicente.so...@gmail.com wrote:
  

On Nov 16, 8:45 pm, Chris Rebert c...@rebertia.com wrote:


On Mon, Nov 16, 2009 at 11:36 AM, vsoler vicente.so...@gmail.com wrote:
  

On Nov 16, 2:35 am, Gabriel Genellina gagsl-...@yahoo.com.ar
wrote:


En Sun, 15 Nov 2009 09:04:06 -0300, vsoler vicente.so...@gmail.com
escribió:
  

Ever since I installed my Python 2.6 interpreter (I use IDLE), I've
been saving my
*.py files in the C:\Program Files\Python26 directory, which is the
default directory for such files in my system.

However, I have realised that the above is not the best practice.

Therefore I created the C:\Program Files\Python26\test directory and I
want it to be my default directory for saving *.py files, importing
modules, etc.


This is *not* a good place either. Non-privileged users should not have
write permission in the C:\Program Files directory.
  

I'd like to do something like the DOS equivalent of   CD test but I
do not know kow to do it.

I am currently doing something really awful: I open a *.py file in the

test subdirectory, I run it with the F5 key and it works! but I am
doing really something stupid.


it works! What's the problem then?
  

How should I proceed, if I want to proceed properly?


Sorry but I don't even see your problem. You can save your .py files
anywhere you like...
  

When I enter IDLE, I'd like to say at the prompt: my current
directory is...  ...test and then be able to run a module in that
directory. This is what my problem is!!!


1. File - Open
2. Navigate to file and choose it
3. Press F5
  

Say that you wanted to import a file in the test directory after just
entering IDLE. How would you do it?



import sys
sys.path.insert(0, C:/path/to/test/dir/here)
import something_in_test_dir

Cheers,
Chris
--
http://blog.rebertia.com

  

Change directory to the test-directory
Then run idle


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


Re: IDE for python

2009-11-16 Thread Ben Finney
Jonathan Hartley tart...@tartley.com writes:

 I'd like to offer the group the anecdote of the great Resolver IDE
 migration.
[…]

It's great to see something refreshing and new — data beyond a single
person's subjective experience! — come out of a topic that looked like
it was just going to re-hash the same tired topic.

Thank you.

-- 
 \   “What I resent is that the range of your vision should be the |
  `\ limit of my action.” —Henry James |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: directory wildcard

2009-11-16 Thread Tim Chase

I try to assign value to force_mcs sitting in a wildcard
subdirectory /sys/kernel/debug/ieee80211/phy*, but python does
not work for that such as:

os.system(echo %i 
/sys/kernel/debug/ieee80211/phy*/iwlagn/data/force_mcs % mcs)

Any right way to do it?


I'm not sure your code works if there's more than one phy* 
directory in that folder anyways since  piping usually only 
works for a single destination.  Though I'd imagine this is only 
a problem for folks that have more than one 802.11 card in their 
machine (which I've done...a useless on-board and a PCMCIA on an 
older laptop).


I'd use python's built-in glob module to do something like

  from glob import glob
  def set_force_mcs(mcs):
for fname in glob('/sys/kernel/debug/'
'ieee80211/phy*/iwlagn/data/force_mcs'):
  f = open(fname, 'w')
  f.write('%i\n' % mcs)
  f.close()
  #the following should all work
  set_force_mcs(True)
  set_force_mcs(False)
  set_force_mcs(1)
  set_force_mcs(0)

(I broke the for/glob line intentionally in a way that python 
transparently restores in case mailers munged them between here 
in there...normally, I'd just use a single string parameter for 
glob() instead of line-breaking it if it fit in 80 chars)


If you're using a more recent version of python that has the 
with command (I think it was added in 2.6, and available from 
2.5's future), it could be tidied to


  with open(fname, 'w') as f:
f.write('%i\n' % mcs)


-tkc


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


mySQL access speed

2009-11-16 Thread Hans Müller
Hello,

I have some programs doing a lot sql IO in some mySQL databases.
This works very fine and the DBAPI is quite simple to understand.

Now I came to the point where I had to insert millions of lines into a table.
My first aproach was to insert the data using executemany().
That's not bad and fairly simple to use.
But it isn't very fast.
For executemany I have some hundred thousend lines in a list of tuples.
I joined() these lines to form an insert into table values () statement and
blew it into the mysql cmdline client via os.popen().
This was 60(!) times faster and loaded my table in seconds!

Is the mySQL module so slow ?

Any ideas to have the mySQL module working faster ?
The popen() way seems quite clumsy and not very pythonic for me,

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


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-16 Thread Barry W Brown
On Nov 16, 10:54 am, Steve Ferg steve.ferg.bitbuc...@gmail.com
wrote:
 This is a question for the language mavens that I know hang out here.
 It is not Python related, except that recent comparisons of Python to
 Google's new Go language brought it to mind.

 NOTE that this is *not* a suggestion to change Python.  I like Python
 just the way it is.  I'm just curious about language design.

 For a long time I've wondered why languages still use blocks
 (delimited by do/end, begin/end, { } , etc.) in ifThenElse statements.

 I've often thought that a language with this kind of block-free syntax
 would be nice and intuitive:

     if condition then
         do stuff
     elif condition then
         do stuff
     else
         do stuff
     endif

 Note that you do not need block delimiters.

 Obviously, you could make a more Pythonesque syntax by using a colon
 rather then then for the condition terminator.  You could make it
 more PL/I-like by using do, etc.

 You can write shell scripts using if ... fi, but other than that I
 don't recall a language with this kind of syntax.

 Does anybody know a language with this kind of syntax for
 ifThenElseEndif?

 Is there any particular reason why this might be a *bad* language-
 design idea?

Fortran95.  You can even label the IF...END IF structure -- handy for
immense blocks.

This is not a criticism of Python (or of Fortran).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: directory wildcard

2009-11-16 Thread hong zhang


--- On Mon, 11/16/09, Jeff McNeil j...@jmcneil.net wrote:

 From: Jeff McNeil j...@jmcneil.net
 Subject: Re: directory wildcard
 To: python-list@python.org
 Date: Monday, November 16, 2009, 3:01 PM
 On Nov 16, 3:33 pm, hong zhang
 henryzhan...@yahoo.com
 wrote:
  List,
 
  I try to assign value to force_mcs sitting in a
 wildcard subdirectory /sys/kernel/debug/ieee80211/phy*, but
 python does not work for that such as:
 
  os.system(echo %i 
 /sys/kernel/debug/ieee80211/phy*/iwlagn/data/force_mcs %
 mcs)
 
  Any right way to do it?
 
  Thanks.
 
  --henry
 
 I'd ditch the echo business altogether. 2.x. Not tested.
 
 import glob
 
 mcs = get_mcs_from_somewhere()
 for i in
 glob.glob('/sys/kernel/debug/ieee80211/phy*/iwlagn/data/
 force_mcs'):
     with open(i, 'w') as f:
         print f, mcs

This assigns decimal value, how can I assign Hex here to mcs?
 


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


Re: mySQL access speed

2009-11-16 Thread Dikkie Dik
 ... But it isn't very fast.
 For executemany I have some hundred thousend lines in a list of tuples.
 I joined() these lines to form an insert into table values () statement 
 and
 blew it into the mysql cmdline client via os.popen().
 This was 60(!) times faster and loaded my table in seconds!
 
 Is the mySQL module so slow ?


No. The fact that each statement is atomic makes it slow. Try the
multiple queries, but precede them with a SET AUTOCOMMIT=0 statement
or use a transaction. You will probably see a tremendous speed increase.

When you combine all the queries into one statement, you are effectively
doing the same.

Best regards,
Dikkie.
-- 
http://mail.python.org/mailman/listinfo/python-list


faster than list.extend()

2009-11-16 Thread Hyunchul Kim
Hi, all.

I want to improve speed of following simple function.
Any suggestion?

**
def triple(inputlist):
  results = []
  for x in inputlist:
results.extend([x,x,x])
  return results
**

Thank you in advance,

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


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-16 Thread Erik Max Francis

r wrote:

On Nov 16, 10:54 am, Steve Ferg steve.ferg.bitbuc...@gmail.com
wrote:


I've often thought that a language with this kind of block-free syntax
would be nice and intuitive:

if condition then
do stuff
elif condition then
do stuff
else
do stuff
endif


WHY? Python's syntax is by far the most elegant of all, no need to
show the end of a block. Python is the smartest kid on the block. And
are you saying you would rather type then instead of : and endif
instead of \n?

No thanks!


You clipped out the part where he explicitly said it was not a 
suggestion to change Python.


--
Erik Max Francis  m...@alcyone.com  http://www.alcyone.com/max/
 San Jose, CA, USA  37 18 N 121 57 W  AIM/Y!M/Skype erikmaxfrancis
  Mona Lisa / Come to discover / I am your daughter
   -- Lamya
--
http://mail.python.org/mailman/listinfo/python-list


Re: Language mavens: Is there a programming with if then else ENDIF syntax?

2009-11-16 Thread Erik Max Francis

Steve Ferg wrote:

I've often thought that a language with this kind of block-free syntax
would be nice and intuitive:

if condition then
do stuff
elif condition then
do stuff
else
do stuff
endif

Note that you do not need block delimiters.

Obviously, you could make a more Pythonesque syntax by using a colon
rather then then for the condition terminator.  You could make it
more PL/I-like by using do, etc.

You can write shell scripts using if ... fi, but other than that I
don't recall a language with this kind of syntax.


It's the same syntax, with `fi` written instead of `endif` -- not sure 
why the difference in keyword is that big of a deal to you.


As others have pointed out, either way, there are quite a few languages 
that use this type of syntax.


--
Erik Max Francis  m...@alcyone.com  http://www.alcyone.com/max/
 San Jose, CA, USA  37 18 N 121 57 W  AIM/Y!M/Skype erikmaxfrancis
  Mona Lisa / Come to discover / I am your daughter
   -- Lamya
--
http://mail.python.org/mailman/listinfo/python-list


Re: faster than list.extend()

2009-11-16 Thread Chris Rebert
On Mon, Nov 16, 2009 at 2:30 PM, Hyunchul Kim
hyunchul.mail...@gmail.com wrote:
 Hi, all.

 I want to improve speed of following simple function.
 Any suggestion?

 **
 def triple(inputlist):
   results = []
   for x in inputlist:
     results.extend([x,x,x])
   return results
 **

You'd probably be better off calling .append() 3 times instead of
.extend() as it would avoid the creation of all those intermediate
3-element lists.

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


Re: Changing the current directory (full post)

2009-11-16 Thread Gabriel Genellina

En Mon, 16 Nov 2009 18:10:51 -0300, Dave Angel da...@ieee.org escribió:

Chris Rebert wrote:
On Mon, Nov 16, 2009 at 11:56 AM, vsoler vicente.so...@gmail.com  
wrote:



When I enter IDLE, I'd like to say at the prompt: my current
directory is...  ...test and then be able to run a module in that
directory. This is what my problem is!!!



Change directory to the test-directory
Then run idle


Or, modify the Initial Directory in the menu shortcut that you use to  
start IDLE (right click, Properties). Or create another shortcut in your  
desktop using your desired initial directory.


--
Gabriel Genellina

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


  1   2   >