Re: Python 2.7.2 on Win7 and IDLE (Try it)

2011-11-18 Thread W. eWatson

On 11/18/2011 9:03 PM, W. eWatson wrote:

...


3.3.2? I do not see that in his single message I found. I see a 3.2.2
release on . Google
shows me nothing for 3.3.2.

I see:
* Windows x86 MSI Installer (3.2.2) (sig) and Visual Studio debug
information files (sig)
* Windows X86-64 MSI Installer (3.2.2) [1] (sig) and Visual Studio debug
information files (sig)

Visual Studio I hope I don't need VS!


If you look more closely you'll see that there are 5 links on each line:

Windows X86-64 MSI Installer (3.2.2)
[1]
(sig)
Visual Studio debug information files
(sig)

Unless you intending to work on the sources, you need just the first
one:

Windows X86-64 MSI Installer (3.2.2)

for a 64-bit build of Python 3.2.2.


An oddity occurs here. Yes, x86-64 is the right installer, maybe. While
noting your msg, my PC got very slow, and I ended up going to a related
site for the downloads of 3.2.2 while trying for the one above.
.

It shows:
Also look at the detailed Python 3.2.2 page:

* Python 3.2.2 Windows x86 MSI Installer (Windows binary -- does not
include source)
* Python 3.2.2 Windows X86-64 MSI Installer (Windows AMD64 / Intel 64 /
X86-64 binary [1] -- does not include source)

The first of the two choices does not say x-bit anything. The second
looks off course for my HP 64-bit PC.

I'm going to just use Windows X86-64 MSI Installer (3.2.2).

Wait a minute Windows X86-64 MSI Installer (3.2.2). Windows X86-64 MSI
Installer (3.2.2) shows it's associated with Visual Studio. Why would I
want that? Ah, I get it The single first line has Windows X86-64 MSI
Installer (3.2.2) and Visual Studio. That's a really weird way to
arrange them. OK, now off to Windows X86-64 MSI Installer (3.2.2)

I'll be back shortly after I've made the install.


I surrender. IDLE does not appear as a choice when I right-click on a py 
file.


IDLE is on the All Programs list, and if I click on it, something more 
or less seems to happen, but it does not reveal anything. There is a 
comparability choice there that asks what OS did it last run on. 
Unfortunately the choices were VISTA (service packs) and Win7. I 
selected Win7 but it didn't help. Off to bed soon.

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


Re: Python 2.7.2 on Win7 and IDLE (Try it)

2011-11-18 Thread W. eWatson

...


3.3.2? I do not see that in his single message I found. I see a 3.2.2
release on . Google
shows me nothing for 3.3.2.

I see:
* Windows x86 MSI Installer (3.2.2) (sig) and Visual Studio debug
information files (sig)
* Windows X86-64 MSI Installer (3.2.2) [1] (sig) and Visual Studio debug
information files (sig)

Visual Studio I hope I don't need VS!


If you look more closely you'll see that there are 5 links on each line:

Windows X86-64 MSI Installer (3.2.2)
[1]
(sig)
Visual Studio debug information files
(sig)

Unless you intending to work on the sources, you need just the first
one:

Windows X86-64 MSI Installer (3.2.2)

for a 64-bit build of Python 3.2.2.


An oddity occurs here. Yes, x86-64 is the right installer, maybe. While 
noting your msg, my PC got very slow, and I ended up going to a related 
site for the downloads of 3.2.2 while trying for the one above. 
.


It shows:
Also look at the detailed Python 3.2.2 page:

* Python 3.2.2 Windows x86 MSI Installer (Windows binary -- does 
not include source)
* Python 3.2.2 Windows X86-64 MSI Installer (Windows AMD64 / Intel 
64 / X86-64 binary [1] -- does not include source)


The first of the two choices does not say x-bit anything. The second 
looks off course for my HP 64-bit PC.


I'm going to just use Windows X86-64 MSI Installer (3.2.2).

Wait a minute Windows X86-64 MSI Installer (3.2.2). Windows X86-64 MSI 
Installer (3.2.2) shows it's associated with Visual Studio.  Why would I 
want that? Ah, I get it The single first line has Windows X86-64 MSI 
Installer (3.2.2) and Visual Studio.  That's a really weird way to 
arrange them. OK, now off to Windows X86-64 MSI Installer (3.2.2)


I'll be back shortly after I've made the install.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7.2 on Win7 and IDLE (Try it)

2011-11-18 Thread Steven D'Aprano
On Fri, 18 Nov 2011 16:31:03 -0800, W. eWatson wrote:

> Somehow 3.3.2 doesn't look like 2.7.2.

Oops, so you're right. Sorry for the noise.

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


Re: Data Plotting Library Dislin 10.2

2011-11-18 Thread sturlamolden
On 18 Nov, 22:16, Tony the Tiger  wrote:

> Ya, but apparently no source unless you dig deep into your pockets.
> Really, why would we need this when we already have gnuplot?
> Just wondering...

Dislin is a very nice plotting library for scientific data,
particularly for scientists and engineers using Fortran (which,
incidentally, is quite a few).

For Python, we have Matplotlib as well (at least for 2D plots).


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


Re: Why sock.bind is always report 10048 error when in a script with multiprocessing

2011-11-18 Thread Junfeng Hu
On Nov 18, 10:55 am, MRAB  wrote:
> On 18/11/2011 15:48, Junfeng Hu wrote:
>
>
>
>
>
> > Thanks
> > Yes, I had tried this before, so you could find that I comment the line
> > sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
> > Here is the results.
> > D:\Python test>mythread2.py
> > Traceback (most recent call last):
> >    File "", line 1, in
> >    File "C:\Python27\lib\multiprocessing\forking.py", line 347, in main
> >      self = load(from_parent)
> >    File "C:\Python27\lib\pickle.py", line 1378, in load
> >      return Unpickler(file).load()
> >    File "C:\Python27\lib\pickle.py", line 858, in load
> >      dispatch[key](self)
> >    File "C:\Python27\lib\pickle.py", line 1133, in load_reduce
> >      value = func(*args)
> >    File "C:\Python27\lib\multiprocessing\reduction.py", line 167, in 
> > rebuild_sock
> > et
> >      _sock = fromfd(fd, family, type_, proto)
> >    File "C:\Python27\lib\multiprocessing\reduction.py", line 156, in fromfd
> >      s = socket.fromfd(fd, family, type_, proto)
> > AttributeError: 'module' object has no attribute 'fromfd'
>
> The documentation for socket.fromfd says:
>
>      Availability: Unix.
>
> You're using Microsoft Windows.- Hide quoted text -
>
> - Show quoted text -

Yes, but my question is , how to make such script work in windows.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7.2 on Win7 and IDLE (Try it)

2011-11-18 Thread MRAB

On 19/11/2011 00:50, W. eWatson wrote:

On 11/18/2011 4:31 PM, W. eWatson wrote:

On 11/18/2011 3:44 PM, Steven D'Aprano wrote:

On Fri, 18 Nov 2011 10:06:47 -0800, W. eWatson wrote:


Undoubtedly some of you have seen my post Both Python 2.5.2 and 2.7.2
flop the same way under Win 7.

One thing I think no one has offered is whether their installation of
2.7.2 has the same IDLE oddity that I've described. That is, if you
right-click on a py file, do you see a choice for the IDLE editor?


Terry Reedy has already said that his installation works fine.

"I installed 3.3.2 on a new Win 7 machine and Edit with IDLE works
fine."


If you have installed the regular, 32-bit version of Python on a 64-bit
version of Windows, chances are good that there will be registry
problems
stopping things from working correctly. See Stephen Hansen's post.




Somehow 3.3.2 doesn't look like 2.7.2.

Ah, I installed a 32-bit. Missed his post. So what should I do? Try
3.3.2 64-bit? I'm game. By the time you read this, I will either have
done it or gotten into it.


3.3.2? I do not see that in his single message I found. I see a 3.2.2
release on . Google
shows me nothing for 3.3.2.

I see:
* Windows x86 MSI Installer (3.2.2) (sig) and Visual Studio debug
information files (sig)
* Windows X86-64 MSI Installer (3.2.2) [1] (sig) and Visual Studio debug
information files (sig)

Visual Studio I hope I don't need VS!


If you look more closely you'll see that there are 5 links on each line:

Windows X86-64 MSI Installer (3.2.2)
[1]
(sig)
Visual Studio debug information files
(sig)

Unless you intending to work on the sources, you need just the first
one:

Windows X86-64 MSI Installer (3.2.2)

for a 64-bit build of Python 3.2.2.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7.2 on Win7 and IDLE (Try it)

2011-11-18 Thread W. eWatson

On 11/18/2011 4:31 PM, W. eWatson wrote:

On 11/18/2011 3:44 PM, Steven D'Aprano wrote:

On Fri, 18 Nov 2011 10:06:47 -0800, W. eWatson wrote:


Undoubtedly some of you have seen my post Both Python 2.5.2 and 2.7.2
flop the same way under Win 7.

One thing I think no one has offered is whether their installation of
2.7.2 has the same IDLE oddity that I've described. That is, if you
right-click on a py file, do you see a choice for the IDLE editor?


Terry Reedy has already said that his installation works fine.

"I installed 3.3.2 on a new Win 7 machine and Edit with IDLE works fine."


If you have installed the regular, 32-bit version of Python on a 64-bit
version of Windows, chances are good that there will be registry problems
stopping things from working correctly. See Stephen Hansen's post.




Somehow 3.3.2 doesn't look like 2.7.2.

Ah, I installed a 32-bit. Missed his post. So what should I do? Try
3.3.2 64-bit? I'm game. By the time you read this, I will either have
done it or gotten into it.


3.3.2? I do not see that in his single message I found. I see a 3.2.2 
release on . Google 
shows me nothing for 3.3.2.


I see:
* Windows x86 MSI Installer (3.2.2) (sig) and Visual Studio debug 
information files (sig)
* Windows X86-64 MSI Installer (3.2.2) [1] (sig) and Visual Studio 
debug information files (sig)


Visual Studio  I hope I don't need VS!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7.2 on Win7 and IDLE (Try it)

2011-11-18 Thread W. eWatson

On 11/18/2011 3:44 PM, Steven D'Aprano wrote:

On Fri, 18 Nov 2011 10:06:47 -0800, W. eWatson wrote:


Undoubtedly some of you have seen my post Both Python 2.5.2 and 2.7.2
flop the same way under Win 7.

One thing I think no one has offered is whether their installation of
2.7.2 has the same IDLE oddity that I've described.  That is, if you
right-click on a py file, do you see a choice for the IDLE editor?


Terry Reedy has already said that his installation works fine.

"I installed 3.3.2 on a new Win 7 machine and Edit with IDLE works fine."


If you have installed the regular, 32-bit version of Python on a 64-bit
version of Windows, chances are good that there will be registry problems
stopping things from working correctly. See Stephen Hansen's post.




Somehow 3.3.2 doesn't look like 2.7.2.

Ah, I installed a 32-bit.  Missed his post. So what should I do? Try 
3.3.2 64-bit? I'm game. By the time you read this, I will either have 
done it or gotten into it.

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


Re: Python 2.7.2 on Win7 and IDLE (Try it)

2011-11-18 Thread Steven D'Aprano
On Fri, 18 Nov 2011 10:06:47 -0800, W. eWatson wrote:

> Undoubtedly some of you have seen my post Both Python 2.5.2 and 2.7.2
> flop the same way under Win 7.
> 
> One thing I think no one has offered is whether their installation of
> 2.7.2 has the same IDLE oddity that I've described.  That is, if you
> right-click on a py file, do you see a choice for the IDLE editor?

Terry Reedy has already said that his installation works fine.

"I installed 3.3.2 on a new Win 7 machine and Edit with IDLE works fine."


If you have installed the regular, 32-bit version of Python on a 64-bit 
version of Windows, chances are good that there will be registry problems 
stopping things from working correctly. See Stephen Hansen's post.



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


Re: Both Python 2.5.2 and 2.7.2 flop the same way under Win 7

2011-11-18 Thread Stephen Hansen
On 11/17/11 8:34 PM, W. eWatson wrote:
> On 11/17/2011 7:04 PM, alex23 wrote:
>> On Nov 18, 2:55 am, "W. eWatson"  wrote:
>>> Comments?
>>
>> Are you using the vanilla installer or ActiveState's ActivePython? I
>> find the latter integrates better with Windows.
>>
>> Also, out of curiousity, 32 or 64 bit Windows?
> 64-bit and plain old python msi installer.

That'd be it, I expect.

Windows has two parallel registry trees; if you launch a 32-bit program,
it sees one.. if you launch a 64-bit program, it sees the other. What
looks like the exact same keys can be different as a result.

The MSI is probably writing the keys into the 32-bit registry, and
Explorer is now a 64-bit application.

You can add the associations for Edit manually. Though not to
"idle.pyw", which you keep -- repeatedly -- saying you try and errors.
Of course it errors. That's a python script, not an executable.

Associate to pythonw.exe, and pass it the path to idle.pyw, and then -n
-e "%1" -- which will be replaced with the actual filename. But you were
told that already and seem to have just dismissed it out of hand.

Like: PATH\pythonw.exe PATH\idle.pyw -n -e "%1"

... where PATH is whatever the location of those files are in your
environment.

Yes, its moderately annoying that you have to do this yourself; maybe
you wouldn't if you installed 64-bit python, but I can't be sure. Maybe
it has nothing to do with 32 or 64-bitness at all and my guess is wrong.
Maybe your profile has gone wonky. But it doesn't matter. You can add
the Edit association yourself. Its a one-time fix.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Resources consumed by parent

2011-11-18 Thread Mihai Badoiu
How do I get the resources consumed by the parent process?

getrusage() in the resource module seems to work only for self or the
children processes.

thanks,

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


Re: Python 2.7.2 on Win7 and IDLE (Try it)

2011-11-18 Thread W. eWatson

On 11/18/2011 10:06 AM, W. eWatson wrote:

Undoubtedly some of you have seen my post Both Python 2.5.2 and 2.7.2
flop the same way under Win 7.

One thing I think no one has offered is whether their installation of
2.7.2 has the same IDLE oddity that I've described. That is, if you
right-click on a py file, do you see a choice for the IDLE editor?


Try it on Win 7.
--
http://mail.python.org/mailman/listinfo/python-list


Python 2.7.2 on Win7 and IDLE (Try it)

2011-11-18 Thread W. eWatson
Undoubtedly some of you have seen my post Both Python 2.5.2 and 2.7.2 
flop the same way under Win 7.


One thing I think no one has offered is whether their installation of 
2.7.2 has the same IDLE oddity that I've described.  That is, if you 
right-click on a py file, do you see a choice for the IDLE editor?

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


Re: Dynamically Generate Methods

2011-11-18 Thread Ian Kelly
On Fri, Nov 18, 2011 at 7:51 AM, GZ  wrote:
> Hi,
>
> I have a class Record and a list key_attrs that specifies the names of
> all attributes that correspond to a primary key.
>
> I can write a function like this to get the primary key:
>
> def get_key(instance_of_record):
>   return tuple(instance_of_record.__dict__[k] for k in key_attrs)
>
> However, since key_attrs are determined at the beginning of the
> program while get_key() will be called over and over again, I am
> wondering if there is a way to dynamically generate a get_ley method
> with the key attributes expanded to avoid the list comprehension/
> generator.

(Accidentally sent this to the OP only)

This is exactly what the attrgetter factory function produces.

from operator import attrgetter
get_key = attrgetter(*key_attrs)

But if your attribute names are variable and arbitrary, I strongly
recommend you store them in a dict instead.  Setting them as instance
attributes risks that they might conflict with the regular attributes
and methods on your objects.

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


Re: Both Python 2.5.2 and 2.7.2 flop the same way under Win 7

2011-11-18 Thread W. eWatson

On 11/17/2011 9:25 PM, Benjamin Kaplan wrote:

On Thu, Nov 17, 2011 at 11:21 PM, W. eWatson  wrote:


On 11/17/2011 7:59 PM, Dave Angel wrote:


On 11/17/2011 03:31 PM, W. eWatson wrote:


On 11/17/2011 9:39 AM, John Gordon wrote:



Can you add IDLE manually to the associated applications list?


Tried that by sending it directly to idle.pyw, but then trying to get
there through the Edit with menu caused a "invalid Win32 app."


You've been told repeatedly that building an association to idle.pyw is
useless. It must be to something Windows understands, such as .exe, or
.bat (or several other extensions, as I said in an earlier message) So
why waste our time telling us yet again that it doesn't work?




Because some  people think that's a solution, and ask. It's not. It leads to an 
error message.



Checking my Python install, there should be an idle.bat file in there
too. Have you tried that?

Yes. I tried running it. Got nowhere.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Both Python 2.5.2 and 2.7.2 flop the same way under Win 7

2011-11-18 Thread W. eWatson

On 11/17/2011 11:35 PM, Terry Reedy wrote:

On 11/17/2011 7:03 PM, W. eWatson wrote:


I have not found any successful way to get to IDLE.


Use the start menu to start IDLE once. Then pin it to your taskbar.
If you do not have STart/ all programs / Python / IDLE, then your
installation is bad.

As for the right click problem, you probably have something screwy in
the registry. The python installer (or uninstaller) will not fix it (my
experience on my old xp machine). You will have to do so manually.

IDLE is a choice on the Start menu (All Programs). Pressing it does 
nothing. I see nothing that suggests it's open.


The IDLE entry is pointing at c:\Python27\ (shortcut)

A post above yours suggests IDLE is a script, and somehow needs a 
"boost" to use it. An exe file, apparently.  Beats the heck out of me.

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


Re: Dynamically Generate Methods

2011-11-18 Thread Duncan Booth
GZ  wrote:

> For example, if key_attrs=['A','B'], I want the generated function to
> be equivalent to the following:
> 
> def get_key(instance_of_record):
>return (instance_of_record['A'],instance_of_record['B'] )
> 
> I realize I can use eval or exec to do this. But is there any other
> way to do this?
> 

Use operator.itemgetter:

>>> key_attrs = ['A', 'B']
>>> import operator
>>> get_key = operator.itemgetter(*key_attrs)
>>> d = {'A': 42, 'B': 63, 'C': 99}
>>> get_key(d)
(42, 63)

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Both Python 2.5.2 and 2.7.2 flop the same way under Win 7

2011-11-18 Thread W. eWatson

On 11/18/2011 9:19 AM, rusi wrote:

On Nov 18, 10:12 pm, MRAB  wrote:

On 18/11/2011 15:29, W. eWatson wrote:








On 11/18/2011 5:11 AM, Neil Cerutti wrote:

On 2011-11-18, W. eWatson  wrote:

On 11/17/2011 4:24 PM, Steven D'Aprano wrote:

On Thu, 17 Nov 2011 16:03:14 -0800, W. eWatson wrote:



I have not found any successful way to get to IDLE. It's on on the
right-click of a py menu, and, if I go the ...lib/idle.pyw, it fails
with a "invalid Win32 app" msg.



If you associate .pyw files with pythonw.exe, and then open idle.pyw,
does it work?



Failing that, go to your laptop where the associations are right,
and see
what they are, then duplicate the settings on your Windows 7 machine.



Sounds like a good idea except I've not used associations in so
long under XP, I have no idea where to start. Control Panel. My
Computer Tools?



Open Windows Explorer.
With the menu, to to Tools->Folder Options
Click the File Types tab in the Folder Options menu.



There will be an upper view with registered filed types, and some
buttons below far making changes to them.



OK, I've found that. I see
Py
Pyc
Pyo
Pyw
If I click on each, it basically it gives a short description of each.
If I click advanced, there's more info. For example for py, Actions are
IDLE and Open.



What does this tell me that's relevant to Win7?



If on Win7, I go to Default Programs I see under associations various
python items. Py shows Unknown application. Since installing 2.7.2 I
have not messed with these associations. If I right-click on Unknown, I
see Notepad and python.exe for choices to open the file. I want neither.
Why isn't IDLE listed there?



If I right-click on junk.py, I see "Open with". Notepad and python.exe
are choices. However, that menu allows me to choose something else. For
example, Adobe Reader, or Internet Explorer. I suppose the next question
is should I use the browse there and try to connect to IDLE in
...\Lib\idlelib? My guess is that if I do, I will run into the "invalid
Win32 app", when I try to use it.


You can't associate .py with Idle because Idle is a Python script, not
an executable (an .exe).

Have a look 
here:http://superuser.com/questions/68852/change-windows-7-explorer-edit-c...

In my PC's registry (Windows XP, but Windows 7 should be similar or the
same) it has the entry:

Key: HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE\command
Value: "C:\Python31\pythonw.exe" "C:\Python31\Lib\idlelib\idle.pyw" -n
-e "%1"

Note how it actually associates the Edit action of Python files with an
.exe file.


The tools ->  folder options approach is the user-friendly approach --
when it works.
The 'Correct the registry' is the muscular approach -- it will set
right everything iff you are a wizard.

In between the two is assoc and ftype see
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ftype.mspx?mfr=true
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/assoc.mspx?mfr=true
These two seem equally muscular. I shudder to think where these choices 
might lead me.

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


Re: Both Python 2.5.2 and 2.7.2 flop the same way under Win 7

2011-11-18 Thread W. eWatson

On 11/18/2011 9:12 AM, MRAB wrote:

On 18/11/2011 15:29, W. eWatson wrote:

On 11/18/2011 5:11 AM, Neil Cerutti wrote:

On 2011-11-18, W. eWatson wrote:

On 11/17/2011 4:24 PM, Steven D'Aprano wrote:

On Thu, 17 Nov 2011 16:03:14 -0800, W. eWatson wrote:


I have not found any successful way to get to IDLE. It's on on the
right-click of a py menu, and, if I go the ...lib/idle.pyw, it fails
with a "invalid Win32 app" msg.


If you associate .pyw files with pythonw.exe, and then open idle.pyw,
does it work?

Failing that, go to your laptop where the associations are right,
and see
what they are, then duplicate the settings on your Windows 7 machine.


Sounds like a good idea except I've not used associations in so
long under XP, I have no idea where to start. Control Panel. My
Computer Tools?


Open Windows Explorer.
With the menu, to to Tools->Folder Options
Click the File Types tab in the Folder Options menu.

There will be an upper view with registered filed types, and some
buttons below far making changes to them.


OK, I've found that. I see
Py
Pyc
Pyo
Pyw
If I click on each, it basically it gives a short description of each.
If I click advanced, there's more info. For example for py, Actions are
IDLE and Open.

What does this tell me that's relevant to Win7?

If on Win7, I go to Default Programs I see under associations various
python items. Py shows Unknown application. Since installing 2.7.2 I
have not messed with these associations. If I right-click on Unknown, I
see Notepad and python.exe for choices to open the file. I want neither.
Why isn't IDLE listed there?

If I right-click on junk.py, I see "Open with". Notepad and python.exe
are choices. However, that menu allows me to choose something else. For
example, Adobe Reader, or Internet Explorer. I suppose the next question
is should I use the browse there and try to connect to IDLE in
...\Lib\idlelib? My guess is that if I do, I will run into the "invalid
Win32 app", when I try to use it.


You can't associate .py with Idle because Idle is a Python script, not
an executable (an .exe).


Odd, but OK.



Have a look here:
http://superuser.com/questions/68852/change-windows-7-explorer-edit-context-menu-action-for-jpg-and-other-image-fil

Are you suggesting that I use the "default" program mentioned there?



In my PC's registry (Windows XP, but Windows 7 should be similar or the
same) it has the entry:

Key: HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE\command
Value: "C:\Python31\pythonw.exe" "C:\Python31\Lib\idlelib\idle.pyw" -n
-e "%1"

Note how it actually associates the Edit action of Python files with an
.exe file.

So pythonw.exe and idle.pyw are not scripts but somehow can fire up idle?

Are you suggesting I modify my registry?  I still find it bizarre the 
install did not put it IDLE choice on the menu for py. It's there on XP.

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


Re: Both Python 2.5.2 and 2.7.2 flop the same way under Win 7

2011-11-18 Thread rusi
On Nov 18, 10:12 pm, MRAB  wrote:
> On 18/11/2011 15:29, W. eWatson wrote:
>
>
>
>
>
>
>
> > On 11/18/2011 5:11 AM, Neil Cerutti wrote:
> >> On 2011-11-18, W. eWatson wrote:
> >>> On 11/17/2011 4:24 PM, Steven D'Aprano wrote:
>  On Thu, 17 Nov 2011 16:03:14 -0800, W. eWatson wrote:
>
> > I have not found any successful way to get to IDLE. It's on on the
> > right-click of a py menu, and, if I go the ...lib/idle.pyw, it fails
> > with a "invalid Win32 app" msg.
>
>  If you associate .pyw files with pythonw.exe, and then open idle.pyw,
>  does it work?
>
>  Failing that, go to your laptop where the associations are right,
>  and see
>  what they are, then duplicate the settings on your Windows 7 machine.
>
> >>> Sounds like a good idea except I've not used associations in so
> >>> long under XP, I have no idea where to start. Control Panel. My
> >>> Computer Tools?
>
> >> Open Windows Explorer.
> >> With the menu, to to Tools->Folder Options
> >> Click the File Types tab in the Folder Options menu.
>
> >> There will be an upper view with registered filed types, and some
> >> buttons below far making changes to them.
>
> > OK, I've found that. I see
> > Py
> > Pyc
> > Pyo
> > Pyw
> > If I click on each, it basically it gives a short description of each.
> > If I click advanced, there's more info. For example for py, Actions are
> > IDLE and Open.
>
> > What does this tell me that's relevant to Win7?
>
> > If on Win7, I go to Default Programs I see under associations various
> > python items. Py shows Unknown application. Since installing 2.7.2 I
> > have not messed with these associations. If I right-click on Unknown, I
> > see Notepad and python.exe for choices to open the file. I want neither.
> > Why isn't IDLE listed there?
>
> > If I right-click on junk.py, I see "Open with". Notepad and python.exe
> > are choices. However, that menu allows me to choose something else. For
> > example, Adobe Reader, or Internet Explorer. I suppose the next question
> > is should I use the browse there and try to connect to IDLE in
> > ...\Lib\idlelib? My guess is that if I do, I will run into the "invalid
> > Win32 app", when I try to use it.
>
> You can't associate .py with Idle because Idle is a Python script, not
> an executable (an .exe).
>
> Have a look 
> here:http://superuser.com/questions/68852/change-windows-7-explorer-edit-c...
>
> In my PC's registry (Windows XP, but Windows 7 should be similar or the
> same) it has the entry:
>
> Key: HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE\command
> Value: "C:\Python31\pythonw.exe" "C:\Python31\Lib\idlelib\idle.pyw" -n
> -e "%1"
>
> Note how it actually associates the Edit action of Python files with an
> .exe file.

The tools -> folder options approach is the user-friendly approach --
when it works.
The 'Correct the registry' is the muscular approach -- it will set
right everything iff you are a wizard.

In between the two is assoc and ftype see
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ftype.mspx?mfr=true
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/assoc.mspx?mfr=true
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Both Python 2.5.2 and 2.7.2 flop the same way under Win 7

2011-11-18 Thread MRAB

On 18/11/2011 15:29, W. eWatson wrote:

On 11/18/2011 5:11 AM, Neil Cerutti wrote:

On 2011-11-18, W. eWatson wrote:

On 11/17/2011 4:24 PM, Steven D'Aprano wrote:

On Thu, 17 Nov 2011 16:03:14 -0800, W. eWatson wrote:


I have not found any successful way to get to IDLE. It's on on the
right-click of a py menu, and, if I go the ...lib/idle.pyw, it fails
with a "invalid Win32 app" msg.


If you associate .pyw files with pythonw.exe, and then open idle.pyw,
does it work?

Failing that, go to your laptop where the associations are right,
and see
what they are, then duplicate the settings on your Windows 7 machine.


Sounds like a good idea except I've not used associations in so
long under XP, I have no idea where to start. Control Panel. My
Computer Tools?


Open Windows Explorer.
With the menu, to to Tools->Folder Options
Click the File Types tab in the Folder Options menu.

There will be an upper view with registered filed types, and some
buttons below far making changes to them.


OK, I've found that. I see
Py
Pyc
Pyo
Pyw
If I click on each, it basically it gives a short description of each.
If I click advanced, there's more info. For example for py, Actions are
IDLE and Open.

What does this tell me that's relevant to Win7?

If on Win7, I go to Default Programs I see under associations various
python items. Py shows Unknown application. Since installing 2.7.2 I
have not messed with these associations. If I right-click on Unknown, I
see Notepad and python.exe for choices to open the file. I want neither.
Why isn't IDLE listed there?

If I right-click on junk.py, I see "Open with". Notepad and python.exe
are choices. However, that menu allows me to choose something else. For
example, Adobe Reader, or Internet Explorer. I suppose the next question
is should I use the browse there and try to connect to IDLE in
...\Lib\idlelib? My guess is that if I do, I will run into the "invalid
Win32 app", when I try to use it.


You can't associate .py with Idle because Idle is a Python script, not
an executable (an .exe).

Have a look here:
http://superuser.com/questions/68852/change-windows-7-explorer-edit-context-menu-action-for-jpg-and-other-image-fil

In my PC's registry (Windows XP, but Windows 7 should be similar or the
same) it has the entry:

Key: HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE\command
Value: "C:\Python31\pythonw.exe" "C:\Python31\Lib\idlelib\idle.pyw" -n 
-e "%1"


Note how it actually associates the Edit action of Python files with an
.exe file.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamically Generate Methods

2011-11-18 Thread Jean-Michel Pichavant

GZ wrote:

Hi,

I have a class Record and a list key_attrs that specifies the names of
all attributes that correspond to a primary key.

I can write a function like this to get the primary key:

def get_key(instance_of_record):
   return tuple(instance_of_record.__dict__[k] for k in key_attrs)

However, since key_attrs are determined at the beginning of the
program while get_key() will be called over and over again, I am
wondering if there is a way to dynamically generate a get_ley method
with the key attributes expanded to avoid the list comprehension/
generator.

For example, if key_attrs=['A','B'], I want the generated function to
be equivalent to the following:

def get_key(instance_of_record):
   return (instance_of_record['A'],instance_of_record['B'] )

I realize I can use eval or exec to do this. But is there any other
way to do this?

Thanks,
gz



  

Hi,

you may want to do something like

class Record(object):
 PRIMARY_KEY = []
 def __init__(self):
   for key in self.PRIMARY_KEY:
 setattr(self, key, None)

 def getPrimaryKeyValues(self):
   return [ getattr(self, key) for key in self.PRIMARY_KEY]


class FruitRecord(Record):
 PRIMARY_KEY = ['fruit_id', 'fruit_name']



JM

PS : there's a high chance that a python module already exists to access 
your database with python objects.

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


Re: Why sock.bind is always report 10048 error when in a script with multiprocessing

2011-11-18 Thread MRAB

On 18/11/2011 15:48, Junfeng Hu wrote:

Thanks
Yes, I had tried this before, so you could find that I comment the line
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Here is the results.
D:\Python test>mythread2.py
Traceback (most recent call last):
   File "", line 1, in
   File "C:\Python27\lib\multiprocessing\forking.py", line 347, in main
 self = load(from_parent)
   File "C:\Python27\lib\pickle.py", line 1378, in load
 return Unpickler(file).load()
   File "C:\Python27\lib\pickle.py", line 858, in load
 dispatch[key](self)
   File "C:\Python27\lib\pickle.py", line 1133, in load_reduce
 value = func(*args)
   File "C:\Python27\lib\multiprocessing\reduction.py", line 167, in 
rebuild_sock
et
 _sock = fromfd(fd, family, type_, proto)
   File "C:\Python27\lib\multiprocessing\reduction.py", line 156, in fromfd
 s = socket.fromfd(fd, family, type_, proto)
AttributeError: 'module' object has no attribute 'fromfd'


The documentation for socket.fromfd says:

Availability: Unix.

You're using Microsoft Windows.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why sock.bind is always report 10048 error when in a script with multiprocessing

2011-11-18 Thread Chris Angelico
On Sat, Nov 19, 2011 at 3:11 AM, Junfeng Hu  wrote:
> Hi Chris.
> The socket only binded once. That's the problem I'm puzzleing, I think it may 
> a bug of multiprocessing in windows, or something I missed.

I don't know how multiprocessing goes about initializing those
subprocesses; I suspect that's where it creates the additional
sockets.

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


Re: Why sock.bind is always report 10048 error when in a script with multiprocessing

2011-11-18 Thread Junfeng Hu
Hi Chris.
The socket only binded once. That's the problem I'm puzzleing, I think it may a 
bug of multiprocessing in windows, or something I missed.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why sock.bind is always report 10048 error when in a script with multiprocessing

2011-11-18 Thread Chris Angelico
On Sat, Nov 19, 2011 at 2:51 AM, Junfeng Hu  wrote:
> And actually ,the socket hadn't been used in this script.

Doesn't matter that you haven't used it; you're binding to the port,
that's what causes the 10048.

I think the main problem is that you're trying to share sockets across
processes, but I haven't used the Python multiprocessing module with
sockets before. I would recommend, if you can, creating separate
sockets in each subprocess; that might make things a bit easier.

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


Re: Both Python 2.5.2 and 2.7.2 flop the same way under Win 7

2011-11-18 Thread W. eWatson

On 11/17/2011 8:34 PM, Dennis Lee Bieber wrote:

On Thu, 17 Nov 2011 08:55:36 -0800, "W. eWatson"
  declaimed the following in
gmane.comp.python.general:


Months ago 2.5.2 stopped functioning on my Win7 PC, so a few days ago I
uninstalled and installed. Same problem. If one right-clicks on a py
file, IDLE is not shown in the menu as Edit with IDLE. After playing
with matters I gave up, and uninstalled 2.5.2 and turned to 2.7.2. Same
results.

If I look at a 2.4 install on my laptop, I get the desired reference to
Edit with IDLE.


Fine... so open a directory window, follow

Tools/Folder Options/File Types

Scroll down to PYW, click [Advanced]

You should get an "Edit File Type" dialog. Mine shows just one
action "open", yours probably has "open" and "edit". Select "edit" and
then click [Edit] button. See what it says for the application to be
used.

Do the same on the Win7 machine -- it probably doesn't have "edit"
as an action, so you'll be picking the [New] button. Define the new
action to look like the action on the laptop (use the correct path to
the python executable, and maybe to IDLE).

Heck, check what those actions show for PY files too... The only
difference between PY and PYW should be the application used in the
"open" action.
PY =>  .../python.exe
PYW =>  .../pythonw.exe

Also make sure that the "open" action is the defined default (select
the action, and click the default button); when there are more than one
action, the default will be in bold.







My guess is that Win 7 is behind this. If so, it's good-bye Python.

Comments?

See my response to Neil Cerutti a few msgs above this one.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Both Python 2.5.2 and 2.7.2 flop the same way under Win 7

2011-11-18 Thread W. eWatson

On 11/17/2011 8:34 PM, Dennis Lee Bieber wrote:

On Thu, 17 Nov 2011 08:55:36 -0800, "W. eWatson"
  declaimed the following in
gmane.comp.python.general:


Months ago 2.5.2 stopped functioning on my Win7 PC, so a few days ago I
uninstalled and installed. Same problem. If one right-clicks on a py
file, IDLE is not shown in the menu as Edit with IDLE. After playing
with matters I gave up, and uninstalled 2.5.2 and turned to 2.7.2. Same
results.

If I look at a 2.4 install on my laptop, I get the desired reference to
Edit with IDLE.


Fine... so open a directory window, follow

Tools/Folder Options/File Types

Scroll down to PYW, click [Advanced]

You should get an "Edit File Type" dialog. Mine shows just one
action "open", yours probably has "open" and "edit". Select "edit" and
then click [Edit] button. See what it says for the application to be
used.

Do the same on the Win7 machine -- it probably doesn't have "edit"
as an action, so you'll be picking the [New] button. Define the new
action to look like the action on the laptop (use the correct path to
the python executable, and maybe to IDLE).

Heck, check what those actions show for PY files too... The only
difference between PY and PYW should be the application used in the
"open" action.
PY =>  .../python.exe
PYW =>  .../pythonw.exe

Also make sure that the "open" action is the defined default (select
the action, and click the default button); when there are more than one
action, the default will be in bold.







My guess is that Win 7 is behind this. If so, it's good-bye Python.

Comments?

See my response to Neil Cerutii a few msgs above this one.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why sock.bind is always report 10048 error when in a script with multiprocessing

2011-11-18 Thread Junfeng Hu
And actually ,the socket hadn't been used in this script.

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


Re: Why sock.bind is always report 10048 error when in a script with multiprocessing

2011-11-18 Thread Junfeng Hu
Thanks 
Yes, I had tried this before, so you could find that I comment the line 
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Here is the results.
D:\Python test>mythread2.py
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python27\lib\multiprocessing\forking.py", line 347, in main
self = load(from_parent)
  File "C:\Python27\lib\pickle.py", line 1378, in load
return Unpickler(file).load()
  File "C:\Python27\lib\pickle.py", line 858, in load
dispatch[key](self)
  File "C:\Python27\lib\pickle.py", line 1133, in load_reduce
value = func(*args)
  File "C:\Python27\lib\multiprocessing\reduction.py", line 167, in rebuild_sock
et
_sock = fromfd(fd, family, type_, proto)
  File "C:\Python27\lib\multiprocessing\reduction.py", line 156, in fromfd
s = socket.fromfd(fd, family, type_, proto)
AttributeError: 'module' object has no attribute 'fromfd'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Both Python 2.5.2 and 2.7.2 flop the same way under Win 7

2011-11-18 Thread W. eWatson

On 11/18/2011 5:11 AM, Neil Cerutti wrote:

On 2011-11-18, W. eWatson  wrote:

On 11/17/2011 4:24 PM, Steven D'Aprano wrote:

On Thu, 17 Nov 2011 16:03:14 -0800, W. eWatson wrote:


I have not found any successful way to get to IDLE. It's on on the
right-click of a py menu, and, if I go the ...lib/idle.pyw, it fails
with a "invalid Win32 app" msg.


If you associate .pyw files with pythonw.exe, and then open idle.pyw,
does it work?

Failing that, go to your laptop where the associations are right, and see
what they are, then duplicate the settings on your Windows 7 machine.


Sounds like a good idea except I've not used associations in so
long under XP, I have no idea where to start. Control Panel. My
Computer Tools?


Open Windows Explorer.
With the menu, to to Tools->Folder Options
Click the File Types tab in the Folder Options menu.

There will be an upper view with registered filed types, and some
buttons below far making changes to them.


OK, I've found that. I see
Py
Pyc
Pyo
Pyw
If I click on each, it basically it gives a short description of each. 
If I click advanced, there's more info. For example for py, Actions are 
IDLE and Open.


What does this tell me that's relevant to Win7?

If on Win7, I go to Default Programs I see under associations various 
python items. Py shows Unknown application. Since installing 2.7.2 I 
have not messed with these associations. If I right-click on Unknown, I 
see Notepad and python.exe for choices to open the file. I want neither. 
Why isn't IDLE listed there?


If I right-click on junk.py, I see "Open with".  Notepad and python.exe 
are choices. However, that menu allows me to choose something else. For 
example, Adobe Reader, or Internet Explorer. I suppose the next question 
is should I use the browse there and try to connect to IDLE in 
...\Lib\idlelib?  My guess is that if I do, I will run into the "invalid 
Win32 app", when I try to use it.



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


Re: Why sock.bind is always report 10048 error when in a script with multiprocessing

2011-11-18 Thread Chris Angelico
On Fri, Nov 18, 2011 at 9:23 PM, Junfeng Hu  wrote:
> Hi All, I'm trying to leverage my core i5 to send more UDP packets with 
> multiprocssing, but I found a interesting thing is that the socket.bind is 
> always reporting 10048 error even the process didn't do anything about the 
> socket.
> sock.bind((localIP,localPort))
> socket.error: [Errno 10048] Only one usage of each socket address 
> (protocol/netw
> ork address/port) is normally permitted

Try setting the socket to SO_REUSEADDR.

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


Re: Why sock.bind is always report 10048 error when in a script with multiprocessing

2011-11-18 Thread Junfeng Hu
I did a test on linux, it works well, so the issue is related to os.

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


Dynamically Generate Methods

2011-11-18 Thread GZ
Hi,

I have a class Record and a list key_attrs that specifies the names of
all attributes that correspond to a primary key.

I can write a function like this to get the primary key:

def get_key(instance_of_record):
   return tuple(instance_of_record.__dict__[k] for k in key_attrs)

However, since key_attrs are determined at the beginning of the
program while get_key() will be called over and over again, I am
wondering if there is a way to dynamically generate a get_ley method
with the key attributes expanded to avoid the list comprehension/
generator.

For example, if key_attrs=['A','B'], I want the generated function to
be equivalent to the following:

def get_key(instance_of_record):
   return (instance_of_record['A'],instance_of_record['B'] )

I realize I can use eval or exec to do this. But is there any other
way to do this?

Thanks,
gz




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


Re: Passing DLL handle as an argument (in Windows)

2011-11-18 Thread Ulrich Eckhardt

Am 18.11.2011 12:49, schrieb Pekka Kytölä:

What I'd like to do is that after fetching those SDK function
pointers I'd like to fire up .py/.pyc that snoops for possible
plugins written in python and registers those plugins and callbacks
and let them react to events. Obviously this python code needs access
to those SDK functions. Essentially it would show for the host app as
one .dll but registers multiple plugins from different python files.


Okay, so you want to export functions from your host application (it 
doesn't matter if that is inside a DLL or not) to a bunch of Python 
plugins. This is actually the embedding that I hinted at and documented, 
but here's some example code (stripped of any error handling and 
reference counting, so beware!):


// append line to debug log
static PyObject*
log_string(PyObject *self, PyObject *args)
{
char const* arg = 0;
if(!PyArg_ParseTuple(args, "s", &arg))
return NULL;

fprintf(debug_output, "%s", arg);
Py_RETURN_NONE;
}

// exported API
static PyMethodDef host_api[] =
{
{"log_string", log_string, METH_VARARGS,
"log_string(string) -> None\n"
"Write text to debug output."},
{NULL, NULL, 0, NULL}
};

Py_Initialize();
PyObject* host_api_module = Py_InitModule("host", host_api);
PyObject* test_module = PyImport_ImportModule("./test.py");
PyObject* main_function = PyObject_GetAttrString(test_module, "main");
PyObject* res = PyObject_CallObject(main_function, NULL);
Py_Finalize();


This has the disadvantage that it blocks, for multiple Python threads, 
you need to program a dispatcher. Also, you can only have a single 
interpreter loaded, so other parts of your program may not call 
Py_Initialize().


It does the job for my uses, so I hope it helps!

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


Re: Both Python 2.5.2 and 2.7.2 flop the same way under Win 7

2011-11-18 Thread Neil Cerutti
On 2011-11-18, W. eWatson  wrote:
> On 11/17/2011 4:24 PM, Steven D'Aprano wrote:
>> On Thu, 17 Nov 2011 16:03:14 -0800, W. eWatson wrote:
>>
>>> I have not found any successful way to get to IDLE. It's on on the
>>> right-click of a py menu, and, if I go the ...lib/idle.pyw, it fails
>>> with a "invalid Win32 app" msg.
>>
>> If you associate .pyw files with pythonw.exe, and then open idle.pyw,
>> does it work?
>>
>> Failing that, go to your laptop where the associations are right, and see
>> what they are, then duplicate the settings on your Windows 7 machine.
>
> Sounds like a good idea except I've not used associations in so
> long under XP, I have no idea where to start. Control Panel. My
> Computer Tools?

Open Windows Explorer.
With the menu, to to Tools->Folder Options
Click the File Types tab in the Folder Options menu.

There will be an upper view with registered filed types, and some
buttons below far making changes to them.

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


Re: What exactly is "pass"? What should it be?

2011-11-18 Thread MRAB

On 18/11/2011 04:34, Dennis Lee Bieber wrote:

On Thu, 17 Nov 2011 18:18:11 -0800 (PST), John Ladasky
  declaimed the following in
gmane.comp.python.general:


I'm trying to write tidy, modular code which includes a long-running process.  
From time to time I MIGHT like to check in on the progress being made by that 
long-running process, in various ways.  Other times, I'll just want to let it 
run.  So I have a section of code which, generally, looks like this:

def _pass(*args):
 pass


This is the equivalent of

def _pass(*args):
return None


Wouldn't "pass_" be a more Pythonic name?


(functions with no explicit return statement implicitly return None)


def long_running_process(arg1, arg2, arg_etc, report = _pass):
 result1 = do_stuff()
 report(result1)


So this is a call to a function that just returns a None, which is
dropped by the interpreter...



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


Re: Passing DLL handle as an argument (in Windows)

2011-11-18 Thread Pekka Kytölä
Hmm. Let me describe what is going a bit more carefully:

What I build is a dll file that has exported function that gets called
when the host application/dll loads my dll. In this function the
function pointers to the actual SDK functions are fetched. After this
my dll's registers some plugins that have callbacks. After that it's
all about reacting to an event/callback. What I'd like to do is that
after fetching those SDK function pointers I'd like to fire
up .py/.pyc that snoops for possible plugins written in python and
registers those plugins and callbacks and let them react to events.
Obviously this python code needs access to those SDK functions.
Essentially it would show for the host app as one .dll but registers
multiple plugins from different python files.

I don't mind if it's not ShellExecute route, but I'd prefer
approaching this so that I don't need to compile different dll's to
different versions of python but let the python code take care of that
stuff.
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] Data Plotting Library Dislin 10.2

2011-11-18 Thread Helmut Michels

Dear Python programmers,

I am pleased to announce version 10.2 of the data plotting software
Dislin.

Dislin is a high-level and easy to use plotting library for
displaying data as curves, bar graphs, pie charts, 3D-colour plots,
surfaces, contours and maps. Several output formats are supported
such as X11, VGA, OpenGL, PostScript, PDF, CGM, WMF, HPGL, TIFF, GIF, 
PNG, BMP and SVG.


The software is available for the most C, Fortran 77 and Fortran 90/95
compilers. Plotting extensions for the interpreting languages Perl,
Python and Java are also supported.

Dislin is available from the site

 http://www.dislin.de

and via FTP from the server

 ftp://ftp.gwdg.de/pub/grafik/dislin

All Dislin distributions are free for non-commercial use. Licenses
for commercial use are available from http://www.dislin.de.

 ---
  Helmut Michels
  Max Planck Institute for
  Solar System Research  Phone: +49 5556 979-334
  Max-Planck-Str. 2  Fax  : +49 5556 979-240
  D-37191 Katlenburg-Lindau  Mail : mich...@mps.mpg.de
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to insert my own module in front of site eggs?

2011-11-18 Thread Hans Mulder

On 18/11/11 03:58:46, alex23 wrote:

On Nov 18, 11:36 am, Roy Smith  wrote:

What if the first import of a module is happening inside some code you
don't have access to?



No import will happen until you import something.


That would be the case if you use the '-S' command line option.

Otherwise, site.py is imported before you get a chance to alter
sys.path, and by default site.py imports other modules.

-- HansM

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


Re: Passing DLL handle as an argument (in Windows)

2011-11-18 Thread Pekka Kytölä
On Nov 18, 10:27 am, Ulrich Eckhardt 
wrote:
> Am 18.11.2011 08:51, schrieb Pekka Kytölä:
>
> > Is it possible to pass my own dll's (already loaded) handle as an
> > argument to load/attach to the very same instance of dll? Thing is
> > that I've done plugin (dll) to a host app and the SDK's function
> > pointers are assigned once the dll is loaded in the host process.
>
> DLL handles are valid anywhere in a process, but...
>
> > I'd like to fire up python code with ShellExecuteEx from my plugin
> > dll and expose (wrap) these SDK funcs to that script. If I just load
> > the dll in python it will be different instance and the SDK function
> > pointers are all NULL. I tried passing the dll handle as lpParameter
> > but in vain.
>
> ...ShellExecuteEx will create a new process, where the DLL handle is not
> valid. A new process has a separate memory space, so the function
> pointers are different etc. This is so by design, it shouldn't matter to
> one process when a DLL it uses is loaded into another process, too.
>
> > Is this ShellExecute + dll handle passing even possible or do I need
> > to take a totally different route? What route that would be? Doesn't
> > have to be portable, just so it works in Windows environment.
>
> If all you want is to run Python code inside your application, you can
> link in a Python interpreter and run it from there. This is called
> embedding Python (docs.python.org/extending/embedding.html), as opposed
> to writing Python modules, don't confuse those two Python C APIs.
>
> Another way to get both into the same process is to convert your host
> application into a Python module, which you then import into Python.
> This would use the other Python C API
> (docs.python.org/extending/extending.html).
>
> It depends a bit on what you want to achieve, so you might want to
> elaborate on that. This is often better than asking for a way to achieve
> a solution that is impossible.
>
> Good luck!
>
> Uli

Thanks for reply, I'll try to elaborate a bit :)

I should have included this bit from:

http://docs.python.org/library/ctypes.html#loading-shared-libraries

"All these classes can be instantiated by calling them with at least
one argument, the pathname of the shared library. If you have an
existing handle to an already loaded shared library, it can be passed
as the handle named parameter, otherwise the underlying platforms
dlopen or LoadLibrary function is used to load the library into the
process, and to get a handle to it."

So, I've got this handle to my .dll and would want to get that passed
as an argument when firing up .py via ShellExecute and use one of the
dll load functions that take in handle. What I don't know if these
windows/python dll handles are interchangable at all. Think it would
be quite nice if they were. But if they aren't I need to forget about
it and just #include 
-- 
http://mail.python.org/mailman/listinfo/python-list


Why sock.bind is always report 10048 error when in a script with multiprocessing

2011-11-18 Thread Junfeng Hu
Hi All, I'm trying to leverage my core i5 to send more UDP packets with 
multiprocssing, but I found a interesting thing is that the socket.bind is 
always reporting 10048 error even the process didn't do anything about the 
socket.
Here is the script

import threading,socket,random,pp,os
import time
from multiprocessing import Process
import multiprocessing.reduction

localIP='10.80.2.24'
localPort=2924
remoteIP='10.80.5.143'
remotePort=2924
sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
#sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((localIP,localPort))
sock.connect((remoteIP,remotePort))

addRequest="MEGACO/1 ["+localIP+"]:"+str(localPort)+"\r\nTRANSACTION = 100 
{\r\n" \
"\tCONTEXT = $ {\r\n" \
"\t\tADD = TDMs15c1f1/11{ \r\n" \
" Media { LocalControl { Mode=SendReceive,tdmc/ec=on  }} " \
"\t}\r\n}}\r\n"

def sendAddRequest(sock,addRequst):
#for i in range(2500):
#sock.send(addRequest)
print "hello"



if __name__ == '__main__':
reader = Process(target=sendAddRequest,args=(sock,addRequest))
reader.start()


Here is the output

D:\Python test>mythread2.py
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python27\lib\multiprocessing\forking.py", line 346, in main
prepare(preparation_data)
  File "C:\Python27\lib\multiprocessing\forking.py", line 461, in prepare
'__parents_main__', file, path_name, etc
  File "D:\Python test\mythread2.py", line 12, in 
sock.bind((localIP,localPort))
  File "C:\Python27\lib\socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 10048] Only one usage of each socket address (protocol/netw
ork address/port) is normally permitted
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What exactly is "pass"? What should it be?

2011-11-18 Thread Thomas Rachel

Am 18.11.2011 05:34 schrieb Dennis Lee Bieber:
>> def _pass(*args):
>>  pass
>>
>> def long_running_process(arg1, arg2, arg_etc, report = _pass):
>>  result1 = do_stuff()
>>  report(result1)
>
> So this is a call to a function that just returns a None, which is
> dropped by the interpreter...

I'm not sure about this. I think, the call will be executed, but the 
callee will return immediately. It is different from call being dropped.


Another optimized alternative could be to do

def long_running_process(arg1, arg2, arg_etc, report=None):
result1 = do_stuff()
if report: report(result1)

but I think that is too low benefit at the cost of too much readability.

Such a function call is

  2   0 LOAD_FAST0 (a)
  3 POP_JUMP_IF_FALSE   16
  6 LOAD_FAST0 (a)
  9 CALL_FUNCTION0
 12 POP_TOP
 13 JUMP_FORWARD 0 (to 16)

  3 >>   16 ...

as opposed to just

  2   0 LOAD_FAST0 (a)
  3 CALL_FUNCTION0
  6 POP_TOP

with a call target of

  1   0 LOAD_CONST   0 (None)
  3 RETURN_VALUE

I don't think that a call is sooo expensive that it would make any 
noticeable difference.



Thomas

BTW: Sorry, Dennis, for the private mail - I am incapable to use 
Thunderbird correctly :-(

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


Re: Passing DLL handle as an argument (in Windows)

2011-11-18 Thread Ulrich Eckhardt

Am 18.11.2011 08:51, schrieb Pekka Kytölä:

Is it possible to pass my own dll's (already loaded) handle as an
argument to load/attach to the very same instance of dll? Thing is
that I've done plugin (dll) to a host app and the SDK's function
pointers are assigned once the dll is loaded in the host process.


DLL handles are valid anywhere in a process, but...


I'd like to fire up python code with ShellExecuteEx from my plugin
dll and expose (wrap) these SDK funcs to that script. If I just load
the dll in python it will be different instance and the SDK function
pointers are all NULL. I tried passing the dll handle as lpParameter
but in vain.


...ShellExecuteEx will create a new process, where the DLL handle is not 
valid. A new process has a separate memory space, so the function 
pointers are different etc. This is so by design, it shouldn't matter to 
one process when a DLL it uses is loaded into another process, too.




Is this ShellExecute + dll handle passing even possible or do I need
to take a totally different route? What route that would be? Doesn't
have to be portable, just so it works in Windows environment.


If all you want is to run Python code inside your application, you can 
link in a Python interpreter and run it from there. This is called 
embedding Python (docs.python.org/extending/embedding.html), as opposed 
to writing Python modules, don't confuse those two Python C APIs.


Another way to get both into the same process is to convert your host 
application into a Python module, which you then import into Python. 
This would use the other Python C API 
(docs.python.org/extending/extending.html).



It depends a bit on what you want to achieve, so you might want to 
elaborate on that. This is often better than asking for a way to achieve 
a solution that is impossible.



Good luck!

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


useless python - term rewriter

2011-11-18 Thread Sean McIlroy

## term rewriter (python 3.1.1)

def gettokens(string):
spaced = string.replace('(',' ( ').replace(')',' ) ')
return spaced.split()

def getterm(tokens):
if tokens[0] in '()':
term = []
assert tokens[0] == '('
tokens.pop(0)
while not tokens[0] == ')': term.append(getterm(tokens))
tokens.pop(0)
return term
return tokens.pop(0)

def parse(strg):
tokens = gettokens(strg)
term = getterm(tokens)
assert not tokens
return term

def unparse(term):
if type(term) == str: return term
subterms = [unparse(subterm) for subterm in term]
return '({})'.format(' '.join(subterms))

def atom(term):
return type(term) == str

def compound(term):
return type(term) == list

def variable(term):
return atom(term) and term[0].isupper()

def constant(term):
return atom(term) and not term[0].isupper()

def conformable(term1,term2):
return compound(term1) and compound(term2) and len(term1) ==
len(term2)

def getrule(string):
left, right = string.split('=')
return [parse(left), parse(right)]

def getrules(string):
nonblank = lambda substring: substring and not substring.isspace()
return [getrule(substring) for substring in string.splitlines() if
nonblank(substring)]

def substitute(bindings,term):
if constant(term): return term
if variable(term): return bindings.get(term,term)
return [substitute(bindings,subterm) for subterm in term]

def match(term,pattern):
from operator import concat
from functools import reduce
if variable(pattern): return [[pattern, term]]
if constant(pattern) and pattern == term: return []
if conformable(pattern,term):
matches = [match(subterm,subpattern) for subterm, subpattern
in zip(term,pattern)]
return reduce(concat,matches)
raise Exception

def rewrite(term,rule):
if type(rule) == dict:
function = rule[term[0]]
arguments = [int(subterm) for subterm in term[1:]]
return str(function(*arguments))
left, right = rule
bindings = dict(match(term,left))
return substitute(bindings,right)

def apply(rule,term):
try: return [rewrite(term,rule), True]
except:
if atom(term): return [term, False]
applications = [apply(rule,subterm) for subterm in term]
subterms = [subterm for subterm, change in applications]
changes  = [change  for subterm, change in applications]
return [subterms, any(changes)]

def normalize(term,rules):
while True:
changes = []
for rule in rules:
term, change = apply(rule,term)
changes.append(change)
if not any(changes): break
return term

def translate(rules):
string = input('>>> ')
if string and not string.isspace():
try:
term = parse(string)
normal = normalize(term,rules)
string = unparse(normal)
print(string)
except: print('parse error')

def interpret(equations):
import operator
rules = [vars(operator)] + getrules(equations)
while True:
try: translate(rules)
except KeyboardInterrupt:
print('end session')
break

example = """

(factorial 0) = 1
(factorial N) = (mul N (factorial (sub N 1)))

(fibonacci 0) = 0
(fibonacci 1) = 1
(fibonacci N) = (add (fibonacci (sub N 1)) (fibonacci (sub N 2)))

"""

interpret(example)

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