[Tutor] iterating over a sequence question..

2007-06-17 Thread Iyer

say, if I have a list l = [1,2,3,5]

and another tuple t = ('r', 'g', 'b')

Suppose I iterate over list l, and t at the same time, if I use the zip 
function as in zip(l,t) , I will not be able to cover elements 3 and 5 in list l

>>> l = [1,2,3,5]
>>> t = ('r', 'g', 'b')
>>> for i in zip(l,t):
... print i
... 
(1, 'r')
(2, 'g')
(3, 'b')

is there an elegant way in python to print all the elements in l, while looping 
over list t, if len(t) != len(l) as to get the output:

(1, 'r')
 (2, 'g')
 (3, 'b')
(5, 'r')

I could iterate over l only and reset the index to point to the first element 
of t, in case the elements in t are "exhausted" . Any pythonic way to iterate 
over a sequence, while iterating over another shorter sequence continously 
(granted that the lengths of the two lists are different)?


-iyer
   
-
Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel 
and lay it on us.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] iterating over a sequence question..

2007-06-17 Thread John Fouhy
On 17/06/07, Iyer <[EMAIL PROTECTED]> wrote:
>
> say, if I have a list l = [1,2,3,5]
>
> and another tuple t = ('r', 'g', 'b')
>
> Suppose I iterate over list l, and t at the same time, if I use the zip
> function as in zip(l,t) , I will not be able to cover elements 3 and 5 in
> list l
>
> >>> l = [1,2,3,5]
> >>> t = ('r', 'g', 'b')
> >>> for i in zip(l,t):
> ... print i
> ...
> (1, 'r')
> (2, 'g')
> (3, 'b')
>
> is there an elegant way in python to print all the elements in l, while
> looping over list t, if len(t) != len(l) as to get the output:
>
> (1, 'r')
>  (2, 'g')
>  (3, 'b')
> (5, 'r')

Check out the itertools module.  I don't have the ability to test this
right now, but try something like:

import itertools
lst = [1,2,3,5]
t = ('r', 'g', 'b')

itertools.izip(lst, itertools.cycle(t))

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] iterating over a sequence question..

2007-06-17 Thread Alan Gauld

"Iyer" <[EMAIL PROTECTED]> wrote

> Any pythonic way to iterate over a sequence, while iterating 
> over another shorter sequence continously 

I don;t know how pythonic it is, but I'd do it thus:

>>> a = (1, 2, 3, 4)
>>> b = ('a', 'b', 'c')
>>> n = len(a)/len(b) + 1
>>> t = map(None,a,b*n)[:len(a)]
>>> t
[(1, 'a'), (2, 'b'), (3, 'c'), (4, 'a')]
>>> for x,y in t:
... print x,y
... 
1 a
2 b
3 c
4 a


I suspect you could use a list comp too but map seemed easier.
And of course you could compress it into less lines:

>>> for x,y in map(None,a,b*(len(a)/len(b)+1))[:len(a)]:
... print x,y

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] iterating over a sequence question..

2007-06-17 Thread Luke Paireepinart
Alan Gauld wrote:
> "Iyer" <[EMAIL PROTECTED]> wrote
>
>   
>> Any pythonic way to iterate over a sequence, while iterating 
>> over another shorter sequence continously 
>> 
The first thing that occurred to me was just to use a modulus to index 
into the second, shorter list.
 >>> l = [1,2,3,4,5]
 >>> t = ('r','g','b')
 >>> for i in range(len(l)):
print (l[i], t[i%len(t)])

which results in
   
(1, 'r')
(2, 'g')
(3, 'b')
(4, 'r')
(5, 'g')

not exactly Pythonic either, and you are assuming that l is longer than 
t (it is easy to account for opposite case as well.)

a more expanded version that accounts for either list being the longer 
one, or both being the same length, would be:

 >>> if len(t) > len(l): x = len(t)
else: x = len(l)
 >>> print [(l[i%len(l)],t[i%len(t)]) for i in range(x)]
[(1, 'r'), (2, 'g'), (3, 'b'), (4, 'r'), (5, 'g')]


-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] iterating over a sequence question..

2007-06-17 Thread Alan Gauld

"Luke Paireepinart" <[EMAIL PROTECTED]> wrote

> The first thing that occurred to me was just to use a modulus to 
> index
> into the second, shorter list.

That was the first thing that occured to me too but when
I tried it I couldn't get it to work...

> >>> l = [1,2,3,4,5]
> >>> t = ('r','g','b')
> >>> for i in range(len(l)):
>print (l[i], t[i%len(t)])

because I was trying t[len(t) % i]
and various  variations, I never thought of reversing the arguments!"
I knew a modulus trick existed but couldn't figure it out this 
morning.

I hadn't had coffee yet, at least that's my excuse! :-)

Alan G.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] iterating over a sequence question..

2007-06-17 Thread Reed O'Brien

On Jun 17, 2007, at 3:44 AM, John Fouhy wrote:

> On 17/06/07, Iyer <[EMAIL PROTECTED]> wrote:
>>
>> say, if I have a list l = [1,2,3,5]
>>
>> and another tuple t = ('r', 'g', 'b')
>>
>> Suppose I iterate over list l, and t at the same time, if I use  
>> the zip
>> function as in zip(l,t) , I will not be able to cover elements 3  
>> and 5 in
>> list l
>>
> l = [1,2,3,5]
> t = ('r', 'g', 'b')
> for i in zip(l,t):
>> ... print i
>> ...
>> (1, 'r')
>> (2, 'g')
>> (3, 'b')
>>
>> is there an elegant way in python to print all the elements in l,  
>> while
>> looping over list t, if len(t) != len(l) as to get the output:
>>
>> (1, 'r')
>>  (2, 'g')
>>  (3, 'b')
>> (5, 'r')
>
> Check out the itertools module.  I don't have the ability to test this
> right now, but try something like:
>
> import itertools
> lst = [1,2,3,5]
> t = ('r', 'g', 'b')
>
> itertools.izip(lst, itertools.cycle(t))
>
> -- 
> John.
>

+1 for John's solution

usage:
 >>> [x for x in itertools.izip(lst, itertools.cycle(t)]
 >>> [(1, 'r'), (2, 'g'), (3, 'b'), (5, 'r')]


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Class error

2007-06-17 Thread Henry Dominik
Hello people,

I was trying my hands on Python's Classes and have a first hurdle and can't 
seem to get past it.

-Below is the error message --

Traceback (most recent call last):
  File "C:/Development/python/EmplAddrBookEntry.py", line 3, in -toplevel-
class EmplAddrBookEntry(AddrBookEntry):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)
-end-
Here are the classes, and they are saved in diferent files
--AddrBookEntry.py-
class AddrBookEntry(object):
'address book entry class'
def __init__(self, nm, ph):
self.name = nm
self.phone = ph
print  'Created instance of ', self.name

def updatePhone(self, newPh):
self.phone = newPh
print 'Updated the phone number to: ', self.phone


--EmplAddrBookEntry.py-
import AddrBookEntry

class EmplAddrBookEntry(AddrBookEntry):

def __init__(self, nm, ph, id, em):
AddrBookEntry.__init__(self, nm, ph)
self.empid = id
self.email = em

def updateEmail(self, newEmail):
self.email = newEmail
print 'Updated with new email', self.email

-
The error message spills out onto the  IDLE Python Shell window when I press 
the F5.

Your help is highly appreciated.

--Dom

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Class error

2007-06-17 Thread Luke Paireepinart
Henry Dominik wrote:
> Hello people,
>
> I was trying my hands on Python's Classes and have a first hurdle and can't 
> seem to get past it.
>
> -Below is the error message --
>
> Traceback (most recent call last):
>   File "C:/Development/python/EmplAddrBookEntry.py", line 3, in -toplevel-
> class EmplAddrBookEntry(AddrBookEntry):
> TypeError: Error when calling the metaclass bases
> module.__init__() takes at most 2 arguments (3 given)
>   
It says "module.__init__" not "AddrBookEntry.__init__" which leads me to 
believe that
> --AddrBookEntry.py-
>   
the filename of your module
> class AddrBookEntry(object):
>   
and the class name itself are confusing you.
> import AddrBookEntry
>
> class EmplAddrBookEntry(AddrBookEntry):
>
> def __init__(self, nm, ph, id, em):
> AddrBookEntry.__init__(self, nm, ph)
>   
I believe this should be "AddrBookEntry.AddrBookEntry.__init__"

I can't be certain, but that's what it looks like off the top of my head.
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] editing macros for catia V5

2007-06-17 Thread pierre cutellic

I am new to Python and trying to get my head around catia V5
I would like to start to write some automated process in python for catia,
does anybody know the way to or some docs maybe?

cheers
Pierre
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] iterating over a sequence question..

2007-06-17 Thread David Heiser

I love this [Tutor] list. There are always new tricks that change the
way I write code. And it makes me like Python more every day.

I keep a script file with "notes" on the things I learn here and I refer
to these notes frequently. Here are the notes I made for this thread:


""" iterate/map/modulus/(zip) """
a = (1, 2, 3, 4, 5)
b = ('r', 'g', 'b')
na = len(a)
nb = len(b)

print
print "==="
# zip
A = ''.join([str(i) for i in a])  # "12345"
B = ''.join(b)# "rgb"
print zip(A, B), "  - zip (inadequate)"
print
print "==="
# brute force
m = 0
n = 0
t = []
##x = 10
##for i in range(x):
for i in range(max(na, nb)):
if m == na:
m = 0
if n == nb:
n = 0
t.append((a[m], b[n]))
m += 1
n += 1
print t,  "- brute force"
print
print "==="
# itertools
from itertools import izip, cycle
print list(izip(a, cycle(b))), "- itertools"
print
print "==="
# map
print map(None,a,b*(na/nb+1))[:na], "- map"
print
print "==="
# modulus
print [(a[i], b[i%nb]) for i in range(na)], "- modulus"
print
print "---"
##x = max(na, nb)
x = 10
print [(a[i%na], b[i%nb]) for i in range(x)], "- modulus (extended)"
print
print "==="

This mailing list is great. Thanks to all the experienced Python coders
who offer various solutions to the questions, and to all the beginners
who ask them.



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Reed O'Brien
Sent: Sunday, June 17, 2007 8:59 AM
To: Iyer; tutor@python.org
Subject: Re: [Tutor] iterating over a sequence question..



On Jun 17, 2007, at 3:44 AM, John Fouhy wrote:

> On 17/06/07, Iyer <[EMAIL PROTECTED]> wrote:
>>
>> say, if I have a list l = [1,2,3,5]
>>
>> and another tuple t = ('r', 'g', 'b')
>>
>> Suppose I iterate over list l, and t at the same time, if I use
>> the zip
>> function as in zip(l,t) , I will not be able to cover elements 3  
>> and 5 in
>> list l
>>
> l = [1,2,3,5]
> t = ('r', 'g', 'b')
> for i in zip(l,t):
>> ... print i
>> ...
>> (1, 'r')
>> (2, 'g')
>> (3, 'b')
>>
>> is there an elegant way in python to print all the elements in l,
>> while
>> looping over list t, if len(t) != len(l) as to get the output:
>>
>> (1, 'r')
>>  (2, 'g')
>>  (3, 'b')
>> (5, 'r')
>
> Check out the itertools module.  I don't have the ability to test this

> right now, but try something like:
>
> import itertools
> lst = [1,2,3,5]
> t = ('r', 'g', 'b')
>
> itertools.izip(lst, itertools.cycle(t))
>
> --
> John.
>

+1 for John's solution

usage:
 >>> [x for x in itertools.izip(lst, itertools.cycle(t)]
 >>> [(1, 'r'), (2, 'g'), (3, 'b'), (5, 'r')]


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Class error

2007-06-17 Thread Alan Gauld

"Henry Dominik" <[EMAIL PROTECTED]> wrote


> import AddrBookEntry
> 
> class EmplAddrBookEntry(AddrBookEntry):

This says you are creating a new class that inherits 
from the *module* AddrBookEntry. Notice that the 
error message referred to the module not the class...

You probably meant:

class EmplAddrBookEntry(AddrBookEntry.AddrBookEntry):

>def __init__(self, nm, ph, id, em):
>AddrBookEntry.__init__(self, nm, ph)

Which makes this line become
 AddrBookEntry.AddrBookEntry.__init__(self, nm, ph)

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] editing macros for catia V5

2007-06-17 Thread Alan Gauld

"pierre cutellic" <[EMAIL PROTECTED]> wrote

>I am new to Python and trying to get my head around catia V5
> I would like to start to write some automated process in python for 
> catia,
> does anybody know the way to or some docs maybe?

Until your post I'd never even heard of Catia. Having looked at
the IBM web site for it I'm not sure why you would choose
Python to write automated processes for it? However there
is a web page here:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347243

That shows an example using Windows COM automation but in my
experience COM via Python is no easier than via VBScript or any
other scripting language. So if you know VB/VBscript etc stick with 
those.

There are several other web pages that sjhow up if you google
catia python

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Class error

2007-06-17 Thread Henry Dominik
Thanks a million Alan,

Your suggestion helped solve the problem.
Besides, why did I have to do this: class 
EmplAddrBookEntry(AddrBookEntry.AddrBookEntry):

The AddrBookEntry and EmplAddrBookEntry classes are in the same folder, I 
didn't think I needed to call another module or something..

Well, I need to learn more :)

Thanks anyway

--Dom
- Original Message - 
From: "Alan Gauld" <[EMAIL PROTECTED]>
To: 
Sent: Sunday, June 17, 2007 7:28 PM
Subject: Re: [Tutor] Class error


>
> "Henry Dominik" <[EMAIL PROTECTED]> wrote
>
>
>> import AddrBookEntry
>>
>> class EmplAddrBookEntry(AddrBookEntry):
>
> This says you are creating a new class that inherits
> from the *module* AddrBookEntry. Notice that the
> error message referred to the module not the class...
>
> You probably meant:
>
> class EmplAddrBookEntry(AddrBookEntry.AddrBookEntry):
>
>>def __init__(self, nm, ph, id, em):
>>AddrBookEntry.__init__(self, nm, ph)
>
> Which makes this line become
> AddrBookEntry.AddrBookEntry.__init__(self, nm, ph)
>
> HTH,
>
> -- 
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Class error

2007-06-17 Thread Andreas Kostyrka
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Well, Python is not Java :)

Unqualified names reference always only objects defined in the local
module by default.

If you want to use unqualified names, you could do something like that:

from AddrBookEntry import AddrBookEntry

or

import AddrBookEntry as abe
AddrBookEntry = abe.AddrBookEntry

Andreas

Henry Dominik wrote:
> Thanks a million Alan,
> 
> Your suggestion helped solve the problem.
> Besides, why did I have to do this: class 
> EmplAddrBookEntry(AddrBookEntry.AddrBookEntry):
> 
> The AddrBookEntry and EmplAddrBookEntry classes are in the same folder, I 
> didn't think I needed to call another module or something..
> 
> Well, I need to learn more :)
> 
> Thanks anyway
> 
> --Dom
> - Original Message - 
> From: "Alan Gauld" <[EMAIL PROTECTED]>
> To: 
> Sent: Sunday, June 17, 2007 7:28 PM
> Subject: Re: [Tutor] Class error
> 
> 
>> "Henry Dominik" <[EMAIL PROTECTED]> wrote
>>
>>
>>> import AddrBookEntry
>>>
>>> class EmplAddrBookEntry(AddrBookEntry):
>> This says you are creating a new class that inherits
>> from the *module* AddrBookEntry. Notice that the
>> error message referred to the module not the class...
>>
>> You probably meant:
>>
>> class EmplAddrBookEntry(AddrBookEntry.AddrBookEntry):
>>
>>>def __init__(self, nm, ph, id, em):
>>>AddrBookEntry.__init__(self, nm, ph)
>> Which makes this line become
>> AddrBookEntry.AddrBookEntry.__init__(self, nm, ph)
>>
>> HTH,
>>
>> -- 
>> Alan Gauld
>> Author of the Learn to Program web site
>> http://www.freenetpages.co.uk/hp/alan.gauld
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGdZEbHJdudm4KnO0RAnz9AJ409z7wGgQgQxC2T9u7JQJz8W2h6wCcCFQD
OqhkiSC897klBc1SMZ0rMTc=
=DPIk
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] newbie question

2007-06-17 Thread Kent Johnson
bellzii wrote:
> hey everyone , can any1 tell me what does the module optparse do ?

It helps parse command line arguments. See the docs at
http://docs.python.org/lib/module-optparse.html

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using zip

2007-06-17 Thread Kent Johnson
lucio arteaga wrote:
> 
> - Original Message - From: "Kent Johnson" <[EMAIL PROTECTED]>
> To: "lucio arteaga" <[EMAIL PROTECTED]>
> Cc: 
> Sent: Saturday, June 16, 2007 8:33 AM
> Subject: Re: [Tutor] using zip
> 
> 
>> lucio arteaga wrote:
>>> I am trying to learn using zip in combination of if statemeny. , If I 
>>> do not make mistakes the program runs well. Otherwise is very bad?
>>
>> I don't understand your question. Are you talking about the zip() 
>> function or the zipfile module? What are you trying to do with it? 
>> Perhaps if you showed us the code you are having trouble with that 
>> would help.
> 
> I am using it as a function

OK, what are you trying to do with it? What have you tried? What does 
the code look like?

We need a lot more information before we can give you any help.

Kent

PS Please use Reply All to reply to the list.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to use replace() from a list

2007-06-17 Thread Kent Johnson
Norman Khine wrote:
> 
> Hi I have this class:
> 
> def title_to_name(title):
> title = title.encode('ascii', 'replace')
> name = title.lower().replace('/', '_').replace('?',
> '_').replace('.', '')
> return '_'.join(name.split())
> 
> Is there a way to have just one replace and so that:
> 
> replace('/', '_').replace('?', '_').replace('.', '_')

You can use re.sub():
In [1]: title = 'www.example.com/foo?bar'
In [2]: import re
In [5]: re.sub(r'[/?.]', '_', title)
Out[5]: 'www_example_com_foo_bar'

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] newbie question

2007-06-17 Thread bellzii

hey everyone , can any1 tell me what does the module optparse do ?

thanks 4 ur time
-- 
View this message in context: 
http://www.nabble.com/newbie-question-tf3935888.html#a11162803
Sent from the Python - tutor mailing list archive at Nabble.com.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using zip

2007-06-17 Thread lucio arteaga
I have used a function  to input the data and then a module Tproblem has 
been solved .Thank you to all

From: "Kent Johnson" <[EMAIL PROTECTED]>
To: "lucio arteaga" <[EMAIL PROTECTED]>; "tutor-python" 
Sent: Sunday, June 17, 2007 3:41 PM
Subject: Re: [Tutor] using zip


> lucio arteaga wrote:
>>
>> - Original Message - From: "Kent Johnson" <[EMAIL PROTECTED]>
>> To: "lucio arteaga" <[EMAIL PROTECTED]>
>> Cc: 
>> Sent: Saturday, June 16, 2007 8:33 AM
>> Subject: Re: [Tutor] using zip
>>
>>
>>> lucio arteaga wrote:
 I am trying to learn using zip in combination of if statemeny. , If I 
 do not make mistakes the program runs well. Otherwise is very bad?
>>>
>>> I don't understand your question. Are you talking about the zip() 
>>> function or the zipfile module? What are you trying to do with it? 
>>> Perhaps if you showed us the code you are having trouble with that would 
>>> help.
>>
>> I am using it as a function
>
> OK, what are you trying to do with it? What have you tried? What does the 
> code look like?
>
> We need a lot more information before we can give you any help.
>
> Kent
>
> PS Please use Reply All to reply to the list. 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sockets

2007-06-17 Thread Linus Nordström
Hello
I'm trying to rewrite a chat-program i did in school this spring in
python, the school program was in java. All this to leran python.

Anyway. I m trying to send a message using udp to a server that
conntains the message 3 0 0 0, it has to be in network byte order and
unsigned. I have tried to send it like a string "3000" but get an
error message from the server saying that it did recive 4 bytes, but
that it was an unknown message

So what i am wondering is if there are anny special byte arrays, or
some thing i should use. or if there are anny other way than to send
the message than a string.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sockets

2007-06-17 Thread Andreas Kostyrka
Tip: consult the documentation of the struct module.

Andreas

-- Ursprüngl. Mitteil. --
Betreff:[Tutor] sockets
Von:"Linus Nordström" <[EMAIL PROTECTED]>
Datum:  17.06.2007 22:47

Hello
I'm trying to rewrite a chat-program i did in school this spring in
python, the school program was in java. All this to leran python.

Anyway. I m trying to send a message using udp to a server that
conntains the message 3 0 0 0, it has to be in network byte order and
unsigned. I have tried to send it like a string "3000" but get an
error message from the server saying that it did recive 4 bytes, but
that it was an unknown message

So what i am wondering is if there are anny special byte arrays, or
some thing i should use. or if there are anny other way than to send
the message than a string.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Class error

2007-06-17 Thread Alan Gauld
"Henry Dominik" <[EMAIL PROTECTED]> wrote

> Besides, why did I have to do this: class 
> EmplAddrBookEntry(AddrBookEntry.AddrBookEntry):
> 
> The AddrBookEntry and EmplAddrBookEntry classes 
> are in the same folder, 

Python doesn't care abpout the foldrs it only cares about 
the modules. They are in different modules therefore you 
need to import the other module. But importing the module 
just makes the module name available inside your module.
To make the contents of the module available you must 
reference the module. Modules are first class objects in 
Python they are not simply files (although they are 
implemented as simple files!)  You might think of the 
module as being like a class that you can't instantiate 
if you like.

Alternarively you can use the other form of import:

from Module import Name

In your cae that would be

from AddrBookEntry import AddrBookEntry

Now when you use AddrBookentry it refers to the named object  
inside the AddrBookEntry module.

HTH,

Alan G.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sockets

2007-06-17 Thread Linus Nordström
Oh, thank you, exactly what i was looking for :)

On 6/18/07, Andreas Kostyrka <[EMAIL PROTECTED]> wrote:
> Tip: consult the documentation of the struct module.
>
> Andreas
>
> -- Ursprüngl. Mitteil. --
> Betreff:[Tutor] sockets
> Von:"Linus Nordström" <[EMAIL PROTECTED]>
> Datum:  17.06.2007 22:47
>
> Hello
> I'm trying to rewrite a chat-program i did in school this spring in
> python, the school program was in java. All this to leran python.
>
> Anyway. I m trying to send a message using udp to a server that
> conntains the message 3 0 0 0, it has to be in network byte order and
> unsigned. I have tried to send it like a string "3000" but get an
> error message from the server saying that it did recive 4 bytes, but
> that it was an unknown message
>
> So what i am wondering is if there are anny special byte arrays, or
> some thing i should use. or if there are anny other way than to send
> the message than a string.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] newbie question

2007-06-17 Thread Alan Gauld

"bellzii" <[EMAIL PROTECTED]> wrote
> hey everyone , can any1 tell me what does the module optparse do ?


It parses options.
That is it takes a command string and works out what
the various bits mean, in particular the command line
options or "switches".

For example you can call python like this:

$ python -i foo.py

And the -i is an option that tells python not to exity the 
intrerpreter
after running foo.py.

optparse can be usd to validate and select options in your programs.

The documentation includes background info and an extensive
tutorial (this must be one of the best documented modules in
the library) , did you read through it before posting? If so what
did you not understand?

HTH,

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] wxPython GUI builders?

2007-06-17 Thread Colin J. Williams
Alan Gauld wrote:
> What's available and in what state of readiness?
> 
> I tried Boa Constructor but after half a dozen code tweaks 
> I was still running into compatibility errors with the latest 
> wxPython and gave up. 
> 
> I know that Glade is out there, but what state is it in?
> And PythonCard offers another approach but I haven't 
> looked at it for about 3 years.
> 
> Are there any others? And which ones do people 
> actually use? Commercial or Freeware.
> 
> Alan G.
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
Dabo is another but it's under continuing development.

Colin W.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor