Re: [Tutor] re module

2014-08-19 Thread Sunil Tech
Hey thanks Danny Yoo, Chris “Kwpolska” Warrick, D.V.N Sarma
​.

I will take all your inputs.

Thanks a lot.​


On Fri, Aug 15, 2014 at 3:32 AM, Danny Yoo  wrote:

> On Thu, Aug 14, 2014 at 8:39 AM, D.V.N.Sarma డి.వి.ఎన్.శర్మ
>  wrote:
> > I tested it on IDLE. It works.
>
>
> Hi Sarma,
>
>
> Following up on this one.  I'm pretty sure that:
>
> print re.search("
> is going to print something, but it almost certainly will not do what
> Sunil wants.  See:
>
> https://docs.python.org/2/howto/regex.html#greedy-versus-non-greedy
>
> for why.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] howto create virtual environment for Enthought Training on Debian?

2014-08-19 Thread Tom Roche

I'm running a 64-bit flavor of Debian (LMDE) with GNOME, which includes a 
system python and various python-using applets and applications. I have a 
long-standing interest in scientific software, but only recently acquired some 
spare time and an Enthought Training license. So I'd like to get setup to work 
the Enthought Training exercises, which apparently means installing Canopy 
(formerly EPD), possibly et al. However, the last time I tried to do something 
similar (2 years ago? installing EPD), using the provided installer, it whacked 
some system-python-dependent appss.

I therefore want to install Canopy (and whatever else I need to do the 
Enthought Training that is not independently available via debian packages) 
into a virtual environment (so as not to cause problems with dependencies of my 
system python). How to do this? conda? venv? virtualenv? Unfortunately I'm not 
seeing any howto's on Enthought's site[1].

Please reply to me as well as the list: I'm on the digest, which gets huge. 
Alternatively, add your answer to this StackOverflow[2] (which I setup at 
Enthought's apparent recommendation[1]).

TIA, Tom Roche 

[1]: https://support.enthought.com/home
[2]: 
http://stackoverflow.com/questions/25375171/create-virtual-environment-for-enthought-training-on-debian
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-19 Thread Marc Tompkins
On Mon, Aug 18, 2014 at 1:00 AM, Marc Tompkins  wrote:

> Also, looking at the Ninja-IDE website more closely I see that,
> although they do mention compatibility with multiple languages, they
> were designed by and for Python programmers - which makes the
> tab/space issue less likely.  I dunno.

Update: I tried out NinjaIDE myself, and confirmed that copying
four-space indented code from Ninja, then pasting it into a plain-text
compose box in GMail results in flat code/extra newlines; I can only
presume that it's much the same with TBird.  The problem is definitely
not (as I had thought) a space/tab problem; it has something to do
with how Ninja (and GMail, and TBird) deals with the clipboard.

I can copy from Ninja and paste into Notepad++; the indentation is
preserved.  If I then re-copy the same text from Notepad++ and paste
it into the compose box, the indentation is preserved.  But if I go
straight from Ninja to compose - flat!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-19 Thread Mark Lawrence

On 19/08/2014 19:14, Marc Tompkins wrote:

On Mon, Aug 18, 2014 at 1:00 AM, Marc Tompkins  wrote:


Also, looking at the Ninja-IDE website more closely I see that,
although they do mention compatibility with multiple languages, they
were designed by and for Python programmers - which makes the
tab/space issue less likely.  I dunno.


Update: I tried out NinjaIDE myself, and confirmed that copying
four-space indented code from Ninja, then pasting it into a plain-text
compose box in GMail results in flat code/extra newlines; I can only
presume that it's much the same with TBird.  The problem is definitely
not (as I had thought) a space/tab problem; it has something to do
with how Ninja (and GMail, and TBird) deals with the clipboard.



I'm not aware of any problem with Thunderbird or any (semi-)decent mail 
client.  Having said that I can't really comment on gmail but I do know 
that google groups screws up anything and everything that goes near it. 
 That's why https://wiki.python.org/moin/GoogleGroupsPython exists.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-19 Thread Marc Tompkins
On Tue, Aug 19, 2014 at 1:04 PM, Mark Lawrence  wrote:
> I'm not aware of any problem with Thunderbird or any (semi-)decent mail
> client.

The original poster uses NinjaIDE and Thunderbird, and his code was
being persistently flattened when he copied/pasted.  I believe I've
just tracked it down to an incompatibility between the two (which also
happens to extend to Ninja/Gmail.)  I'm not sure how Google Groups
enters into it.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-19 Thread Cameron Simpson

On 19Aug2014 13:29, Marc Tompkins  wrote:

On Tue, Aug 19, 2014 at 1:04 PM, Mark Lawrence  wrote:

I'm not aware of any problem with Thunderbird or any (semi-)decent mail
client.


It may depend a great deal on the source program.


The original poster uses NinjaIDE and Thunderbird, and his code was
being persistently flattened when he copied/pasted.  I believe I've
just tracked it down to an incompatibility between the two (which also
happens to extend to Ninja/Gmail.)  I'm not sure how Google Groups
enters into it.


Your experiment with Notepad suggests that it is pasting "rich" text that may 
be the issue. If you paste from the IDE into Notepad it works and then the text 
from Notepad pastes ok into the others. I am imagining that Notepad is plain 
fixed width text? Or just a better-handled formatting when handed to TBird or 
Gmail/GGroups?


Debugging is not helped by the fact that for some things the GMail/GGroups HTML 
looks ok but the associated plain text version that they generate and send is 
usually awful.


Cheers,
Cameron Simpson 

A ridiculous place!  Leaping from one bump to another, 187 corners or whatever
it was!  The number of times I've thanked God when I finished a lap there!
It gave you amazing satisfaction, no doubt about it, but anyone who says he
loved it is either a liar or wasn't going fast enough!  - Jackie Stewart
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-19 Thread Terry--gmail
The down side of setting the python.org domain to be mailed to as plain 
text, appears to be that Thunderbirdy has changed all my email to plain 
text, instead of just the email going to this domainwhich is weird.


Leam Hall:

I have just one additional function to create in the User Design section 
where the the user designs his own starship, to complete, before I move 
on to the Alien Design section where the computer semi-intelligently and 
randomly designs the unknown Alien ship we are going to meet out in 
interstellar space. That will be in 1 dimensional space to start with. 
You can either try to run away, charge right in and try to match 
relative direction and speed, or sweep in and fly right past the enemy 
blasting away at it. As the program gets worked out, I will alter for 
more dimensionseventually, as I learn graphics. Right now, it is 
about the combat against an unknown enemy of unknown strength and 
capabilities. I figure it's a fun way to acquire pythonic skills and 
manage to remember all the commands possible. It's what I did when I 
first learned BASIC. So...it's going to be traditional with me...


If you want, and if it doesn't violate any rules for this mailing list, 
I could post the User Design section for you to look over to see what my 
basic concepts are, just after I add and test this last section. 
Ultimately, I want this design section to be really easy to add 
additional capabilities to later and it is sort of written for the most 
part that way right nowalthough necessity also requires some custom 
filtering for different catagories of parts - like, you can only 
purchase one Hull for your ship!


( :) I probably wouldn't try to learn my techniques thoughmy python 
skills and vocabulary are a real work in progress and I read so much 
that I am forgetting what I have read. And I have no doubt I have 
probably broken pythonic rules and slaughtered proper methodology to 
high heaven in the layout and implementation. Ha Ha Ha)


But this section does workat least until I discover a bug in some 
untested possible combination of choices. The way I broke it was by 
adding additional functions.


Just let me know if you want me to post it for you to look over.

DaveA:

The bare 'except' was a throw away. By bare 'except' I am assuming you 
mean without defining the type of error 'except' is to act upon?


try:
something
except ValueError:
do something

-Or does bare 'except' mean something else?

Alan Guald:

I have been trying out the different ways you suggested for doing this, 
and have ran into a problem on making the very last one work. I stuck a 
print statement in it to help, but I am not sure what the error 
statement is telling me:


for row in catalog2:
print(row)
for col, item in row:
lens[col].append(len(item))
lens = [max(col) for col in lens]

and I get the following error in 'for col, item in row:'

 'ValueError: too many values to unpack (expected 2)':

I don't see why it would possibly say there are too many values to 
unpack or why it would expect only 2!


Also, the list comprehension you have used on the final line reminds me 
that I would really like to understand comprehensions better. Is there 
some info on the Internet that starts very basic concerning 
comprehensions and explains step by step in complexity how they are 
structured and what the computer is doing?


Just looking at the code setting there inside the list brackets and know 
what the output is going to be, reminds me of a programmed cell of a 
spreadsheetkind of.


Mark Tompkins:

"Does (x) have Buddha-nature?"

In college, in a Psychology of Communications class, I spent a lot of 
time studying, writing about, and contemplating "The Is-ness of IS!"  
Does that count?


I hand typed all of the above code in, except the error portion.

This is pasted from Ninja-IDE and it comes out in smaller letters and is 
impossible to make larger...


for row in catalog2:

for col, item in row:

lens[col].append(len(item))

lens = [max(col) for col in lens]



Mark Lawrence gave me the idea to copy from Ninja-IDE to gedit and then 
copied it from gedit  here:  (actually I saved it in gedit and then 
re-grabbed it with gedit )


for row in catalog2:
print(row)
for col, item in row:
lens[col].append(len(item))
lens = [max(col) for col in lens]

Boy! It looks far better on my page than the straight Ninja-ide paste 
above! And it is now manipulatable, I can enlarge and shrink 
it...whereas, the Ninja paste resists things like trying to delete the 
extra lines of white space below it and I have even saw it collapse to 
flat right before my eyes!


So, I guess the best route is to paste from Ninja to gedit and then to 
my emailassuming this is good on your end.












On 08/19/2014 02:29 PM, Marc Tompkins wrote:

On Tue, Aug 19, 2014 at 1:04 PM, Mark Lawrence  wrote:

I'm not aware of any problem with Thunderbird or any (semi-)decent mail
c

Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-19 Thread Cameron Simpson

On 19Aug2014 16:41, Terry--gmail  wrote:

The bare 'except' was a throw away. By bare 'except' I am assuming you mean 
without defining the type of error 'except' is to act upon?

try:
   something
except ValueError:
   do something

-Or does bare 'except' mean something else?


You're right, it means "except" with no exception type.

The trouble with bare excepts is that they catch every exception, not just the 
one you expected to get. For example, this code:


  x = 1
  y = 2
  z = xx + y

would raise a NameError because "xx" is unknown. To my mind and yours it is 
just a typo, but in a dynamic language like Python this is only detected at 
runtime. If that code were inside a bare try/except then you might spent a very 
long time figuring out what was wrong because you're expecting one kind of 
failure be getting another.


As general practice, the rule of thumb is that you should make "except"s as 
precise as possible and only handle errors you explicitly expect and know what 
to do with.


An example from some of my code:

try:
  arfp = open(arpath)
except OSError as e:
  if e.errno == errno.ENOENT:
arfp = None
  else:
raise

Here I'm catching the expected possibility that the file I'm opening does not 
exist and setting arfp to None. Any other type of problem (permission denied, 
etc) continues on to raise an exception.


While this makes you code fragile in one sense, it prevents it _silently_ 
misinterpreting one thing as another, and that is usually best.


Cheers,
Cameron Simpson 

The aim of AI is to make computers act like the ones in the movies.
- Graham Mann
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-19 Thread Cameron Simpson

On 19Aug2014 16:41, Terry--gmail  wrote:

Alan Guald:

I have been trying out the different ways you suggested for doing 
this, and have ran into a problem on making the very last one work. I 
stuck a print statement in it to help, but I am not sure what the 
error statement is telling me:


for row in catalog2:
   print(row)
   for col, item in row:
   lens[col].append(len(item))
lens = [max(col) for col in lens]

and I get the following error in 'for col, item in row:'

'ValueError: too many values to unpack (expected 2)':

I don't see why it would possibly say there are too many values to 
unpack or why it would expect only 2!


Your for-loop says:

  for col, item in row:

That iterates over each element in "row" and attempts to unpack it into the two 
variables "col" and "item". Presumably the row element has more than two items 
in it. We'd need to see to say.


Try this:

   for element in row:
   print(element)
   col, item = element
   lens[col].append(len(item))

and see what you get.

Cheers,
Cameron Simpson 

Archiving the net is like washing toilet paper! - Leader Kibo
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-19 Thread Cameron Simpson

On 19Aug2014 16:41, Terry--gmail  wrote:

Alan Guald:

[...]

lens = [max(col) for col in lens]

[...]
Also, the list comprehension you have used on the final line reminds 
me that I would really like to understand comprehensions better. Is 
there some info on the Internet that starts very basic concerning 
comprehensions and explains step by step in complexity how they are 
structured and what the computer is doing?


The line above is essentially equivalent to this:

  lens_orig = lens
  lens = []
  for col in lens_orig:
lens.append(max(col))

It just assembles a list of values, each being max(col), for each element in 
lens. The mucking with "lens" and "lens_orig" above is only because you're 
replacing "lens" with the new list.


Just looking at the code setting there inside the list brackets and 
know what the output is going to be, reminds me of a programmed cell 
of a spreadsheetkind of.


It is very like that, if you consider two spreadsheet columns, the first with 
the original values in "lens" and the second having "max(col)" for each.


Cheers,
Cameron Simpson 

ERROR 155 - You can't do that.  - Data General S200 Fortran error code list
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-19 Thread Alan Gauld

On 19/08/14 23:41, Terry--gmail wrote:


Alan Guald:


for row in catalog2:
 print(row)
 for col, item in row:
 lens[col].append(len(item))


My bad, it should have been

for col, item in enumerate(row):

Sorry,

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

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


Re: [Tutor] Building Starships -- object of type 'int' has no len()

2014-08-19 Thread Alan Gauld

On 19/08/14 23:41, Terry--gmail wrote:


Also, the list comprehension you have used on the final line reminds me
that I would really like to understand comprehensions better. Is there
some info on the Internet that starts very basic concerning
comprehensions and explains step by step in complexity how they are
structured and what the computer is doing?


You can try the Functional Programming topic in my tutorial.
Comprehensions start roughly half way down.

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

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


[Tutor] (no subject)

2014-08-19 Thread diliup gabadamudalige
Hi all!

Is there any way I can bundle all my graphics only using Python and Pygame
so that the user may not be able to read them out of the program?
Let us assume that the user does NOT know Python and will not go looking
for people who knows Python to crack the files. In other words an average
user.

1.
I have tried the Zip file method by making a Zip file with Win Rar or
Winzip and password lock the file. But the unpacking is WAY TOO SLOW!

with ZipFile('stuff.zip') as zf:
zf.extract("image.jpg", pwd="123456")

2.
I have used the repr command and written the code to a py file but again
the unpacking is WAY TOO SLOW.

with open(name4pypath,"wb") as outfile:
outfile.write(name4pyfile + "=" + repr(str1))

3.
The best out of the lot has been the one using base64

str1 = base64.b64encode(from_disk.read())
with open(code_to_dir, "ab+") as to_disk:
to_disk.write(str1)

Can anyone show me a better way?

Thanks in advance



-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor