[Tutor] Variable Swap

2007-01-29 Thread Steve Nelson
Hello,

I understand the use of xor to do a variable swap without a temporary variable:

>>> x=2
>>> y=3
>>> y=x^y
>>> x=x^y
>>> y=x^y
>>> x
3
>>> y
2


However, why do I see this?

>>> y=x^y
>>> y
1

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


Re: [Tutor] Variable Swap

2007-01-29 Thread Kent Johnson
Steve Nelson wrote:
> Hello,
> 
> I understand the use of xor to do a variable swap without a temporary 
> variable:
> 
 x=2
 y=3
 y=x^y
 x=x^y
 y=x^y
 x
> 3
 y
> 2
> 
> 
> However, why do I see this?
> 
 y=x^y
 y
> 1

Because 2 ^ 3 == 1, right? Are you sure you understand what xor does? It 
is a bitwise exclusive or:
http://en.wikipedia.org/wiki/Xor#Bitwise_operation

By the way in Python you can write
x, y = y, x
as a readable alternative.

Kent

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


[Tutor] Advanced tutorial on pygtk

2007-01-29 Thread Tino Dai

Hi there Everybody,

 I'm currently writing a program in pygtk, and I'm looking for a more
advanced tutorial in pygtk. I have read the one that is on the
pygtk.orgsite, and that has given a me a good basis from which to
start. Now, I am
looking to expand my range of knowledge. Also with that, I looking for good
programming practices in reference to GUIs. Could anybody recommend a site
tutorial that fits the bill?


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


Re: [Tutor] question about a list of lists

2007-01-29 Thread shawn bright

Thanks Kent,
  i am going with option A, the helper set, because i also need to count
the occurances and this seems to be the easiest solution.

thanks for your help.

shawn

On 1/28/07, Kent Johnson <[EMAIL PROTECTED]> wrote:


shawn bright wrote:
> lo there all.
>
> i have a list of lists that i want to build, only if an item is not in
> the list already.
>
> kinda like this
> new_list = []
> for item in lists: # item will look something like [var1, var2, var3]
> if item[0] in new_list ( only the first element of each list ) like
> new_list[0][0]
>
> basicly, i want to know if item[0]   is one of the items[0] in my
new_list
>
> whats a good pythonic way to do this? i mean, i have a couple of way to
> do this, but they are ugly.

One way to do this is to keep a helper set that contains the first
elements of each list. Something like
new_list = []
firsts = set()
for item in lists:
   if item[0] not in firsts:
 new_list.append(item)
 firsts.add(item[0]

If you don't care about the order of the result, and if two lists have
duplicate first items you are happy to use the first, then you could use
a dict mapping first item to list:

new_list = dict((item[0], item) for item in lists).values()

Kent


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


Re: [Tutor] question about a list of lists

2007-01-29 Thread Kent Johnson
shawn bright wrote:
> Thanks Kent,
>i am going with option A, the helper set, because i also need to 
> count the occurances and this seems to be the easiest solution.

If you need the number of unique items that is just the length of the 
final list. If you need the number of occurrences of each initial item 
then a dict mapping initial item to count (or maybe a list of lists) 
would be the way to go.

Kent

> 
> thanks for your help.
> 
> shawn
> 
> On 1/28/07, *Kent Johnson* <[EMAIL PROTECTED] > 
> wrote:
> 
> shawn bright wrote:
>  > lo there all.
>  >
>  > i have a list of lists that i want to build, only if an item is
> not in
>  > the list already.
>  >
>  > kinda like this
>  > new_list = []
>  > for item in lists: # item will look something like [var1, var2,
> var3]
>  > if item[0] in new_list ( only the first element of each list
> ) like
>  > new_list[0][0]
>  >
>  > basicly, i want to know if item[0]   is one of the items[0] in my
> new_list
>  >
>  > whats a good pythonic way to do this? i mean, i have a couple of
> way to
>  > do this, but they are ugly.
> 
> One way to do this is to keep a helper set that contains the first
> elements of each list. Something like
> new_list = []
> firsts = set()
> for item in lists:
>if item[0] not in firsts:
>  new_list.append(item)
>  firsts.add(item[0]
> 
> If you don't care about the order of the result, and if two lists have
> duplicate first items you are happy to use the first, then you could use
> a dict mapping first item to list:
> 
> new_list = dict((item[0], item) for item in lists).values()
> 
> Kent
> 
> 


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


[Tutor] learning curve

2007-01-29 Thread Daniel Klose
Hi all,

All I would like to do is take a file and count the number of times a
letter occurs in it.  It so happens that there letters are amino acids.
There are also some other checks in the script but these are not a
concern just yet.

What I would like to do is create a dictionary of arrays.
In perl (my current scripting language of choice) I would simply put:
 ${$dictionary{$key}}[$element] += 1
I have no idea how to create this kind of structure in python.

Also I have a while loop.  If this were perl, rather than using the i =
0 while(i < len(x)):
I would do : for (my $i = 0; $i < @array; $i++) {}.  I have found the
range function but I am not sure how to use it properly.
What I would like to do is create an index that allows me to access the
same element in two arrays (lists) of identical size.

I have pasted in my current code below, I would be very grateful if you
could help me trim up this code.
#!/usr/bin/python

import sys, os

structDir = '/home/danny/dataset/structure/'
seqDir   = '/home/danny/dataset/sequence/'

target = sys.argv[1]

seqFile = seqDir  + target
strFile = structDir   + target

seqDictionary = {}

if (os.path.isfile(seqFile) and os.path.isfile(strFile)):
   
structureHandle = open(strFile)
structureString = structureHandle.readline()
   
sequenceHandle  = open(seqFile)
sequenceString = sequenceHandle.readline()
   
strArray = list(structureString)
seqArray = list(sequenceString)

if len(strArray) == len(seqArray):
print "Length match\n"
   
i=0
while(i < len(strArray)):
if seqDictionary.has_key(seqArray[i]):
seqDictionary[seqArray[i]] += 1
else:
seqDictionary[seqArray[i]] = 1
   
i += 1
   
else:
print "Some data is missing!\n"
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] learning curve

2007-01-29 Thread Kent Johnson
Daniel Klose wrote:
> Hi all,
> 
> All I would like to do is take a file and count the number of times a
> letter occurs in it.  It so happens that there letters are amino acids.
> There are also some other checks in the script but these are not a
> concern just yet.
> 
> What I would like to do is create a dictionary of arrays.
> In perl (my current scripting language of choice) I would simply put:
>  ${$dictionary{$key}}[$element] += 1
> I have no idea how to create this kind of structure in python.

I don't speak perl much but it looks like you have a dict whose values 
are lists. Not quite the same as what you have below, which is a dict 
whose values are integers.
> 
> Also I have a while loop.  If this were perl, rather than using the i =
> 0 while(i < len(x)):
> I would do : for (my $i = 0; $i < @array; $i++) {}.  I have found the
> range function but I am not sure how to use it properly.

You could use
   for i in range(len(strArray)):
but this is not good usage; better to iterate over strArray directly.

> What I would like to do is create an index that allows me to access the
> same element in two arrays (lists) of identical size.

You can use the zip() function to process two lists in parallel:
for x, y in zip(xlist, ylist):
   # x is an element from xlist
   # y is the corresponding element from ylist
> 
> I have pasted in my current code below, I would be very grateful if you
> could help me trim up this code.
> #!/usr/bin/python
> 
> import sys, os
> 
> structDir = '/home/danny/dataset/structure/'
> seqDir   = '/home/danny/dataset/sequence/'
> 
> target = sys.argv[1]
> 
> seqFile = seqDir  + target
> strFile = structDir   + target

os.path.join() would be more idiomatic here though what you have works.
> 
> seqDictionary = {}
> 
> if (os.path.isfile(seqFile) and os.path.isfile(strFile)):
>
> structureHandle = open(strFile)
> structureString = structureHandle.readline()
>
> sequenceHandle  = open(seqFile)
> sequenceString = sequenceHandle.readline()
>
> strArray = list(structureString)
> seqArray = list(sequenceString)

You don't have to convert to lists; strings are already sequences.
> 
> if len(strArray) == len(seqArray):
> print "Length match\n"
>
> i=0
> while(i < len(strArray)):
> if seqDictionary.has_key(seqArray[i]):
> seqDictionary[seqArray[i]] += 1
> else:
> seqDictionary[seqArray[i]] = 1
>
> i += 1

The idiomatic way to iterate over sequenceString is just
   for c in sequenceString:

You don't seem to be using strArray except to get the length. Maybe this 
is where you need zip()? For example you could say
   for structChr, seqChr in zip(structureString, sequenceString):

An alternative to your conditional with has_key() is to use dict.get() 
with a default value:
   seqDictionary[c] = seqDictionary.get(c, 0) + 1

so the whole loop becomes just
   for c in sequenceString:
 seqDictionary[c] = seqDictionary.get(c, 0) + 1

In Python 2.5 you can use defaultdict to create a dict with a default 
value of 0:
from collections import defaultdict
seqDictionary = defaultdict(int)

then in the loop you can say
 seqDictionary[c] += 1

Kent

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


Re: [Tutor] Best IDE for Python

2007-01-29 Thread Gabriel Farrell
On Sat, Jan 27, 2007 at 02:58:38AM -0800, Dick Moores wrote:
> 
> 
> At 07:12 PM 1/24/2007, Shadab Sayani wrote:
> Hi,
> I am using vim editor to code my project in python.Is there a good
> IDE  where in I type the name of the class object and then dot then
> all the attributes of the object are displayed so on.
> Ulipad can do this.
> Dick Moores
> 
> UliPad <>:
> http://wiki.woodpecker.org.cn/moin/UliPad";>
> http://wiki.woodpecker.org.cn/moin/UliPad 
> 
> 

If you want to stick with VIM, you can get the functionality you're
looking for if it's 7.0+ and compiled with +python.  A web search for
"omnicomplete python vim" (no quotes) brings up some useful pages.

Gabe

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


Re: [Tutor] learning curve

2007-01-29 Thread Daniel Klose
Thanks Kent,

I now have:

target = sys.argv[1]

seqDictionary =  {} # python 2.5 import defaultdict from collections.
structureArray = [0, 0, 0]

#THIS TAKES THE PLACE OF THE STANDARD PERL $DIR,$file
#shorter to do the os.path.join once to a variable.
if (os.path.isfile(os.path.join(structDir, target)) and
os.path.isfile(os.path.join(seqDir, target))):
structureHandle = open(os.path.join(structDir, target))
structureString = structureHandle.readline()
   
sequenceHandle  = open(os.path.join(seqDir, target))
sequenceString = sequenceHandle.readline()

if len(structureString) == len(sequenceString):
   
for strChar, seqChar in zip(structureString, sequenceString):
#SET DEFAULT VALUE AS ZERO ELSE INCREMENT
seqDictionary[seqChar] = seqDictionary.get(seqChar, 0) + 1
if (strChar.count('-')):
structureArray[0] += 1
elif (strChar.count('H')):
structureArray[1] += 1
elif (strChar.count('E')):
structureArray[2] += 1
else:
print strChar, " is not valid"
break;
else:
print "Some data is missing!\n"

The reason I want to create a dictionary of lists is because for each of
the keys in the dictionary I wanted to keep tabs on the associated
structure.  For example:

dictionary[A] = [0,0,0]

list x element = A
list y element = '-'

then dictionary[A][0] = 1

print dictionary[A]
: [1, 0, 0]

I thought that a dictionary would be the best way (it is the same way as
I have done it in perl and java).  I am using google but having limited
success.

*Do you folks bottom post or top post?  The users of the perl list are
sensitive about this stuff!

I am only running python 2.4 and the system admin doesn't like me so I
won't ask him to upgrade it.

Kent Johnson wrote:
> Daniel Klose wrote:
>> Hi all,
>>
>> All I would like to do is take a file and count the number of times a
>> letter occurs in it.  It so happens that there letters are amino acids.
>> There are also some other checks in the script but these are not a
>> concern just yet.
>>
>> What I would like to do is create a dictionary of arrays.
>> In perl (my current scripting language of choice) I would simply put:
>>  ${$dictionary{$key}}[$element] += 1
>> I have no idea how to create this kind of structure in python.
>
> I don't speak perl much but it looks like you have a dict whose values
> are lists. Not quite the same as what you have below, which is a dict
> whose values are integers.
>>
>> Also I have a while loop.  If this were perl, rather than using the i =
>> 0 while(i < len(x)):
>> I would do : for (my $i = 0; $i < @array; $i++) {}.  I have found the
>> range function but I am not sure how to use it properly.
>
> You could use
>   for i in range(len(strArray)):
> but this is not good usage; better to iterate over strArray directly.
>
>> What I would like to do is create an index that allows me to access the
>> same element in two arrays (lists) of identical size.
>
> You can use the zip() function to process two lists in parallel:
> for x, y in zip(xlist, ylist):
>   # x is an element from xlist
>   # y is the corresponding element from ylist
>>
>> I have pasted in my current code below, I would be very grateful if you
>> could help me trim up this code.
>> #!/usr/bin/python
>>
>> import sys, os
>>
>> structDir = '/home/danny/dataset/structure/'
>> seqDir   = '/home/danny/dataset/sequence/'
>>
>> target = sys.argv[1]
>>
>> seqFile = seqDir  + target
>> strFile = structDir   + target
>
> os.path.join() would be more idiomatic here though what you have works.
>>
>> seqDictionary = {}
>>
>> if (os.path.isfile(seqFile) and os.path.isfile(strFile)):
>>structureHandle = open(strFile)
>> structureString = structureHandle.readline()
>>sequenceHandle  = open(seqFile)
>> sequenceString = sequenceHandle.readline()
>>strArray = list(structureString)
>> seqArray = list(sequenceString)
>
> You don't have to convert to lists; strings are already sequences.
>>
>> if len(strArray) == len(seqArray):
>> print "Length match\n"
>>i=0
>> while(i < len(strArray)):
>> if seqDictionary.has_key(seqArray[i]):
>> seqDictionary[seqArray[i]] += 1
>> else:
>> seqDictionary[seqArray[i]] = 1
>>i += 1
>
> The idiomatic way to iterate over sequenceString is just
>   for c in sequenceString:
>
> You don't seem to be using strArray except to get the length. Maybe
> this is where you need zip()? For example you could say
>   for structChr, seqChr in zip(structureString, sequenceString):
>
> An alternative to your conditional with has_key() is to use dict.get()
> with a default value:
>   seqDictionary[c] = seqDictionary.get(c, 0) + 1
>
> so the whole loop becomes just
>   for c in sequenceString:
> seqDictionary[c] = seqDictionary.get(c, 0) + 1
>
> In P

Re: [Tutor] learning curve

2007-01-29 Thread Kent Johnson
Daniel Klose wrote:
> Thanks Kent,
> 
> I now have:
> 
> target = sys.argv[1]
> 
> seqDictionary =  {} # python 2.5 import defaultdict from collections.
> structureArray = [0, 0, 0]
> 
> #THIS TAKES THE PLACE OF THE STANDARD PERL $DIR,$file
> #shorter to do the os.path.join once to a variable.
> if (os.path.isfile(os.path.join(structDir, target)) and
> os.path.isfile(os.path.join(seqDir, target))):
> structureHandle = open(os.path.join(structDir, target))
> structureString = structureHandle.readline()
>
> sequenceHandle  = open(os.path.join(seqDir, target))
> sequenceString = sequenceHandle.readline()
> 
> if len(structureString) == len(sequenceString):
>
> for strChar, seqChar in zip(structureString, sequenceString):
> #SET DEFAULT VALUE AS ZERO ELSE INCREMENT
> seqDictionary[seqChar] = seqDictionary.get(seqChar, 0) + 1
> if (strChar.count('-')):

Since strChar is a single character you can just do
   if strChar == '-':
etc.

> structureArray[0] += 1
> elif (strChar.count('H')):
> structureArray[1] += 1
> elif (strChar.count('E')):
> structureArray[2] += 1
> else:

You could put all of the above into a dict lookup, something like

offsets = { '-': 0, 'H': 1, 'E': 2 }# this can be defined outside the loop
offset = offsets.get(strChr)
if offset is None:
   print strChar, " is not valid"
else:
   structureArray[offset] += 1

Or you could just use another dict for structureArray and index it by 
strChar directly.

> print strChar, " is not valid"
> break;
> else:
> print "Some data is missing!\n"
> 
> The reason I want to create a dictionary of lists is because for each of
> the keys in the dictionary I wanted to keep tabs on the associated
> structure.  For example:
> 
> dictionary[A] = [0,0,0]
> 
> list x element = A
> list y element = '-'
> 
> then dictionary[A][0] = 1
> 
> print dictionary[A]
> : [1, 0, 0]
> 
> I thought that a dictionary would be the best way (it is the same way as
> I have done it in perl and java).  I am using google but having limited
> success.

You can easily make a dict whose values are lists or dicts. I'm not sure 
how the above pseudo-code fits in to your code but maybe you want 
something like this:

structureArray = structureDict.get(seqChar, [0, 0, 0])
# figure out offset as above
structureArray[offset] = 1 # or += 1 if you are keeping counts.

> *Do you folks bottom post or top post?  The users of the perl list are
> sensitive about this stuff!

We're pretty casual here on python-tutors but on comp.lang.python you 
will get scolded for top-posting and bottom-posting is more common here 
as well.
> 
> I am only running python 2.4 and the system admin doesn't like me so I
> won't ask him to upgrade it.

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


Re: [Tutor] converting tab-delimited text files to csv

2007-01-29 Thread Carroll, Barry
> -Original Message-
> Date: Fri, 26 Jan 2007 22:40:24 -0500
> From: Kent Johnson <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] converting tab-delimited text files to csv
> To: Luke Paireepinart <[EMAIL PROTECTED]>
> Cc: tutor@python.org
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=windows-1252; format=flowed
> 
> Luke Paireepinart wrote:
> > csv is comma-separated values, right?
> > you should be able to just do a string replace of tabs -> commas on
each
> > line in the new file...
> > or is the csv format more complicated than that?
> 
> Yes, it is more complicated than that because the data itself may
> contain commas.
> 
> Kent


Greetings:

It's useful to recall that the Python CSV module was written to handle
Microsoft's implementation of the format.  According to Wikipedia

(http://en.wikipedia.org/wiki/Comma-separated_values)

there is no formal specification. The article includes these two links:

http://tools.ietf.org/html/rfc4180
http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm

Here's another link that I've found useful:

http://object-craft.com.au/projects/csv/

HTH.

Regards,
 
Barry
[EMAIL PROTECTED]
541-302-1107

We who cut mere stones must always be envisioning cathedrals.

-Quarry worker's creed



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


[Tutor] site-packages and permissions to byte-compile

2007-01-29 Thread Tim Johnson
Hello:

I just installed python 2.5 on Linux/Slackware 10.0

I have placed three files in the root of site-packages
on my machine that is 
/usr/local/lib/python2.5/site-packages

python appears to be importing this files with no complaint, but
they are not being byte-compiled. 

Note: I see that MySQLdb files are being byte-compiled.
Their ownership is root:root and permissions are 644
I've set the same ownership and permissions for the other
files to same.

What do I need to do to insure that they are byte-compiled?

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


Re: [Tutor] site-packages and permissions to byte-compile

2007-01-29 Thread Dave Kuhlman
On Mon, Jan 29, 2007 at 01:35:22PM -0900, Tim Johnson wrote:
> Hello:
> 
> I just installed python 2.5 on Linux/Slackware 10.0
> 
> I have placed three files in the root of site-packages
> on my machine that is 
> /usr/local/lib/python2.5/site-packages
> 
> python appears to be importing this files with no complaint, but
> they are not being byte-compiled. 
> 
> Note: I see that MySQLdb files are being byte-compiled.
> Their ownership is root:root and permissions are 644
> I've set the same ownership and permissions for the other
> files to same.
> 
> What do I need to do to insure that they are byte-compiled?

They do not compile because you are importing these files as a user
that does not have permission to write in the directory containing
those modules.

Your Python distribution should have a Python script called
compileall.py.  You can run that as root to compile *all* the files
in a directory.

For individual files, there is a module named py_compile.py.  Here
is an example of its use on my machine:

$ python /usr/local/lib/python2.5/py_compile.py test_path.py

Again, you will need write privileges to the directory containing
the module to be compiled (in this case test_path.py).

See the modules py_compile and compileall in the Python standard
library.

You may notice that when you install Python packages (e.g. using
setup.py), compiling happens automatically for you.

Another alternative is to put those modules in a directory in which
you *do* have write access and then add that directory to your
PYTHONPATH.

Dave

-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] [OT?] PyCon

2007-01-29 Thread Rob Andrews
I hope it's not unforgivably off-topic to ask if anyone's planning on
attending PyCon in Feb.

My manager gave a thumbs-up for me to attend today.

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


Re: [Tutor] site-packages and permissions to byte-compile

2007-01-29 Thread Tim Johnson
On Monday 29 January 2007 03:17 pm, Dave Kuhlman wrote:
> On Mon, Jan 29, 2007 at 01:35:22PM -0900, Tim Johnson wrote:
> > Hello:
> >
> > I just installed python 2.5 on Linux/Slackware 10.0
> >
> > I have placed three files in the root of site-packages
> > on my machine that is
> > /usr/local/lib/python2.5/site-packages
> >
> > python appears to be importing this files with no complaint, but
> > they are not being byte-compiled.
> >
> > Note: I see that MySQLdb files are being byte-compiled.
> > Their ownership is root:root and permissions are 644
> > I've set the same ownership and permissions for the other
> > files to same.
> >
> > What do I need to do to insure that they are byte-compiled?
>
> They do not compile because you are importing these files as a user
> that does not have permission to write in the directory containing
> those modules.
>
> Your Python distribution should have a Python script called
> compileall.py.  You can run that as root to compile *all* the files
> in a directory.

Yes. That was the solution.
Thank you Dave.
tj

> For individual files, there is a module named py_compile.py.  Here
> is an example of its use on my machine:
>
> $ python /usr/local/lib/python2.5/py_compile.py test_path.py
>
> Again, you will need write privileges to the directory containing
> the module to be compiled (in this case test_path.py).
>
> See the modules py_compile and compileall in the Python standard
> library.
>
> You may notice that when you install Python packages (e.g. using
> setup.py), compiling happens automatically for you.
>
> Another alternative is to put those modules in a directory in which
> you *do* have write access and then add that directory to your
> PYTHONPATH.
>
> Dave
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python code to connect using PPPoE

2007-01-29 Thread Johan Geldenhuys
Thanks,

Unfortunately I am on a device that does not have this in the kernel and I
can't recompile the kernel to include PPPoE nor can I load other utils to do
tasks for me. 

So I must do it all in Python.
I found Scapy that seems to support PPPoE connections, but finding out how
that can be used, seems to be a trial and error process. The scapy mailing
list does seem to be so helpful than this one.

Any other suggestions would be appreciated.
Thanks

Johan 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Hugo
González Monteverde
Sent: 26 January 2007 12:25 AM
To: tutor@python.org
Subject: Re: [Tutor] Python code to connect using PPPoE

Hi Johan,

PPPoE is both in the Linux Kernel (for the low level work) and as some
executables and scripts.

It fou want to establish a connection from a Python script (E.G. ehn the
computer has no internet access and you need it) The best way would be to
call the appropriate utilities, and parse their output. This means calling
adsl-connect, ficonfig, and the like, maybe parsing the output from
ifconfig. Take a look at the module named subprocess to do that.

Reimplementing these utilities in Python is some work, but doable. 
Implementing PPPoE in Python, reading the device files and all that... 
well... it's almost nonsense. For this, you have to use the kernel.

Johan Geldenhuys wrote:
> Kent,
> I want to establish the connection with Python. I think in Linux you 
> can use a PPPoE package to make life easier, but I don't want to use 
> the Kernel to do that.
> 
> Johan
> 

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

-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.11/652 - Release Date: 2007/01/25
03:32 PM
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.12/655 - Release Date: 2007/01/28
01:12 PM
 

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


[Tutor] Diff between opening files in 'r' and 'r+' mode

2007-01-29 Thread vanam

i want to know the difference between 'r' mode and 'r+' mode
1.i = open('c:\python25\integer.txt','w')>for writiing
 i.write('hai')->written some content in text file
 i = open('c:\python25\integer.txt','r')>for reading
 print i.read()>for printing the contents in that text file
 i = open('c:\python25\integer.txt','w')-->for writing
 i.write('how')---?Rewrite the contents
 print i.read()
[MY QUESTION]:i want to read the text file contents cant it be done by
giving (print i.read())?
Before going to next question [I deleted all the contents in the text file]

2.i = open('c:\python25\integer.txt','r+')-For reading and writing
  i.write('hai')->written some content  to text file
  print i.read()->{؆('c:\python25\integer.txt','w')
  i write('')
  print i.read()how')
  i = open('c:\python25\integer.txt','r')
  print i.read()
  i = open('c:\python25\integer.txt','w')
  i.write()
  i = open('c:\python25\integer.txt','r')
 print i.read() } --->Thats what i saw on
interpreter(In curly braces) when  i ran the script
[MY QUESTION]:1.from where the above in curly braces is printed?and i have
written only 'hai' to the text file
 2.Should i recall again the opening of the file in
'r' mode to read the file?

--

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


[Tutor] Explanation of Pickle

2007-01-29 Thread vanam

can any one explain about pickle i read in the book but they have not
provided any example for that so please explain with a simple example

--

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