Re: [Tutor] how to remove the coming duplication

2011-11-10 Thread Asokan Pichai
I was so miffed at not reading the OP's
mail carefully that I wrote a one liner.

Ok. Here it goes:

def no_adjacent_dup(lst):
   return [ x for x, y in zip(lst, lst[1:]) if x != y] + [lst[-1]]

:-) Enjoyed working that one out; but whether it is a good solution 

Asokan Pichai
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to remove the coming duplication

2011-11-10 Thread lina


Thanks for all, I found the problems I faced is more tricky than the
simple list I gave.

Here the list is: a row of numbers, not one number,

such as print a_list[1] is:

1
1
9
7
7
9
9
9

print(a_list) is:

617
617
790
571
571
790
790
790

I attached the codes written based on the suggestions all you have
given, and also attached the to-be-handled file in the following link:

#!/usr/bin/python3

import os.path

INFILEEXT=".out"
OUTFILEEXT=".bri"

atoms=[]

def fetchonefiledata(infilename):
for line in open(infilename,"r"):
parts=line.strip().split()
atoms=parts[2]
print(atoms[0])

def remove_coming_duplications(a_list):
for idx, element in enumerate(a_list):
if element != a_list[idx-1]:
print(element)

if __name__=="__main__":
for filename in os.listdir("."):
base, ext = os.path.splitext(filename)
if ext == INFILEEXT:
fetchonefiledata(filename)
remove_coming_duplications(atoms)

https://docs.google.com/open?id=0B93SVRfpVVg3MjVlODdiOWYtY2FlYy00NDIzLThjMzAtMDk0NTQ4ZTRjZjRh

Thanks with best regards,

P.S My primary interest is getting the lists from different files,
hopefully in the end find some rules between those numbers. or
pathway, such as
1 2 4 8 7 6
4 8 7 6 5 1
so it shares a feature of 4 -> 8 -> 7 -> 6.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to remove the coming duplication

2011-11-10 Thread Peter Otten
Christian Witts wrote:

> def remove_coming_duplication(a_list):
>  return [element for idx, element in enumerate(a_list) if element !=
> a_list[idx-1]]

Beware of negative indices:

>>> remove_coming_duplication([1, 2, 1])
[2, 1] # should be [1, 2, 1]


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to remove the coming duplication

2011-11-10 Thread Asokan Pichai
On Thu, Nov 10, 2011 at 2:07 PM, Peter Otten <__pete...@web.de> wrote:

> Christian Witts wrote:
>
> > def remove_coming_duplication(a_list):
> >  return [element for idx, element in enumerate(a_list) if element !=
> > a_list[idx-1]]
>
> Beware of negative indices:
>
> >>> remove_coming_duplication([1, 2, 1])
> [2, 1] # should be [1, 2, 1]
>
>
I ran into that and hence I chose to zip, compare and add the last element

Asokan Pichai
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to remove the coming duplication

2011-11-10 Thread Peter Otten
Asokan Pichai wrote:

> On Thu, Nov 10, 2011 at 2:07 PM, Peter Otten <__pete...@web.de> wrote:
> 
>> Christian Witts wrote:
>>
>> > def remove_coming_duplication(a_list):
>> >  return [element for idx, element in enumerate(a_list) if element
>> >  !=
>> > a_list[idx-1]]
>>
>> Beware of negative indices:
>>
>> >>> remove_coming_duplication([1, 2, 1])
>> [2, 1] # should be [1, 2, 1]
>>
>>
> I ran into that and hence I chose to zip, compare and add the last element

I have one for you, too ;)

>>> def no_adjacent_dup(lst):
...return [ x for x, y in zip(lst, lst[1:]) if x != y] + [lst[-1]]
...
>>> no_adjacent_dup([])
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in no_adjacent_dup
IndexError: list index out of range

And a subtle one as a bonus:

>>> no_adjacent_dup([1, 1.0])
[1.0] # should be 1

Here's a highlevel approach, probably not very efficient:

>>> from itertools import groupby
>>> [k for k, g in groupby([1, 1.0, 2, 1, 3, 3, 3])]
[1, 2, 1, 3]


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] The python implementation of the "class relationship".

2011-11-10 Thread Jerry Zhang
As you know, there are several kinds of relationships between classes in
the UML -- dependency, association, aggregation, composition.
Q1. Is there any article or code example on its implementation in python?
Q2. More specific, in composition model, the container object may be
responsible for the handling of embedded objects' lifecycle. The common way
would be adding __del__ to the container class or something else?

Thanks!
Biao
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Another question about graphics.

2011-11-10 Thread Timo

Op 10-11-11 06:03, Nathaniel Trujillo schreef:
I am using python version 2.7.2. I put the version of livewires for 
python 2.x in the right folder this time and after running the 
following program I got a different error message. Here they are.

program
# New Graphics Window
# Demonstrates creating a graphics window
from livewires import games
games.init(screen_width = 640, screen_height = 480, fps = 50)
games.screen.mainloop()
error message
Traceback (most recent call last):
  File "C:/Python27/new_graphics_window.py", line 6, in 
games.init(screen_width = 640, screen_height = 480, fps = 50)
AttributeError: 'module' object has no attribute 'init'
Well, the error says it all. The games module has no init method. You 
should probably see the livewires documentation or mailing list for such 
questions. The chance for getting your third-party module questions 
answered is pretty small here.


Cheers,
Timo


Thanks for the help.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] lb4cwpci h5woidb

2011-11-10 Thread Mario Cavett
2sovs4c, 83a6uf6jpq.
 http://2ufgrfdi6r.blog.com/w64/ 
52fdsyt04v hwfqg zzxy9lf1dx, d3xxy67x4 acih3ta8. 7hnkugc99tv waacqm1ao.
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] [OSX] "Executable" .py or pyc script (stuck at Applescript)

2011-11-10 Thread learner404
Hello list!

- myapp.py is in a "myfolder" folder that the "users" will be able to
download and put anywhere on their Mac.

- users don't have any Python knowledge and I have no idea if there's a
python launcher on their mac

=> trying to make an applescript file in the folder right next to myapp.py

I tried and failed at :

*tell* *application* "Terminal"

*do script* "python myapp.py"# tried also with ./myapp.py

*end* *tell*

or

do shell script "python myapp.py" # tried also with ./myapp.py


In both cases OSX complains it can't find the file. It works though if I
give the full path but I can't do that since I have no idea where the
folder will be on their macs.

With Applescript how would write it  so that Python starts in the
application folder? (myapp.py & "myfolder")

Any other way to do it maybe knowing my constraints above? (I tried py2app
but it failed on wxpython on my Lion with Apple Python that I need to use)

Thanks!

francois
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to remove the coming duplication

2011-11-10 Thread Andreas Perstinger

On 2011-11-10 09:26, lina wrote:

atoms=[]

def fetchonefiledata(infilename):
 for line in open(infilename,"r"):
 parts=line.strip().split()
 atoms=parts[2]
 print(atoms[0])


First you define "atoms" as an empty list, but in the line

atoms = parts[2]

you are redefining it by assigning a string to it. Thus, at the end of 
the for-loop, only the last string is stored (in every iteration you 
overwrite the former value with a new one).


You probably want to append the values:

atoms.append(parts[2])

Bye, Andreas
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to remove the coming duplication

2011-11-10 Thread Steven D'Aprano

lina wrote:

Hi,

How to remove the coming duplication,

Here I wrote one (not working):



a=['2', '5', '7', '5', '5']

[...]

I wish to get a is [2,5,7,5]

just remove the coming duplication, not unique the list.


a = [2, 5, 7, 5, 5]
b = a[0:1]  # slice of the first item only
for x in a[1:]:  # slice of the second item to the end
if x != b[-1]:
b.append(x)


gives b = [2, 5, 7, 5] as requested.



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [OSX] "Executable" .py or pyc script (stuck at Applescript)

2011-11-10 Thread Steven D'Aprano

learner404 wrote:

Hello list!

- myapp.py is in a "myfolder" folder that the "users" will be able to
download and put anywhere on their Mac.

[...]
In both cases OSX complains it can't find the file. 


Do you mean that AppleScript can't find the file, or that Python can't 
find the file?


Please don't summarize or paraphrase errors. Please copy and paste the 
EXACT error message that is shown.


If this is a problem with AppleScript being unable to find the file, you 
will be better off asking on an AppleScript mailing list.


In general, on Unix-like systems (and that includes Mac OS X), you can't 
expect a command like:


python myapp.py

to work unless myapp.py is in the current directory.



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] some ideas about some network

2011-11-10 Thread lina
Hi,

Thanks all again for your help in previous post.

Here I meet something I am not experienced, about:

from 10 groups of data  (namely from 1-84) find some pathway, or network.

such as
Group 1 (file 1): 1 3 8 5 7 4
Group 2 (file 2): 2 8 5 7 4 3 4 8 5 7 4

so we can see that the 8 -> 5 -> 7 -> 4  is a pathway.

Thanks for any suggestions.

P.S I attached the data file in below link:

https://docs.google.com/open?id=0B93SVRfpVVg3MDU0YTEwY2MtNWZjNS00ZWNkLWJiNDAtNTJlNTRlYTg4YTU5


Best regards,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] The python implementation of the "class relationship".

2011-11-10 Thread Steven D'Aprano

Jerry Zhang wrote:

As you know, there are several kinds of relationships between classes in
the UML -- dependency, association, aggregation, composition.


"As you know"... no, I'm afraid I don't know. Believe it or not, it is 
possible to be an experienced, good programmer and still know nothing 
about Unified Modeling Language.




Q1. Is there any article or code example on its implementation in python?
Q2. More specific, in composition model, the container object may be
responsible for the handling of embedded objects' lifecycle. The common way
would be adding __del__ to the container class or something else?


If I have guessed correctly what you mean, no, containers are not 
responsible for handling embedded objects' lifecycle in Python. Every 
object is responsible for itself. Python objects are garbage collected 
when there are no longer any references to that object, regardless of 
whether those references are in the form of name bindings, containment 
inside a container or attribute, closures, or any other reference.


This list is for learning about the Python programming language, aimed 
mostly at beginners. You might have better luck getting detailed answers 
on the python-l...@python.org mailing list, also available as 
comp.lang.python on Usenet.




--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to remove the coming duplication

2011-11-10 Thread lina
On Thu, Nov 10, 2011 at 8:48 PM, Steven D'Aprano  wrote:
> lina wrote:
>>
>> Hi,
>>
>> How to remove the coming duplication,
>>
>> Here I wrote one (not working):
>>
>>
> a=['2', '5', '7', '5', '5']
>
> [...]
>>
>> I wish to get a is [2,5,7,5]
>>
>> just remove the coming duplication, not unique the list.
>
> a = [2, 5, 7, 5, 5]
> b = a[0:1]  # slice of the first item only
> for x in a[1:]:  # slice of the second item to the end
>    if x != b[-1]:
>        b.append(x)

   for index, b in enumerate([b_list]):
print(b)

how can I avoid the output not as:
['53', '76', '57']

but as
53
76
57

Thanks

>
>
> gives b = [2, 5, 7, 5] as requested.
>
>
>
> --
> Steven
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] some ideas about some network

2011-11-10 Thread Wayne Werner
On Thu, Nov 10, 2011 at 7:05 AM, lina  wrote:

> Hi,
>
> Thanks all again for your help in previous post.
>
> Here I meet something I am not experienced, about:
>
> from 10 groups of data  (namely from 1-84) find some pathway, or network.
>
> such as
> Group 1 (file 1): 1 3 8 5 7 4
> Group 2 (file 2): 2 8 5 7 4 3 4 8 5 7 4
>
> so we can see that the 8 -> 5 -> 7 -> 4  is a pathway.
>
> Thanks for any suggestions.
>

I'm confused -  what are you trying to do with this data? I can only guess
you're referring to a graph and you would like some way to visualize this
data?

It helps when you can show what you've tried to do as well.

-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] some ideas about some network

2011-11-10 Thread Walter Prins
Hi Lina,

On 10 November 2011 13:05, lina  wrote:

> from 10 groups of data  (namely from 1-84) find some pathway, or network.
>
> such as
> Group 1 (file 1): 1 3 8 5 7 4
> Group 2 (file 2): 2 8 5 7 4 3 4 8 5 7 4
>
> so we can see that the 8 -> 5 -> 7 -> 4  is a pathway.
>

I'm sorry but I'm not really sure what you're asking.  Can you be more
specific?  How exactly do those 2 (or more) combine to form a pathway or
network, and what exactly do you mean by pathway?

Also, your attachment zip is empty, so you might want to post that again.

Going out on a limb and guessing here, though:  Is the problem you're
trying to solve the same as this (the "longest common substring" problem)?:
http://is.gd/pc6zlk

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] some ideas about some network

2011-11-10 Thread lina
On Thu, Nov 10, 2011 at 10:02 PM, Wayne Werner  wrote:
>
> On Thu, Nov 10, 2011 at 7:05 AM, lina  wrote:
>>
>> Hi,
>>
>> Thanks all again for your help in previous post.
>>
>> Here I meet something I am not experienced, about:
>>
>> from 10 groups of data  (namely from 1-84) find some pathway, or network.
>>
>> such as
>> Group 1 (file 1): 1 3 8 5 7 4
>> Group 2 (file 2): 2 8 5 7 4 3 4 8 5 7 4
>>
>> so we can see that the 8 -> 5 -> 7 -> 4  is a pathway.
>>
>> Thanks for any suggestions.
>
> I'm confused -  what are you trying to do with this data? I can only guess
> you're referring to a graph and you would like some way to visualize this
> data?

The data is the position, I wanted to see the pathway.
a roadmap which connected those positions, but one-way, has direction,

from 8 --> 5

Thanks,

> It helps when you can show what you've tried to do as well.
> -Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] The python implementation of the "class relationship".

2011-11-10 Thread Jerry Zhang
Thanks for your reply.

2011/11/10 Steven D'Aprano 

> Jerry Zhang wrote:
>
>> As you know, there are several kinds of relationships between classes in
>> the UML -- dependency, association, aggregation, composition.
>>
>
> "As you know"... no, I'm afraid I don't know. Believe it or not, it is
> possible to be an experienced, good programmer and still know nothing about
> Unified Modeling Language.


Yeah, but these kinds of relationship still exists in real word whatever
UML is.

For example, the relationship between Cls_arm and Cls_body could be
composition, one arm instance only live with one body instance, and once
this body die, this arm also die. All of this should be described by python
if your application need.


>
>
>
>  Q1. Is there any article or code example on its implementation in python?
>> Q2. More specific, in composition model, the container object may be
>> responsible for the handling of embedded objects' lifecycle. The common
>> way
>> would be adding __del__ to the container class or something else?
>>
>
> If I have guessed correctly what you mean, no, containers are not
> responsible for handling embedded objects' lifecycle in Python. Every
> object is responsible for itself. Python objects are garbage collected when
> there are no longer any references to that object, regardless of whether
> those references are in the form of name bindings, containment inside a
> container or attribute, closures, or any other reference.
>

Yeah, python objects garbage may be another story. Think about you have a
ZODB running which stores your objects data, you will care their lifecycle.
 maybe because i did not make myself understood yet.

Here is a more detail example question.
I have a classes sets described by UML, which could be refered as Cls_A,
Cls_B, CLs_C, Cls_D, Cls_E. There are four relationship between
them--dependency, association, aggregation, composition. What i need to do
is define all of the classes by python, and,of course, the class definition
should describe there relationship correctly.
For example, implement composition relationship between Cls_A and Cls_B,
which may means a instance of Cls_B is created and destroyed by a Cls_A
instance, My code may be like this(not sure since i am not quite familiar
with python yet):

Cls_a:
def __init__(self):
self.at1 = 1

Cls_b:
def __init__(self):
self.com1 = Cls_a()
def __del__(self):
del self.com1
Is it a right implementation for composition?

and i need also do other relationship definition into class, like
dependency, association, aggregation...

Is there any article or code example on the relationships implementation?


>
> This list is for learning about the Python programming language, aimed
> mostly at beginners. You might have better luck getting detailed answers on
> the python-l...@python.org mailing list, also available as
> comp.lang.python on Usenet.
>

I am trying.

>
>
>
> --
> Steven
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] some ideas about some network

2011-11-10 Thread lina
On Thu, Nov 10, 2011 at 10:02 PM, Walter Prins  wrote:
> Hi Lina,
>
> On 10 November 2011 13:05, lina  wrote:
>>
>> from 10 groups of data  (namely from 1-84) find some pathway, or network.
>>
>> such as
>> Group 1 (file 1): 1 3 8 5 7 4
>> Group 2 (file 2): 2 8 5 7 4 3 4 8 5 7 4
>>
>> so we can see that the 8 -> 5 -> 7 -> 4  is a pathway.
>
> I'm sorry but I'm not really sure what you're asking.  Can you be more
> specific?  How exactly do those 2 (or more) combine to form a pathway or
> network, and what exactly do you mean by pathway?

Actually there are 10 trajectories,
or ten paths (road) for a person to travel 84 sites.

and we don't have a specific map of this 84 sites.

so I wish to find some common pathway,

>
> Also, your attachment zip is empty, so you might want to post that again.

The tar.gz link:
https://docs.google.com/open?id=0B93SVRfpVVg3N2E0ZWFhNWUtZTY4Ny00NWE0LWJlMmItODMwOTBiYjE4YzRi

The .zip link:
https://docs.google.com/open?id=0B93SVRfpVVg3NzE5ZWFiYmYtM2JmMS00ODM3LWIwMGEtNjBmN2Q1NmRhMWI2

>
> Going out on a limb and guessing here, though:  Is the problem you're trying
> to solve the same as this (the "longest common substring" problem)?:
> http://is.gd/pc6zlk
Thanks, I will try to understand it.

Best regards,
>
> Walter
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] some ideas about some network

2011-11-10 Thread lina
On Thu, Nov 10, 2011 at 10:02 PM, Walter Prins  wrote:
> Hi Lina,
>
> On 10 November 2011 13:05, lina  wrote:
>>
>> from 10 groups of data  (namely from 1-84) find some pathway, or network.
>>
>> such as
>> Group 1 (file 1): 1 3 8 5 7 4
>> Group 2 (file 2): 2 8 5 7 4 3 4 8 5 7 4
>>
>> so we can see that the 8 -> 5 -> 7 -> 4  is a pathway.
>
> I'm sorry but I'm not really sure what you're asking.  Can you be more
> specific?  How exactly do those 2 (or more) combine to form a pathway or
> network, and what exactly do you mean by pathway?
>
> Also, your attachment zip is empty, so you might want to post that again.
>
> Going out on a limb and guessing here, though:  Is the problem you're trying
> to solve the same as this (the "longest common substring" problem)?:
> http://is.gd/pc6zlk

Thanks, this one is very helpful, something about the longest common substring.


>
> Walter
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] some ideas about some network

2011-11-10 Thread lina


My mistakes, the first generated-data has some problems:
the newly uploaded

tar.gz one is:
https://docs.google.com/open?id=0B93SVRfpVVg3Mjk0YjYzYTMtNzgzZS00NDk4LWI1M2QtNGE5OGZlMjYyNmM5
zip one is
https://docs.google.com/open?id=0B93SVRfpVVg3MDYwZWMzYzItYmI4ZC00MmIxLTg0NmMtMzM5MzZkZTAxZjJl

The below code generated those data has problems in appending parts
(reading mulitiple files), I don't know which parts was wrong:
#!/usr/bin/python3

import os.path
from itertools import groupby

DICTIONARYFILE="dictionary.pdb"
INFILEEXT=".out"
OUTFILEEXT=".txt"

mapping={}

def generate_dict(dictionarysourcefile):
for line in open(dictionarysourcefile,"r"):
parts=line.strip().split()
mapping[parts[2]]=parts[0]

def fetchonefiledata(dictionary,infilename):
with open(infilename,"r") as f:
residues=[]
residueID=[]
residues=[dictionary[line.split()[2]] for line in f]
print(residues)
for i in range(len(residues)):
residueID.append(residues[i][:-3])
remove_coming_dup(residueID)

def remove_coming_dup(a_list):
b_list=a_list[0:1]
for x in a_list[1:]:
if x != b_list[-1]:
b_list.append(x)
with open(base+OUTFILEEXT,"w") as f:
for index, b in enumerate([b_list]):
print(b,file=f)

if __name__=="__main__":
generate_dict(DICTIONARYFILE)
for filename in os.listdir("."):
base, ext = os.path.splitext(filename)
if ext == INFILEEXT:
fetchonefiledata(mapping,filename)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [OSX] "Executable" .py or pyc script (stuck at Applescript)

2011-11-10 Thread learner404
On Thu, Nov 10, 2011 at 2:14 PM, Steven D'Aprano wrote:

> learner404 wrote:
>
>> Hello list!
>>
>> - myapp.py is in a "myfolder" folder that the "users" will be able to
>> download and put anywhere on their Mac.
>>
> [...]
>
>  In both cases OSX complains it can't find the file.
>>
>
> Do you mean that AppleScript can't find the file, or that Python can't
> find the file?
>

When I double click on the AppleScript the terminal opens with

$ python myapp.py
$ python: can't open file 'avcOsxLinux.py': [Errno 2] No such file or
directory

myapp.py and the AppleScript are both in the same directory. If I open
manually a shell in this directory "python myapp.py" works.

It all seems like the Python invoked in the AppleScript have his current
directory in root (and not the folder where i'm executing the AppleScript).
I don't see how I can change this from the AppleScript or simply find a
general solution to execute a .py script on Mac within the constrains I
mentioned above.


> Please don't summarize or paraphrase errors. Please copy and paste the
> EXACT error message that is shown.
>
> If this is a problem with AppleScript being unable to find the file, you
> will be better off asking on an AppleScript mailing list.
>
> In general, on Unix-like systems (and that includes Mac OS X), you can't
> expect a command like:
>
> python myapp.py
>
> to work unless myapp.py is in the current directory.
>
>
>
> --
> Steven
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [OSX] "Executable" .py or pyc script (stuck at Applescript)

2011-11-10 Thread Rich Lovely

On 10 Nov 2011, at 15:20, learner404 wrote:

> 
> 
> On Thu, Nov 10, 2011 at 2:14 PM, Steven D'Aprano  wrote:
> learner404 wrote:
> Hello list!
> 
> - myapp.py is in a "myfolder" folder that the "users" will be able to
> download and put anywhere on their Mac.
> [...]
> 
> In both cases OSX complains it can't find the file. 
> 
> Do you mean that AppleScript can't find the file, or that Python can't find 
> the file?
> 
> When I double click on the AppleScript the terminal opens with
> 
> $ python myapp.py
> $ python: can't open file 'avcOsxLinux.py': [Errno 2] No such file or 
> directory
>  
> myapp.py and the AppleScript are both in the same directory. If I open 
> manually a shell in this directory "python myapp.py" works.
> 
> It all seems like the Python invoked in the AppleScript have his current 
> directory in root (and not the folder where i'm executing the AppleScript). I 
> don't see how I can change this from the AppleScript or simply find a general 
> solution to execute a .py script on Mac within the constrains I mentioned 
> above. 
> 
> 
> Please don't summarize or paraphrase errors. Please copy and paste the EXACT 
> error message that is shown.
> 
> If this is a problem with AppleScript being unable to find the file, you will 
> be better off asking on an AppleScript mailing list.
> 
> In general, on Unix-like systems (and that includes Mac OS X), you can't 
> expect a command like:
> 
> python myapp.py
> 
> to work unless myapp.py is in the current directory.
> 
> 
> 
> -- 
> Steven
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

It looks like your script is being found fine, meaning the problem lies 
elsewhere - unless your actual app is called "avcOsxLinux.py, and you missed 
renaming it in the error message.  Try adding a print statement as the very 
first line - before any imports - to test this.

The only reference to that filename is a french audio-visual library, which 
might not be installed on your target system.

Rich "RoadieRich" Lovely

There are 10 types of people in the world:
Those who know binary,
Those who do not,
And those who are off by one.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Find all strings that....

2011-11-10 Thread Alexander Etter


Hi. My friend gave me a good wake up exercise which I do not want you to solve 
for me: find all strings which can be converted to alpha with at most two 
operations, where alpha is some string constant, and a substring of at least 
length three of alpha must be in the answers. 
So, my question is: is there a library or .txt dictionary ( not the data type, 
rather the merriam webster kind ) I can use to test my script on? I'd imagine 
this library/dictionary to contain thousands of words. Not random words. 
Thanks for reading,
Alexander
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Find all strings that....

2011-11-10 Thread Alex Hall
What about just grabbing a bit text file, such as from Project
Gutenberg (sorry for the possibly incorrect spelling)? Or copying the
text from a large webpage and pasting it into a text file?

On 11/10/11, Alexander Etter  wrote:
>
>
> Hi. My friend gave me a good wake up exercise which I do not want you to
> solve for me: find all strings which can be converted to alpha with at most
> two operations, where alpha is some string constant, and a substring of at
> least length three of alpha must be in the answers.
> So, my question is: is there a library or .txt dictionary ( not the data
> type, rather the merriam webster kind ) I can use to test my script on? I'd
> imagine this library/dictionary to contain thousands of words. Not random
> words.
> Thanks for reading,
> Alexander
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] longest common substring

2011-11-10 Thread lina
Hi,

I tested the one from
http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Longest_common_substring

mainly:

#!/usr/bin/python3

a=['1','2','3','7']

b=['2','3','7']

def LongestCommonSubstring(S1, S2):
M = [[0]*(1+len(S2)) for i in range(1+len(S1))]
longest, x_longest = 0, 0
for x in range(1,1+len(S1)):
for y in range(1,1+len(S2)):
M[x][y] = M[x-1][y-1]+1
if M[x][y] > longest:
longest = M[x][y]
x_longest = x
else:
M[x][y] = 0
return S1[x_longest-longest:x_longest]


if __name__=="__main__":
print(LongestCommonSubstring(a,b))

$ python3 LongestCommonSubstring.py
['1', '2', '3']

The results isn't right.

Thanks for your suggestions and comments,

Best regards,
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Find all strings that....

2011-11-10 Thread Rich Lovely
If you're on linux or OSX, there's /usr/share/dict/words, which has a few 
thousand words.  Although no plurals, which caught me out once.  If you're on 
windows, it's not a hard file to find.

On 10 Nov 2011, at 16:14, Alex Hall wrote:

> What about just grabbing a bit text file, such as from Project
> Gutenberg (sorry for the possibly incorrect spelling)? Or copying the
> text from a large webpage and pasting it into a text file?
> 
> On 11/10/11, Alexander Etter  wrote:
>> 
>> 
>> Hi. My friend gave me a good wake up exercise which I do not want you to
>> solve for me: find all strings which can be converted to alpha with at most
>> two operations, where alpha is some string constant, and a substring of at
>> least length three of alpha must be in the answers.
>> So, my question is: is there a library or .txt dictionary ( not the data
>> type, rather the merriam webster kind ) I can use to test my script on? I'd
>> imagine this library/dictionary to contain thousands of words. Not random
>> words.
>> Thanks for reading,
>> Alexander
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>> 
> 
> 
> -- 
> Have a great day,
> Alex (msg sent from GMail website)
> mehg...@gmail.com; http://www.facebook.com/mehgcap
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

Rich "RoadieRich" Lovely

There are 10 types of people in the world:
Those who know binary,
Those who do not,
And those who are off by one.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [OSX] "Executable" .py or pyc script (stuck at Applescript)

2011-11-10 Thread learner404
On Thu, Nov 10, 2011 at 4:33 PM, Rich Lovely wrote:

>
> It looks like your script is being found fine, meaning the problem lies
> elsewhere - unless your actual app is called "avcOsxLinux.py, and you
> missed renaming it in the error message.  Try adding a print statement as
> the very first line - before any imports - to test this.
>

Sorry I missed replacing this one when I copy/pasted on the list;
 avcOsxLinux.py is "myapp.py" (I renamed it for clarity). Unfortunately the
problem is still the same.

$ python myapp.py
$ python: can't open file 'myapp.py': [Errno 2] No such file or directory


> The only reference to that filename is a french audio-visual library,
> which might not be installed on your target system.
>
> Rich "RoadieRich" Lovely
>
> There are 10 types of people in the world:
> Those who know binary,
> Those who do not,
> And those who are off by one.
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] getting ImportError: No module named beginners

2011-11-10 Thread Nathaniel Trujillo
First I typed help() into the python 3.1.1 interpreter and then I typed
modules to see if there was a beginners module and it wasn't there but when
I went into the
C:\Python31\Lib\site-packages\livewires folder I saw the file beginners.py
right there in front of my face. So here is the program I am trying to
run...

# New Graphics Window
# Demonstrates creating a graphics window
from livewires import games
games.init(sreen_width = 640, screen_height = 480, fps = 50)
games.screen.mainloop()
and here is the error message...

Traceback (most recent call last):
  File "C:\Python31\new_graphics_window.py", line 4, in 
from livewires import games
  File "C:\Python31\lib\site-packages\livewires\__init__.py", line 30, in

from beginners import *
ImportError: No module named beginners

Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] longest common substring

2011-11-10 Thread Peter Otten
lina wrote:

> Hi,
> 
> I tested the one from
> 
http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Longest_common_substring
> 
> mainly:
> 
> #!/usr/bin/python3
> 
> a=['1','2','3','7']
> 
> b=['2','3','7']
> 
> def LongestCommonSubstring(S1, S2):
> M = [[0]*(1+len(S2)) for i in range(1+len(S1))]
> longest, x_longest = 0, 0
> for x in range(1,1+len(S1)):
> for y in range(1,1+len(S2)):
> M[x][y] = M[x-1][y-1]+1
> if M[x][y] > longest:
> longest = M[x][y]
> x_longest = x
> else:
> M[x][y] = 0
> return S1[x_longest-longest:x_longest]
> 
> 
> if __name__=="__main__":
> print(LongestCommonSubstring(a,b))
> 
> $ python3 LongestCommonSubstring.py
> ['1', '2', '3']
> 
> The results isn't right.

That's not the code from the site you quote. You messed it up when you tried 
to convert it to Python 3 (look for the suspicious 8-space indent)

Hint: the function doesn't contain anything specific to Python 2 or 3, apart 
from the xrange builtin. If you add the line

xrange = range

to your code the unaltered version will run in Python 3 -- and produce the 
correct result:

$ cat longest_common_substring3.py
xrange = range

def LongestCommonSubstring(S1, S2):
M = [[0]*(1+len(S2)) for i in xrange(1+len(S1))]
longest, x_longest = 0, 0
for x in xrange(1,1+len(S1)):
for y in xrange(1,1+len(S2)):
if S1[x-1] == S2[y-1]:
M[x][y] = M[x-1][y-1] + 1
if M[x][y]>longest:
longest = M[x][y]
x_longest  = x
else:
M[x][y] = 0
return S1[x_longest-longest: x_longest]

if __name__ == "__main__":
a = ['1','2','3','7']
b = ['2','3','7']

print(LongestCommonSubstring(a, b))
$ python3 longest_common_substring3.py
['2', '3', '7']


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] longest common substring

2011-11-10 Thread Walter Prins
Hi,

On 10 November 2011 16:23, lina  wrote:

> def LongestCommonSubstring(S1, S2):
>M = [[0]*(1+len(S2)) for i in range(1+len(S1))]
>longest, x_longest = 0, 0
>for x in range(1,1+len(S1)):
>for y in range(1,1+len(S2)):
>M[x][y] = M[x-1][y-1]+1
>if M[x][y] > longest:
>longest = M[x][y]
>x_longest = x
>else:
>M[x][y] = 0
>return S1[x_longest-longest:x_longest]
>

This is not the same as the implementation given on wikibooks Have you
tried reverting your changes and using the coe that was given on the site
exactly as is?  (I assume not, and if so, why not?)

(Specifically, I notice most the likely culprit is a missing if statement
just below the "for y in range..." line that's been deleted)


> The results isn't right.
>

Yes.  You appear to have introduced a bug by not using the same code as
what was given on the wiki page.  (Why did you modify the code and then
when the modified code didn't work assume the original solution was broken
instead of checking first and/or suspecting that your changes may have
broken it?)

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] getting ImportError: No module named beginners

2011-11-10 Thread Peter Otten
Nathaniel Trujillo wrote:

> First I typed help() into the python 3.1.1 interpreter and then I typed
> modules to see if there was a beginners module and it wasn't there but
> when I went into the
> C:\Python31\Lib\site-packages\livewires folder I saw the file beginners.py
> right there in front of my face. So here is the program I am trying to
> run...
> 
> # New Graphics Window
> # Demonstrates creating a graphics window
> from livewires import games
> games.init(sreen_width = 640, screen_height = 480, fps = 50)
> games.screen.mainloop()
> and here is the error message...
> 
> Traceback (most recent call last):
>   File "C:\Python31\new_graphics_window.py", line 4, in 
> from livewires import games
>   File "C:\Python31\lib\site-packages\livewires\__init__.py", line 30, in
> 
> from beginners import *
> ImportError: No module named beginners
> 
> Thanks for the help.

Are you talking about this software?

http://www.livewires.org.uk/python/package

Then you are trying to run it on an incompatible Python version. Quoting:

"""
The LiveWires package works with Python 2.x, but not (yet) with Python 3.x.
"""

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How do I get livewires for python version 3.1.1 ?

2011-11-10 Thread Nathaniel Trujillo
Could you tell me where I can get a free download of livewires for python
version 3.1.1 ? And one that does not have a trial period please. I looked
and looked but all I found was the one for version 2.x. I thought I had the
one for version 3.1.1 but I guess I was wrong. I don't know if I am
directing this question to the right people so if not I apologize for any
inconvenience.

Thanks for your help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I get livewires for python version 3.1.1 ?

2011-11-10 Thread Wayne Werner
On Thu, Nov 10, 2011 at 11:55 AM, Nathaniel Trujillo
wrote:

> Could you tell me where I can get a free download of livewires for python
> version 3.1.1 ? And one that does not have a trial period please. I looked
> and looked but all I found was the one for version 2.x. I thought I had the
> one for version 3.1.1 but I guess I was wrong. I don't know if I am
> directing this question to the right people so if not I apologize for any
> inconvenience.
>

You don't - as someone mentioned in reply to one of your previous emails,
Livewires is only for version 2.x.

Honestly, the experiences that I had with Livewires didn't give me an
impression that it was that much easier to use that just your standard
Pygame/Tkinter, both of which are available for Python 3.

You would probably be better off picking up Pygame and Tkinter by
themselves. I'm under the impression that Livewires isn't a terribly
popular package, and there is plentiful documentation for both Pygame and
Tkinter.

Of course this also assumes that you're at least familiar enough with
Python to be able to write the code you need.

HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] My response to How do I get livewires for python version 3.1.1 ?

2011-11-10 Thread Nathaniel Trujillo
I actually am not familiar with python enough to know what code to use.
Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Find all strings that....

2011-11-10 Thread Alexander
> On 11/10/11, Original Poster Alexander Etter  wrote:
>>
>> Hi. My friend gave me a good wake up exercise which I do not want you to
>> solve for me: find all strings which can be converted to alpha with at
most
>> two operations, where alpha is some string constant, and a substring of
at
>> least length three of alpha must be in the answers.
>> So, my question is: is there a library or .txt dictionary ( not the data
>> type, rather the merriam webster kind ) I can use to test my script on?
I'd
>> imagine this library/dictionary to contain thousands of words. Not random
>> words.
>> Thanks for reading,
>> Alexander

On 10 Nov 2011, at 16:14, Alex Hall wrote:

> What about just grabbing a bit text file, such as from Project
> Gutenberg (sorry for the possibly incorrect spelling)?
Spelling is correct. No worries.

Or copying the
> text from a large web-page and pasting it into a text file?

I will give this a try sometime, thanks for the suggestions.
However, as a member of this mailing list, it is my duty to tell you both
that you have top posted in reply to the initial question. Top posting is
frowned upon. Consider when John Doe finds this thread, sees the subject
line, finds it appealing and decides to read it; only to find the first
thing he reads is a response from somebody and not the Original post. Now
Mr. Doe is scrambling through the file confused about who sent what first
and where the original question is. Maybe me typing in the middle of your
reply is bad, but it is distinguishable from your email and I am finding it
relevant.

> --
> Have a great day,
> Alex (msg sent from GMail website)
> mehg...@gmail.com; http://www.facebook.com/mehgcap
__
On Thu, Nov 10, 2011 at 11:28 AM, Rich Lovely wrote:

> If you're on linux or OSX, there's /usr/share/dict/words, which has a few
> thousand words.  Although no plurals, which caught me out once.  If you're
> on windows, it's not a hard file to find.
>
>
> Rich "RoadieRich" Lovely
>
> There are 10 types of people in the world:
> Those who know binary,
> Those who do not,
> And those who are off by one.
>
> Thanks Rich. I'm on Ubuntu 11.04 and Trisquel. And will make use of that
file. It's an interesting collection of words, but certainly missing some
of what I would want to see. Like "better" isn't in there, but "Bette" is.
Anyway at least I can start coding with your suggestion. Thanks. And if you
haven't seen above, please don't top post.
Au revoir.
Alexander E.
--
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Find all strings that....

2011-11-10 Thread Francesco Loffredo

Alexander Etter wrote:


Hi. My friend gave me a good wake up exercise which I do not want you to solve 
for me: find all strings which can be converted to alpha with at most two 
operations, where alpha is some string constant, and a substring of at least 
length three of alpha must be in the answers.

I'd like to try this exercise too; would you mind defining "operations" more 
specifically, please?
Given a sufficiently broad meaning of "operations" (e.g. operation = any 
function call)
then any word can be converted into any given word with at most ONE operation.


So, my question is: is there a library or .txt dictionary ( not the data type, 
rather the merriam webster kind ) I can use to test my script on? I'd imagine 
this library/dictionary to contain thousands of words. Not random words.

http://www.cs.nmsu.edu/~hfugal/cs167/labs/words.txt

Thanks for reading,
Alexander

More thanks for writing!
Francesco


-
Nessun virus nel messaggio.
Controllato da AVG - www.avg.com
Versione: 2012.0.1869 / Database dei virus: 2092/4606 -  Data di rilascio: 
09/11/2011

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I get livewires for python version 3.1.1 ?

2011-11-10 Thread Wayne Werner
On Thu, Nov 10, 2011 at 12:01 PM, Wayne Werner wrote:

>
> On Thu, Nov 10, 2011 at 11:55 AM, Nathaniel Trujillo <
> hothottr...@gmail.com> wrote:
>
>> Could you tell me where I can get a free download of livewires for python
>> version 3.1.1 ? And one that does not have a trial period please. I looked
>> and looked but all I found was the one for version 2.x. I thought I had the
>> one for version 3.1.1 but I guess I was wrong. I don't know if I am
>> directing this question to the right people so if not I apologize for any
>> inconvenience.
>>
>
> You don't - as someone mentioned in reply to one of your previous emails,
> Livewires is only for version 2.x.
>
> Honestly, the experiences that I had with Livewires didn't give me an
> impression that it was that much easier to use that just your standard
> Pygame/Tkinter, both of which are available for Python 3.
>
> You would probably be better off picking up Pygame and Tkinter by
> themselves. I'm under the impression that Livewires isn't a terribly
> popular package, and there is plentiful documentation for both Pygame and
> Tkinter.
>
> Of course this also assumes that you're at least familiar enough with
> Python to be able to write the code you need.
>

On Thu, Nov 10, 2011 at 12:08 PM, Nathaniel Trujillo 
 wrote:

> I actually am not familiar with python enough to know what code to use.
> Thanks for the help.


Please don't create a new email or change the subject line, this makes it
very difficult for those of us who use thread-based clients to keep the
thread of the conversation. I see that your email address is gmail so I
know that if you're using their web client that this is not the default
behavior. You should definitely read this link
http://catb.org/~esr/faqs/smart-questions.html that should have been sent
in the email welcoming you to the tutor list.

If you're interested in learning to program, there are several great
tutorials out there. This one (http://inventwithpython.com/chapters/) uses
game design as a way to teach programming concepts.

Snake Wrangling for Kids is a great book that's geared towards a younger
audience: http://www.briggs.net.nz/log/writing/snake-wrangling-for-kids/

There are a variety of other tutorials out there, just pick one and get
started!

HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sifting through a long program

2011-11-10 Thread Nathaniel Trujillo
How do I get to line 362 of a program without counting each line ?  Thanks
for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sifting through a long program

2011-11-10 Thread Joel Goldstick
if you are using vim type 262G

This is a list for python tutoring.  People use a variety of text editors.
You should google 'how do I go to a specific line in 


On Thu, Nov 10, 2011 at 1:58 PM, Nathaniel Trujillo
wrote:

> How do I get to line 362 of a program without counting each line ?  Thanks
> for the help.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: sifting through a long program

2011-11-10 Thread Rance Hall
I accidentally replied just to the OP, so I'm forwarding my comments
to the list for the record.


-- Forwarded message --
From: Rance Hall 
Date: Thu, Nov 10, 2011 at 1:36 PM
Subject: Re: [Tutor] sifting through a long program
To: Nathaniel Trujillo 


On Thu, Nov 10, 2011 at 12:58 PM, Nathaniel Trujillo
 wrote:
> How do I get to line 362 of a program without counting each line ?  Thanks
> for the help.

Use an editor with line numbers visible?


I've been a silent lurker on this list for awhile learning python as I
read what other people were doing with it.

The teacher in me wants you to get your questions answered, but the
volunteer in me wants you to not waste my time and the time of other
people on this list.

This is clearly not a python question.

It is a question on what tools are needed to write effective code
regardless of language.

Its starting to appear as if you are too lazy to even try to address
your own problems on your own, and with Google at your fingertips
there is no excuse for this.

Perhaps you are trying, and it just appears as if you are not trying.
Perhaps though, you really aren't trying.

A word of warning, most of us have email clients that can silently
delete messages from specific email addresses without having to read
them. You don't want to be on the ignore list for people who can help
you but don't want to spoon feed you in the process.

Good luck learning python.

Rance
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sifting through a long program

2011-11-10 Thread Max S.
Alt+G, or Edit>Go To Line.

On Thu, Nov 10, 2011 at 1:58 PM, Nathaniel Trujillo
wrote:

> How do I get to line 362 of a program without counting each line ?  Thanks
> for the help.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] positional output

2011-11-10 Thread Cranky Frankie
What is the easiest way in Python 3.x to write output positionally?
For example I have one literal I want in column 1, the next one in
column 40, the third one in column 50. I've tried usings tabs and I'm
not getting what I want. Is it something to do with C style printf
formatting? An example would be greatly appreciated.

-- 
Frank L. "Cranky Frankie" Palmeri, Guilderland, NY, USA
             Risible Riding Raconteur & Writer
Don't sweat the petty things, and don't pet the sweaty things.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] positional output

2011-11-10 Thread Dave Angel

On 11/10/2011 03:54 PM, Cranky Frankie wrote:

What is the easiest way in Python 3.x to write output positionally?
For example I have one literal I want in column 1, the next one in
column 40, the third one in column 50. I've tried usings tabs and I'm
not getting what I want. Is it something to do with C style printf
formatting? An example would be greatly appreciated.

Narrow down your environment a bit.  Where is this output going?  To a 
file, to a printer, to the console?  If the latter, in what environment?


The only portable way to position yourself would be to pad with spaces.  
If you want to output a fixed width string, perhaps you'd want to use 
the format method of str.

--

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-10 Thread Nathaniel Trujillo
I decided to try using python version 2.1.3 with pygame version 1.7.1 (I
hope they're compatable) and the livewires version that was available at
livewires.org.uk, I think it's version 2.1 . After getting the following
error message I tried researching the problem myself at bing.com and then
google.com. I typed the error into both search engines but the info that I
got just led to more questions. For example, the suggestion that I thought
most applied to me was to reset the PYTHONPATH to the directory that
contains the module games.py but that led to the question how do I do that.
So I tried typing help() but that doesn't work in version 2.1.3 so I went
to google and typed "how to reset PYTHONPATH in python 2.1.3" and I also
typed "how to reset PYTHONPATH" and didn't find much. I was told not to
make a new email or change the subject line (which to me basically means to
reply) but I was also told by someone not to reply and to make a new email
so I didn't know what to do? Also, python is my first language and I
started out knowing absolutely nothing about programming so please bare
with me. Thanks.

here is the code

# New Graphics Window
# Demonstrates creating a graphics window
from livewires import games
games.init(screen_width = 640, screen_height = 480, fps = 50)
games.mainloop()

and here is the error message. I appologize but the error message refered
to above is not the same one I just got after running the program again to
copy the error messge but here is the message anyway. Actually come to
think of it, the first message was

ImportError: cannot import name games

and the one I just got is

Traceback (most recent call last):
  File "", line 1, in ?
  File "C:\Python21\new_graphics_window.py", line 4, in ?
from livewires import games
  File "C:\Python21\livewires\games.py", line 59, in ?
import pygame, pygame.transform, pygame.draw
ImportError: No module named pygame

Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] positional output

2011-11-10 Thread Andreas Perstinger

On 2011-11-10 21:54, Cranky Frankie wrote:

What is the easiest way in Python 3.x to write output positionally?
For example I have one literal I want in column 1, the next one in
column 40, the third one in column 50. I've tried usings tabs and I'm
not getting what I want. Is it something to do with C style printf
formatting? An example would be greatly appreciated.


Two ideas:

1) Using string formatting:
>>> print("x{0}x{1}x".format(" " * 38, " " * 9))

2) Using a helper list (assuming screen width = 80):
>>> line = [" "] * 80
>>> line[0] = "x"
>>> line[39] = "x"
>>> line[49] = "x"
>>> print("".join(line))

Bye, Andreas

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Find all strings that....

2011-11-10 Thread Alexander Etter

On Nov 10, 2011, at 13:52, Francesco Loffredo  wrote:

> Alexander Etter wrote:
>> 
>> Hi. My friend gave me a good wake up exercise which I do not want you to 
>> solve for me: find all strings which can be converted to alpha with at most 
>> two operations, where alpha is some string constant, and a substring of at 
>> least length three of alpha must be in the answers.
> I'd like to try this exercise too; would you mind defining "operations" more 
> specifically, please?
> Given a sufficiently broad meaning of "operations" (e.g. operation = any 
> function call)
> then any word can be converted into any given word with at most ONE operation.
Consider an operation not as a function. A function could easily contain more 
than two operations. An operation would remove two letters. An operation would 
add one letter. Etc. 
Alexander
> 
>> So, my question is: is there a library or .txt dictionary ( not the data 
>> type, rather the merriam webster kind ) I can use to test my script on? I'd 
>> imagine this library/dictionary to contain thousands of words. Not random 
>> words.
> http://www.cs.nmsu.edu/~hfugal/cs167/labs/words.txt
>> Thanks for reading,
>> Alexander
> More thanks for writing!
> Francesco
> 
> 
> -
> Nessun virus nel messaggio.
> Controllato da AVG - www.avg.com
> Versione: 2012.0.1869 / Database dei virus: 2092/4606 -  Data di rilascio: 
> 09/11/2011
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] positional output

2011-11-10 Thread Prasad, Ramit
>1) Using string formatting:
> >>> print("x{0}x{1}x".format(" " * 38, " " * 9))
You can specify alignment and padding with string formatting too. It just 
requires you to know the formatting mini-language.

>>> 'x{0:>40}x{1:^30}x{2:<40}'.format( 'right', 'center' , 'left' )

'x   rightxcenterxleft  
  '

http://docs.python.org/library/string.html 
See 7.1.3.2 for examples

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [OSX] "Executable" .py or pyc script (stuck at Applescript)

2011-11-10 Thread Prasad, Ramit
From: tutor-bounces+ramit.prasad=jpmorgan@python.org 
[mailto:tutor-bounces+ramit.prasad=jpmorgan@python.org] On Behalf Of 
learner404
Sent: Thursday, November 10, 2011 10:44 AM
To: Rich Lovely
Cc: Tutor Python
Subject: Re: [Tutor] [OSX] "Executable" .py or pyc script (stuck at Applescript)


On Thu, Nov 10, 2011 at 4:33 PM, Rich Lovely  wrote:

It looks like your script is being found fine, meaning the problem lies 
elsewhere - unless your actual app is called "avcOsxLinux.py, and you missed 
renaming it in the error message.  Try adding a print statement as the very 
first line - before any imports - to test this.

Sorry I missed replacing this one when I copy/pasted on the list;  
avcOsxLinux.py is "myapp.py" (I renamed it for clarity). Unfortunately the 
problem is still the same. 

$ python myapp.py
$ python: can't open file 'myapp.py': [Errno 2] No such file or directory


The only reference to that filename is a french audio-visual library, which 
might not be installed on your target system.

Rich "RoadieRich" Lovely

There are 10 types of people in the world:
Those who know binary,
Those who do not,
And those who are off by one.


You can try using locate or find, but any usage of this is probably system 
specific and prone to bugs. If you have the option to "install" something you 
can try setting an environment variable with the location of myapp.py. It is 
probably easiest to keep myapp.py in the home directory (or subdirectory of it) 
and say "python ~/myapp.py" (or "python ~/.roadierich/myapp.py) from the 
applescript



Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Find all strings that....

2011-11-10 Thread Steven D'Aprano

Alexander Etter wrote:

On Nov 10, 2011, at 13:52, Francesco Loffredo  wrote:


Alexander Etter wrote:

Hi. My friend gave me a good wake up exercise which I do not want
you to solve for me: find all strings which can be converted to
alpha with at most two operations, where alpha is some string
constant, and a substring of at least length three of alpha must
be in the answers.



I'd like to try this exercise too; would you mind defining
"operations" more specifically, please? Given a sufficiently broad
meaning of "operations" (e.g. operation = any function call) then
any word can be converted into any given word with at most ONE
operation.



Consider an operation not as a function. A function could easily
contain more than two operations. An operation would remove two
letters. An operation would add one letter. Etc.



Sounds to me like you're discussing edit distance, i.e. given only the 
three permissible edit operations:


delete a letter
insert a letter
replace a letter with another letter

what is the least number of edits needed to go from (say) "winner" to 
"whiner"?




--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-10 Thread Steven D'Aprano

Nathaniel Trujillo wrote:
I decided to try using python version 2.1.3 



Nathaniel, that's SIX VERSIONS OLD. That's ancient history. Python 2.1 
is missing a lot of important features.


Please use at least Python 2.6, 2.7 would be better.

I admire your perseverance in the face of adversity. Man, I would have 
given up by now! Well done. But honestly you're going at this like a 
bull in a china shop, just charging ahead trying to overcome all 
obstacles by sheer activity. Time to slow down and work smarter, not harder.


Please start off by installing Python 2.6 or 2.7. Unless you have 
specific reason to use an old version, you should always stick to a 
recent version: either the newest, or the one before it. (Python 3.x is 
a bit of a special case.)


Once you have installed Python, run this from the command line to test it:

python -c "import sys; print sys.version"

and tell us what it says. Please copy and paste the exact output, don't 
re-type it or summarize.


It should say something like "2.7.3 blah blah blah...". If it does, 
launch the Python interactive interpreter by running:


python

from the command line (with no additional arguments), then when the 
prompt changes to >>> type this:


import pygame

If you get an error, please copy and paste the full output.


Once you've done that, we'll see what happens next.



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] The python implementation of the "class relationship".

2011-11-10 Thread Alan Gauld

On 10/11/11 09:23, Jerry Zhang wrote:

As you know, there are several kinds of relationships between classes in
the UML -- dependency, association, aggregation, composition.


There are several more besides, but lets not get carried away... :-)


Q1. Is there any article or code example on its implementation in python?


Probably if you try using google, but the principles are simple.

Dependencies are both loose and implicit in Python.
If an object uses another object in its implementation there is a 
dependency relationship, but the dependency is only on the operations 
exposed by the object not necessarily on the object, or even on

its type.

Association is likewise loose. If an attribute refers to another object 
then there is an association. If the referenced object is part of a 
collection then it is a 1-M association.


Aggregation is a form of association and nothing more.

Composition is a form of aggregation/association.

Because of the way Python variables work object attributes can only ever 
be references to other objects, they objects are never tightly bound 
together.


The relationships implied by UML are relationships of logical intent. In 
Python it's up to you to "enforce" the intent by the way you write your 
code. UML provides a wide variety of modeling concepts which the modeler 
can use depending on the concept he wishes to convey and also based on 
the implementation language. If designing for a language like C++ or 
Java it may make sense to specify precisely which relationship to use. 
In a freer language, like Python, you may just model everything as 
associations and/or aggregation. UML does not require anything more 
specific any more than it requires that you include deployment designs 
or state machines. They are tools in the toolbox, that's all. If you are 
sculpting in plasticine you probably don't need your power chisel, if 
you are using granite it might be useful. Pick the tool for the job.



Q2. More specific, in composition model, the container object may be
responsible for the handling of embedded objects' lifecycle. The common
way would be adding __del__ to the container class or something else?


That would be one way, and of course by having an __init__ method too.
You might even go one step further and use a __new__ so that the 
relationship is already extant by the time the program hits __init__


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sifting through a long program

2011-11-10 Thread Alan Gauld

On 10/11/11 18:58, Nathaniel Trujillo wrote:

How do I get to line 362 of a program without counting each line ?
Thanks for the help.



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


M-x goto-line

If you are using emacs.


But you hardly ever need to do that because most IDEs will take you 
there from an error message.


And if they don't searching for the text on the line is often easier.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-10 Thread Nathaniel Trujillo
Okay, I typed into the command line of version 2.7.2, python -c "import
sys; print sys.version". I tried it with and without the quotes. I tried
copying the error messages from the command line but it wouldn't let me so
I copied them from the python shell instead.

here is what I got after typing it in with the quotes

SyntaxError: invalid syntax

and I got the same exact message when I typed it in without the quotes.
This happened in both the command line and the shell.

So that's what I got so far. Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-10 Thread Alan Gauld

On 10/11/11 21:27, Nathaniel Trujillo wrote:

I decided to try using python version 2.1.3 with pygame version 1.7.1


Why so old? Python 2.1 was about 10 years ago!

The current version of PyGame should work with Python v2.6 or 2.7 both 
readily available from python.org


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-10 Thread Steven D'Aprano

Nathaniel Trujillo wrote:

Okay, I typed into the command line of version 2.7.2, python -c "import
sys; print sys.version". I tried it with and without the quotes. I tried
copying the error messages from the command line but it wouldn't let me so
I copied them from the python shell instead.


You're running that command from *inside* Python.

I asked:

Once you have installed Python, run this from the command
line to test it:

python -c "import sys; print sys.version"


I'm sorry, I should have been more explicit that I meant from your 
system command line, the shell or command.exe or cmd.com, not from 
inside Python.


You should see a prompt ending with % or possibly % but not Python's 
prompt >>>.


My intention is to ensure that the bare python command is working correctly.


Later on, I asked you to:

launch the Python interactive interpreter by running:

python


which implies that you *hadn't* launched the interactive interpreter 
before this point.



Sorry for the confusion.



--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-10 Thread Dave Angel

On 11/10/2011 08:01 PM, Nathaniel Trujillo wrote:

Okay, I typed into the command line of version 2.7.2, python -c "import
sys; print sys.version". I tried it with and without the quotes. I tried
copying the error messages from the command line but it wouldn't let me so
I copied them from the python shell instead.

here is what I got after typing it in with the quotes

SyntaxError: invalid syntax

and I got the same exact message when I typed it in without the quotes.
This happened in both the command line and the shell.

So that's what I got so far. Thanks for the help.


You're apparently on Windows.

You need to understand the difference between being at a cmd prompt, 
being at the python interpreter, and maybe being in whatever shell 
you're using.


You also need to be able to copy & paste from the cmd window (console 
window, dos box, whatever).  There are menu items that let you select a 
rectangular section of the console box and copy it to the clipboard.  
it's been too long for me to remember, but try right-click on the cmd 
window.


Without pasting exactly what you're doing (and not just the error msg), 
people are going to continue being frustrated.



--

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-10 Thread Nathaniel Trujillo
Okay, I typed in python -c "import sys; print sys.version" at the command
prompt. I didn't see a prompt ending with %. Instead I saw a prompt ending
with >. But here is the message I got.

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Users\net2010>python -c "import sys; print sys.version"
'python' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\net2010>

Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] The python implementation of the "class relationship".

2011-11-10 Thread Jerry Zhang
2011/11/11 Alan Gauld 

> On 10/11/11 09:23, Jerry Zhang wrote:
>
>> As you know, there are several kinds of relationships between classes in
>> the UML -- dependency, association, aggregation, composition.
>>
>
> There are several more besides, but lets not get carried away... :-)
>
>
>  Q1. Is there any article or code example on its implementation in python?
>>
>
> Probably if you try using google, but the principles are simple.
>
I tried and failed to find some code example. So i maybe i have to do such
very carefully by myself.

>
> Dependencies are both loose and implicit in Python.
> If an object uses another object in its implementation there is a
> dependency relationship, but the dependency is only on the operations
> exposed by the object not necessarily on the object, or even on
> its type.
>
> Association is likewise loose. If an attribute refers to another object
> then there is an association. If the referenced object is part of a
> collection then it is a 1-M association.
>
> Aggregation is a form of association and nothing more.
>
> Composition is a form of aggregation/association.
>
> Because of the way Python variables work object attributes can only ever
> be references to other objects, they objects are never tightly bound
> together.
>
Very fair comments. It deserve a big thanks.


>
> The relationships implied by UML are relationships of logical intent. In
> Python it's up to you to "enforce" the intent by the way you write your
> code. UML provides a wide variety of modeling concepts which the modeler
> can use depending on the concept he wishes to convey and also based on the
> implementation language. If designing for a language like C++ or Java it
> may make sense to specify precisely which relationship to use. In a freer
> language, like Python, you may just model everything as associations and/or
> aggregation. UML does not require anything more specific any more than it
> requires that you include deployment designs or state machines. They are
> tools in the toolbox, that's all. If you are sculpting in plasticine you
> probably don't need your power chisel, if you are using granite it might be
> useful. Pick the tool for the job.

To my understand, python's feature such as "name-reference-object" and
"garbage collection" system did some of work for you, it makes your life
easier, but you still need to add your explicit application in your code.

For example,
Composition implementation: you may need to do 5 job with C++, but only 2
job with python, the other 3 job is done by python implicitly.
association implementation: You need 3 job with C++, but 1 with python. it
seems python's object's lifecycle handling has reached this level, all you
should do is just "associating and de-association".

Here is exactly of my question, for composition,
 the best code may be you do 2 job explicitly, 3 job done by python
implicitly.
Code_Zero. 1 job(by you) + 4(by python) does NOT work.
Code_one. 2 job(by you) + 3(by python) works. That is the best one.
Code_two. 3 job( by you) + 2 (by python) works too,
Code_three. 4 job(by you) + 1(by python) works too.

Since i am not familiar with python yet, my code most likely would gets
into Code_two or Code_three(Code_Zero is also possible for new guys like
me), though they also work, they are bad code.
What i am looking for is the Code_one example, i thought many OOP
application designer may have met this issue, so a good Code_one reference
is the best choice to start this project.



>
>  Q2. More specific, in composition model, the container object may be
>> responsible for the handling of embedded objects' lifecycle. The common
>> way would be adding __del__ to the container class or something else?
>>
>
> That would be one way, and of course by having an __init__ method too.
> You might even go one step further and use a __new__ so that the
> relationship is already extant by the time the program hits __init__
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-10 Thread Nathaniel Trujillo
Okay this time I think it worked because it said

2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]

then I typed python at the command prompt and the little >>> came up. Then
I typed import pygame but I did not get an error, it just prompted me again
like this >>>.

Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] longest common substring

2011-11-10 Thread lina
On Fri, Nov 11, 2011 at 1:21 AM, Peter Otten <__pete...@web.de> wrote:
> lina wrote:
>
>> Hi,
>>
>> I tested the one from
>>
> http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Longest_common_substring
>>
>> mainly:
>>
>> #!/usr/bin/python3
>>
>> a=['1','2','3','7']
>>
>> b=['2','3','7']
>>
>> def LongestCommonSubstring(S1, S2):
>>         M = [[0]*(1+len(S2)) for i in range(1+len(S1))]
>>         longest, x_longest = 0, 0
>>         for x in range(1,1+len(S1)):
>>                 for y in range(1,1+len(S2)):
>>                         M[x][y] = M[x-1][y-1]+1
>>                         if M[x][y] > longest:
>>                                 longest = M[x][y]
>>                                 x_longest = x
>>                         else:
>>                                 M[x][y] = 0
>>         return S1[x_longest-longest:x_longest]
>>
>>
>> if __name__=="__main__":
>>         print(LongestCommonSubstring(a,b))
>>
>> $ python3 LongestCommonSubstring.py
>> ['1', '2', '3']
>>
>> The results isn't right.
>
> That's not the code from the site you quote. You messed it up when you tried
> to convert it to Python 3 (look for the suspicious 8-space indent)
>
You are right.
also correct it to 4-space indention now. Thanks.
> Hint: the function doesn't contain anything specific to Python 2 or 3, apart
> from the xrange builtin. If you add the line
>
> xrange = range

Thanks, I did not realize I could substitute the xrange to range this way. cool.

>
> to your code the unaltered version will run in Python 3 -- and produce the
> correct result:
>
> $ cat longest_common_substring3.py
> xrange = range
>
> def LongestCommonSubstring(S1, S2):
>    M = [[0]*(1+len(S2)) for i in xrange(1+len(S1))]
>    longest, x_longest = 0, 0
>    for x in xrange(1,1+len(S1)):
>        for y in xrange(1,1+len(S2)):
>            if S1[x-1] == S2[y-1]:

I did not understand the code well, and the  if S1[x-1] == S2[y-1]:
was missing during I was typing ( I did not copy/paste, try to type to
enhance the learning)

>                M[x][y] = M[x-1][y-1] + 1
>                if M[x][y]>longest:
>                    longest = M[x][y]
>                    x_longest  = x
>            else:
>                M[x][y] = 0
>    return S1[x_longest-longest: x_longest]
>
> if __name__ == "__main__":
>    a = ['1','2','3','7']
>    b = ['2','3','7']
>
>    print(LongestCommonSubstring(a, b))
> $ python3 longest_common_substring3.py
> ['2', '3', '7']
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] longest common substring

2011-11-10 Thread lina
On Fri, Nov 11, 2011 at 1:23 AM, Walter Prins  wrote:
> Hi,
>
> On 10 November 2011 16:23, lina  wrote:
>>
>> def LongestCommonSubstring(S1, S2):
>>        M = [[0]*(1+len(S2)) for i in range(1+len(S1))]
>>        longest, x_longest = 0, 0
>>        for x in range(1,1+len(S1)):
>>                for y in range(1,1+len(S2)):
>>                        M[x][y] = M[x-1][y-1]+1
>>                        if M[x][y] > longest:
>>                                longest = M[x][y]
>>                                x_longest = x
>>                        else:
>>                                M[x][y] = 0
>>        return S1[x_longest-longest:x_longest]
>
> This is not the same as the implementation given on wikibooks Have you
> tried reverting your changes and using the coe that was given on the site
> exactly as is?  (I assume not, and if so, why not?)
I used python3, it showed me NameError: name 'xrange' is not defined
so I made a little changes, before I even worried I might forget to
import some modules to make the xrange work.
>
> (Specifically, I notice most the likely culprit is a missing if statement
> just below the "for y in range..." line that's been deleted)
Thanks for that. adding this missing line, works. I am still lack of
understanding how the code works, so made above mistake.
>
>>
>> The results isn't right.
>
> Yes.  You appear to have introduced a bug by not using the same code as what
> was given on the wiki page.  (Why did you modify the code and then when the
> modified code didn't work assume the original solution was broken instead of
> checking first and/or suspecting that your changes may have broken it?)
Sorry. I did not assume the original code was broken, might a little
unconsciously worry it might be out of date at that time.
I checked by eyes, bad, and did not check carefully.

Thanks with best regards,


>
> Walte
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] longest common substring

2011-11-10 Thread lina


#!/usr/bin/python3

import os.path

xrange = range


c=['71', '82', '80', '70', '84', '56', '58', '34', '77', '76', '61',
'76', '34', '76', '58', '34', '56', '61', '65', '82', '65', '80',
'65', '82', '80', '82', '65', '82', '61', '80', '82', '65', '61',
'63', '65', '70', '80', '71', '34', '71', '64', '34', '58', '61',
'80', '34', '40', '72', '38', '4', '70', '72', '40', '72', '4', '72',
'42', '69', '40', '70', '40', '61', '40', '34', '61', '33', '34',
'61', '34', '35', '61', '35', '61', '70', '61', '34', '61', '34',
'54', '34', '32', '35', '59', '55', '59', '34', '43', '32', '34',
'32', '24', '34', '32', '35', '32', '43', '34', '32', '34', '45',
'35', '32', '83', '61', '58', '32', '58', '83', '32', '34', '61',
'52', '34', '32', '34', '84', '32', '52', '34', '57', '34', '52',
'20', '58', '34', '32', '34', '58', '34', '58', '61', '34', '30',
'35', '28', '52', '22', '21', '22', '30', '61', '79', '70', '80',
'70', '65', '61', '80', '59', '52', '61', '20', '30', '20', '58',
'20', '29', '74', '58', '20', '31', '20', '31', '57', '31', '34',
'20', '58', '34', '52', '34', '20', '58', '83', '58', '34', '61',
'34', '32', '76', '34', '35', '52', '77', '76', '74', '76', '58',
'20', '57', '58', '33', '76', '58', '52', '74', '20', '36', '61',
'36', '74', '61', '36', '83', '61', '83', '31', '61', '59', '33',
'36', '61', '20', '34', '84', '70', '61', '36', '61', '36', '77',
'20', '38', '36', '61', '59', '38', '10', '38', '36', '38', '77',
'36', '39', '38', '36', '23', '26', '8', '36', '8', '19', '8', '19',
'8', '19', '20', '8', '36', '34', '8', '21', '8', '28', '22', '18',
'10', '20', '76', '36', '57', '20', '26', '10', '20', '28', '33',
'35', '36', '34', '36', '20', '34', '10', '36', '76', '57', '76',
'57', '16', '10', '59', '20', '19', '59', '20', '28', '20', '37',
'23', '38', '21', '23', '79', '32', '29', '36', '29', '31', '29',
'36', '20', '34', '79', '23', '20', '28', '20', '79', '74', '34',
'20', '59', '32', '20', '23', '28', '20', '10', '56', '22', '56',
'52', '57', '28', '76', '74', '20', '34', '77', '20', '36', '22',
'61', '59', '22', '20', '22', '21', '23', '20', '61', '59', '77',
'22', '34', '58', '20', '34', '28', '29', '22', '8', '22', '23', '20',
'59', '22', '20', '57', '20', '57', '22', '77', '20', '76', '36',
'20', '77', '23', '35', '77', '20', '8', '74', '10', '76', '20', '34',
'10', '31', '20', '33', '59', '61', '42', '41']

d=['45', '64', '13', '5', '64', '45', '13', '15', '13', '16', '10',
'7', '16', '10', '8', '16', '8', '10', '13', '64', '10', '45', '64',
'43', '64', '47', '64', '43', '64', '45', '47', '45', '15', '43',
'17', '64', '47', '64', '62', '75', '16', '60', '45', '64', '13',
'64', '75', '45', '47', '64', '75', '64', '60', '64', '60', '64',
'58', '60', '64', '45', '16', '64', '58', '16', '58', '60', '64', '7',
'60', '64', '7', '64', '47', '10', '64', '58', '64', '60', '58', '64',
'58', '75', '60', '64', '45', '64', '45', '58', '45', '60', '64',
'58', '64', '45', '60', '58', '75', '58', '75', '45', '60', '58',
'60', '58', '7', '13', '58', '49', '57', '64', '49', '63', '50', '63',
'49', '50', '81', '61', '49', '69', '70', '49', '39', '48', '83',
'29', '52', '39', '29', '52', '37', '52', '29', '52', '27', '83',
'52', '83', '52', '39', '27', '39', '27', '39', '41', '27', '29',
'39', '27', '83', '29', '39', '27', '29', '41', '39', '61', '28',
'41', '81', '28', '41', '28', '41', '81', '36', '51', '61', '59',
'53', '48', '53', '83', '59', '48', '59', '53', '57', '41', '83',
'61', '42', '81', '61', '40', '79', '41', '28', '59', '27', '33',
'28', '41', '83', '79', '81', '41', '61', '29', '39', '28', '61',
'39', '28', '42', '41', '31', '41', '84', '82', '84', '61', '31',
'41', '61', '41', '82', '28', '41', '57', '48', '59', '83', '48',
'83', '48', '57', '61', '57', '83', '42', '48', '61', '46', '48',
'51', '59', '51', '81', '51', '57', '51', '81', '51', '57', '48',
'59', '48', '83', '61', '83', '48', '81', '60', '48', '51', '48',
'57', '48', '51', '74', '53', '51', '53', '51', '81', '52', '51',
'61', '51', '41', '61', '83', '81', '83', '61', '81', '39', '28',
'41', '84', '42', '61', '36', '61', '63', '84', '83', '41', '72',
'41', '37', '39', '41', '82', '41', '61', '28', '39', '28', '41',
'39', '28', '41', '83', '41', '83', '61', '84', '83', '84', '83',
'51', '61', '83', '40', '83', '63', '61', '59', '28', '84', '42',
'28', '84', '61', '40', '41', '40', '41', '63', '84', '63', '59',
'83', '61', '59', '61', '39', '84', '72', '61', '40', '84', '61',
'83', '42', '59', '36', '40', '61', '63', '61', '59', '61', '40',
'29', '61', '29', '61', '39', '61', '31', '61', '70', '61']

def LongestCommonSubstring(S1, S2):
M = [[0]*(1+len(S2)) for i in xrange(1+len(S1))] ## creat 4*5 matrix
longest, x_longest = 0, 0
for x in xrange(1,1+len(S1)): ## read each row
for y in xrange(1,1+len(S2)): ## read each coloumn
if S1[x-1] == S2[y-1]:
M[x][y] = M[x-1][y-1]+1
if M[x][y] > longest:
longest = M[x][y]

Re: [Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-10 Thread delegbede
If you didn't get any error and you were returned to the prompt as you 
mentioned, it means pygame has been successfully imported. 

Try running a pygame command to confirm. If you type pygame at the prompt, it 
should tell you the location of pygame on your system. 

Regards. 
Sent from my BlackBerry wireless device from MTN

-Original Message-
From: Nathaniel Trujillo 
Sender: tutor-bounces+delegbede=dudupay@python.org
Date: Thu, 10 Nov 2011 19:41:54 
To: 
Subject: [Tutor] Okay,
 this time I tried doing a little research but no luck in solving
 this one.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor