Re: XML Patch

2014-10-27 Thread Stefan Behnel
Hi,

please keep this on-list.

Nicholas Cole schrieb am 26.10.2014 um 22:43:
> On Sun, Oct 26, 2014 at 6:30 PM, Stefan Behnel wrote:
>> Nicholas Cole schrieb am 26.10.2014 um 18:00:
>>> I'm looking for a python library that can parse XML Documents and 
>>> create xml-aware "diff" files, and then use those to patch
>>> documents. In other words, I'd like something similar to the Google 
>>> diff-match-patch tools, but something which is XML aware.
>>> 
>>> I can see several projects on Pypi that can generate some form of
>>> xml diff, but I can't seem to see anything that can also do the
>>> patching side of things.
>> 
>> Is there a use case for this?
> 
> Yes - I want to store a series of XML diffs/patches and be able to 
> generate documents by applying them.

Could you be a little more specific? There are lots of ways to generate
XML, but I never heard of anyone who wanted to do this based on diffs
between other documents. What kind of document differences are you talking
about here?

Stefan


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


Re: XML Patch

2014-10-27 Thread Nicholas Cole
On Mon, Oct 27, 2014 at 7:28 AM, Stefan Behnel  wrote:
> Hi,
>
> please keep this on-list.

Sorry about that. Wrong button!

[snip]

>> Yes - I want to store a series of XML diffs/patches and be able to
>> generate documents by applying them.
>
> Could you be a little more specific? There are lots of ways to generate
> XML, but I never heard of anyone who wanted to do this based on diffs
> between other documents. What kind of document differences are you talking
> about here?

I don't think the specific documents matter, and I don't think it's a
unique use-case.  Here's Microsoft talking about XML diff and patching
(including a hypothetical example):

http://msdn.microsoft.com/en-gb/library/aa302294.aspx

There's a tool here to do it:

http://xmlpatch.sourceforge.net

I'd just really like to be able to do something similar in Python.

Best wishes,

N.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-27 Thread ast


"Mark Lawrence"  a écrit dans le message de 
news:[email protected]...


Also would you please access this list via https://mail.python.org/mailman/listinfo/python-list or 
read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double 
line spacing and single line paragraphs, thanks.


Hi

I read the last document but it seems that it is intended for those who
post messages through Google Groups. I am using a usenet client so i
should not be affected

It seems that he double blank lines spacing comes from buscacio, not me

regards 


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


Callback functions arguments

2014-10-27 Thread ast

Hi

In this web site at example n°5
http://fsincere.free.fr/isn/python/cours_python_tkinter.php

A program is using the "Scale" widget from tkinter module.
Here is a piece of code:

Valeur = StringVar()

echelle = Scale(Mafenetre, from_=-100, to=100, resolution=10, \
orient=HORIZONTAL, length=300, width=20, label="Offset", \
tickinterval=20, variable=Valeur, command=maj)

The "maj" callback function is:

def maj(nouvelleValeur):
   print(nouvelleValeur)

When the user move the scale with the mouse, the new position
is supposed to be printed on the python shell.

The "maj" function has an argument "nouvelleValeur" but no
argument is passed through the Scale widget.

So how the hell Python knows that it has to pass parameter
"Valeur" to the "maj" function ?

thx

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


asyncio: setting file permissions of a Unix socket?

2014-10-27 Thread Martin
Hi! :)

I'm using the asyncio.Protocol interface to build a server which binds
to a unix socket file.  I want other system users to connect to the
unix socket, so to communicate with the server.

Where should I set the permissions of the file?

The problem is that the socket file is created when the programs
starts listening for the connections.  Because of this, I can't change
the file permission before a connection is made.  At the same time, a
connection can't happen because of the file permissions.

Currently, I workaround this with os.umask(0o000).  But I also want to
make other files later with default permissions.  So I have to revert
the umask, but where?  I can only do this in the client connection
code, which is out of place.

Bellow is what I've done.  Can you suggest a better way?  I wish to
avoid permission fixing code like os.umask() for every connection.
Maybe I shouldn't use asyncio.Protocol in the first place?

Thank you! :)

Example code:

#! /usr/bin/env python3

import os
import asyncio

class ExampleServer(asyncio.Protocol):
def __init__(self):
os.umask(0o002)# This is my workaround.  Can I avoid this?
# if not umask_restored: # An alternative workaround.
# os.umask(0o002)

def connection_made(self, transport):
self.transport = transport

def data_received(self, data):
print("Data: ", data)
self.transport.write(b"OK, bye!\n")
self.transport.close()


def main():
socket_filepath = "/tmp/example-server.socket"
loop = asyncio.get_event_loop()
server_coroutine = loop.create_unix_server(ExampleServer, socket_filepath)
server = loop.run_until_complete(server_coroutine)

os.umask(0o000) # This is my workaround.

try:
loop.run_forever()
except KeyboardInterrupt:
print("exit")
finally:
server.close()
loop.close()
os.remove(socket_filepath)


if __name__ == "__main__":
main()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Callback functions arguments

2014-10-27 Thread Peter Otten
ast wrote:

> Hi
> 
> In this web site at example n°5
> http://fsincere.free.fr/isn/python/cours_python_tkinter.php
> 
> A program is using the "Scale" widget from tkinter module.
> Here is a piece of code:
> 
> Valeur = StringVar()
> 
> echelle = Scale(Mafenetre, from_=-100, to=100, resolution=10, \
> orient=HORIZONTAL, length=300, width=20, label="Offset", \
> tickinterval=20, variable=Valeur, command=maj)
> 
> The "maj" callback function is:
> 
> def maj(nouvelleValeur):
> print(nouvelleValeur)
> 
> When the user move the scale with the mouse, the new position
> is supposed to be printed on the python shell.
> 
> The "maj" function has an argument "nouvelleValeur" but no
> argument is passed through the Scale widget.
> 
> So how the hell Python knows that it has to pass parameter
> "Valeur" to the "maj" function ?

Python doesn't "know" it has to pass an argument, it just does it. Change 
the callback to

def maj():
print("no args")

and you'll get an error. If I were to guess

> echelle = Scale(Mafenetre, from_=-100, to=100, resolution=10, \
> orient=HORIZONTAL, length=300, width=20, label="Offset", \
> tickinterval=20, variable=Valeur, command=maj)

you probably are misled by the 'command=maj' part in the above line. This 
means that the function is passed and is different from command=maj() where 
the *result* of the function is passed. 

Here's a self-contained example that may clear things up for you:

>>> def call_them(one, two):
... one(1)
... two(2, 3)
... 
>>> def square(a):
... print(a, "*", a, "=", a*a)
... 
>>> def product(a, b):
... print(a, "*", b, "=", a*b)
... 
>>> call_them(square, product)
1 * 1 = 1
2 * 3 = 6
>>> call_them(product, product)
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in call_them
TypeError: product() missing 1 required positional argument: 'b'

call_them() expects that one() takes 1 argument and two() takes 2 arguments. 
If the user passes a function that expects a different number of arguments a 
TypeError is raised.

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


Re: (test) ? a:b

2014-10-27 Thread Gregory Ewing

Michael Torrie wrote:

As far as I can tell, no BASIC dialect I've looked at (DOS and Linux
worlds only), has ever had any logical operators like AND (&&), OR (||),
and NOT (!).  They only appear to have bitwise operators (&,|,~ C
equivalent).  The fact that comparison operators returned 0 and -1 made
the bitwise operators function the same as logical.


Applesoft used 0 and 1, so its NOT definitely wasn't bitwise
on the whole number. I can't remember what its AND and OR did
for numbers other than 0 or 1 (if I even thought to try it),
but since it did all arithmetic in floating point, I suspect
they were logical rather than bitwise.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Callback functions arguments

2014-10-27 Thread Jean-Michel Pichavant
- Original Message -
> From: "ast" 
> To: [email protected]
> Sent: Monday, 27 October, 2014 9:16:26 AM
> Subject: Callback functions arguments
> 
> Hi
> 
> In this web site at example n°5
> http://fsincere.free.fr/isn/python/cours_python_tkinter.php
> 
> A program is using the "Scale" widget from tkinter module.
> Here is a piece of code:
> 
> Valeur = StringVar()
> 
> echelle = Scale(Mafenetre, from_=-100, to=100, resolution=10, \
> orient=HORIZONTAL, length=300, width=20, label="Offset", \
> tickinterval=20, variable=Valeur, command=maj)
> 
> The "maj" callback function is:
> 
> def maj(nouvelleValeur):
> print(nouvelleValeur)
> 
> When the user move the scale with the mouse, the new position
> is supposed to be printed on the python shell.
> 
> The "maj" function has an argument "nouvelleValeur" but no
> argument is passed through the Scale widget.
> 
> So how the hell Python knows that it has to pass parameter
> "Valeur" to the "maj" function ?
> 
> thx

The Scale object is performing the call, hence it will be the Scale object that 
will call your maj function with a "nouvelleValeur" parameter.

When you write command=maj, you pass the function, but you don't call it. 
That's the purpose of a callback. You provide a function and it get called by 
the object you've been giving the function to. The Scale object should be 
documented and should provide with the callback signature.

See http://effbot.org/zone/tkinter-callbacks.htm

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: asyncio: setting file permissions of a Unix socket?

2014-10-27 Thread Michael Ströder
Martin wrote:
> I'm using the asyncio.Protocol interface to build a server which binds
> to a unix socket file.  I want other system users to connect to the
> unix socket, so to communicate with the server.
> 
> Where should I set the permissions of the file?

You should start the demon with a strict umask and set the permissions after
the socket is created.

Deriving from SocketServer.UnixStreamServer I'm overriding the server_bind()
method:

class MyServer(SocketServer.UnixStreamServer):
[..]
  def server_bind(self):
"""Override server_bind to set socket options."""
self.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
self.socket.settimeout(SOCKET_TIMEOUT)
try:
  os.unlink(self.server_address)
except OSError:
  if os.path.exists(self.server_address):
raise
SocketServer.UnixStreamServer.server_bind(self)
os.chmod(self.server_address,int(SOCKET_PERMISSIONS,8))
return # server_bind()

Ciao, Michael.

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


Re: Classes and the command line

2014-10-27 Thread Jean-Michel Pichavant
- Original Message -
> From: "Seymore4Head" 
> To: [email protected]
> Sent: Monday, 27 October, 2014 3:27:18 AM
> Subject: Classes and the command line
> 
> I am trying to learn classes.
> I am currently using Python 2.7 at the command line.
> If you try to type commands at the command line and make the
> slightest
> mistake you have to start over.
> I was trying to copy and paste these instructions into the command
> prompt.
> 
> http://en.wikibooks.org/wiki/Python_Programming/Classes
> >>> class Foo:
> ... def setx(self, x):
> ... self.x = x
> ... def bar(self):
> ... print self.x
> 
> There is really no way to do that without pasting line by line is
> there and adding deleting spaces?  And if you use spaces and tabs,
> they are not the same.

You could use Ipython http://ipython.org/, if you're familiar with the python 
shell you won't get lost as it's quite the same with a lot of features added.
One of them is the %paste magic function, it will paste your clipboard taking 
care of the indentation for you.

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Classes and the command line

2014-10-27 Thread alister
On Sun, 26 Oct 2014 23:32:08 -0400, Seymore4Head wrote:

> On Mon, 27 Oct 2014 14:06:11 +1100, Ben Finney
>  wrote:
> 
>>Seymore4Head  writes:
>>
>>> I am trying to learn classes.
>>> I am currently using Python 2.7 at the command line.
>>
>>(I think you mean “the interactive Python interpreter”, or just “the
>>Python shell”.)
>>
>>Since you are learning Python, I will strongly recommend you ignore
>>Python 2 unless it becomes unavoidable.
>>
> At the moment, it is unavoidable.  The instructors are teaching Python 2
> so I have to learn Python 2, for now.
> 
>>Instead, learn Python 3 primarily; it is much better because it omits a
>>bunch of legacy behaviour you don't need.
>>
>>> If you try to type commands at the [interactive shell] and make the
>>> slightest mistake you have to start over.
>>
>>Right. There is line-by-line history, and editing enabled with the
>>“readline” plug-in. (This is an advantage of using a programmer-
friendly
>>operating system, which MS Windows sadly is not.)
>>
>>> I was trying to copy and paste these instructions into the
>>> [interactive Python shell].
>>>
>>> http://en.wikibooks.org/wiki/Python_Programming/Classes
>>> >>> class Foo:
>>> ... def setx(self, x):
>>> ... self.x = x ... def bar(self):
>>> ... print self.x
>>>
>>> There is really no way to do that without pasting line by line is
>>> there and adding deleting spaces?  And if you use spaces and tabs,
>>> they are not the same.
>>
>>Right on all counts.
>>
>>The interactive Python shell is good for very quickly experimenting and
>>demonstrating how Python actually behaves, statement by statement. But
>>as you point out, it is not a good choice for anything more complex. It
>>is a good learning and debugging tool.
>>
>>When you start to write larger units of code, like a class or a
>>function, you can trade immediacy for flexibility: write your code into
>>a text editor, save it to a file ‘foo.py’, then run that code at a
>>separate OS command prompt by invoking ‘python foo.py’ in the 
terminal.
>>
>>That way, you can continue to adjust and tweak the code as you learn how
>>your changes affect the code. You do need to keep invoking the actions
>>separately – edit the file, save the file, run the file with Python –
>>but this is what's needed when you want to run a program more than once
>>anyway, so it's a good step to take.
>>
>>Find a good, *general-purpose* programmer's editor. Preferably licensed
>>under free software terms, with a strong community supporting it, and
>>available on all major platforms for when you switch to a decent
>>programmer-friendly operating system.
> 
> I am actually using Notepad some too.
> 
> Thanks

notepad is not a programmer friendly editor

personally I like Geany as it is nice and basic but still offers a lot of 
programmer friendly features such as syntax highlighting, a small 
terminal window which I use to run the interactive terminal for testing 
quick one-liners & pressing f5 will save & run the current file being 
edited.

www.geany.org

Notepad+ is also often suggested along with many other programmer editors/
Integrated development environments (IDE).

I would advise you keep away from the more complex IDE's for now as you 
do not want to overload your learning requirements.


-- 
Who the mad would destroy, first they make Gods.
-- Bernard Levin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Classes and the command line

2014-10-27 Thread Chris Angelico
On Mon, Oct 27, 2014 at 10:17 PM, alister
 wrote:
> Notepad+ is also often suggested along with many other programmer editors/
> Integrated development environments (IDE).

That would be Notepad++, and yes, it's fairly well recommended. It's
based on the same edit component as SciTE, another good editor (and
the one I use).

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


Re: Status of side-effecting functions in python

2014-10-27 Thread Steven D'Aprano
Roy Smith wrote:

>> Yes and no. If something goes wrong in a .write() method,
>> is not Python supposed to raise an error? (!)
> 
> Define "wrong".  It is not an error for a write() call to consume fewer
> bytes than were requested.  

It's not? I'm asking a genuine question here, not a rhetorical one. I would
expect that if I ask to write 2 bytes, and only 1 byte is written, that
absolutely is an error. Under what circumstances is it okay for write() to
throw data away?

> How would you expect this to be handled in Python?  Raise
> DataPartiallyWrittenError? 

I would expect it to raise an IOError, most likely with one of the following
error codes:

* errno.EIO (physical input/output error)

* errno.EFBIG (file is too large)

* errno.ENOSPC (no space left on device, disk is full)


-- 
Steven

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


Re: Status of side-effecting functions in python

2014-10-27 Thread Chris Angelico
On Mon, Oct 27, 2014 at 10:30 PM, Steven D'Aprano
 wrote:
> Roy Smith wrote:
>
>>> Yes and no. If something goes wrong in a .write() method,
>>> is not Python supposed to raise an error? (!)
>>
>> Define "wrong".  It is not an error for a write() call to consume fewer
>> bytes than were requested.
>
> It's not? I'm asking a genuine question here, not a rhetorical one. I would
> expect that if I ask to write 2 bytes, and only 1 byte is written, that
> absolutely is an error. Under what circumstances is it okay for write() to
> throw data away?
>
>> How would you expect this to be handled in Python?  Raise
>> DataPartiallyWrittenError?
>
> I would expect it to raise an IOError, most likely with one of the following
> error codes:
>
> * errno.EIO (physical input/output error)
>
> * errno.EFBIG (file is too large)
>
> * errno.ENOSPC (no space left on device, disk is full)

You're assuming the condition, whatever it is, is permanent. The most
common reason for write() to be temporarily unable to write everything
is a non-blocking socket, pipe, or somesuch. It writes as much as it
can, tells you how much that is, and lets you buffer the rest or deal
with it in whatever other way you choose.

If it is permanent, though, then yes, it should tell you. But what if
you ask it to write a megabyte, it writes half of it, and then finds
that there's no space on the disk? Should it:

1) Back out the write and raise an exception?
2) Write part of the data and raise an exception?
3) Write part of the data and NOT raise an exception?

All three make sense. The third one is an option only if it's
documented as being able to tell you about partial writes. The second
has a problem in that you can't necessarily communicate "this is how
much I wrote" properly while also signalling the exception (imagine if
one function calls write() more than once, and it doesn't catch any
exceptions, just lets them bubble up). And backing out a write isn't
always possible. So what's to do?

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


Re: id == vs is

2014-10-27 Thread Roy Smith
In article ,
 Cameron Simpson  wrote:

> The "is" test is more direct and less subject to iffiness because the longer 
> expression using id() leaves more scope/time for things to change, and of 
> course "id" itself can be rebound to something weird.

Not to mention that Python is case-sensitive and in the code as 
presented by the OP:

Id(x) == id(y)

those are two different functions :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Status of side-effecting functions in python

2014-10-27 Thread Roy Smith
In article <[email protected]>,
 Steven D'Aprano  wrote:

> Roy Smith wrote:
> 
> >> Yes and no. If something goes wrong in a .write() method,
> >> is not Python supposed to raise an error? (!)
> > 
> > Define "wrong".  It is not an error for a write() call to consume fewer
> > bytes than were requested.  
> 
> It's not? I'm asking a genuine question here, not a rhetorical one. I would
> expect that if I ask to write 2 bytes, and only 1 byte is written, that
> absolutely is an error. Under what circumstances is it okay for write() to
> throw data away?

It's not throwing away data.  The write() call returns a count of how 
many bytes is consumed, so you can present the rest of them again in a 
later write() call (assuming that makes sense to do for your 
application).

In some cases, the underlying hardware (or network protocol) may be 
unable to handle the number of bytes you requested, or may fail in 
mid-transmission.  Imagine a serial link.  You tell it to write 100 
bytes.  It starts sending them down the line and after 20 bytes, the 
connection fails.  What should write() do in that case?  It hasn't 
written all the data, so it needs to let you know that.  It also has 
written *some* of the data, so it needs to let you know that too.  What 
you do with that information is up to you, but it clearly needs to 
return a richer status indication than just success/failure.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Classes and the command line

2014-10-27 Thread Seymore4Head
On Sun, 26 Oct 2014 23:32:08 -0400, Seymore4Head
 wrote:

>On Mon, 27 Oct 2014 14:06:11 +1100, Ben Finney
> wrote:
>
>>Seymore4Head  writes:
>>
>>> I am trying to learn classes.
>>> I am currently using Python 2.7 at the command line.
>>
>>(I think you mean “the interactive Python interpreter”, or just “the
>>Python shell”.)
>>
>>Since you are learning Python, I will strongly recommend you ignore
>>Python 2 unless it becomes unavoidable.
>>
>At the moment, it is unavoidable.  The instructors are teaching Python
>2 so I have to learn Python 2, for now.
>
>>Instead, learn Python 3 primarily; it is much better because it omits a
>>bunch of legacy behaviour you don't need.
>>
>>> If you try to type commands at the [interactive shell] and make the
>>> slightest mistake you have to start over.
>>
>>Right. There is line-by-line history, and editing enabled with the
>>“readline” plug-in. (This is an advantage of using a programmer-friendly
>>operating system, which MS Windows sadly is not.)
>>
>>> I was trying to copy and paste these instructions into the
>>> [interactive Python shell].
>>>
>>> http://en.wikibooks.org/wiki/Python_Programming/Classes
>>> >>> class Foo:
>>> ... def setx(self, x):
>>> ... self.x = x
>>> ... def bar(self):
>>> ... print self.x
>>>
>>> There is really no way to do that without pasting line by line is
>>> there and adding deleting spaces?  And if you use spaces and tabs,
>>> they are not the same.
>>
>>Right on all counts.
>>
>>The interactive Python shell is good for very quickly experimenting and
>>demonstrating how Python actually behaves, statement by statement. But
>>as you point out, it is not a good choice for anything more complex. It
>>is a good learning and debugging tool.
>>
>>When you start to write larger units of code, like a class or a
>>function, you can trade immediacy for flexibility: write your code into
>>a text editor, save it to a file ‘foo.py’, then run that code at a
>>separate OS command prompt by invoking ‘python foo.py’ in the terminal.
>>
>>That way, you can continue to adjust and tweak the code as you learn how
>>your changes affect the code. You do need to keep invoking the actions
>>separately – edit the file, save the file, run the file with Python –
>>but this is what's needed when you want to run a program more than once
>>anyway, so it's a good step to take.
>>
>>Find a good, *general-purpose* programmer's editor. Preferably licensed
>>under free software terms, with a strong community supporting it, and
>>available on all major platforms for when you switch to a decent
>>programmer-friendly operating system.
>
>I am actually using Notepad some too.
>
>Thanks

I meant Notepad ++
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Status of side-effecting functions in python

2014-10-27 Thread Grant Edwards
On 2014-10-25, Wolfgang Maier  wrote:

> It may be rare to use an expression both for its side-effects and its
> return value,

It's actually quite common.

For example:

   f = open("filename")
   d = f.readline()

In both of those lines, the side effects and return values are equally
vital.  The same applies to reading from a queue, popping from a
stack, etc.

-- 
Grant Edwards   grant.b.edwardsYow! This PORCUPINE knows
  at   his ZIPCODE ... And he has
  gmail.com"VISA"!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Status of side-effecting functions in python

2014-10-27 Thread Grant Edwards
On 2014-10-27, Steven D'Aprano  wrote:
> Roy Smith wrote:
>
>>> Yes and no. If something goes wrong in a .write() method,
>>> is not Python supposed to raise an error? (!)
>> 
>> Define "wrong".  It is not an error for a write() call to consume fewer
>> bytes than were requested.  
>
> It's not? I'm asking a genuine question here, not a rhetorical one.

No.  

Under Unix/Posix a write() call may _always_ write fewer bytes than
requested.

It may be that the device/pipe/file whatever has filled and blocking
is disabled.  It may be that the device has decided that, at the
moment, it can only handle a certain amount of data for some other
reason.  For example: Let's say you're writing to a network connection
that must segment data, and you try to write more than will fit in the
current segment. The write() call may fill the segment, send the
segment, and "refuse" the rest of the data -- requiring that you make
a subsequent write() with the remaining data (at which point it will
start a new segment).

Or, it may be because the system call was interrupted by something
completely unrelated to your program, the write() call, or the "thing"
to which you're writing [and it was more convenient for whoever wrote
the OS to do a partial write than it was to try to resume the write].

If you really want to make sure that all bytes get written, you _must_
put all write() calls in a loop that checks the return value and keeps
re-writing any unwritten data.

And to answer your next question: yes, Unix application programmers
have been complaining about that (perhaps justifiably) since 1970.

-- 
Grant Edwards   grant.b.edwardsYow! I have a TINY BOWL in
  at   my HEAD
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Web services from python

2014-10-27 Thread loial
What is the best package to use with python 2.6 to access Web services. Is it 
ZSI?

Can anyone recommend a good tutorial, preferably with a sandbox web service?

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


Re: Lazy-evaluation lists/dictionaries

2014-10-27 Thread Jon Ribbens
On 2014-10-26, Terry Reedy  wrote:
> On 10/26/2014 10:14 AM, Jon Ribbens wrote:
>> Is there any better way to do this other than simply re-implementing
>> these types from scratch, emulating all their methods and operations?
>> (i.e. using UserList/UserDict). I was under the impression that that
>> sort of thing was supposed to have gone since Python 2.2 or so.
>
> We considered dropping UserDict and UserList for 3.0 but kept them in 
> collections for cases in which subclassing does not work.

It seems on further investigation to be hard/impossible to subclass
Python classes from C extensions. I've gone with subclassing dict,
and reimplementing most of its methods. It helps that I only need it
to be read-only. It's a pity there's no protocol for 'dynamic'
lists/dicts though.
-- 
https://mail.python.org/mailman/listinfo/python-list


Anyone know the solution

2014-10-27 Thread emmanueloje
Write a program that reads the contents of the two files into two separate 
lists.   The user should be able to enter a boy's name, a girl's 
name or both, and the   application will display messages indicating whether 
the names were among the most popular.

THIS IS THE LIST OF BOY NAMES
Jacob
Michael
Joshua
Matthew
Daniel
Christopher
Andrew
Ethan
Joseph
William
Anthony
David
Alexander
Nicholas
Ryan
Tyler
James
John
Jonathan
Noah
Brandon
Christian
Dylan
Samuel
Benjamin
Zachary
Nathan
Logan
Justin
Gabriel
Jose
Austin
Kevin
Elijah
Caleb
Robert
Thomas
Jordan
Cameron
Jack
Hunter
Jackson
Angel
Isaiah
Evan
Isaac
Mason
Luke
Jason
Gavin
Jayden
Aaron
Connor
Aiden
Aidan
Kyle
Juan
Charles
Luis
Adam
Lucas
Brian
Eric
Adrian
Nathaniel
Sean
Alex
Carlos
Bryan
Ian
Owen
Jesus
Landon
Julian
Chase
Cole
Diego
Jeremiah
Steven
Sebastian
Xavier
Timothy
Carter
Wyatt
Brayden
Blake
Hayden
Devin
Cody
Richard
Seth
Dominic
Jaden
Antonio
Miguel
Liam
Patrick
Carson
Jesse
Tristan
Alejandro
Henry
Victor
Trevor
Bryce
Jake
Riley
Colin
Jared
Jeremy
Mark
Caden
Garrett
Parker
Marcus
Vincent
Kaleb
Kaden
Brady
Colton
Kenneth
Joel
Oscar
Josiah
Jorge
Cooper
Ashton
Tanner
Eduardo
Paul
Edward
Ivan
Preston
Maxwell
Alan
Levi
Stephen
Grant
Nicolas
Omar
Dakota
Alexis
George
Collin
Eli
Spencer
Gage
Max
Cristian
Ricardo
Derek
Micah
Brody
Francisco
Nolan
Ayden
Dalton
Shane
Peter
Damian
Jeffrey
Brendan
Travis
Fernando
Peyton
Conner
Andres
Javier
Giovanni
Shawn
Braden
Jonah
Cesar
Bradley
Emmanuel
Manuel
Edgar
Erik
Mario
Edwin
Johnathan
Devon
Erick
Wesley
Oliver
Trenton
Hector
Malachi
Jalen
Raymond
Gregory
Abraham
Elias
Leonardo
Sergio
Donovan
Colby
Marco
Bryson
Martin

THIS IS THE LIST OF GIRLS NAME
Emily
Madison
Emma
Olivia
Hannah
Abigail
Isabella
Samantha
Elizabeth
Ashley
Alexis
Sarah
Sophia
Alyssa
Grace
Ava
Taylor
Brianna
Lauren
Chloe
Natalie
Kayla
Jessica
Anna
Victoria
Mia
Hailey
Sydney
Jasmine
Julia
Morgan
Destiny
Rachel
Ella
Kaitlyn
Megan
Katherine
Savannah
Jennifer
Alexandra
Allison
Haley
Maria
Kaylee
Lily
Makayla
Brooke
Mackenzie
Nicole
Addison
Stephanie
Lillian
Andrea
Zoe
Faith
Kimberly
Madeline
Alexa
Katelyn
Gabriella
Gabrielle
Trinity
Amanda
Kylie
Mary
Paige
Riley
Jenna
Leah
Sara
Rebecca
Michelle
Sofia
Vanessa
Jordan
Angelina
Caroline
Avery
Audrey
Evelyn
Maya
Claire
Autumn
Jocelyn
Ariana
Nevaeh
Arianna
Jada
Bailey
Brooklyn
Aaliyah
Amber
Isabel
Danielle
Mariah
Melanie
Sierra
Erin
Molly
Amelia
Isabelle
Madelyn
Melissa
Jacqueline
Marissa
Shelby
Angela
Leslie
Katie
Jade
Catherine
Diana
Aubrey
Mya
Amy
Briana
Sophie
Gabriela
Breanna
Gianna
Kennedy
Gracie
Peyton
Adriana
Christina
Courtney
Daniela
Kathryn
Lydia
Valeria
Layla
Alexandria
Natalia
Angel
Laura
Charlotte
Margaret
Cheyenne
Mikayla
Miranda
Naomi
Kelsey
Payton
Ana
Alicia
Jillian
Daisy
Mckenzie
Ashlyn
Caitlin
Sabrina
Summer
Ruby
Rylee
Valerie
Skylar
Lindsey
Kelly
Genesis
Zoey
Eva
Sadie
Alexia
Cassidy
Kylee
Kendall
Jordyn
Kate
Jayla
Karen
Tiffany
Cassandra
Juliana
Reagan
Caitlyn
Giselle
Serenity
Alondra
Lucy
Kiara
Bianca
Crystal
Erica
Angelica
Hope
Chelsea
Alana
Liliana
Brittany
Camila
Makenzie
Veronica
Lilly
Abby
Jazmin
Adrianna
Karina
Delaney
Ellie
Jasmin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Lazy-evaluation lists/dictionaries

2014-10-27 Thread Jon Ribbens
On 2014-10-26, Tim Delaney  wrote:
> On 27 October 2014 01:14, Jon Ribbens  wrote:
>> I have a need, in a Python C extension I am writing, for lists and
>> dictionaries with "lazy evaluation" - by which I mean that at least
>> some of the values in the lists/dictionaries are "proxy objects"
>> which, rather than returning as themselves, should return the thing
>> they are a proxy for when retrieved. This is because retrieving
>> the proxied objects is expensive and only a small minority of them
>> will actually be accessed, so retrieving them all before they are
>> actually accessed is massively inefficient.
>
> Why not put proxy objects into the list/dict?

That's precisely what I am doing. The point is that when they are
retrieved they need to be resolved into the genuine objects.

> Have a look at the weakref module for an API that may be suitable
> for such proxy objects (if you used the same API, that would also
> allow you to transparently use weakrefs in your lists/dicts).

Hmm, the idea behind that appears to be to create a proxy that
emulates every possible method of every conceivable type. My
method of only emulating the list and dict methods seems to be
somewhat simpler for my purpose ;-)

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


Re: Status of side-effecting functions in python

2014-10-27 Thread Marko Rauhamaa
Grant Edwards :

> If you really want to make sure that all bytes get written, you _must_
> put all write() calls in a loop that checks the return value and keeps
> re-writing any unwritten data.
>
> And to answer your next question: yes, Unix application programmers
> have been complaining about that (perhaps justifiably) since 1970.

I wouldn't have it any other way.

Now, I have confused the discussion with some misinformation myself.
Python2's file.write() doesn't return a value but pushes the whole
string out. Python3's file.write() returns the number of *characters*
written. I don't know if the number can ever be different from the total
number of characters in the string.

In POSIX, a write(2) system call on file blocks until all bytes have
been passed on to the file system. The only exception (no pun intended)
I know is the reception of a signal. Even then, I'm not sure Linux file
systems ever cut writes short because of signals. I think the lack of
nonblocking file access in Linux is one of the OS's main shortcomings.

Python's sockets and pipes don't have write methods.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Anyone know the solution

2014-10-27 Thread alister
On Mon, 27 Oct 2014 08:10:04 -0700, emmanueloje wrote:

> Write a   program that reads the contents of the two files into two
> separate lists.   The user should be able to enter a boy's 
name, a girl's
> name or   both, and the   application will display messages 
indicating
> whether the names were among the most popular.
> 
Your tutor for a start & I think I could probably get one working in an 
hour or so without too much difficulty. What do you have?

we do not do homework for you here.
if you have some code that doesn't work as expected we may assist 
-- 
semper en excretus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Anyone know the solution

2014-10-27 Thread Joel Goldstick
2014-10-27 11:10 GMT-04:00  :
> Write a program that reads the contents of the two files into two separate 
> lists.   The user should be able to enter a boy's name, a girl's 
> name or both, and the   application will display messages indicating whether 
> the names were among the most popular.
>
> THIS IS THE LIST OF BOY NAMES
> Jacob
> Michael
> Joshua
> Matthew
> Daniel
> Christopher
> Andrew
> Ethan
> Joseph
> William
> Anthony
> David
> Alexander
> Nicholas
> Ryan
> Tyler
> James
> John
> Jonathan
> Noah
> Brandon
> Christian
> Dylan
> Samuel
> Benjamin
> Zachary
> Nathan
> Logan
> Justin
> Gabriel
> Jose
> Austin
> Kevin
> Elijah
> Caleb
> Robert
> Thomas
> Jordan
> Cameron
> Jack
> Hunter
> Jackson
> Angel
> Isaiah
> Evan
> Isaac
> Mason
> Luke
> Jason
> Gavin
> Jayden
> Aaron
> Connor
> Aiden
> Aidan
> Kyle
> Juan
> Charles
> Luis
> Adam
> Lucas
> Brian
> Eric
> Adrian
> Nathaniel
> Sean
> Alex
> Carlos
> Bryan
> Ian
> Owen
> Jesus
> Landon
> Julian
> Chase
> Cole
> Diego
> Jeremiah
> Steven
> Sebastian
> Xavier
> Timothy
> Carter
> Wyatt
> Brayden
> Blake
> Hayden
> Devin
> Cody
> Richard
> Seth
> Dominic
> Jaden
> Antonio
> Miguel
> Liam
> Patrick
> Carson
> Jesse
> Tristan
> Alejandro
> Henry
> Victor
> Trevor
> Bryce
> Jake
> Riley
> Colin
> Jared
> Jeremy
> Mark
> Caden
> Garrett
> Parker
> Marcus
> Vincent
> Kaleb
> Kaden
> Brady
> Colton
> Kenneth
> Joel
> Oscar
> Josiah
> Jorge
> Cooper
> Ashton
> Tanner
> Eduardo
> Paul
> Edward
> Ivan
> Preston
> Maxwell
> Alan
> Levi
> Stephen
> Grant
> Nicolas
> Omar
> Dakota
> Alexis
> George
> Collin
> Eli
> Spencer
> Gage
> Max
> Cristian
> Ricardo
> Derek
> Micah
> Brody
> Francisco
> Nolan
> Ayden
> Dalton
> Shane
> Peter
> Damian
> Jeffrey
> Brendan
> Travis
> Fernando
> Peyton
> Conner
> Andres
> Javier
> Giovanni
> Shawn
> Braden
> Jonah
> Cesar
> Bradley
> Emmanuel
> Manuel
> Edgar
> Erik
> Mario
> Edwin
> Johnathan
> Devon
> Erick
> Wesley
> Oliver
> Trenton
> Hector
> Malachi
> Jalen
> Raymond
> Gregory
> Abraham
> Elias
> Leonardo
> Sergio
> Donovan
> Colby
> Marco
> Bryson
> Martin
>
> THIS IS THE LIST OF GIRLS NAME
> Emily
> Madison
> Emma
> Olivia
> Hannah
> Abigail
> Isabella
> Samantha
> Elizabeth
> Ashley
> Alexis
> Sarah
> Sophia
> Alyssa
> Grace
> Ava
> Taylor
> Brianna
> Lauren
> Chloe
> Natalie
> Kayla
> Jessica
> Anna
> Victoria
> Mia
> Hailey
> Sydney
> Jasmine
> Julia
> Morgan
> Destiny
> Rachel
> Ella
> Kaitlyn
> Megan
> Katherine
> Savannah
> Jennifer
> Alexandra
> Allison
> Haley
> Maria
> Kaylee
> Lily
> Makayla
> Brooke
> Mackenzie
> Nicole
> Addison
> Stephanie
> Lillian
> Andrea
> Zoe
> Faith
> Kimberly
> Madeline
> Alexa
> Katelyn
> Gabriella
> Gabrielle
> Trinity
> Amanda
> Kylie
> Mary
> Paige
> Riley
> Jenna
> Leah
> Sara
> Rebecca
> Michelle
> Sofia
> Vanessa
> Jordan
> Angelina
> Caroline
> Avery
> Audrey
> Evelyn
> Maya
> Claire
> Autumn
> Jocelyn
> Ariana
> Nevaeh
> Arianna
> Jada
> Bailey
> Brooklyn
> Aaliyah
> Amber
> Isabel
> Danielle
> Mariah
> Melanie
> Sierra
> Erin
> Molly
> Amelia
> Isabelle
> Madelyn
> Melissa
> Jacqueline
> Marissa
> Shelby
> Angela
> Leslie
> Katie
> Jade
> Catherine
> Diana
> Aubrey
> Mya
> Amy
> Briana
> Sophie
> Gabriela
> Breanna
> Gianna
> Kennedy
> Gracie
> Peyton
> Adriana
> Christina
> Courtney
> Daniela
> Kathryn
> Lydia
> Valeria
> Layla
> Alexandria
> Natalia
> Angel
> Laura
> Charlotte
> Margaret
> Cheyenne
> Mikayla
> Miranda
> Naomi
> Kelsey
> Payton
> Ana
> Alicia
> Jillian
> Daisy
> Mckenzie
> Ashlyn
> Caitlin
> Sabrina
> Summer
> Ruby
> Rylee
> Valerie
> Skylar
> Lindsey
> Kelly
> Genesis
> Zoey
> Eva
> Sadie
> Alexia
> Cassidy
> Kylee
> Kendall
> Jordyn
> Kate
> Jayla
> Karen
> Tiffany
> Cassandra
> Juliana
> Reagan
> Caitlyn
> Giselle
> Serenity
> Alondra
> Lucy
> Kiara
> Bianca
> Crystal
> Erica
> Angelica
> Hope
> Chelsea
> Alana
> Liliana
> Brittany
> Camila
> Makenzie
> Veronica
> Lilly
> Abby
> Jazmin
> Adrianna
> Karina
> Delaney
> Ellie
> Jasmin
> --
> https://mail.python.org/mailman/listinfo/python-list


The answer to you question is Yes.
-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Build Question: How to Add -Wl,--option Before Objects In Setup.py?

2014-10-27 Thread Cyd Haselton
I need to add a linker option to the command(s) run by setup.py when
building various objects.  I'm not familiar with Python at all, so I
basically copied and modified a line from one area of the script to
another


ext_modules=[Extension('_struct', ['_struct.c'], extra_link_args =
['Wl,--allow-shlib-undefined'])],
 *snip*

Unfortunately this seems to append the option to the end of the
command line.  What's the best (fastest) way to add it before the
object being built (objectname.o)?
-- 
https://mail.python.org/mailman/listinfo/python-list


A bug?

2014-10-27 Thread [email protected]
I use python 3.4.0 version. In the course of developing / running a python 
program, I have encountered a problem. I have reproduced below a simple program 
to bring it out.
 

>>> d = [[0]*3]*4
>>> dd = [1,2,3,4,5,6,7,8,9,10,11,12]
>>> for i in range(4):
...   for j in range(3): d[i][j] = dd[i*3+j]
... 
>>> d
[[10, 11, 12], [10, 11, 12], [10, 11, 12], [10, 11, 12]]
>>> 
d is not transferred to dd as expected?
Of course I can use 'append' & do my job (less elegantly though).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A bug?

2014-10-27 Thread Wolfgang Maier

On 10/27/2014 05:01 PM, [email protected] wrote:

I use python 3.4.0 version. In the course of developing / running a python 
program, I have encountered a problem. I have reproduced below a simple program 
to bring it out.



d = [[0]*3]*4
dd = [1,2,3,4,5,6,7,8,9,10,11,12]
for i in range(4):

...   for j in range(3): d[i][j] = dd[i*3+j]
...

d

[[10, 11, 12], [10, 11, 12], [10, 11, 12], [10, 11, 12]]



d is not transferred to dd as expected?
Of course I can use 'append' & do my job (less elegantly though).



See 
https://docs.python.org/3/library/stdtypes.html?highlight=list#common-sequence-operations 
under Note 2 .


Also asked and answered multiple times at stackoverflow, e.g., 
http://stackoverflow.com/questions/6688223/




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


Re: A bug?

2014-10-27 Thread Ian Kelly
On Mon, Oct 27, 2014 at 10:17 AM, Wolfgang Maier
 wrote:
> See
> https://docs.python.org/3/library/stdtypes.html?highlight=list#common-sequence-operations
> under Note 2 .
>
> Also asked and answered multiple times at stackoverflow, e.g.,
> http://stackoverflow.com/questions/6688223/

Also see 
https://docs.python.org/3/faq/programming.html#how-do-i-create-a-multidimensional-list
(probably a better resource than that footnote).
-- 
https://mail.python.org/mailman/listinfo/python-list


memory, PE files, etc...

2014-10-27 Thread kiuhnm03
Hi!
I'd like to write one or more scripts that analyze processes in memory on 
Windows 7. I used to do these things in C++ by using native Win32 API calls.
How should I proceed in python? Any pointers?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: memory, PE files, etc...

2014-10-27 Thread Tim Golden
On 27/10/2014 17:16, [email protected] wrote:
> Hi! I'd like to write one or more scripts that analyze processes in
> memory on Windows 7. I used to do these things in C++ by using native
> Win32 API calls. How should I proceed in python? Any pointers?
> 

psutil is definitely your friend:

  https://github.com/giampaolo/psutil

Although WMI can be quite handy too, depending on what you're trying to do:

  http://timgolden.me.uk/python/wmi/

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


variable attribute name

2014-10-27 Thread Harvey Greenberg
I want to let the name of an attribute be the string value of a variable.  Here 
is some code:

class Object(object): pass
A = Object()
s = 'attr'
A. = 1

The last line denotes the variable value by  (not a python form).  What I 
want is to have A.attr = 1, but 'attr' determined by the value of s.  Please 
advise.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: variable attribute name

2014-10-27 Thread Larry Martell
On Mon, Oct 27, 2014 at 2:23 PM, Harvey Greenberg  wrote:
> I want to let the name of an attribute be the string value of a variable.  
> Here is some code:
>
> class Object(object): pass
> A = Object()
> s = 'attr'
> A. = 1
>
> The last line denotes the variable value by  (not a python form).  What I 
> want is to have A.attr = 1, but 'attr' determined by the value of s.  Please 
> advise.

setattr(A, s, 1)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: memory, PE files, etc...

2014-10-27 Thread kiuhnm03
On Monday, October 27, 2014 6:24:19 PM UTC+1, Tim Golden wrote:
> psutil is definitely your friend:
> 
>   https://github.com/giampaolo/psutil
> 
> Although WMI can be quite handy too, depending on what you're trying to do:
> 
>   http://timgolden.me.uk/python/wmi/
> 
> TJG

Thanks for answering.
I don't know if psutil is what I'm looking for.
What I need to do is more related to debugging than to administration.
Let's say I want to search for a sequence of bytes in the .text section of a 
given module. Can I do that with psutil?
Maybe I should buy this book:
http://www.amazon.com/Gray-Hat-Python-Programming-Engineers/dp/1593271921
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: variable attribute name

2014-10-27 Thread Ned Batchelder

On 10/27/14 2:32 PM, Larry Martell wrote:

On Mon, Oct 27, 2014 at 2:23 PM, Harvey Greenberg  wrote:

I want to let the name of an attribute be the string value of a variable.  Here 
is some code:

class Object(object): pass
A = Object()
s = 'attr'
A. = 1

The last line denotes the variable value by  (not a python form).  What I 
want is to have A.attr = 1, but 'attr' determined by the value of s.  Please advise.


setattr(A, s, 1)



Larry's code will work for you.  If you are making many attributes like 
this, you might be better off just using a dictionary in the first place:


a = {}
a[s] = 1


--
Ned Batchelder, http://nedbatchelder.com

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


Re: Build Question: How to Add -Wl, --option Before Objects In Setup.py?

2014-10-27 Thread Ned Deily
In article 
,
 Cyd Haselton  wrote:
> I need to add a linker option to the command(s) run by setup.py when
> building various objects.  I'm not familiar with Python at all, so I
> basically copied and modified a line from one area of the script to
> another
> 
> 
> ext_modules=[Extension('_struct', ['_struct.c'], extra_link_args =
> ['Wl,--allow-shlib-undefined'])],
>  *snip*
> 
> Unfortunately this seems to append the option to the end of the
> command line.  What's the best (fastest) way to add it before the
> object being built (objectname.o)?

It depends on what system and build tools that you are using and that 
the Python you are using was built with but, in general on most 
POSIX-like systems, one way to do it should be to supply it via an 
LDFLAGS environment variable.  The safest approach would be to get the 
default value of LDFLAGS for this Python instance, append your 
additional values to it, and pass it back into the setup.py build.  You 
can do that all in one line:

LDFLAGS="$(python -c 'import 
sysconfig;print(sysconfig.get_config_var("LDFLAGS"))') 
-Wl,--allow-shlib-undefined" python setup.py build

-- 
 Ned Deily,
 [email protected]

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


Re: I am out of trial and error again Lists

2014-10-27 Thread giacomo boffi
Rustom Mody  writes:

> What would you say to a person who
> - Buys a Lambhorgini

I'd say: "Don't buy a Lambhorgini from that nice guy you met at a party,
  but buy a Lamborghini by an authorized dealer"  ;-)

-- 
I was a kid when Lamborghini launched the Miura!
-- 
https://mail.python.org/mailman/listinfo/python-list


different behavior from idle/pycharm and shell

2014-10-27 Thread kiuhnm03
Consider this code:

---
from ctypes import *

user32 = windll.user32
user32.MessageBoxA(0, 'ok', 'ok', 0)
---

If I run it in idle or from pycharm, the messagebox shows 'o' instead of 'ok', 
but if I run it from shell, it shows 'ok' like it should.
The same happens with msvcrt.printf().
Why?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: different behavior from idle/pycharm and shell

2014-10-27 Thread sohcahtoa82
On Monday, October 27, 2014 3:38:31 PM UTC-7, [email protected] wrote:
> Consider this code:
> 
> ---
> from ctypes import *
> 
> user32 = windll.user32
> user32.MessageBoxA(0, 'ok', 'ok', 0)
> ---
> 
> If I run it in idle or from pycharm, the messagebox shows 'o' instead of 
> 'ok', but if I run it from shell, it shows 'ok' like it should.
> The same happens with msvcrt.printf().
> Why?

If I had to take a guess, in the shell, it is encoding the string characters as 
single bytes as expected, but in Idle or PyCharm, it is encoding them as 
WCHARs, which are two-bytes wide.

Two things to try:

1. Change the call to MessageBoxW and see if it works in Idle/PyCharm.  Note 
that this will probably break the call from the shell.
2. Try a string longer than two characters and see what you get.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: different behavior from idle/pycharm and shell

2014-10-27 Thread MRAB

On 2014-10-27 22:38, [email protected] wrote:

Consider this code:

---
from ctypes import *

user32 = windll.user32
user32.MessageBoxA(0, 'ok', 'ok', 0)
---

If I run it in idle or from pycharm, the messagebox shows 'o' instead of 'ok', 
but if I run it from shell, it shows 'ok' like it should.
The same happens with msvcrt.printf().
Why?


You didn't say whether you're using Python 2 or Python 3, but it looks
like you're using Python 3.

There are 2 forms of the MessageBox function, one with the suffix 'A',
which uses bytestrings, and one with the suffix 'W', which uses Unicode
strings.

In Python 3, the str class is a Unicode string, so you'll want the
MessageBoxW function:

from ctypes import *

user32 = windll.user32
user32.MessageBoxW(0, 'ok', 'ok', 0)

Also, the msvcrt.printf function expects a bytestring.
--
https://mail.python.org/mailman/listinfo/python-list


Re: different behavior from idle/pycharm and shell

2014-10-27 Thread kiuhnm03
On Monday, October 27, 2014 11:55:44 PM UTC+1, MRAB wrote:
> On 2014-10-27 22:38, kiuhnm wrote:
> > Consider this code:
> >
> > ---
> > from ctypes import *
> >
> > user32 = windll.user32
> > user32.MessageBoxA(0, 'ok', 'ok', 0)
> > ---
> >
> > If I run it in idle or from pycharm, the messagebox shows 'o' instead of 
> > 'ok', but if I run it from shell, it shows 'ok' like it should.
> > The same happens with msvcrt.printf().
> > Why?
> >
> You didn't say whether you're using Python 2 or Python 3, but it looks
> like you're using Python 3.
> 
> There are 2 forms of the MessageBox function, one with the suffix 'A',
> which uses bytestrings, and one with the suffix 'W', which uses Unicode
> strings.
> 
> In Python 3, the str class is a Unicode string, so you'll want the
> MessageBoxW function:
> 
> from ctypes import *
> 
> user32 = windll.user32
> user32.MessageBoxW(0, 'ok', 'ok', 0)
> 
> Also, the msvcrt.printf function expects a bytestring.

Yes, you're right.
Thank you both.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Build Question: How to Add -Wl, --option Before Objects In Setup.py?

2014-10-27 Thread Cyd Haselton
On Mon, Oct 27, 2014 at 3:39 PM, Ned Deily  wrote:
> In article
> ,
>  Cyd Haselton  wrote:
>> I need to add a linker option to the command(s) run by setup.py when
>> building various objects.  I'm not familiar with Python at all, so I
>> basically copied and modified a line from one area of the script to
>> another
>>
>>
>> ext_modules=[Extension('_struct', ['_struct.c'], extra_link_args =
>> ['Wl,--allow-shlib-undefined'])],
>>  *snip*
>>
>> Unfortunately this seems to append the option to the end of the
>> command line.  What's the best (fastest) way to add it before the
>> object being built (objectname.o)?
>
> It depends on what system and build tools that you are using and that
> the Python you are using was built with but, in general on most
> POSIX-like systems, one way to do it should be to supply it via an
> LDFLAGS environment variable.  The safest approach would be to get the
> default value of LDFLAGS for this Python instance, append your
> additional values to it, and pass it back into the setup.py build.  You
> can do that all in one line:
>
> LDFLAGS="$(python -c 'import
> sysconfig;print(sysconfig.get_config_var("LDFLAGS"))')
> -Wl,--allow-shlib-undefined" python setup.py build
>
> --
>  Ned Deily,
>  [email protected]
>

I'm building python on an Android device in the KBOX
environment...which simulates a Unix type filesystem.
Python isn't installed; I'm building from sources (2.7.8) with GCC
4.8.0 and make.

The problem with the LDFLAGS approach is that some of the libraries
that must be linked (-lc -ldl) do not need the --allow-shlib-undefined
option...it's only the lpython2.7 that does.  Any way to do this?

Cyd Haselton
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Anyone know the solution

2014-10-27 Thread Denis McMahon
On Mon, 27 Oct 2014 08:10:04 -0700, emmanueloje wrote:

> Write a program that reads the contents of the two files into two
> separate lists.

Yep, know how to do that

> The user should be able to enter a boy's name, a girl's
> name or both

Yep, know how to do that

> and the application will display messages
> indicating whether the names were among the most popular.

Nope, not sure how to do that, please define the algorithm for 
determining a "most popular name"

Determining if the name is in either of the lists is easy, know how to do 
that, but I'm not sure from your problem description if that's your 
definition of a "most popular name" or not.

-- 
Denis McMahon, [email protected]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Anyone know the solution

2014-10-27 Thread alex23

On 28/10/2014 1:10 AM, [email protected] wrote:

Write a program that reads the contents of the two files into two separate 
lists.   The user should be able to enter a boy's name, a girl's 
name or both, and the   application will display messages indicating whether 
the names were among the most popular.


This is actually a trick question. This is a classic unsolvable problem 
in computer science, known as the Dual Baskets problem. It is 
NP-complete, meaning that there is no easy solution. It requires 
brute-forcing and can take an indefinite period of time to complete, if 
at all.


The correct answer is "Not possible".
--
https://mail.python.org/mailman/listinfo/python-list


Re: A bug?

2014-10-27 Thread Denis McMahon
On Mon, 27 Oct 2014 09:01:57 -0700, [email protected] wrote:

> I use python 3.4.0 version. In the course of developing / running a
> python program, I have encountered a problem. I have reproduced below a
> simple program to bring it out.
>  
>  
 d = [[0]*3]*4 dd = [1,2,3,4,5,6,7,8,9,10,11,12]
 for i in range(4):
> ...   for j in range(3): d[i][j] = dd[i*3+j]
> ...
 d
> [[10, 11, 12], [10, 11, 12], [10, 11, 12], [10, 11, 12]]
 
> d is not transferred to dd as expected?
> Of course I can use 'append' & do my job (less elegantly though).

Not sure if this is elegant or not:

d = [[list(range(1,13))[i*3+j] for j in range(3)] for i in range(4)]

but it seems to be a one-line solution for what you're trying to do.

-- 
Denis McMahon, [email protected]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A bug?

2014-10-27 Thread Rustom Mody
On Tuesday, October 28, 2014 6:07:14 AM UTC+5:30, Denis McMahon wrote:
> On Mon, 27 Oct 2014 09:01:57 -0700, umatrp wrote:
> > I use python 3.4.0 version. In the course of developing / running a
> > python program, I have encountered a problem. I have reproduced below a
> > simple program to bring it out.
>  d = [[0]*3]*4 dd = [1,2,3,4,5,6,7,8,9,10,11,12]
>  for i in range(4):
> > ...   for j in range(3): d[i][j] = dd[i*3+j]
> > ...
>  d
> > [[10, 11, 12], [10, 11, 12], [10, 11, 12], [10, 11, 12]]
> > d is not transferred to dd as expected?
> > Of course I can use 'append' & do my job (less elegantly though).
> Not sure if this is elegant or not:
> d = [[list(range(1,13))[i*3+j] for j in range(3)] for i in range(4)]
> but it seems to be a one-line solution for what you're trying to do.

Neat

More generally for d being a 2-D reshape of dd (which may be anything
as long as the size matches)

>>> dd = [1,2,3,4,5,6,7,8,9,10,11,12]
>>> d=[[dd[i*3+j] for j in range(3)] for i in range(4)]
>>> d
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A bug?

2014-10-27 Thread Chris Angelico
On Tue, Oct 28, 2014 at 12:12 PM, Rustom Mody  wrote:
> More generally for d being a 2-D reshape of dd (which may be anything
> as long as the size matches)
>
 dd = [1,2,3,4,5,6,7,8,9,10,11,12]
 d=[[dd[i*3+j] for j in range(3)] for i in range(4)]
 d
> [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]

The inner comprehension should surely be a slice:

>>> [dd[i*3:i*3+3] for i in range(4)]
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]

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


Re: A bug?

2014-10-27 Thread Joshua Landau
On 28 October 2014 00:36, Denis McMahon  wrote:
>
> d = [[list(range(1,13))[i*3+j] for j in range(3)] for i in range(4)]

A quick note. Ranges (even 2.7's xrange) are all indexable. The cast
to a list isn't needed.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A bug?

2014-10-27 Thread Rustom Mody
On Tuesday, October 28, 2014 6:56:10 AM UTC+5:30, Chris Angelico wrote:
> On Tue, Oct 28, 2014 at 12:12 PM, Rustom Mody  wrote:
> > More generally for d being a 2-D reshape of dd (which may be anything
> > as long as the size matches)
> >
>  dd = [1,2,3,4,5,6,7,8,9,10,11,12]
>  d=[[dd[i*3+j] for j in range(3)] for i in range(4)]
>  d
> > [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
> 
> The inner comprehension should surely be a slice:
> 
> >>> [dd[i*3:i*3+3] for i in range(4)]
> [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]

Sweet!
[Something for my class today]

Looks even better this way:

>>> dd = range(1,13)
>>> [dd[i*3:i*3+3] for i in range(4)]
[range(1, 4), range(4, 7), range(7, 10), range(10, 13)]
>>> 

In the same vein a transpose:
>>> [list(dd[i::3]) for i in range(3)]
[[0, 3, 6, 9], [1, 4, 7, 10], [2, 5, 8, 11]]

[Not sure why both are 3; no 4's...]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: memory, PE files, etc...

2014-10-27 Thread Rustom Mody
On Tuesday, October 28, 2014 12:41:40 AM UTC+5:30, [email protected] wrote:
> On Monday, October 27, 2014 6:24:19 PM UTC+1, Tim Golden wrote:
> > psutil is definitely your friend:
> > 
> >   https://github.com/giampaolo/psutil
> > 
> > Although WMI can be quite handy too, depending on what you're trying to do:
> > 
> >   http://timgolden.me.uk/python/wmi/
> > 
> > TJG
> 
> Thanks for answering.
> I don't know if psutil is what I'm looking for.
> What I need to do is more related to debugging than to administration.
> Let's say I want to search for a sequence of bytes in the .text section of a 
> given module. Can I do that with psutil?

https://code.google.com/p/pefile/

?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Status of side-effecting functions in python

2014-10-27 Thread Nobody
On Mon, 27 Oct 2014 17:14:58 +0200, Marko Rauhamaa wrote:

> In POSIX, a write(2) system call on file blocks until all bytes have been
> passed on to the file system. The only exception (no pun intended) I know
> is the reception of a signal.

Writing to a file (or block device) will return a short count in the event
that it results in the size of the file exceeding

* the space available on the partition,
* the user's quota,
* the process' file size limit (RLIMIT_FSIZE), or
* any implementation limit on the maximum size of a file,

and at least one byte can be written. This behaviour is mandated by POSIX.

This is different to writing to a socket, pipe or character device,
where a short count is considered an entirely normal result, and
a subsequent write for the remaining bytes will often succeed.

> Even then, I'm not sure Linux file systems ever cut writes short because
> of signals.

Linux never interrupts I/O on discs or block devices due to signals.
These are restarted regardless of whether the signal is set for
automatic restarting (SA_RESTART flag).

> I think the lack of nonblocking file access in Linux is one of the OS's
> main shortcomings. 

It doesn't really matter. In the absence of an explicit mlock() or
mlockall(), the actual code which would be controlling the access is
demand-paged from disc, as is the "memory" to/from which the data is
transferred (along with the memory which would hold the return code from
read() or write(), for that matter).

Asynchronous I/O in the sense of select(), poll(), O_NONBLOCK etc is meant
for situations where delays could be indefinite, e.g. network connections
or terminals. For "short" delays (i.e. disc access), there's not much
point having a mechanism so that you can avoid blocking while the data is
read from disc just so that you can block while the code in the "else"
branch is read from disc.

If you want the program to be able to do something else while waiting for
I/O, use threads. The introduction of threads made most concurrency-
related issues in the POSIX API moot.

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


Re: Classes and the command line

2014-10-27 Thread Terry Reedy

On 10/26/2014 11:24 PM, Chris Angelico wrote:

On Mon, Oct 27, 2014 at 2:18 PM, Rustom Mody  wrote:

On Monday, October 27, 2014 8:40:48 AM UTC+5:30, Chris Angelico wrote:



You can get block-by-block history by using Idle. I find that fairly
convenient for manipulating class/function definitions.

ChrisA


Umm... Nice!
A bit inconsistent in that the '...' does not appear.
But thats good; makes copy|cut-pasting from interpreter to file
a mostly trivial operation.


One of the differences between console interpreter and Idle Shell is 
that the former is line oriented whereas Shell is statement oriented. 
In the console interpreter, you cannot edit a line after it is entered. 
 In Shell, you can edit any line until you enter an entire statment. 
Similarly, c. i. history recalls a line at a time.  Recalling an 
multiline statment has to be done a line at a time, in order.  Shell 
history recalls an entire statement, even if multiple lines (this is 
what Chris means by 'blocks').  Explaining this difference as the reason 
for no ... is on my todo list.



It's inconsistent only because the default sys.ps2 is those dots,
which aren't necessary in Idle. You could make it consistent by simply
changing sys.ps2.


Nope.  User code is executed in the user process.  Its only effect on 
the Idle process is to write to stdout or stderr for display.  There is 
 tracker issue about letting users change sys.ps1 *in the Idle 
process*, but it would have to be through the menu or config dialog.


--
Terry Jan Reedy


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


Re: Classes and the command line

2014-10-27 Thread Terry Reedy

On 10/26/2014 11:28 PM, Seymore4Head wrote:


I am going to be flexible on IDLE in the near future, but I wanted to
try it the old fashion way.  I already know using IDLE is better, but
I am not sure using IDLE will invoke Python 2 and I am not sure how to
change that at the moment.


Currently, Idle executes user code with the same interpreter it is 
running on.


Now that user code is executed in a subprocess, there is the possibility 
of using a different python in the subprocess.  But this is for the future.


--
Terry Jan Reedy

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


Re: Anyone know the solution

2014-10-27 Thread Terry Reedy

On 10/27/2014 11:10 AM, [email protected] wrote:


THIS IS THE LIST OF BOY NAMES

> Jacob
> ...

Writing hundreds of unnecessary lines at minimum inconsiderate. Please 
don't do it.


--
Terry Jan Reedy

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


Re: Classes and the command line

2014-10-27 Thread Chris Angelico
On Tue, Oct 28, 2014 at 3:08 PM, Terry Reedy  wrote:
>> It's inconsistent only because the default sys.ps2 is those dots,
>> which aren't necessary in Idle. You could make it consistent by simply
>> changing sys.ps2.
>
>
> Nope.  User code is executed in the user process.  Its only effect on the
> Idle process is to write to stdout or stderr for display.  There is  tracker
> issue about letting users change sys.ps1 *in the Idle process*, but it would
> have to be through the menu or config dialog.

I knew that, honest I did... umm, let's just pretend I was talking
about changing sys.ps2 in the console interpreter. Yeah. Because I
totally knew that changing it in Idle wouldn't work. Plus, I tested it
before posting, like everyone should. Honest!

Changing it in the console interpreter does work, though.

Python 3.5.0a0 (default:301b9a58021c, Oct  2 2014, 09:20:24)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.ps2=""
>>> def x():
pass

>>>

And if you want consistency, that's a good way to get it.

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


hotel management system

2014-10-27 Thread ngangsia akumbo
Please can someone look at my code and may be advice and may be help me with 
some correction. I have been learning python for some time now. This is my 
first project i wish to write. A hotel management system.


http://pastebin.com/LMHmuTiC

Thnaks
-- 
https://mail.python.org/mailman/listinfo/python-list