Re: option argument length

2005-12-04 Thread Nicolas Couture
I don't think that's actually what you want to do. Yes arguments are
not to be used directly as option arguments (otherwise why have option
arguments anyways ;-) but each option argument is usually evaluated
under the evaluation of the actual option and optparse will error on
invalid use of the options you build.

Why exactly do you think you need to find the number of optional arguments?

Everytime I thought about the need for this kind of option parsing
design I was able to find an easier way to achieve what I wanted to do.

See "How optik handles errors" - http://optik.sourceforge.net/doc/1.5/tutorial.html

If you really think you need to be doing this, you can modify the following function:

def is_empty(options
):"""Returns True or False if an option is set or not.
"""values = options
.__dict__.values()return
 (values == [None] *
 len(values))


On 12/4/05, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote:
-BEGIN PGP SIGNED MESSAGE-Hash: SHA1Hi,I'm using optparse module to parse all options and arguments.My program uses mostly "option arguments" hence my len(args) value is always
zero. I need to check if the user has passed the correct number of "optionarguments". Something like:(options,args) = parser.parse_args()len(options) != 1 or len(options) > 2:print "Incorrect number of arguments passed."
How do I accomplish it ?Regards,rrs- --Ritesh Raj SarrafRESEARCHUT -- http://www.researchut.com"Stealing logics from one person is plagiarism, stealing from many is
research.""Necessity is the mother of invention."Note: Please CC me. I'm not subscribed to the list-BEGIN PGP SIGNATURE-Version: GnuPG v1.4.2 (GNU/Linux)iD8DBQFDk1Nh4Rhi6gTxMLwRApx0AJ9XHlWFU1J0NdN02gtvimogUSgDkACgmkOO
2pX8ocoC7pot1a8R4u2BWrY==piNo-END PGP SIGNATURE---http://mail.python.org/mailman/listinfo/python-list

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

Generating a list of None

2005-07-14 Thread Nicolas Couture
Hi,

Is it possible to generate a list of `None' ?

opts.__dict__.values() below could be represented by [None, None, None]

---
def get_options(opts):
"""Return True or False if an option is set or not"""
vals = opts.__dict__.values()

for val in vals:
if val is not None:
return True

return False
---

This is how I'd like to see it:

---
def get_options(opts):
"""Return True or False if an option is set or not"""
vals = opts.__dict__.values()

for if vals is [None * len(vals)]:
return False

return True
---

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


Re: Generating a list of None

2005-07-14 Thread Nicolas Couture
of course the later snipplet should be:
---
def get_options(opts):
"""Return True or False if an option is set or not"""
vals = opts.__dict__.values()

if vals == [None * len(vals)]:
return False

return True
---

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


Re: Basic Server/Client socket pair not working

2005-08-29 Thread Nicolas Couture

Michael Goettsche wrote:
> Hi there,
>
> I'm trying to write a simple server/client example. The client should be able
> to send text to the server and the server should distribute the text to all
> connected clients. However, it seems that only the first entered text is sent
> and received. When I then get prompted for input again and press return,
> nothing gets back to me. Any hints on what I have done would be very much
> appreciated!
>
> Here's my code:
>
>  SERVER ##
> import socket
> import select
>
> mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> mySocket.bind(('', 1))
> mySocket.listen(1)
>
> clientlist = []
>
> while True:
>connection, details = mySocket.accept()
>print 'We have opened a connection with', details
>clientlist.append(connection)
>readable = select.select(clientlist, [], [])
>msg = ''
>for i in readable[0]:

for i in readable:

>   while len(msg) < 1024:
>  chunk = i.recv(1024 - len(msg))
>  msg = msg + chunk
>
>for i in clientlist:
>   totalsent = 0
>   while totalsent < 1024:
>  sent = i.send(msg)
>  totalsent = totalsent + sent
>
> ## CLIENT 
> import socket
> import select
>
> socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> socket.connect(("127.0.0.1", 1))
>
> while True:
> text = raw_input("Du bist an der Reihe")
> text = text + ((1024 - len(text)) * ".")
> totalsent = 0
> while totalsent < len(text):
> sent = socket.send(text)
> totalsent = totalsent + sent
>
> msg = ''
> while len(msg) < 1024:
> chunk = socket.recv(1024 - len(msg))
> msg = msg + chunk
>  
> print msg

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