[Tutor] cross-compile python?

2008-03-23 Thread Trey Keown
Hey all,
  I've started trying to make homebrew programs for my wii the past couple
of days, and have found that programming it in c is quite hard. I was
wondering how I would go about compiling python for something like this.
The wii has a ppc processor, and runs homebrew in the native .elf format.

Thanks

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


Re: [Tutor] def_a

2008-03-23 Thread elis aeris
it works :D





On Sun, Mar 23, 2008 at 6:40 PM, Alan Gauld <[EMAIL PROTECTED]>
wrote:

>
> "elis aeris" <[EMAIL PROTECTED]> wrote
>
> > def_a =[
> > ["3.2.2.2.2.2.3.", "0.0.3.2.2.2.2.2.3.0.0.0.", "O"],
> > 
> > ["6.", "0.0.1.1.1.1.1.0.1.0.0.0.", "i"],
> > ["6.", "0.0.1.0.1.1.1.1.1.0.0.0.", "!"]
> >   ]
> >
> > def returnzero:
> >return def_a[2]
> >
> > what I am trying to do is to write a generic function like this
> >
> > def returnzero (def_a):
> >return def_a
> >
> > in other words, a generic function that is able to use any list
> > assigned to
> > it, so that i don't have to write 8 functions just to use 8
> > list,because
> > that would be dumb, right?
>
> Yes it would be dumb.
>
> Do you have any other questions?
> Have you tried the code? Did it work as expected?
>
> Alan G.
>
>
> ___
> 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] def_a

2008-03-23 Thread Alan Gauld

"elis aeris" <[EMAIL PROTECTED]> wrote

> def_a =[
> ["3.2.2.2.2.2.3.", "0.0.3.2.2.2.2.2.3.0.0.0.", "O"],
> 
> ["6.", "0.0.1.1.1.1.1.0.1.0.0.0.", "i"],
> ["6.", "0.0.1.0.1.1.1.1.1.0.0.0.", "!"]
>   ]
>
> def returnzero:
>return def_a[2]
>
> what I am trying to do is to write a generic function like this
>
> def returnzero (def_a):
>return def_a
>
> in other words, a generic function that is able to use any list 
> assigned to
> it, so that i don't have to write 8 functions just to use 8 
> list,because
> that would be dumb, right?

Yes it would be dumb.

Do you have any other questions?
Have you tried the code? Did it work as expected?

Alan G. 


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


[Tutor] def_a

2008-03-23 Thread elis aeris
def_a =[
 ["3.2.2.2.2.2.3.", "0.0.3.2.2.2.2.2.3.0.0.0.", "O"],
 ["8.1.1.4.", "0.0.2.2.2.2.3.1.1.1.0.0.", "h"],
 ["1.2.", "0.1.1.1.0.0.0.0.0.0.0.0.", ","],
 ["2.7.2.", "0.0.3.1.1.1.1.1.3.0.0.0.", "I"],
 ["5.1.1.4.1.1.4.", "0.0.3.3.3.3.5.0.0.0.0.0.", "m"],
 ["3.3.3.3.", "0.0.3.1.4.2.2.0.0.0.0.0.", "e"],
 ["1.3.3.4.", "0.0.3.2.3.1.2.0.0.0.0.0.", "a"],
 ["5.1.1.4.", "0.0.2.2.2.2.3.0.0.0.0.0.", "n"],
 ["2.", "0.0.1.1.0.0.0.0.0.0.0.0.", "."],
 ["7.1.1.1.1.", "0.0.5.1.1.1.1.1.1.0.0.0.", "L"],
 ["1.5.2.2.", "0.0.2.1.1.1.4.1.0.0.0.0.", "t"],
 ["3.", "0.0.0.0.0.0.0.1.1.1.0.0.", "'"],
 ["2.3.3.2.", "0.0.3.1.2.1.3.0.0.0.0.0.", "s"],
 ["3.3.3.6.", "2.1.3.2.2.2.3.0.0.0.0.0.", "g"],
 ["3.2.2.3.", "0.0.2.2.2.2.2.0.0.0.0.0.", "o"],
 ["8.2.2.3.", "0.0.3.2.2.2.3.1.1.1.0.0.", "b"],
 ["4.1.1.5.", "0.0.3.2.2.2.2.0.0.0.0.0.", "u"],
 ["6.", "0.0.1.1.1.1.1.0.1.0.0.0.", "i"],
 ["6.", "0.0.1.0.1.1.1.1.1.0.0.0.", "!"]
,

   ]

def returnzero:
return def_a[2]





this is a simple version of the function i use, and of course in the real
version [0] and [1] is used as well.

what I am trying to do is to write a generic function like this

def returnzero (def_a):
return def_a




in other words, a generic function that is able to use any list assigned to
it, so that i don't have to write 8 functions just to use 8 list,because
that would be dumb, right?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what is @classmethod and @staticmethod ??

2008-03-23 Thread Kent Johnson
Tony Cappellini wrote:
>>  I don't use classmethods so I can't discuss that. For staticmethods,
>>  suppose I have in foo.py
> 
> Where is the word "staticmethod" in the example below? Where is it used?
> This is what I was hoping to see.

It would be

class Foo(object):
   @staticmethod
   def doSomethingRelatedToFoo():
 # whatever

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


Re: [Tutor] I am reading the tutorial alright?

2008-03-23 Thread Alan Gauld

"elis aeris" <[EMAIL PROTECTED]> wrote

> looking back to my first post, it seems to be a little weak. Can you 
> suggest
> something that I could have said?

Your first post was downright confusing.
Your second post was better because it described what you wanted.
You did that by drawing comparison with C++ arrays.

In general describe the problem you are trying to solve
and show what you think the code might look like and
the output you would expect. or like to see.

And before posting try a search on google, always
including the work Python in the search string.

-- 
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] returning two values continued

2008-03-23 Thread Alan Gauld

"elis aeris" <[EMAIL PROTECTED]> wrote

> def returning ():
>a = 1
>b = 2
>return a, b
>
>
> ab = returning()
>
>
> does this work?
>
> if it does, is ab a tuple of 2 and [0] being a and [1] being b?

Try it in the >>> prompt, thats what its there for and will give you 
an instant answer:

>>> def returning():
...  a = 1
...  b = 2
...  return a,b
...
>>> ab = returning()
>>> print ab
(1, 2)
>>> print ab[0]
1
>>> print ab[1]
2
>>>

Does that answer your question?

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
Give a man a fish and feed him for a day
Teach him to fish and you feed him for life 


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


Re: [Tutor] I am reading the tutorial alright?

2008-03-23 Thread Alan Gauld

"elis aeris" <[EMAIL PROTECTED]> wrote

> in c++ i use array[n][n] to store things.
>
> how do i create an array like that?

Please read any tutorial they nearly all cover multi dimensional 
lists.
It is also easy to experiment at the >>> prompt. Just try the obvious
thing - create a list of lists. It works as you wouyld expect from 
C++.

People spend a lot of time writing tutorials so that beginners
don't need to ask questions like this. And so the tutors don't
need to spend a lot of their time answering the same things for
every beginner!

We are trying to be helpful but you need to help yourself too.
It is far quicker to spend some time on a tutorial than to
post questions here thenm wait for a reply that answers it.

Try building a list of lists. If you have problems come back and
show us what you did and what went wrong. Then we can offer
specific help.

-- 
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] from __future__ import division

2008-03-23 Thread Alan Gauld

"Steve Willoughby" <[EMAIL PROTECTED]> wrote


> normal division x/y works just as expected, with one caveat: 
> remember
> that if you divide two *integer* values, you will get an *integer*
> division operation yielding an *integer* result.  So:

It's worth pointing out that although beginners tend to find this
behaviour odd it is actually very useful for many types of
programming problem(*). That's why the future mechanism includes
a new operator to do the older style integer division

(*)Some examples include manipulating indices into lists,
selecting from limited ranges, dealing with cyclic lists etc.


-- 
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] returning two values continued

2008-03-23 Thread Marc Tompkins
On Sun, Mar 23, 2008 at 4:41 PM, elis aeris <[EMAIL PROTECTED]> wrote:

> def returning ():
> a = 1
> b = 2
> return a, b
>
>
> ab = returning()
>
>
> does this work?
>

I cut and pasted into an interactive Python session:

>>> def returning ():
... a = 1
... b = 2
... return a, b
...
>>>
>>> ab = returning()
>>> print ab
(1, 2)

if it does, is ab a tuple of 2 and [0] being a and [1] being b?
>

>>> print type(ab)

>>> print ab[0]
1
>>> print ab[1]
2

I don't know what environment you're using - I use Windows XP.
1 - Start/Run, 'cmd', OK gets me a command prompt.
2 - I type "python" and hit Enter - I have a Python interactive session.
3 - I highlight your code snippet, hit Ctrl-Ins to copy it, then right-click
in the Python session and select Paste.
Ten seconds down, and there's your answer.

Your question was reasonably well thought-out and phrased - you're halfway
there.  Go the other half - try it yourself as I did, and if there's still
something (like an error message) you don't understand, post the code AND
the result when you tried it.  It only takes an extra minute, and it gets
you a LOT more credit here.  Cut, Copy, and Paste are your friends.

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


Re: [Tutor] what is @classmethod and @staticmethod ??

2008-03-23 Thread Alan Gauld
"maser" <[EMAIL PROTECTED]> wrote 

> Thanks, Andreas. Why do we need to use classmethod/
> staticmethod and where do we need to use them ?

Although there are minor technical details where they differ 
static methods and class methods are nearly identical. The 
names come from two programming traditions with different 
names for the same thing. Smalltalk and Lisp etc use class 
method. Delphi, C++ and Javba use static method.

In terms of usage they are both the same and have two basic 
purposes:
1) As per my earlier response and example to do something 
to the entire class of objects, either select one instance using 
some kind of search mechanism - database queries are often 
coded in class methods, or a count of all instances (perhaps 
with filters which is similar to a database sel;ect) or it can 
be conversions of one  type/class to another. And this can 
in turn be a kind of factory method or pseudo constructor.

2) class methods can also be used to provide generic 
collections of functions, perhaps with some shared 
data/variables. Booch called these "Class Utilities" in his 
book. They could for example provide a pseudo object 
interface to legacy code or provide namespace protection 
for a commonly used data name.

The second form can usually be provided with functions 
in a module in Python but thats not the case in some 
other languages.

As a practical example of the former consider a client/server 
application where the client sends requests to the server 
specifying the class and instance and method of the target 
object. The interprocess message handler can delegate the 
message to a class method to look up the instance and 
in turn call the actual method of the returned instance. 
This is much lighter weight than using a full blown Object 
Request Broker but provides a simar level of decoupling
and ease of use in the client code. I've built several 
systems using this pattern and the RPC code hardly 
changes.

Another example is where you need to produce highly 
dynamic object systems with lots of introspection and
varying object structures. This is rarely needed in Python 
because the built in introspection is so good but in languages 
like C++ it may be the easiest way of creating new "classes"
(not objects) in real time (although in truth these "classes" are 
restricted to new data members and accessor methods)
One practical case using this was a hospital diagniosis 
system where doctors needed to be able to introduce 
new subclasses of disease/diagnosis and have these 
classes merge seamlessly with the base hard coded 
disease classes. Static methods were used to maintain 
dictionaries of dictionaries representing the sub classes 
and their features. These could then be passed to the 
instances as required and the instances performed a 
similar kind of attribute access to that used by Python.

Its probably worth saying that these kinds of uses are 
powerful when needed but they are not by any means 
needed in every program. Although once you use them 
you tend to find more uses for them than you previously 
expected! :-)

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] I am reading the tutorial alright?

2008-03-23 Thread Marc Tompkins
On Sun, Mar 23, 2008 at 4:24 PM, elis aeris <[EMAIL PROTECTED]> wrote:

> Now I want to talk about this: how should I have asked my Q to let
> everyone know what I was looking for?
>
> looking back to my first post, it seems to be a little weak. Can you
> suggest something that I could have said?
>

Offhand, how about "What's the Python equivalent of a multi-dimensional
array?"

Speaking only for myself, what bugs me about most of your questions so far
is that you don't seem to do any thinking before you hit Send.  For a few of
your questions, it would have taken you less time/effort to do a three-word
Google search than to ask the list; for this one, this list was probably the
right place - but thirty seconds of thought about what you really wanted to
ask would have made the difference.  If you don't know the technical terms(
e.g. "array" versus "list", "dictionary", "tuple"), I for one will not bite
your head off for it - as long as you make a good-faith effort to express
yourself.

Most of us who read and answer questions are going to spend at least a
couple of minutes, and some thought, on our reply.  If it seems that you
spent less than that on your question, it can be irritating.  Some of us can
be downright cranky, but nobody likes to feel disrespected.  Just take a
minute and think.

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


Re: [Tutor] what is @classmethod and @staticmethod ??

2008-03-23 Thread Tony Cappellini
>  I don't use classmethods so I can't discuss that. For staticmethods,
>  suppose I have in foo.py

Where is the word "staticmethod" in the example below? Where is it used?
This is what I was hoping to see.

>
>  class Foo(object):
># Lots of useful stuff
>
>
>  In client.py I have
>
>  from foo import Foo
>
>  # Do interesting things with Foo
>
>
>  Now perhaps I need a function
>  doSomethingRelatedToFoo()
>  that belongs in foo.py but doesn't have to be an instance method - it is
>  just a related function. I could make this a module function and change
>  client.py to read
>
>  from foo import Foo, doSomethingRelatedToFoo
>
>  doSomethingRelatedToFoo()
>
>
>  or I could make doSomethingRelatedToFoo a staticmethod, then I don't
>  have to change the import statement, I can access
>  doSomethingRelatedToFoo() through the already-imported Foo class:
>
>  Foo.doSomethingRelatedToFoo()
>
>  It's a pretty small difference but I like keeping the import simple and
>  not having to change it when I add doSomethingRelatedToFoo() to foo.py.
>
>  Kent
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] returning two values continued

2008-03-23 Thread elis aeris
def returning ():
a = 1
b = 2
return a, b


ab = returning()


does this work?

if it does, is ab a tuple of 2 and [0] being a and [1] being b?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what is @classmethod and @staticmethod ??

2008-03-23 Thread Kent Johnson
Tony Cappellini wrote:
> Kent
> 
> Would you show the examples which show where staticmethod &
> classmethod are used?

Some good discussion here:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/56ee49c203fd72e2/922f84d9d26662fc?hl=en&lnk=gst&;

I don't use classmethods so I can't discuss that. For staticmethods, 
suppose I have in foo.py

class Foo(object):
   # Lots of useful stuff


In client.py I have

from foo import Foo

# Do interesting things with Foo


Now perhaps I need a function
doSomethingRelatedToFoo()
that belongs in foo.py but doesn't have to be an instance method - it is 
just a related function. I could make this a module function and change 
client.py to read

from foo import Foo, doSomethingRelatedToFoo

doSomethingRelatedToFoo()


or I could make doSomethingRelatedToFoo a staticmethod, then I don't 
have to change the import statement, I can access 
doSomethingRelatedToFoo() through the already-imported Foo class:

Foo.doSomethingRelatedToFoo()

It's a pretty small difference but I like keeping the import simple and 
not having to change it when I add doSomethingRelatedToFoo() to foo.py.

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


Re: [Tutor] I am reading the tutorial alright?

2008-03-23 Thread elis aeris
thanks for the reply, btw.

On Sun, Mar 23, 2008 at 4:22 PM, Marc Tompkins <[EMAIL PROTECTED]>
wrote:

> On Sun, Mar 23, 2008 at 4:16 PM, elis aeris <[EMAIL PROTECTED]> wrote:
>
> > in c++ i use array[n][n] to store things.
> >
> > how do i create an array like that?
> >
>
> Python doesn't have "arrays".  It has tuples, lists, and dictionaries.  A
> quick Google will tell you the distinctions between them.
>
> It looks to me like you want to create a list of lists
>
>
> t =[ ["item1", "item2", "item3"], ["itemA", "itemB", "itemC"], ["itemI",
> "itemII", "itemIII"] ]
>
> t[0][0] == "item1"
> t[1][1] == "itemB"
> t[2][2] == "itemIII"
>
>
>
>
>
> >
> >
> >
> >
> >
> > On Sun, Mar 23, 2008 at 4:13 PM, bob gailer <[EMAIL PROTECTED]>
> > wrote:
> >
> > > elis aeris wrote:
> > > > t = 12345, 54321, "hello!"
> > > > print t[0]
> > > >
> > > > the way the 3 items are saved and access fits my need, now how do I
> > > > make t have more than one entry so effectively I get this?
> > > >
> > > > t[n][n]
> > > >
> > > (1) are you going through the tutorials as requested?
> > > (2) please learn how to ask meaningful questions
> > > For example t[n][n] does not communicate the outcome you desire.
> > > In Python t[n][n] would get you the nth element of the nth element of
> > > t.
> > > For example if n were 2 you'd get 3. If that is what you want you just
> > > answered your own question, as a simple test in the Python interactive
> > > window would reveal.
> > >
> > > Otherwise we can only guess as to what you want and that wastes all of
> > > our time!
> > >
> > > It would be far more effective to show us what the result would look
> > > like based on the data you entered into t.
> > >
> > > PLEASE do as much as you can to solve problems yourself and express
> > > questions CLEARLY!
> > >
> > > --
> > > Bob Gailer
> > > 919-636-4239 Chapel Hill, NC
> > >
> > >
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
>
> --
> www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am reading the tutorial alright?

2008-03-23 Thread elis aeris
t =[ ["item1", "item2", "item3"], ["itemA", "itemB", "itemC"], ["itemI",
"itemII", "itemIII"] ]

yes this is what I am looking for.

Now I want to talk about this: how should I have asked my Q to let everyone
know what I was looking for?


looking back to my first post, it seems to be a little weak. Can you suggest
something that I could have said?



On Sun, Mar 23, 2008 at 4:22 PM, Marc Tompkins <[EMAIL PROTECTED]>
wrote:

> On Sun, Mar 23, 2008 at 4:16 PM, elis aeris <[EMAIL PROTECTED]> wrote:
>
> > in c++ i use array[n][n] to store things.
> >
> > how do i create an array like that?
> >
>
> Python doesn't have "arrays".  It has tuples, lists, and dictionaries.  A
> quick Google will tell you the distinctions between them.
>
> It looks to me like you want to create a list of lists
>
>
> t =[ ["item1", "item2", "item3"], ["itemA", "itemB", "itemC"], ["itemI",
> "itemII", "itemIII"] ]
>
> t[0][0] == "item1"
> t[1][1] == "itemB"
> t[2][2] == "itemIII"
>
>
>
>
>
> >
> >
> >
> >
> >
> > On Sun, Mar 23, 2008 at 4:13 PM, bob gailer <[EMAIL PROTECTED]>
> > wrote:
> >
> > > elis aeris wrote:
> > > > t = 12345, 54321, "hello!"
> > > > print t[0]
> > > >
> > > > the way the 3 items are saved and access fits my need, now how do I
> > > > make t have more than one entry so effectively I get this?
> > > >
> > > > t[n][n]
> > > >
> > > (1) are you going through the tutorials as requested?
> > > (2) please learn how to ask meaningful questions
> > > For example t[n][n] does not communicate the outcome you desire.
> > > In Python t[n][n] would get you the nth element of the nth element of
> > > t.
> > > For example if n were 2 you'd get 3. If that is what you want you just
> > > answered your own question, as a simple test in the Python interactive
> > > window would reveal.
> > >
> > > Otherwise we can only guess as to what you want and that wastes all of
> > > our time!
> > >
> > > It would be far more effective to show us what the result would look
> > > like based on the data you entered into t.
> > >
> > > PLEASE do as much as you can to solve problems yourself and express
> > > questions CLEARLY!
> > >
> > > --
> > > Bob Gailer
> > > 919-636-4239 Chapel Hill, NC
> > >
> > >
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
>
> --
> www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am reading the tutorial alright?

2008-03-23 Thread Marc Tompkins
On Sun, Mar 23, 2008 at 4:16 PM, elis aeris <[EMAIL PROTECTED]> wrote:

> in c++ i use array[n][n] to store things.
>
> how do i create an array like that?
>

Python doesn't have "arrays".  It has tuples, lists, and dictionaries.  A
quick Google will tell you the distinctions between them.

It looks to me like you want to create a list of lists


t =[ ["item1", "item2", "item3"], ["itemA", "itemB", "itemC"], ["itemI",
"itemII", "itemIII"] ]

t[0][0] == "item1"
t[1][1] == "itemB"
t[2][2] == "itemIII"





>
>
>
>
>
> On Sun, Mar 23, 2008 at 4:13 PM, bob gailer <[EMAIL PROTECTED]> wrote:
>
> > elis aeris wrote:
> > > t = 12345, 54321, "hello!"
> > > print t[0]
> > >
> > > the way the 3 items are saved and access fits my need, now how do I
> > > make t have more than one entry so effectively I get this?
> > >
> > > t[n][n]
> > >
> > (1) are you going through the tutorials as requested?
> > (2) please learn how to ask meaningful questions
> > For example t[n][n] does not communicate the outcome you desire.
> > In Python t[n][n] would get you the nth element of the nth element of t.
> > For example if n were 2 you'd get 3. If that is what you want you just
> > answered your own question, as a simple test in the Python interactive
> > window would reveal.
> >
> > Otherwise we can only guess as to what you want and that wastes all of
> > our time!
> >
> > It would be far more effective to show us what the result would look
> > like based on the data you entered into t.
> >
> > PLEASE do as much as you can to solve problems yourself and express
> > questions CLEARLY!
> >
> > --
> > Bob Gailer
> > 919-636-4239 Chapel Hill, NC
> >
> >
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


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


Re: [Tutor] I am reading the tutorial alright?

2008-03-23 Thread elis aeris
in c++ i use array[n][n] to store things.

how do i create an array like that?





On Sun, Mar 23, 2008 at 4:13 PM, bob gailer <[EMAIL PROTECTED]> wrote:

> elis aeris wrote:
> > t = 12345, 54321, "hello!"
> > print t[0]
> >
> > the way the 3 items are saved and access fits my need, now how do I
> > make t have more than one entry so effectively I get this?
> >
> > t[n][n]
> >
> (1) are you going through the tutorials as requested?
> (2) please learn how to ask meaningful questions
> For example t[n][n] does not communicate the outcome you desire.
> In Python t[n][n] would get you the nth element of the nth element of t.
> For example if n were 2 you'd get 3. If that is what you want you just
> answered your own question, as a simple test in the Python interactive
> window would reveal.
>
> Otherwise we can only guess as to what you want and that wastes all of
> our time!
>
> It would be far more effective to show us what the result would look
> like based on the data you entered into t.
>
> PLEASE do as much as you can to solve problems yourself and express
> questions CLEARLY!
>
> --
> Bob Gailer
> 919-636-4239 Chapel Hill, NC
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am reading the tutorial alright?

2008-03-23 Thread bob gailer
elis aeris wrote:
> t = 12345, 54321, "hello!"
> print t[0]
>
> the way the 3 items are saved and access fits my need, now how do I 
> make t have more than one entry so effectively I get this?
>
> t[n][n]
>
(1) are you going through the tutorials as requested?
(2) please learn how to ask meaningful questions
For example t[n][n] does not communicate the outcome you desire.
In Python t[n][n] would get you the nth element of the nth element of t. 
For example if n were 2 you'd get 3. If that is what you want you just 
answered your own question, as a simple test in the Python interactive 
window would reveal.

Otherwise we can only guess as to what you want and that wastes all of 
our time!

It would be far more effective to show us what the result would look 
like based on the data you entered into t.

PLEASE do as much as you can to solve problems yourself and express 
questions CLEARLY!

-- 
Bob Gailer
919-636-4239 Chapel Hill, NC

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


Re: [Tutor] what is @classmethod and @staticmethod ??

2008-03-23 Thread Tony Cappellini
Kent

Would you show the examples which show where staticmethod &
classmethod are used?

I've often wondered about the usefulness of these myself. Having read
many of the popular books on python, none provide a good clear
explanation
of why or where these should be used, and what the alternatives are
(if any). They typically show an extremely terse example of the syntax
with little explanation.


Message: 7
Date: Sun, 23 Mar 2008 18:26:26 -0400
From: Kent Johnson <[EMAIL PROTECTED]>
Subject: Re: [Tutor] what is @classmethod and @staticmethod ??
To: maser <[EMAIL PROTECTED]>
Cc: tutor@python.org
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

maser wrote:
> Thanks, Andreas. Why do we need to use classmethod/
> staticmethod and where do we need to use them ?

I use staticmethods as a convenience to put related functions in the
namespace of a class. Perhaps foo.py contains class Foo with
staticmethod bar(). In client code I can say

from foo import Foo
Foo.bar()

If bar was a module method it would be

from foo import Foo, bar
bar()


I prefer the former in cases where bar is related to Foo.

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


[Tutor] I am reading the tutorial alright?

2008-03-23 Thread elis aeris
t = 12345, 54321, "hello!"
print t[0]

the way the 3 items are saved and access fits my need, now how do I make t
have more than one entry so effectively I get this?

t[n][n]

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


Re: [Tutor] Maybe advanced pexpect question?

2008-03-23 Thread mwalsh
Kent Johnson wrote:
> Nathan McBride wrote:
>> I've used pexpect for a few projects and love it.  Basically pexpect
>> lets you spawn a program and interact with it from code like you
>> yourself were running it in a console.  How would you send the ctrl key?
> 
> I don't use pexpect, so I am guessing...
> 
> The ctrl key by itself is not a character so you can't send that. ctrl-C 
> is a character that is represented in a string as \x03. I expect you 
> would send a control character with sendline(), for example to sent 
> ctrl-C try
>child.sendline ('\x03')

In recent versions of pexpect (I'm looking at 2.3), 'spawn' objects 
include a sendcontrol  method which does almost exactly that for cntl-c, 
with send instead of sendline.

> Kent
> ___
> 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] what is @classmethod and @staticmethod ??

2008-03-23 Thread Kent Johnson
maser wrote:
> Thanks, Andreas. Why do we need to use classmethod/
> staticmethod and where do we need to use them ?

I use staticmethods as a convenience to put related functions in the 
namespace of a class. Perhaps foo.py contains class Foo with 
staticmethod bar(). In client code I can say

from foo import Foo
Foo.bar()

If bar was a module method it would be

from foo import Foo, bar
bar()


I prefer the former in cases where bar is related to Foo.

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


[Tutor] Handling XMLHTTPRequests

2008-03-23 Thread Konstantinos Rousis
Dear all,

I am trying to build an extension for the Firefox that will automatically
authorize users through KeyNote system. My components are the following:

   1. Python implementation of KeyNote. Stand-alone, given some
   information makes the authorization decision.
   2. Firefox Extension: When some events are triggered, an
   XMLHTTPRequest (XHR) should be sent to the server.
   3. *(?)A python script that should handle the XHRs.*

1 and 2 are ready and my difficulties are in 3. I need some conceptual help
on the following:

   - Is it possible a Python script hosted on Apache, accept the XHRs
   made from Firefox extension's JavaScript?
   - Can data sent (e.g. XML files) along with the XHR be extracted from
   my python script and be redirected to the stand-alone Python KeyNote
   application, as well as getting the result back (i.e. authorization
   decision)?
   - Can I define the HTTP response that will be sent back to the
   browser/client?

The important thing is this script to be hosted on an Apache server and not
be a stand-alone server. Moreover I would like to avoid the use of CGI and
rather use the mod_python.

Any help would be really appreciated.

-- 
Regards,

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


Re: [Tutor] what is @classmethod and @staticmethod ??

2008-03-23 Thread Andreas Kostyrka
One usual usage for classmethods are "alternate" constructors.

Andreas


Am Sonntag, den 23.03.2008, 10:49 -0700 schrieb maser:
> Thanks, Andreas. Why do we need to use classmethod/
> staticmethod and where do we need to use them ?
> 
> thanks
> iyer
> 
> --- Andreas Kostyrka <[EMAIL PROTECTED]> wrote:
> 
> > Well, it's classmethod/staticmethod in truth, @ is
> > the decorator
> > operator:
> > 
> > def testdec(func):
> > return {"funcobj": func}
> > 
> > class Abc(object):
> > @testdec
> > def method():
> > pass
> > 
> > assert isinstance(Abc.method, dict)
> > 
> > Basically as you can see above, @X before a function
> > definition takes
> > the function, applies X, and use the result instead.
> > 
> > Now, naive Python level implementations of
> > classmethod and staticmethod
> > would be (untested, all typed in the mailer):
> > 
> > def classmethod(func):
> > def wrapper(self, *args, **kw):
> > return func(self.__class__, *args, **kw)
> > return wrapper
> > 
> > def staticmethod(func):
> > def wrapper(self, *args, **kw):
> > return func(*args, **kw)
> > return wrapper
> > 
> > Andreas
> > 
> > Am Freitag, den 21.03.2008, 20:08 -0700 schrieb
> > maser:
> > > Hi
> > > 
> > > I couldn't find a good resource explaining what
> > > @classmethod and @staticmethod are in python and
> > when,
> > > how these could be used.
> > > 
> > > If someone could explain what these are, or point
> > me
> > > to resources that may help, it is appreciated.
> > > 
> > > Thanks
> > > iyer
> > > 
> > > 
> > >  
> >
> 
> > > Be a better friend, newshound, and 
> > > know-it-all with Yahoo! Mobile.  Try it now. 
> >
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
> > > ___
> > > Tutor maillist  -  Tutor@python.org
> > > http://mail.python.org/mailman/listinfo/tutor
> > 
> 
> 
> 
>   
> 
> Be a better friend, newshound, and 
> know-it-all with Yahoo! Mobile.  Try it now.  
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ


signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Calling super classs __init__?

2008-03-23 Thread Andreas Kostyrka

Am Mittwoch, den 19.03.2008, 10:36 -0300 schrieb Ricardo Aráoz:
> Luciano Ramalho wrote:
> > Nowadays the best practice for invoking a method from all superclasses
> > (yes, multiple inheritance) is this:
> > 
> > class SubClass(BaseClass):
> > def __init__(self, t, *args, **kw):
> > super(SubClass, self).__init__(*args, **kw)
> > # do something with t
> > 
> > That way you let Python decide which superclasses your SubClass has,
> > instead of hard-coding it in several places.
> > 
> 
> You are actually hard-coding it here too, "class SubClass(BaseClass):" 
> has "BaseClass" hard-coded. All you do here is hard-code it once instead 
> of twice.

Yes and no. Yes a human has specified the relationships. But you do not
have to specify what other baseclasses your class has. This is relevant
for multiple inheritence, like:

D => B => A
D => C => A

The problem is mostly hiding implementation details.

Using super, you just let Python pick the "next" class to give control.
Using B.__init__ and C.__init__, A.__init__ would be called twice.

Andreas

> 
> > Cheers,
> > 
> > Luciano
> > 
> > 
> > On Tue, Mar 18, 2008 at 9:37 PM, John Fouhy <[EMAIL PROTECTED]> wrote:
> >> On 19/03/2008, Allen Fowler <[EMAIL PROTECTED]> wrote:
> >>  >  I have a super class that accepts many arguments to it's constructor, 
> >> and a subclass that should define one additional argument.
> >>  >
> >>  >  What's the most "pythonic" way to make this work?
> >>
> >>  class BaseClass(object):
> >>   def __init__(self, x, y, z, foo='foo'): # whatever
> >>  # etc
> >>
> >>  class SubClass(BaseClass):
> >>   def __init__(self, t, *args, **kw):
> >> BaseClass.__init__(self, *args, **kw)
> >> # do something with t
> >>
> >>  This does mean that the special sub class argument has to come before
> >>  the base class arguments when you create instances.
> >>
> >>  Whether you call BaseClass.__init__ early or late in the subclass init
> >>  method could depend on what your classes are doing.  Remember, in
> >>  Python, __init__ only initializes objects, it doesn't create them.
> >>  It's just another bit of code that you can call whenever you want.
> >>
> >>  --
> >>  John.
> >>
> >>
> >> ___
> >>  Tutor maillist  -  Tutor@python.org
> >>  http://mail.python.org/mailman/listinfo/tutor
> >>
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> > 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] from __future__ import division

2008-03-23 Thread Steve Willoughby
Dinesh B Vadhia wrote:
> I spent fruitless hours trying to get a (normal) division x/y to work and 
> then saw that you have to declare:

normal division x/y works just as expected, with one caveat: remember
that if you divide two *integer* values, you will get an *integer*
division operation yielding an *integer* result.  So:

1.0 / 2.0 --> 0.5
1.0 / 2   --> 0.5
1 / 2.0   --> 0.5
1 / 2 --> 0

So if you make sure at least one operand is a real number you'll get
a real result.  This is now division works in many programming languages
including C and C++.

In the future, Python will switch to always yielding a real result,
and to force an integer division operation you use the special "//"
integer division operator.  If you want that behavior now, just
import that "from the future":

from __future__ import division

now:

1 / 2 --> 0.5
4 / 2 --> 2.0
1 // 2 --> 0
4 // 2 --> 2

HTH HAND

>> from __future__ import division
> 
> .. at the top of a module file.  What is this all about?
> 
> Dinesh
> 
> 
> 
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


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


[Tutor] from __future__ import division

2008-03-23 Thread Dinesh B Vadhia
I spent fruitless hours trying to get a (normal) division x/y to work and then 
saw that you have to declare:

> from __future__ import division

.. at the top of a module file.  What is this all about?

Dinesh

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


Re: [Tutor] what is @classmethod and @staticmethod ??

2008-03-23 Thread maser
Thanks, Andreas. Why do we need to use classmethod/
staticmethod and where do we need to use them ?

thanks
iyer

--- Andreas Kostyrka <[EMAIL PROTECTED]> wrote:

> Well, it's classmethod/staticmethod in truth, @ is
> the decorator
> operator:
> 
> def testdec(func):
> return {"funcobj": func}
> 
> class Abc(object):
> @testdec
> def method():
> pass
> 
> assert isinstance(Abc.method, dict)
> 
> Basically as you can see above, @X before a function
> definition takes
> the function, applies X, and use the result instead.
> 
> Now, naive Python level implementations of
> classmethod and staticmethod
> would be (untested, all typed in the mailer):
> 
> def classmethod(func):
> def wrapper(self, *args, **kw):
> return func(self.__class__, *args, **kw)
> return wrapper
> 
> def staticmethod(func):
> def wrapper(self, *args, **kw):
> return func(*args, **kw)
> return wrapper
> 
> Andreas
> 
> Am Freitag, den 21.03.2008, 20:08 -0700 schrieb
> maser:
> > Hi
> > 
> > I couldn't find a good resource explaining what
> > @classmethod and @staticmethod are in python and
> when,
> > how these could be used.
> > 
> > If someone could explain what these are, or point
> me
> > to resources that may help, it is appreciated.
> > 
> > Thanks
> > iyer
> > 
> > 
> >  
>

> > Be a better friend, newshound, and 
> > know-it-all with Yahoo! Mobile.  Try it now. 
>
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> 



  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Calling super classs __init__?

2008-03-23 Thread Ricardo Aráoz
Luciano Ramalho wrote:
> Nowadays the best practice for invoking a method from all superclasses
> (yes, multiple inheritance) is this:
> 
> class SubClass(BaseClass):
> def __init__(self, t, *args, **kw):
> super(SubClass, self).__init__(*args, **kw)
> # do something with t
> 
> That way you let Python decide which superclasses your SubClass has,
> instead of hard-coding it in several places.
> 

You are actually hard-coding it here too, "class SubClass(BaseClass):" 
has "BaseClass" hard-coded. All you do here is hard-code it once instead 
of twice.

> Cheers,
> 
> Luciano
> 
> 
> On Tue, Mar 18, 2008 at 9:37 PM, John Fouhy <[EMAIL PROTECTED]> wrote:
>> On 19/03/2008, Allen Fowler <[EMAIL PROTECTED]> wrote:
>>  >  I have a super class that accepts many arguments to it's constructor, 
>> and a subclass that should define one additional argument.
>>  >
>>  >  What's the most "pythonic" way to make this work?
>>
>>  class BaseClass(object):
>>   def __init__(self, x, y, z, foo='foo'): # whatever
>>  # etc
>>
>>  class SubClass(BaseClass):
>>   def __init__(self, t, *args, **kw):
>> BaseClass.__init__(self, *args, **kw)
>> # do something with t
>>
>>  This does mean that the special sub class argument has to come before
>>  the base class arguments when you create instances.
>>
>>  Whether you call BaseClass.__init__ early or late in the subclass init
>>  method could depend on what your classes are doing.  Remember, in
>>  Python, __init__ only initializes objects, it doesn't create them.
>>  It's just another bit of code that you can call whenever you want.
>>
>>  --
>>  John.
>>
>>
>> ___
>>  Tutor maillist  -  Tutor@python.org
>>  http://mail.python.org/mailman/listinfo/tutor
>>
> ___
> 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] unsubscription

2008-03-23 Thread Alan Gauld

"Meftah Tayeb" <[EMAIL PROTECTED]> wrote 

> please ho to Unsubscrib from this mailing list ?

Go to the mailing list page on python.org and unsubscribe 
there.

http://mail.python.org/mailman/listinfo/tutor

HTH

Alan g

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


Re: [Tutor] suggestion on improving script

2008-03-23 Thread bob gailer
Norman Khine wrote:
> Hello,
>
> Please excuse me in advance if this post is long winded. I have the 
> following nagging issue for which I have found a work around, but wanted 
> a better solution.
>   

The reason
http://uk.expert.travel/companies/abakuc/;view?batchstart=5
fails while
http://uk.expert.travel/;view?t2=5
succeeds does not have to do with using a global method.

t2=5 tells the CGI program which tab was clicked, whereas batchstart=5 
does not.
You only need one "t" function as long as you use the t2=5 approach (or 
some other way to
communicate WHICH tab and WHERE to start (e.g. ?tab=2,batchstart=5.

Also - 99% of list_news, list_jobs, et. al. can be factored out into 
common code.

Does this make sense? Would you like more help or can you start figuring 
it out yourself?
> I am using jQuery to populate tabs with some data, such as news and jobs 
> posts, as can be seen at http://uk.expert.travel
>
> In my application, I have the following structure (only partially listed):
>
> $ tree -L 2
> .
> |-- expert_travel.py
> |-- ui
> |   `-- ui.tabs.js
> ...
> `-- utils.py
>
>
>
> #expert_travel.py
>
> from utils import t1, t2, t3, t4
>
> ...
>
>  
>  # News - List
>  
>
>  def list_news(self, context):
>  namespace = {}
>  namespace['batch'] = ''
>  #Search the catalogue, list all news items in company
>
> ...
>
> # Set batch informations
>
> [t1]batch_start = int(context.get_form_value('t1', default=0))
>
>  batch_size = 5
>  batch_total = len(news_items)
>  batch_fin = batch_start + batch_size
>  if batch_fin > batch_total:
>  batch_fin = batch_total
>  news_items = news_items[batch_start:batch_fin]
>  # Namespace
>  if news_items:
>  msgs = (u'There is one news item.',
>  u'There are ${n} news items.')
>
> [t1]news_batch = t1(context.uri, batch_start, batch_size,
>batch_total, msgs=msgs)
>
>  msg = None
>  else:
>  news_batch = None
>  msg = u'Currently there is no news.'
>
>
>  
>  # List jobs
>  list_jobs__label__ = u'List jobs'
>  list_jobs__access__ = True
>  def list_jobs(self, context):
> ...
>
>  # Set batch informations
>
> [t2]batch_start = int(context.get_form_value('t2', default=0))
>
>  batch_size = 5
>  batch_total = len(jobs)
>  batch_fin = batch_start + batch_size
>  if batch_fin > batch_total:
>  batch_fin = batch_total
>  jobs = jobs[batch_start:batch_fin]
>  # Namespace
>  if jobs:
>  msgs = (u'There is one job.',
>  u'There are ${n} jobs.')
>
> [t2]job_batch = t2(context.uri, batch_start, batch_size,
>batch_total, msgs=msgs)
>
>  msg = None
>  else:
>  job_table = None
>  job_batch = None
>  msg = u'Sorry but there are no jobs'
> ...
>
>
>
> 
>
> #utils.py
>
> def t1(uri, start, size, total, gettext=Handler.gettext,
>msgs=(u"There is 1 object.", u"There are ${n} objects.")):
>
>  # Plural forms
>  if total == 1:
>  msg1 = gettext(msgs[0])
>  else:
>  msg1 = gettext(msgs[1])
>  msg1 = Template(msg1).substitute(n=total)
>  msg1 = msg1.encode('utf-8')
>
>  # Calculate end
>  end = min(start + size, total)
>
>  # Previous
>  previous = None
>  if start > 0:
>  previous = max(start - size, 0)
>  previous = str(previous)
>
> [t1]previous = uri.replace(t1=previous)
>
>  previous = str(previous)
>  previous = XMLAttribute.encode(previous)
>  previous = '<<' \
> % (previous, gettext(u'Previous'))
>  # Next
>  next = None
>  if end < total:
>  next = str(end)
>
> [t1]next = uri.replace(t1=next)
>
>  next = str(next)
>  next = XMLAttribute.encode(next)
>  next = '>>' \
> % (next, gettext(u'Next'))
>
>  # Output
>  if previous is None and next is None:
>  msg = msg1
>  else:
>  # View more
>  if previous is None:
>  link = next
>  elif next is None:
>  link = previous
>  else:
>  link = '%s %s' % (previous, next)
>
>  msg2 = gettext(u"View from ${start} to ${end} (${link}):")
>  msg2 = Template(msg2)
>  msg2 = msg2.substitute(start=(start+1), end=end, link=link)
>  msg2 = msg2.encode('utf-8')
>
>  msg = '%s %s' % (msg1, msg2)
>
>  # Wrap around a paragraph
>  return Parser('%s' % msg

Re: [Tutor] Maybe advanced pexpect question?

2008-03-23 Thread Chris Fuller

What about Alt keys?  I was thinking terminal control voodoo.  But I don't 
know any.  man 5 termcap might be a start, though.

Cheers

On Sunday 23 March 2008 06:58, Kent Johnson wrote:
> Nathan McBride wrote:
> > I've used pexpect for a few projects and love it.  Basically pexpect
> > lets you spawn a program and interact with it from code like you
> > yourself were running it in a console.  How would you send the ctrl key?
>
> I don't use pexpect, so I am guessing...
>
> The ctrl key by itself is not a character so you can't send that. ctrl-C
> is a character that is represented in a string as \x03. I expect you
> would send a control character with sendline(), for example to sent
> ctrl-C try
>child.sendline ('\x03')
>
> Kent
> ___
> 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] Maybe advanced pexpect question?

2008-03-23 Thread Chris Fuller
What about Alt keys?  I was thinking terminal control voodoo.  But I don't 
know any.  man 5 termcap might be a start, though.

Cheers

On Sunday 23 March 2008 06:58, Kent Johnson wrote:
> Nathan McBride wrote:
> > I've used pexpect for a few projects and love it.  Basically pexpect
> > lets you spawn a program and interact with it from code like you
> > yourself were running it in a console.  How would you send the ctrl key?
>
> I don't use pexpect, so I am guessing...
>
> The ctrl key by itself is not a character so you can't send that. ctrl-C
> is a character that is represented in a string as \x03. I expect you
> would send a control character with sendline(), for example to sent
> ctrl-C try
>child.sendline ('\x03')
>
> Kent
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] unsubscription

2008-03-23 Thread Meftah Tayeb
hi, 
please ho to Unsubscrib from this mailing list ?

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


Re: [Tutor] Python Grammer

2008-03-23 Thread Kent Johnson
Eric Walker wrote:
> Ok, I found the responses, sorry.. 
> I have been reading the book "Text Processing in PYTHON" by David Mertz.
> I have some text that I have to parse. I want to use grammers.

It's grammAr. A grammar is a formal description of the structure of a 
language. It is not a parser; rather it is a specification of what the 
parser needs to do.

Perhaps if you describe your actual problem and say why you want to use 
a grammar we can be of more help, either pointing you to a parsing 
solution or helping to solve the problem without a formal parser. (Most 
Python text processing problems can be solved with simple string 
processing or regular expressions.)

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


Re: [Tutor] Maybe advanced pexpect question?

2008-03-23 Thread Kent Johnson
Nathan McBride wrote:
> I've used pexpect for a few projects and love it.  Basically pexpect
> lets you spawn a program and interact with it from code like you
> yourself were running it in a console.  How would you send the ctrl key?

I don't use pexpect, so I am guessing...

The ctrl key by itself is not a character so you can't send that. ctrl-C 
is a character that is represented in a string as \x03. I expect you 
would send a control character with sendline(), for example to sent 
ctrl-C try
   child.sendline ('\x03')

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


Re: [Tutor] More Converter

2008-03-23 Thread Alan Gauld

"bob gailer" <[EMAIL PROTECTED]> wrote> Adding key testing:
> 
> if (original, to) in factors:
>  factor = factors[(original, to)]
>  print variable * factor
> elif (to, original):

probably meant to be

elif (to,original) in factors:

>  factor = factors[(to, original)]
>  print variable / factor
> else:
>  print "no conversion available for %s to %s" % (original, to)

Alan G

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


Re: [Tutor] windows: pop up window

2008-03-23 Thread Luke Paireepinart
On Sat, Mar 22, 2008 at 5:17 PM, elis aeris <[EMAIL PROTECTED]> wrote:

> sweet,  I love built in functions. thanks !


Seriously, Elis. You would have learned raw_input in *any* Python tutorial.
You need to read some tutorials.
Seriously.
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor