Re: [Tutor] Python

2013-08-18 Thread Wayne Werner

On Thu, 15 Aug 2013, Jake Wohldmann wrote:



Hello I am a beginner to using any type of programming lanhuage  How long
does it take to become fluent at a script? Do you know and good sites to
learn python?  I will only be able to practice python on weekends since
school is starting.  I was also wondering if I could use python on my
android phone.


The official python tutorial is pretty handy - www.python.org

Also if you can install 3rd party APKs, search for the SL4a (Scripting 
Layer for Android). You can install Python3 (recommended - the future of 
Python), or Python2.7 (current version).


Not all 3rd party modules are available for Python3, but most 3rd party modules
aren't available on Android anyway so you wouldn't be missing out too much.

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


Re: [Tutor] 3to2?

2013-04-22 Thread Wayne Werner

On Sun, 21 Apr 2013, Steven D'Aprano wrote:


On 21/04/13 04:32, Jim Mooney wrote:

I was looking at google pengine for python and it only supports 2.7. I've
installed 3 and would rather not go back (I kept doing Print without the
parentheses for awhile and it was really annoying ;')

So the question comes up. If there is a 2to3 script, which I got working,
is there a 3to2 script?. Or does that even makes sense since 3 has features
2 does not, although I read somewhere that many have been backported?


from __future__ import division, print_function

from future_builtins import *


This is the route I recommend, and take myself. Usually I'll do:

from __future__ import print_function, division, unicode_literals

try:
input = raw_input
range = xrange
except NameError:
pass #using python 3 already, whee!


which makes you able to write code that mostly looks to Python3.


You could also look at how Django does their 2/3 support: 
https://www.djangoproject.com/weblog/2012/aug/19/experimental-python-3-support/


Looks like they use the `six` library:
http://pythonhosted.org/six/


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


Re: [Tutor] design question (Django?)

2013-04-18 Thread Wayne Werner

On Sun, 14 Apr 2013, Don Jennings wrote:



On Apr 14, 2013, at 7:06 AM, Albert-Jan Roskam wrote:




 Subject: Re: [Tutor] design question (Django?)


On 13/04/13 09:48, Albert-Jan Roskam wrote:


I think I have to make a diagram of this. This stuff is quite hard



Would it also be a good idea to simultaneously make a paper-and-pencil drawing 
of the UI?


Absolutely! Test it with three users. See Jakob Nielsen's brief take on the 
matter:



A recommendation - check out Balsamiq Mockups for UI design. If you plan 
to make this project open source they'll provide you a free license (with 
a bit of documentation, e.g. link to project on Bitbucket/Github/etc with 
a OSI approved license).


They also have a free web demo that's pretty powerful and just nags every 
5 (or 15?) minutes. http://www.balsamiq.com/


I've not found a better tool for doing quick and rough UI mockps!

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


Re: [Tutor] Guidance if possible

2013-04-12 Thread Wayne Werner

On Fri, 12 Apr 2013, Alan Gauld wrote:


On 11/04/13 23:33, Scurvy Scott wrote:


the other for something like this. I have no intention of doing
anything professional/shady/annoying with this code and want to write
it purely for my own amusement as well as to learn and obviously to
perhaps win something cool.


Seems reasonable to me.

Try looking at the http, urllib and cookie stuff in the stdlib.


Ick httplib/urllib - if you want to write code for getting information off 
a website, the 
requests module is the way to go:


http://docs.python-requests.org/en/latest/

It makes http requests pretty trivial.

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


Re: [Tutor] Looks like a judgment bug.

2013-04-11 Thread Wayne Werner

On Thu, 11 Apr 2013, Timo wrote:


Op 11-04-13 12:41, w qj schreef:

I found this under Windows Python3

l=http://f/;
l[-1] is not '/'

False
and this under Linux Python3

l = http://ff.f/;
l[-1]

'/'

l[-1] is not '/'

True

It's Looks like a python bug?
This looks like a is not versus != thing. Someone (I think Steven 
Apprano) posted a couple of days ago on this mailing list to only use is 
and is not when comparing to None.


You're absolutely correct.

`is` compares the identity (basically id('/') == id('/') )

*sometimes* CPython will use a trick that caches smaller strings, so this 
might work one time:


 x = '/'
 y = '/'
 x is y
True

But then the next time you do the same thing it could return False. Or on 
a different OS. There's nothing (that I'm aware of) that will guarantee 
either result in this case.


In the example case we were comparing that `l[-1]` referred to the same 
spot in memory as the literal string `/`. And as the example showed, 
sometimes it will be, other times it won't.



The takeaway is to use `is` when you want to compare identity, and `==` 
when you want equaltiy. For example,


   That car is *my* car.

The car I'm referring to is one specific car. But if I were to say...

   My car is a Chevette.

That would be more like saying `car.model == 'Chevette'` - many different 
cars may actually be a Chevette.


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


Re: [Tutor] Code to open a website

2013-02-09 Thread Wayne Werner

On Sat, 9 Feb 2013, mann kann wrote:


Dear Jedi, 
I wrote my first program but it doesn't open a website as I intended it to.
Please correct my mistake. 

Sincerely, 
Mann


You'll actually want the webbrowser module, which will open the links in 
your web browser - at least if you want to load sites like YouTube.


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


Re: [Tutor] running multiple versions of python

2013-01-12 Thread Wayne Werner

On Thu, 10 Jan 2013, Fowler, Trent wrote:

I am running Windows 7 and I've installed two versions of python, 3.3 and 2.7. 
Python 3.3 was the first version I installed and I was able to run scripts from 
the desktop (not the command line). I installed python 2.7 so that I could get 
numpy, scipy, and matplotlib down the road, but I found that all the scripts on 
my desktop defaulted to python 2.7. Since I coded in 3.3 this caused some 
issues.

I was able to fix this by right clicking the script icon, browsing programs, 
navigating to the python 3.3 file in my C: drive, and selecting the idle inside 
that directory. But then I found I wasn't able to run those scripts with python 
2.7 using the exact same procedure.

Unfortunately I don't know command-line programming very much at all, and it 
seemed like most of what I've seen online is geared towards that as a solution. 
Ideally I'd like to specify which python I want to run a script from the 
desktop, or possibly while I'm editing the script.


I basically have this same setup. To make things work for me, I do this:

- Go to your Python 2 directory ( probably C:\Python2.7 ) and rename
  python.exe to python2.exe and pythonw.exe to pythonw2.exe

- Make sure that both your Python 2 directory and Python 3 directories are on
  your path. You do this by opening the Start Menu and typing Path - then hit
  enter. You should have an environment variable called PATH - if not, create a
  new one. You'll want to make sure that you have the paths to Python 3 and 2
  in there. Assuming you've got C:\Python3.3 and C:\Python2.7, you'd want to
  have a path that contains C:\Python3.3;C:\Python2.7;

Now if you run a python script from cmd or powershell you should be able to do:

C:\some\path python2 a_matplot_program.py

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


Re: [Tutor] writing effective unittests

2013-01-09 Thread Wayne Werner

On Thu, 3 Jan 2013, Japhy Bartlett wrote:


The general idea is to write tests that use your code in realistic ways and 
check the results.  So if you have a function that takes an input and returns
a result, you write a test that passes that function an input checks the 
result.  If some inputs should make it error, you write a test that checks that
it errors.
In web programming, a common thing is to make a web request with different 
variations of GET / PUT params, then check that it returns the right status
code, or that the result is valid JSON, etc.  Basically, try to simulate all 
the things a real world user would be able to use, and test that your code
does what you intend for it to do.

TDD is a good principle but usually seems a little too pedantic for real world 
programming.  Where tests (in my experience) get really useful is in
making sure that a new change hasn't unexpectedly broken something already 
written.


That's funny, I find it exactly the opposite - unless I'm writing some 
prototype throw-away code, doing TDD has actually exposed problems with 
the underlying program structure precisely because it *is* pedantic.


Granted, if I needed to get a fix in place in production code that was 
costing buckets of cash every minute it wasn't fixed, I'd write the code, 
push that out, and *then* write the tests... but when I've been practicing 
TDD I've not had that problem.


My experience is that it has a tendency to bundle all the development 
costs right up front - instead of a little here, a little there.



But... that's just my experience ;)
-Wayne___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] IronPython any tutors with experience out there?

2013-01-06 Thread Wayne Werner

On Thu, 3 Jan 2013, Bjorn Madsen wrote:


Hello PythonTutor- I'm a scientist and very happy with python 2.7. I have been 
asked to assist a development program where everything is written in dotNET/
C# (visual studio 2012) and luckily Microsoft Visual Studio supports IronPython 
which is a clean Python implementation in C#, so I can use the Python
syntax I'm so familiar with... 

However ... to interact with the c# modules which my colleagues wrote, I need to add 
clr references.

Example:
 import clr
 clr.AddReferenceToFile(Mapack.dll)
 from Mapack import *
 dir()

Unfortunately I can't get it to run and the tutorials after 12 hours of 
google-reading are terribly sparse. Is there any experience somewhere in the
network with IronPython in VSTO-2012 in this forum and what could the top five 
clr.addreference bugs be?


Assuming everything else checks out... what you have to import is the namespace
of whatever the .dll is. So if it was compiled with a root namespace of say,

Fizz.Buzz.Foo

Then you'll have to do:

from Fizz.Buzz.Foo import *

Though, I've never tried that version. I always did

import Fizz.Buzz.Foo as foo

in my own code.
HTH,
Wayne___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Recommended texts for self-study to master software engineering?

2012-12-15 Thread Wayne Werner

On Fri, 14 Dec 2012, boB Stepp wrote:


This is obviously not a directly python-related question; however, I
do believe that it would be of interest to many aspiring programmers
who are diligently learning python on their own.

So, through self-study, I would like to be able to acquire the
knowledge I would need to become a competent designer and programmer,
using good software engineering practices. Now I could go online and
look at typical courses taken by those pursuing software engineering
or computer science degrees and even come up with the textbooks that
such courses use. But I would have no idea of how well-suited such
textbooks would be for self-study. So my question is what would be a
sequence of books to acquire the knowledge I would need that are
especially well-suited to self-study? I may be asking for the
unanswerable, but I am hoping to be pointed to some good texts for my
future studies.


Rather than simple self-study, why not take advantage of the offerings by 
such folks as Coursera, Edx, or Kahn Academy?


They all have free courses in programming and software development that 
require a large degree of self-motivation (after all, you didn't pay 
anything for it so you don't have the same drive as regular college), but 
it has the added benefit of hundreds, perhaps thousands of other active 
participants who are also learning at the same time.


*Most* of the Python books that I've read are at least as well-suited to 
self study as any of the rest of them. Although, my own personal 
experience is that contributing to this list has done more to help me 
really understand the basics of Python and development than anything else.


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


Re: [Tutor] Tutor Digest, Vol 106, Issue 5

2012-12-04 Thread Wayne Werner

On Tue, 4 Dec 2012, Steven D'Aprano wrote:


On Mon, Dec 03, 2012 at 05:56:30PM -0600, Luke Paireepinart wrote:


I just wanted to make the observation that, at least in gmail, the default
behavior is to hide the entire quoted text behind an innocuous ...
button.


Good lord, the more I hear about Gmail, the more horrible I discover it
to be. Why does anyone use this crappy, anti-social product?


Because it didn't use to suck.

Also protip: you can use insert better client here with gmail. Like 
alpine ;)


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


Re: [Tutor] I am learning python3 and would like some more python3 modules/programs on my...

2012-10-15 Thread Wayne Werner

On Tue, 9 Oct 2012, Prasad, Ramit wrote:


You can even think about switching later if necessary. Although, it is probably 
easier to
go from 2 to 3 due to the existence of automated conversion tools.


There is actually a python 3to2.py script now. And if you pick up Python 3 
you'll have much less problems because you'll develop the correct mental 
model for dealing with strings/bytes, so if you *do* do any Python 2 work, 
then n problem.


Unless you're using Django or one of the other big packages, my 
recommendation is always to pick up Python3, with the caveat that many of 
the tutorials will be Python 2 oriented, so if they run into problems, 
they should ask a question here. Plus, there will be no Python 2.8. Sure, 
people are still developing tools in Python 2.x, but more and more are 
migrating to 3.x, and *many* of the larger packages are Python 3 
compatible.


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


Re: [Tutor] Through a glass, darkly: the datetime module

2012-10-07 Thread Wayne Werner

On Sun, 7 Oct 2012, Steven D'Aprano wrote:


It is a little-known fact that Unix sys admins, and C programmers, can
only type a fixed number of keys before their brains explode. Sad but
true. Since nobody knows how many keys that will be, but only that it is
fixed at birth, they have a horror of typing four characters when two
would do.


lol. I really did, too!

+1

(I think this might apply to COBOL programmers, too.)
-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Lotka-Volterra Model Simulation Questions

2012-09-29 Thread Wayne Werner

On Sat, 29 Sep 2012, Oscar Benjamin wrote:

On Sep 29, 2012 2:25 AM, Alan Gauld alan.ga...@btinternet.com wrote:

 On 28/09/12 21:32, Jim Apto wrote:

 I'm relatively new to python, and was asked to program a lotka-volterra
 model (predator and prey relation) simulator.


 x represents prey population
 y represents predator population


 so use names that say so, like preyPop and predatorPop
 Its only a few extra letters typing but makes things much more readable.

As a mathematician I'd have to disagree with you there Alan. This model
already has an established notation:


Regardless of established notation, unless only mathematicians will be reading
the code, and only those intimately familiar with the equation, it makes much
more sense to use meaningful names. Because that way, when sending the code to
a mailing list full of non-mathematician programmers, they'll know exactly what
the variables are supposed to be for, so they wont have to look anything up on
wikipedia. After all, they've got a finite amount of volunteer time, and would
you prefer to get more advice about logic errors, or the guarenteed responses
about variable names?

I for one, prefer to get the most value from my question as possible. It shows
respect to the people I'm asking, and to everything else that they could
possibly be spending their time on, including answering other questions.

Respectfully-and-somewhat-tongue-in-cheekily,
Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Lotka-Volterra Model Simulation Questions

2012-09-29 Thread Wayne Werner

On Sat, 29 Sep 2012, Wayne Werner wrote:


On Sat, 29 Sep 2012, Oscar Benjamin wrote:

On Sep 29, 2012 2:25 AM, Alan Gauld alan.ga...@btinternet.com wrote:

 On 28/09/12 21:32, Jim Apto wrote:

 I'm relatively new to python, and was asked to program a lotka-volterra
 model (predator and prey relation) simulator.


 x represents prey population
 y represents predator population


 so use names that say so, like preyPop and predatorPop
 Its only a few extra letters typing but makes things much more readable.

As a mathematician I'd have to disagree with you there Alan. This model
already has an established notation:


Regardless of established notation, unless only mathematicians will be 
reading

the code, and only those intimately familiar with the equation, it makes much
more sense to use meaningful names.


And lest I sound like I'm completely ignoring the mathematical aspect - 
what *does* make sense to do is this:


x = prey_popluation
y = pred_population

# insert mathematical formula here.

This satesfies all parties:

1) It gives us programmers nice, meaningful names
2) It gives mathematicians the formula that screams FORMULA!
3) It clearly separates the math-y bits from the program-y bits.

Because let's face it,

x = float(input(Starting Prey Population: ))

isn't exactly something you find in (most) math classes. And I think 
clearly separating concerns is always a good thing.


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


Re: [Tutor] OT: Netiquette

2012-09-28 Thread Wayne Werner

On Fri, 28 Sep 2012, Bod Soutar wrote:


On Sep 28, 2012 4:47 AM, Dwight Hutto dwightdhu...@gmail.com wrote:
 Yeah, all up in my fucking cranium with nothing but me and God to hold
 on  to one another.

 --
 Best Regards,
 David Hutto
 CEO: http://www.hitwebdevelopment.com

Probably not a good idea to advertise that your the CEO of 
hitwebdevelopment.com if your gonna post like that.

Bodsda


That's OK, if you don't like that sort of attitude you're obviously not in 
his target market (the one that enjoys was it 60MB GIF files, and 
background music).


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


Re: [Tutor] Lotka-Volterra Model Simulation Questions

2012-09-28 Thread Wayne Werner

On Fri, 28 Sep 2012, Jim Apto wrote:


Hello folks,
I'm relatively new to python, and was asked to program a lotka-volterra model 
(predator and prey
relation) simulator.  The program basically will basically have a menu that 
takes user input, collect
data, and then create a graph.  Currently i've been working on the simulator 
section; I can't seem to
get the lists right.  I've assigned the following variables and parameters to 
the model for the program:


I don't know anything about the Lotka-Volterra model, but I've definitely 
got some recommendation



x represents prey population
y represents predator population
dy/dt and dx/dt represents growth rate of the two populations over time
t represents time

a is the growth rate of prey
b is the rate at which predators kill prey
g is the death rate of predators
d is the rate at which the predators population increases by consuming prey

The equation:
dx/dt = x(a-by)
dy/dt = -y(g-dx)

The code I have for this section is:
def deltaX(a,b,x,y):
    dx = x*(a-b*y)

def deltaY(g,d,x,y):
    dy = -y*(g-d*x)

The simulation function is where I am having trouble.

For the simulation function, I need to ask the user for the number of runs and 
then save it in a
variable, create a list for prey and predator.  For each run, i need to 
calculate the increment of
change in prey and predator populations by calling the deltaX and deltaY 
functions, then save these in a
variable, and then update the population information.  The newly calculated 
populations then need to be
added to the existing lists.  After this is completed, a function for the graph 
is called.

The following is my current simulation function:

def simulation():
    a=eval(input(Growth rate of prey:))
    b=eval(input(Rate at which predators eat prey:))
    g=eval(input(Death rate of predators:))
    d=eval(input(Rate at which predators increase by consuming prey:))
    x=eval(input(Current prey population:))
    y=eval(input(Current predator population:))



Woah! Stop that right now - eval is an *incredibly* dangerous function. If 
you want to convert these numbers to integer or float, there's the int() 
and float() function. Additionally, single letter variables are really 
horrible. You could do:


prey_growth_rate = float(input(Growth rate of prey: ))
predator_consumption_rate = #your code here
predator_death_rate = ...
predator_growth_rate = ...
initial_prey_population = ...
initial_predator_population = ...


deltaX(a,b,x,y)
deltaY(g,d,x,y)


I don't see where you defined deltaX or deltaY...



n=eval(input(Number of runs:)
    r = 0
    count=0
    yList = [0]
    while r = n:
        r = r + 1
        count = count + 1
        yList.append(dx + dx)

    zList= [0]
       while r = n:
       r = r + 1
       count = count +1
       zList.append(dy + dy)

It seems terribly wrong.  The following is my graph function:

def drawCurve(yList,zList,n):
    x = pylab.arange(n)
    pylab.title(Foxes and Rabbits)
    pylab.ylabel(Number of predator (Foxes))
    pylab.xlabel(\nNumber of prey  (Rabbits))
    pylab.plot(x, yList, 'b') 
    pylab.plot(x, zList, 'r')
    pylab.legend(('Rabbits','Foxes'),loc='upper left')
    pylab.show()

The issue i'm having is the logic in the lists.  How can I create the 
simulation function using lists
and make it perform the expected task of creating a graph?  I can't seem to get 
the logic right.


Posting an image of what you expect, and what you got instead to imgur or 
some other free hosting site would be a good thing to do.


When asking a question you should always post what you wanted to happen, 
and what happened instead.


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


Re: [Tutor] help me decide

2012-09-05 Thread Wayne Werner
 a certain way to do things and you don't really have a 
choice if you'd like to do it different.


Python is an enabling language - which in my words means it's a 
language that gets out of your way. My experience is that when I write 
Python code I can express the solution to a problem the way I want to. If 
it's easier to express the solution in an OOP way, I can do that. If it's 
easier to express procedurally, or even functionally, I can do that too.


Which meant that it's easier to just get stuff done. I don't have to worry 
about how I can shoehorn the problem into something that the language can 
solve - I can just solve it.


So I find great joy in writing Python code, and encourage everyone to 
learn it.


My recommendation for you would be to learn some OOP basics, and once you 
feel comfortable around objects start learning Tkinter. Unless you really 
want to do some web programming, in which case, do that ;)


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


Re: [Tutor] running more than one python program at the same time

2012-09-04 Thread Wayne Werner

On Mon, 3 Sep 2012, William R. Wing (Bill Wing) wrote:

junk = raw_input(Yes Master?)


You don't even need the 'junk' bit:

raw_input(Yes Master?)

Will run just fine.

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


Re: [Tutor] making a shortcut in windows

2012-09-04 Thread Wayne Werner

On Tue, 4 Sep 2012, Garry Willgoose wrote:


Oscar,

I actually just want the functionality of a shortcut so that I can put an
icon on the desktop. symlink allows that in Unix (and a few other
capabilities that I'm not that intersted in) and just want something
equivalent to the menu item for making a shortcut in Windows. 


At least in Windows 7+, you can use the mklink command (as administrator):

import subprocess
subprocess.check_call(['mklink',
   '/D', #Use /H for a hard link
   '\users\yourname\desktop\yourfile.txt',
   '\path\to\yourfile.txt'])

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


Re: [Tutor] Why begin a function name with an underscore

2012-09-01 Thread Wayne Werner

On Thu, 30 Aug 2012, Steven D'Aprano wrote:


On 28/08/12 21:24, Wayne Werner wrote:

On Mon, 27 Aug 2012, Richard D. Moores wrote:



What the best way to test if something's an integer?


try:
whatever_you_want(supposed_integer)
except ValueError:
print(Oops, that wasn't an integer! Please try again)

That's usually the best way...


Actually, that's close to the worst way, since you take a nice, useful
exception which prints a traceback showing exactly what went wrong, and
replace it with a pointless, silly message which can't be caught by the
caller.

Trying again may be impossible, or inappropriate, and certainly isn't
up to the function to make that decision, that's up to the caller to
decide what is the appropriate response to invalid data.


I suppose I should've replaced the print() call with

# Whatever recovery/handling code you need here

My intention was to remove the bit about checking for an integer away from 
the spot that was checking it, out into an exception handler where it 
belongs.


I was also under the (mistaken?) impression that the use case was an 
interactive type call, and used something like:


supposed_integer = raw_input(Please enter an integer: )

# exception handling here



But yes, if you're writing code that is meant to be called by someone else 
then that code is horrible, and exactly the wrong pattern to follow.


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


Re: [Tutor] using multiprocessing efficiently to process large data file

2012-09-01 Thread Wayne Werner

On Thu, 30 Aug 2012, Abhishek Pratap wrote:


Hi Guys

I have a with few million lines. I want to process each block of 8
lines and from my estimate my job is not IO bound. In other words it
takes a lot more time to do the computation than it would take for
simply reading the file.

I am wondering how can I go about reading data from this at a faster
pace and then farm out the jobs to worker function using
multiprocessing module.

I can think of two ways.

1. split the split and read it in parallel(dint work well for me )
primarily because I dont know how to read a file in parallel
efficiently.
2. keep reading the file sequentially into a buffer of some size and
farm out a chunks of the data through multiprocessing.


As other folks have mentioned, having at least your general algorithm 
available would make things a lot better.


But here's another way that you could iterate over the file if you know 
exactly how many  you have available (or at least a number that it's 
divisible by):


with open('inputfile') as f:
for line1, line2, line3, line4 in zip(f,f,f,f):
# do your processing here

The caveat to this is that if your lines aren't evenly divisible by 4 then 
you'll loose the last count % 4 lines.


The reason that this can work is because zip() combines several sequences 
and returns a new iterator. In this case it's combining the file handles 
f, which are themselves iterators. So each successive call to next() - 
i.e. pass through the for loop - next() is successively called on f. The 
problem of course is that when you reach the end of the file - say your 
last pass through and you've only got one line left. Well, when zip's 
iterator calls next on the first `f`, that returns the last line. But 
since f is now at the end of the file, calling next on it will raise 
StopIteration, which will end your loop without actually processing 
anything on the inside!


So, this probably isn't the best way to handle your issue, but maybe it 
is!


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


Re: [Tutor] Why begin a function name with an underscore

2012-08-28 Thread Wayne Werner

On Mon, 27 Aug 2012, Richard D. Moores wrote:


On Mon, Aug 27, 2012 at 6:33 PM, Japhy Bartlett ja...@pearachute.com wrote:


something like:

def _validate_int(obj):
Raise an exception if obj is not an integer.
m = int(obj + 0)  # May raise TypeError.
if obj != m:
raise ValueError('expected an integer but got %r' % obj)


is a really awkward way to test if something's an integer, and checking
types in general is usually a sign of larger flaws in laying out useful
code.


What the best way to test if something's an integer?


try:
whatever_you_want(supposed_integer)
except ValueError:
print(Oops, that wasn't an integer! Please try again)

That's usually the best way...

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


Re: [Tutor] Script won't run for no apparent reason

2012-08-10 Thread Wayne Werner

On Fri, 10 Aug 2012, Dave Angel wrote:


On 08/10/2012 03:53 PM, Joel Goldstick wrote:

snip

The clue was actually in his code.  See his shebang line -- he's using
Python 3.  So the error is on the data that the user inputs.
The other clue, that I noticed, was that his innermost error was on line
1, called from input().
Anyway, the cure is to use raw_input() everywhere instead.


Or alternatively, if you want to write forward-looking code:

try:
input = raw_input
except NameError:
pass # since we're using python 3+

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


Re: [Tutor] suggestion for an editor

2012-07-20 Thread Wayne Werner



On Fri, 20 Jul 2012, Steven D'Aprano wrote:


Bala subramanian wrote:

Friends,
At present i write programs using vi editor. I am interested to change to
something else. My specific need is that i want to select a portion/small
segment of my program (for eg. a nested loop) and then monitor processing
time it takes for that portion while i run the program. By this i hope to
find the segment that takes time and modify to achieve better speed. Can
someone please share their experience.


I don't think that what you want exists. As far as I know, even full-featured 
IDEs (Integrated Development Environments) don't include profiling of 
selected sections of code.


It *would* be possible with a programmers editor (like Vim/Emacs) to write 
a macro or some type of extension to mark a block of code and have it 
profiled for you. But this would most likely consist of taking the exising 
code, finding the place where it's called in your application, and 
replacing that with a call through timeit, executing the app, and then 
removing the code (or do that in a temp file).


But you could also write a fairly simple Python script to do that for you, 
without any type of IDE integration.


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


Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Wayne Werner

I'll preface my response by saying that I know/understand fairly little about
it, but since I've recently been smacked by this same issue when converting
stuff to Python3, I'll see if I can explain it in a way that makes sense.

On Wed, 18 Jul 2012, Jordan wrote:


OK so I have been trying for a couple days now and I am throwing in the
towel, Python 3 wins this one.
I want to convert a string to binary and back again like in this
question: Stack Overflow: Convert Binary to ASCII and vice versa
(Python)
http://stackoverflow.com/questions/7396849/convert-binary-to-ascii-and-vice-versa-python
But in Python 3 I consistently get  some sort of error relating to the
fact that nothing but bytes and bytearrays support the buffer interface
or I get an overflow error because something is too large to be
converted to bytes.
Please help me and then explian what I am not getting that is new in
Python 3. I would like to point out I realize that binary, hex, and
encodings are all a very complex subject and so I do not expect to
master it but I do hope that I can gain a deeper insight. Thank you all.


The way I've read it - stop thinking about strings as if they are text. The
biggest reason that all this has changed is because Python has grown up and
entered the world where Unicode actually matters. To us poor shmucks in the
English speaking countries of the world it's all very confusing becaust it's
nothing we have to deal with. 26 letters is perfectly fine for us - and if we
want uppercase we'll just throw another 26. Add a few dozen puncuation marks
and 256 is a perfectly fine amount of characters.

To make a slightly relevant side trip, when you were a kid did you ever send
secret messages to a friend with a code like this?

A = 1
B = 2
.
.
.
Z = 26

Well, that's basically what is going on when it comes to bytes/text/whatever.
When you input some text, Python3 believes that whatever you wrote was encoded
with Unicode. The nice thing for us 26-letter folks is that the ASCII alphabet
we're so used to just so happens to map quite well to Unicode encodings - so
'A' in ASCII is the same number as 'A' in utf-8.

Now, here's the part that I had to (and still need to) wrap my mind around - if
the string is just bytes then it doesn't really matter what the string is
supposed to represent. It could represent the LATIN-1 character set. Or
UTF-8, -16, or some other weird encoding. And all the operations that are
supposed to modify these strings of bytes (e.g. removing spaces, splitting on a
certain character, etc.) still work. Because if I have this string:

9 45 12 9 13 19 18 9 12 99 102

and I tell you to split on the 9's, it doesn't matter if that's some weird
ASCII character, or some equally weird UTF character, or something else
entirely. And I don't have to worry about things getting munged up when I try
to stick Unicode and ASCII values together - because they're converted to bytes
first.

So the question is, of course, if it's all bytes, then why does it look like
text when I print it out? Well, that's because Python converts that byte stream
to Unicode text when it's printed. Or ASCII, if you tell it to.

But Python3 has converted all(?) of those functions that used to operate on
text and made them operate on byte streams instead. Except for the ones that
operate on text ;)



Well, I hope that's of some use and isn't too much of a lie - like I said, I'm
still trying to wrap my head around things and I've found that explaining (or
trying to explain) to someone else is often the best way to work out the idea
in your own head. If I've gone too far astray I'm sure the other helpful folks
here will correct me :)

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


Re: [Tutor] Problem When Iterating Over Large Test Files

2012-07-19 Thread Wayne Werner

Just a few notes...

On Wed, 18 Jul 2012, Ryan Waples wrote:
snip


import glob

my_in_files = glob.glob ('E:/PINK/Paired_End/raw/gzip/*.fastq')

for each in my_in_files:
#print(each)
out = each.replace('/gzip', '/rem_clusters2' )
#print (out)
INFILE = open (each, 'r')
OUTFILE = open (out , 'w')



It's slightly confusing to see your comments left-aligned instead of with the
code they refer to. At first glance it looked as though your block ended here,
when it does, in fact, continue.


# Tracking Variables
Reads = 0
Writes = 0
Check_For_End_Of_File = 0

#Updates
print (Reading File:  + each)
print (Writing File:  + out)

# Read FASTQ File by group of four lines
while Check_For_End_Of_File == 0:


This is Python, not C - checking for EOF is probably silly (unless you're
really checking for end of data) - you can just do:

for line in INFILE:
ID_Line_1 = line
Seq_line = next(INFILE) # Replace with INFILE.next() for Python2
ID_Line_2 = next(INFILE)
Quality_Line = next(INFILE)



# Read the next four lines from the FASTQ file
ID_Line_1   = INFILE.readline()
Seq_Line= INFILE.readline()
ID_Line_2   = INFILE.readline()
Quality_Line= INFILE.readline()

# Strip off leading and trailing whitespace characters
ID_Line_1   = ID_Line_1.strip()
Seq_Line= Seq_Line.strip()
ID_Line_2   = ID_Line_2.strip()
Quality_Line= Quality_Line.strip()



Also, it's just extra clutter to call strip like this when you can just tack it
on to your original statement:

for line in INFILE:
ID_Line_1 = line.strip()
Seq_line = next(INFILE).strip() # Replace with INFILE.next() for Python2
ID_Line_2 = next(INFILE).strip()
Quality_Line = next(INFILE).strip()


Reads = Reads + 1

#Check that I have not reached the end of file
if Quality_Line == :
#End of file reached, print update
print (Saw  + str(Reads) +  reads)
print (Wrote  + str(Writes) +  reads)
Check_For_End_Of_File = 1
break


This break is superfluous - it will actually remove you from the while loop -
no further lines of code will be evaluated, including the original `while`
comparison. You can also just test the Quality_Line for truthiness directly,
since empty string evaluate to false. I would actually just say:

if Quality_Line:
#Do the rest of your stuff here



#Check that ID_Line_1 starts with @
if not ID_Line_1.startswith('@'):
print (**ERROR**)
print (each)
print (Read Number  + str(Reads))
print ID_Line_1 + ' does not start with @'
break #ends the while loop

# Select Reads that I want to keep
ID = ID_Line_1.partition(' ')
if (ID[2] == 1:N:0: or ID[2] == 2:N:0:):
# Write to file, maintaining group of 4
OUTFILE.write(ID_Line_1 + \n)
OUTFILE.write(Seq_Line + \n)
OUTFILE.write(ID_Line_2 + \n)
OUTFILE.write(Quality_Line + \n)
Writes = Writes +1


INFILE.close()
OUTFILE.close()


You could (as long as you're on 2.6 or greater) just use the `with` block for
reading the files then you don't need to worry about closing - the block takes
care of that, even on errors:

for each in my_in_files:
out = each.replace('/gzip', '/rem_clusters2' )
with open (each, 'r') as INFILE, open (out, 'w') as OUTFILE:
for line in INFILE:
# Do your work here...


A few stylistic points:
ALL_CAPS are usually reserved for constants - infile and outfile are perfectly
legitimate names.

Caps_In_Variable_Names are usually discouraged. Class names should be CamelCase
(e.g. SimpleHTTPServer), while variable names should be lowercase with
underscores if needed, so id_line_1 instead of ID_Line_1.

If you're using Python3 or from __future__ import print_function, rather than
doing OUTFILE.write(value + '\n') you can do:

print(value, file=OUTFILE)

Then you get the \n for free. You could also just do:

print(val1, val2, val3, sep='\n', end='\n', file=OUTFILE)

The end parameter is there for example only, since the default value for end is
'\n'


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


Re: [Tutor] suggestion for an editor

2012-07-19 Thread Wayne Werner

On Thu, 19 Jul 2012, Bala subramanian wrote:


Friends,
At present i write programs using vi editor. I am interested to change to 
something else. My specific need is that i want to select a portion/small 
segment of my
program (for eg. a nested loop) and then monitor processing time it takes for 
that portion while i run the program. By this i hope to find the segment that 
takes
time and modify to achieve better speed. Can someone please share their 
experience.


I'm not sure how vi has anything to do with the speed of your program(!)

For performance measurements you should look into the Timeit module. How 
long does it take your program to run currently? After all, premature 
optimisation is the root of all evil...



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


Re: [Tutor] passing global variable as argument.

2012-07-16 Thread Wayne Werner

On Mon, 16 Jul 2012, Bala subramanian wrote:


Friends,
I want to define a function that can populate an array by taking its name
(which is defined globally).


Are you sure this is what you really want to do? I've noticed that many times
that I want to do something, but only because I don't understand how to do it a
better way.


I defined two empty arrays as follows and a
function that can populate the array.

REF_F1=np.array([])
REF_F2=np.array([])

# populating the given array
def ref(ln,REF_F1):
   global REF_F1


My command of the global syntax is a little weak, but I'm going to say what is
probably happening with this line is that you are telling python you now want
to refer to the REF_F1 that lives in the global namespace, not the one that was
passed in to your function.


   REF_F1=np.zeros((ln,3),dtype='float32')


This line here tells me that what I mentioned first is correct. You don't care
*what* the array is before hand, because you're actually zeroing the array.
Read the conclusion below.


   for i in range(ln):
   for j in range(3):
  REF_F1x[i,j]=resid[Index[i]].cent()[j]


I'm not sure what `resid` or `Index` are. Also, REF_F1x wasn't defined anywhere
so you're probably getting a name error here. When sending code, especially
misbehaving code, the best thing to do is provide a SMALL, but complete
program that can be run on its own, as long as one has the dependencies.



ref(ln, REF_F2)

In this case, when i pass REF_F2 as argument, the fn. always populates
array REF_F1. I also tried something like the following
*def ref(ln,x=REF_F1)* and then calling as *ref(ln,x=REF_F2)*. The result
is the same. Could someone please give me hint on how pass global variables
as arguments.


First off, the whole point of global variables are so that you don't have to
pass them as arguments. This is fine, and there are occasions where you
legitimately want to have a global variable - but this isn't one of them. When
you use globals improperly, they cause maintenance nightmares by making it
really hard to figure out what's going on in your code. At least Python
requires you to explicitly state that you care about some global value with the
global keyword.

But in this case it looks like you don't actually care about the original array
- you're completely replacing the values based on whatever the value of `ln`
  is. So instead you could do something like

def initialize_array(ln):
new_array = np.zeros((ln,3),dtype='float32')
for i in range(ln):
for j in range(3):
   new_array[i,j]=resid[Index[i]].cent()[j]
return new_array

And then you would call it like this:

REF_F2 = ref(ln)

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


Re: [Tutor] newbie Questions

2012-07-16 Thread Wayne Werner


On Mon, 16 Jul 2012, Walter Prins wrote:


Hi again Matthew,

I forgot to include the following link which I originally thought to
include, which is one guy's set of (IMHO very cogent) criticisms
against PHP as programming language:  http://is.gd/z1POXC  Hopefully
it gives you something else to think about regarding the PHP vs Python
question apart from just whether doing websites in it is easy.



I read that article recently and recommend it as well. I used to
think that PHP was just fine... but since reading that article (and 
several related ones), I've since revised my opinion.


I would now tell someone to learn any language besides php.

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


Re: [Tutor] str object is not callable

2012-07-10 Thread Wayne Werner

On Wed, 11 Jul 2012, Steven D'Aprano wrote:


Chris Hare wrote:
Okay - I am officially embarrassed. 

[...]


Meh, don't beat yourself up too badly. We've all been where you are now. 
Sometimes I look back at my early Python code... I tell you, that's always a 
good antidote for a big head.


I read a marvelous quote today:

Good code is anything I wrote today. Bad code is anything I wrote more 
than a week ago.


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


Re: [Tutor] updating step size while in loop

2012-07-09 Thread Wayne Werner

While you can't do it with a straight generator, you can create your own:

class MyIter:
def __init__(self, start, stop, step=1):
self.start = start
self.stop = stop
self.step = step
def __iter__(self):
self.cur = self.start
while self.cur  self.stop:
yield self.cur
self.cur += 1

And then you could do the following:
In [36]: i = MyIter(1, 10)

In [37]: for x in i:
   : if x % 2:
   : i.cur += 1
   : print(x)
   :
1
3
5
7
9

-HTH,
Wayne

On Tue, 10 Jul 2012, Hugo Arts wrote:


On Mon, Jul 9, 2012 at 11:59 PM, Abhishek Pratap abhishek@gmail.com
wrote:
  hey guys

  I want to know whether it is possible for dynamically update the
  step
  size in xrange  or someother slick way.

  Here is what I am trying to do, if during a loop I find the x in
  list
  I want to skip next #n iterations.


  for x in xrange(start,stop,step):
      if x in list:
           step = 14
      else:
           step = 1



  Thanks!
  -Abhi


It is not possible with a range object. You'll have to make a while loop and
keep track of the step yourself.

Hugo

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


Re: [Tutor] Simple Python Address Book (Advice welcome!)

2012-06-17 Thread Wayne Werner


On Sun, 17 Jun 2012, Alan Gauld wrote:


On 17/06/12 02:45, mariocatch wrote:

after each row?
 #it's causing multiple line separations when writing back out
to file (because each
 #  time we finish reading, it ends with a trailing newline).
 f.write({0}{1}{2}\n.format(k, recordDelimiter, v))


Sorry, you have to add a newline when writing to the file and strip it off 
when reading. Its just how it is...


If you're using Python3 or from __future__ import print_function, you can do
this

print(k,v, sep=recordDelimiter, file=f)

Which might make things a little cleaner. There's also the end parameter which
defaults to end='\n'

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


Re: [Tutor] creating a regularly placed fields in a line

2012-04-26 Thread Wayne Werner

On Wed, 25 Apr 2012, Prasad, Ramit wrote:

snip Useful to
know both though, since lots of people swear by % substitution.


And % formatting is slightly faster - if you end out doing tons of 
formatting and you find your script isn't fast enough, it's worth taking a 
look there.


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


Re: [Tutor] Readabilty vs 80 characters

2012-04-19 Thread Wayne Werner



On Thu, 19 Apr 2012, Tino Dai wrote:


Hi!
     I have a question about style. In PEP-8, it says
don't exceed 79 characters, but can this rule ever be
trumped by 
readability?


PEP 8 is style guidelines, not hard and fast rules or they wouls be syntax
errors. But that would just be annoying, so yes, there are cases where you
would want to extend...

Eg.

     
     if someobject.filter(something) \
          .filter(somethingreallyreallyreallyreallylong
== somethingelsereallyreallylong) \
          .filter(othethingreallylongreallyreally ==
ternarythingreallyreallyreallylong) \
          .filter(thirdthingreallylessreallymaybelong ==
thirdotherthingreallylong) \
          .first():
           do something 

      if someobject.filter(something) \
         
.filter(somethingreallyreallyreallyreallylong == \
               somethingelsereallyreallylong) \
          .filter(othethingreallylongreallyreally == \
              ternarythingreallyreallyreallylong ) \
          .filter(thirdthingreallylessreallymaybelong ==
\
               thirdotherthingreallylong) \
          .first():
           do something 

    
The first example is more readable to me but violates
the 80 character rule. The second is less readable, but
doesn't violate
the 80 character rule.


This is exactly what the style guide is meant to help. Regardless of which
format you chose here I would tell you that both ways are wrong. The right way
is to fix your algorithm (how you solve the problem) so you don't have to have
such an insane amount of code on one line.

Of course this isn't a hard and fast rule either, but I'd say about 99% of the
time a lot of nesting or chaining indicates a broken flow (even if the logic is
100% accurate). 


Is there a guideline or convention that pythonistas
follow about this style case?

Refactor!

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


Re: [Tutor] regex question

2012-04-08 Thread Wayne Werner

On Fri, 6 Apr 2012, Khalid Al-Ghamdi wrote:


hi all,
I'm trying to extract the domain in the following string. Why doesn't my 
pattern (patt) work:

 redata
'Tue Jan 14 00:43:21 2020::eax...@gstwyysnbd.gov::1578951801-6-10 Sat Jul 31 
15:17:39 1993::rz...@wgxvhx.com::744121059-5-6 Mon Sep 21 20:22:37
1987::ttw...@rpybrct.edu::559243357-6-7 Fri Aug  2 07:15:23 
1991::t...@mgfyitsks.net::681106523-4-9 Mon Mar 18 19:59:47 
2024::dgz...@fhyykji.org::1710781187-6-7 '
 patt=r'\w+\.\w{3}(?=@)'
 re.findall(patt,redata)
[]

This pattern works but the first should, too. shouldn't it?


The all too familiar quote looks like it applies here: Often programmers, 
when faced with a problem, think 'Aha! I'll use a regex!'. Now you have 
two problems.


It looks like you could easily split this string with redata.split('::') 
and then look at every second element in the list and split *that* element 
on the last '.' in the string.


With data as well-formed as this, regex is probably overkill.

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


Re: [Tutor] New to Python programing

2012-04-03 Thread Wayne Werner

On Mon, 2 Apr 2012, wesley chun wrote:


greetings walter, and welcome to the Python family!

snip

as far as books go, the best way to learn Python is by writing games.
this is an approach that works both with children as well as adults.
there are several excellent books that can help you with this regard:


There is another book that I didn't notice mentioned: Game Programming: The L 
line, the express
line to learning.

The book is unfortunately named because it makes no mention of Python, but it's
quite a good book for learning both programming and Python... and games!

Good luck and welcome to Python!
-Wayne Werner
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] breeds of Python .....

2012-04-03 Thread Wayne Werner

On Sat, 31 Mar 2012, Modulok wrote:

If you're just starting out, go with 3.x. If you have a need for some third
party modules that aren't yet available for 3.x, you'll have to stick with 2.x.


For a handy list, check out the Python3 Wall of Shame (soon to be superpowers?)
http://python3wos.appspot.com/

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


Re: [Tutor] feedback on writing pipelines in python

2012-03-22 Thread Wayne Werner

On Wed, 21 Mar 2012, Abhishek Pratap wrote:

Hi Guys
I am  in the process of perl to python transition for
good.


Welcome!


1. stitch pipelines : I want python to act as a glue
allowing me to run various linux shell based programs.
If needed wait for a program to finish and then move on,
logs if required 


You'll want to take a look at the subprocess module. One thing you will notice
is that Perl has a lot more terse syntax when it comes to commands line
integration. That being said, Python is still fully capable.

 You may want to check out an Oreilly book called Python for the system 
administrator by Noah Gift. It doesn't tell you much about each tool but 
it exposes you to a ton of them.


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


Re: [Tutor] help writing functions

2012-02-24 Thread Wayne Werner



On Thu, 23 Feb 2012, Saad Javed wrote:


I am learning python and need guidance for
writing some code. I've written a simple
program (with pointers from people) that
parses an tv show xml feed and prints their
values in plain text after performing some
string operations.


Unless you're really interested in doing this fire the sake of the exercise you
should probably take a look at feedparser
 it's designed for parsing read and atom feeds.

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


Re: [Tutor] (no subject)

2012-01-18 Thread Wayne Werner
On Wed, Jan 18, 2012 at 6:00 AM, Selwyn Mileham smile...@vodamail.co.zawrote:

  Help someone

 Trying to print to printer using python 3.2.2

 Get error load dll error can’t find win32print.

 It is in site library


What have you tried? If you get an exception, please post the exact text of
the traceback. If the code you used is short enough then it's reasonable to
just paste it in your email (make sure HTML formatting is off, though,
because it will probably break the formatting).

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


Re: [Tutor] Reg. Expressions Parenthesis

2012-01-17 Thread Wayne Werner
On Tue, Jan 17, 2012 at 3:07 AM, Chris Kavanagh cka...@msn.com wrote:

 Hey guys, girls, hope everyone is doing well.

 Here's my question, when using Regular Expressions, the docs say when
 using parenthesis, it captures the data. This has got me confused
 (doesn't take much), can someone explain this to me, please??

 Here's an example to use. It's kinda long, so, if you'd rather provide
 your own shorter ex, that'd be fine. Thanks for any help as always.


Here's a quick example:

import re

data = 'Wayne Werner fake-phone: 501-555-1234, fake-SSN: 123-12-1234'
parsed = re.search('([\d]{3})-([\d]{3}-[\d]{4})', data)
print(parsed.group())
print(parsed.groups())

parsed = re.search('[\d]{3}-[\d]{3}-[\d]{4}', data)
print(parsed.group())
print(parsed.groups())

You'll notice that you can access the individual clusters using the
.groups() method. This makes capturing the individual groups pretty easy.
Of course, capturing isn't just for storing the results. You can also use
the captured group later on.

Let's say, for some fictitious reason you want to find every letter that
appears as a double in some data. If you were to do this the brute force
way you'd pretty much have to do something like this:

for i in range(len(data)-1):
   found = []
   if data[i] == data[i+1]:
  if not data[i] in found:
found.append(i)
   print(found)

The regex OTOH looks like this:

In [29]: data = 'aaabababbcacacceadbacdb'

In [32]: parsed = re.findall(r'([a-z])\1', data)

In [33]: parsed
Out[33]: ['a', 'b', 'c']

Now, that example was super contrived and also simple. Very few real-world
applications will be as simple as that one - usually you have much crazier
specifications, like find every person who has blue eyes AND blue hair, but
only if they're left handed. Assuming you had data that looked like this:

NameEye ColorHair Color   Handedness Favorite type of potato
WayneBlue BrownDexter Mashed
Sarah  Blue Blonde   SinisterSpam(?)
Kane   Green  White Dexter None
Kermit Blue Blue   SinisterIdaho


You could parse out the data using captures and backrefrences [1].

HTH,
Wayne

[1] In this situation, of course, regex is overkill. It's easier to just
.split() and compare. But if you're parsing something really nasty like EDI
then sometimes a regex is just the best way to go[2].

[2] When people start to understand regexes they're like the proverbial man
who only has a hammer. As Jamie Zawinski said[3], Some people, when
confronted with a problem, think
“I know, I'll use regular expressions.”   Now they have two problems. I've
come across very few occasions that regexes were actually useful, and it's
usually extracting very specifically formatted data (money, phone numbers,
etc.) from copious amounts of text. I've not yet had a need to actually
process words with it. Especially using Python.

[3]http://regex.info/blog/2006-09-15/247
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Return to my python26.dll python.dll problems on bootup

2012-01-07 Thread Wayne Watson
You are right about posting here, but I was hoping someone might have 
related to the problem. I went to the WinAmp forum for help. But who 
would have guessed that WinAmp would have provided a program not ready 
for prime time, and nothing buy an advertisement to get you to buy the 
latest drivers for your PC.  Lesson learned.  Someone on their forum 
suggested hijackthis.log, which will fix a registry.  Five stars by 
CNET, but it may not be quite free.  Ah, I just got through to uniblue's 
tech support by mail.


As an aside, I've noticed that a lot of downloadable freebies have pages 
that are thick  with other $ products advertising. Once you get through 
several pages of them, you then find the download.


On 1/5/2012 10:25 AM, Steven D'Aprano wrote:

Wayne Watson wrote:

  I have two problems upon bootup of my Win7 PC, 64-bit.


Wayne, I sympathize with your problems, but they are Windows problems, 
not Python problems, and have absolutely nothing to do with learning 
to program Python. You are spamming this mailing list with off-topic 
questions about fixing your Windows system. This list is about 
learning Python programming, not we'll fix any problem that has some 
vague connection to Python, no matter how slight. Have you tried 
asking for help on Windows-related forums or mailing lists?


It has been many years since I've used Windows regularly, but I can 
tell you this: you don't do yourself any favours by installing and 
uninstalling programs under Windows. I know it is less than helpful, 
but my advice is *never* install any program you aren't sure you will 
want to keep, because uninstalling always leaves traces of crud 
behind, eventually leading to exactly the sorts of problems you are 
experiencing.






--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] question about a exercise

2012-01-05 Thread Wayne Werner
On Thu, Jan 5, 2012 at 9:22 AM, daedae11 daeda...@126.com wrote:

 **
 The exercise is:

 Write a function which has 3 parameters. First parameter is a char, second
 parameter is a integer, third parameter is a integer.
 The function would create a file which have following requests:
 1. the length of the file is in accordance with the third parameter.
 2. the content of the file must be random generated.
 3. the time first parameter occurred in the content must be in accordance
 with second parameter.

 please give me some hints. It would be better if you give me the code.


It would be better if /you/ gave us the code that shows what you've tried.
Also, if we give you the solution(s) then you won't learn.

To accomplish this exercise you need a few skills:

1. Write a function that takes parameters - can you do this?
2. Create a file - can you do this?
3. Generate random text - can you do this?
4. Modify text (or generate slightly less-random text) - can you do this?

If you can do those four things then you should be able to easily
accomplish this task (that looks an awful lot like homework)

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


[Tutor] Return to my python26.dll python.dll problems on bootup

2012-01-05 Thread Wayne Watson

  
  
I have two problems upon bootup of my Win7 PC, 64-bit.

1. This may or may not be related to #2, which is the more
important of the two, I think.
C:\Program Files9x86)\Uniblue\DriverScanner\Python26.dll not
installed. What is Uniblue you ask? I installed a new version of the
video program Winamp back in early Nov, and it had some selections.
One of which was to include Uniblue Driver Checker. I thought I'd
give it a try. 

After the install completed, I thought I'd give it a try. It goes
through all your drivers to find which ones are out of date.
Surprise. You can buy the latest ones through them. I uninstalled
Uniblue, but as it turns out, it was an incomplete uninstall. I
spent the 30-45 minutes trying to get it uninstalled. Finally, I
sent an e-mail on how to do it to them. Never got an answer. Next is
Winamp. I have no idea how it got entangled with Python 2.6. 

2.

This

  appears too: Specified module could not be found:Module could not
  be found. Load Lib, python.dll







Python works fine. What's the problem?

-- 
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39 15' 7" N, 121 2' 32" W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT 
-- "The Date" The mystery unfolds.

Web Page: www.speckledwithstars.net/



  

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


Re: [Tutor] Which libraries for Python 2.5.2 [SOLVED]

2012-01-01 Thread Wayne Watson
This problem was solved when my wife noticed that there was a second 
install disk for the 5 year old XP zx6000 PC she had given me, which I 
will now give to a friend.


The problem originally was a missing dll that Python wanted.  All is 
well now.


--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries [Reset]

2011-12-26 Thread Wayne Watson



On 12/24/2011 11:24 AM, Alan Gauld wrote:

On 24/12/11 18:58, Wayne Watson wrote:

Yikes. I gave the permissions for .idlerc above. The problem is with
recent-files.py.

IOError: [Errno 13] Permission denied:
'C:\\Users\\Wayne\\.idlerc\\recent-files.lst'



Can you open it in Notepad from the same command prompt?
ie. is it just idle that can't open it, or is it any program?


Opens with Notepad and jEdit  from the menu off a py file.
I'm suspicious of the Unknown Account(S-1-21-lots of digits) seen in 
Properties' Security tab. It seems bizarre and has read and readexecute 
properties only. Unknown User exits for txt and jpg files, so it's not 
isolated to py.


Perhaps there's an ownership problem; however, Owner (recent-files.lst) 
is: solarblast\Wayne.  That's me.


I'm looking at the General tab of .idlerc.  Attributes Read-only check 
box is blue. If I click on it, it goes white. If I click again, it shows 
the check mark. Eventually, I get back to blue.


I'm now looking at Properties-General for recent-files.lst, and Read 
-only check box is white.  Presently, I do not know if this amounts to 
anything.


I see recent-files.lst is openable with Word.

I see mydir_math.py is opened with python.exe!!??  True of other py files.

--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries [SOLVED]

2011-12-26 Thread Wayne Watson

Excellent strategy!! It worked.

I just examined the properties for each .idlerc, and noticed that the 
troublesome one was created in Feb 4,2010.  Probably with Python 2.5.2.  
I don't know why or necessarily whether new installs shouldn't have 
changed the folder or recreated it.


Thanks to all who followed this long perplexing thread.


On 12/24/2011 8:08 PM, Lie Ryan wrote:

On 12/25/2011 06:24 AM, Alan Gauld wrote:

On 24/12/11 18:58, Wayne Watson wrote:

Yikes. I gave the permissions for .idlerc above. The problem is with
recent-files.py.

IOError: [Errno 13] Permission denied:
'C:\\Users\\Wayne\\.idlerc\\recent-files.lst'



Can you open it in Notepad from the same command prompt?
ie. is it just idle that can't open it, or is it any program?


also, try deleting the whole folder (or just in case, move the folder 
somewhere else), IDLE should create a new folder and config files, 
hopefully with the correct permission.


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



--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] Which libraries for Python 2.5.2

2011-12-26 Thread Wayne Watson
Yes, that's a  reasonable request, and I expected it, but hoped it might 
be apparent from what I revealed.  Why? It's on another PC this 
happened, and getting the messages of it is not easily done, but today I 
have time, so soon I will post the details.


On 12/24/2011 10:49 AM, Hugo Arts wrote:

On Sat, Dec 24, 2011 at 6:37 PM, Wayne Watson
sierra_mtnv...@sbcglobal.net  wrote:

I'm trying to restore Python 2.5.2 on an old PC for a particular application
that uses it from 4-5 years ago.
According to the latest manual on it, the following should be installed.

python-2.5.2.msi
PIL-1.1.6.win32-py2.5.exe
numpy-1.1.0-win32-superpack-python2.5.exe
matplotlib-0.98.1.win32-py2.5.exe

When I install them, and try to run the app program, Sentinel.py, some part
of matplotlib complains (error msgs) and the program quits.


If we are to give any kind of useful advice at all, we're going to
need to see those error messages.


The program begins with:
from Tkinter import *
from numpy import *
import Image
import ImageChops
import ImageTk
import time
import binascii
import tkMessageBox
import tkSimpleDialog
from pylab import plot, xlabel, ylabel, title, show, xticks, bar

I tried numpy-1.2.0 and matplotlib-0.98.3 and had the same difficulty. What
are wiser choices?


This question is based on the assumption that version mismatch is the
cause of your problems. Even though that might be correct, it is not
an assumption you can safely make. In general, when asking questions
here (and anywhere really, imho) you should try to provide as much
factual information and as little conjecture as you can.

Hugo



--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] Which libraries for Python 2.5.2

2011-12-26 Thread Wayne Watson

Here's the traceback.

Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit 
(Intel)] on win32

Type copyright, credits or license() for more information.


Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer's internal loopback
interface.  This connection is not visible on any external
interface and no data is sent to or received from the Internet.


IDLE 1.2.2   No Subprocess 

Traceback (most recent call last):
  File C:\Sentinel\Sent_user-20080716.py, line 16, in module
from pylab import plot, xlabel, ylabel, title, show, xticks, bar
  File C:\Python25\lib\site-packages\pylab.py, line 1, in module
from matplotlib.pylab import *
  File C:\Python25\lib\site-packages\matplotlib\pylab.py, line 206, 
in module

from matplotlib import mpl  # pulls in most modules
  File C:\Python25\lib\site-packages\matplotlib\mpl.py, line 1, in 
module

from matplotlib import artist
  File C:\Python25\lib\site-packages\matplotlib\artist.py, line 4, in 
module
from transforms import Bbox, IdentityTransform, TransformedBbox, 
TransformedPath
  File C:\Python25\lib\site-packages\matplotlib\transforms.py, line 
34, in module

from matplotlib._path import affine_transform
ImportError: DLL load failed: The specified module could not be found.


On 12/26/2011 11:44 AM, Wayne Watson wrote:
Yes, that's a  reasonable request, and I expected it, but hoped it 
might be apparent from what I revealed.  Why? It's on another PC this 
happened, and getting the messages of it is not easily done, but today 
I have time, so soon I will post the details.


On 12/24/2011 10:49 AM, Hugo Arts wrote:

On Sat, Dec 24, 2011 at 6:37 PM, Wayne Watson
sierra_mtnv...@sbcglobal.net  wrote:
I'm trying to restore Python 2.5.2 on an old PC for a particular 
application

that uses it from 4-5 years ago.
According to the latest manual on it, the following should be 
installed.


python-2.5.2.msi
PIL-1.1.6.win32-py2.5.exe
numpy-1.1.0-win32-superpack-python2.5.exe
matplotlib-0.98.1.win32-py2.5.exe

When I install them, and try to run the app program, Sentinel.py, 
some part

of matplotlib complains (error msgs) and the program quits.


If we are to give any kind of useful advice at all, we're going to
need to see those error messages.


The program begins with:
from Tkinter import *
from numpy import *
import Image
import ImageChops
import ImageTk
import time
import binascii
import tkMessageBox
import tkSimpleDialog
from pylab import plot, xlabel, ylabel, title, show, xticks, bar

I tried numpy-1.2.0 and matplotlib-0.98.3 and had the same 
difficulty. What

are wiser choices?


This question is based on the assumption that version mismatch is the
cause of your problems. Even though that might be correct, it is not
an assumption you can safely make. In general, when asking questions
here (and anywhere really, imho) you should try to provide as much
factual information and as little conjecture as you can.

Hugo





--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries [Reset]

2011-12-26 Thread Wayne Watson
Regardless, the problem is  solved.  See my  [SOLVED] msg I put up this 
morning (USA).  It's in response to Lie Ryan.   However, I have no real 
idea how is was caused.


On 12/26/2011 1:28 PM, Alan Gauld wrote:

On 26/12/11 18:57, Wayne Watson wrote:


IOError: [Errno 13] Permission denied:
'C:\\Users\\Wayne\\.idlerc\\recent-files.lst'


Can you open it in Notepad from the same command prompt?


Opens with Notepad and jEdit from the menu off a py file.


That's not what I asked.
Does it open in Notepad from the same command prompt
where you try to run python? Or indeed any command prompt:

C:\WINDOWS notepad C:\Users\Wayne\.idlerc\recent-files.lst


I see recent-files.lst is openable with Word.


Thats nort a surprise, its probably just a text file, so Windows could 
associate just about anything!



I see mydir_math.py is opened with python.exe!!??

 True of other py files.

Which is what you'd expect, after all the default behaviour for a 
python script should surely be to get executed by Python? What else 
would you expect?




--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries [Reset]

2011-12-24 Thread Wayne Watson
My guess is that some months ago I looked at .idlerc on another 
mission to figure what ails my python install, and just more or less 
backed up the recent-files.lst.  However, the important point here is, I 
think, how to change the permissions for the .idlerc folder.  They vary 
by how I might login.


On 12/23/2011 11:47 PM, Lie Ryan wrote:

On 12/23/2011 03:20 PM, Wayne Watson wrote:

Hi, I found it, but not in a place I would expect. It's under my
username, Wayne. It is a folder and has three files:
breakpoints.lst
recent-files.lst
ZZrecent-files.lst

The last one has the odd ZZ, but is empty. breakpoints.lst is empty too.



That certainly is curious, have you tried renaming ZZrecent-files.lst 
to recent-file.lst?


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



--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


[Tutor] Which libraries for Python 2.5.2

2011-12-24 Thread Wayne Watson
I'm trying to restore Python 2.5.2 on an old PC for a particular 
application that uses it from 4-5 years ago.

According to the latest manual on it, the following should be installed.

python-2.5.2.msi
PIL-1.1.6.win32-py2.5.exe
numpy-1.1.0-win32-superpack-python2.5.exe
matplotlib-0.98.1.win32-py2.5.exe

When I install them, and try to run the app program, Sentinel.py, some 
part of matplotlib complains (error msgs) and the program quits.


The program begins with:
from Tkinter import *
from numpy import *
import Image
import ImageChops
import ImageTk
import time
import binascii
import tkMessageBox
import tkSimpleDialog
from pylab import plot, xlabel, ylabel, title, show, xticks, bar

I tried numpy-1.2.0 and matplotlib-0.98.3 and had the same difficulty. 
What are wiser choices?


--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries [Reset]

2011-12-24 Thread Wayne Watson

Permissions as follows:
SYSTEM: All. From Full control to write
Account Unknown(S-1-5-21...): read, exec, list folder contents, Read
Wayne: (normal use) All. From Full control to write
Admin: All. From Full control to write
 WMPNetwork:  Read

--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries [Reset]

2011-12-24 Thread Wayne Watson
Yikes. I gave the permissions for .idlerc above.  The problem is with 
recent-files.py.


IOError: [Errno 13] Permission denied: 
'C:\\Users\\Wayne\\.idlerc\\recent-files.lst'


These are for it. Same as before except for Account Unknown, which had 
list folder contents.


Permissions as follows:
SYSTEM: All. From Full control to write
Account Unknown(S-1-5-21...): readexec, Read
Wayne: (normal use) All. From Full control to write
Admin: All. From Full control to write
WMPNetwork:  Read

--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


[Tutor] Unable to remove three libs from XP

2011-12-23 Thread Wayne Watson
I have three py libs and the python program itself, 2.52, installed on 
an 6 year old HP Laptop. I decided to remove them, and removed Python 
with the Control Panel Add/Remove icon. Worked fine. When I tried to 
remove any of the remaining libs, press the add/remove button does 
nothing but blink. How  do I get around this  problem?


--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] Unable to remove three libs from XP

2011-12-23 Thread Wayne Watson
This is a laugher.  The Add/Remove screen was hiding a dialog that 
wanted to know if I really wanted to remove the program. Argh.


On 12/23/2011 4:56 AM, Wayne Watson wrote:
I have three py libs and the python program itself, 2.52, installed on 
an 6 year old HP Laptop. I decided to remove them, and removed Python 
with the Control Panel Add/Remove icon. Worked fine. When I tried to 
remove any of the remaining libs, press the add/remove button does 
nothing but blink. How  do I get around this  problem?




--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries [Reset]

2011-12-22 Thread Wayne Watson

Hi, Walter.

On 12/21/2011 8:20 PM, Walter Prins wrote:

Hi Wayne,

On 22 December 2011 03:21, Wayne Watsonsierra_mtnv...@sbcglobal.net  wrote:

I uninstalled Uniblue, but as it turns out, it
was an incomplete uninstall.  I just spent the last 30-45 minutes trying to
get it uninstalled. Finally, I sent an e-mail on how to do it. I have no
idea how it got entangled with Python 2.6. So for the time being it's out of
the picture.

Well, presumably it uses/depends on Python 2.6...
I'm looking at the Uniblue DriverScanner, and see mostly exe files, and 
a few dll files.  They may all relate to the uniblue program itself.  
There's a language folder there, and a x64 folder there. x64 has the 
installer. Otherwise, there is no reference to anything that looks like 
a 26 dll, nor is there a list of drivers the program might want to 
examine for age.  Of course, all of this should have been uninstalled.


Although, the Win7 indexed search is very fast to find something there 
are times when it flubs (possibly since I don't know all the tricks one 
can use in a search). looking for 26.dll has turned up nothing an either 
a folder or inside a file. Supposedly, Uniblue supply an answer in 24 
hours. If not, I'll try Winamp.

As a question asked by others, is Python27 under ...\System32. It is under
C:\Python27.  Further, it is the 64-bit version associated with Python.

I didn't ask.  I stated, and to clarify: When you install the standard
distribution of Python, the majority of the files get put under
C:\PythonNN (unless otherwise specified by the user).  However, the
Python engine in the form of a DLL is *also* put under the System32
directory.
I'm looking at System32 entries right now. I see folders such as spool, 
speech, setup,restore, and lots of dll files.  Some of the p dll files 
are p2psvc.dll, packager.dll, p2p.dll, and python27.dll. No 
python26.dll, and nothing starting with py other than the 27 file.

In reading some of the other posts, I was unsure of whether Python27 is put
on the PATH or not by the install.  The question remains unanswered.  I just
left it there, as I re-installed 2.7.2 minutes ago.  Here's where matters
stand.

I've already answered this also, with an unambigious exception to my
answer pointed out by another poster, which is that it depends on
whether you installed the standard Python distribution or whether you
Standard. Interesting dependency. I considered Active once, but did not 
install it.

installed the ActiveState Python distribution.  So, did you install
the standard Python distribution or did you install the ActiveState
version of Python?  The answer to this question will determine whether
the PATH will have been affected by the Python installation.  Even so,
it's an irrelevance w.r.t. your IDLE problems...

What is the outcome based on what I wrote about not Active?



The fact that when I right click on a py file, it begins with Open and then
Edit with IDLE is very encouraging.

Having this entry in your context menu simply means certain entries
are in your system's registery but says very little else about whether
it will work or not.


The downside is that IDLE does not come up.

Which suggests that the associations/registry entries are in fact
broken, perhaps because they're pointing to a non-existent
installation of Python...

If so, how I can I tell?



However, the Start menu's Python27 entry shows Edit with IDLE, Manuals,
..., and Python Console.  The console works. The fact that IDLE actually
appears in both places is again encouraging.

Does IDLE start from the Start menu when you click it?
Nothing happens that I can detect. I'm looking at Properties of it. It 
shows

  Start in: c:\Python27.
  Type of File: shortcut (link).
 Location: ...\star menu\programs\python2.7

Interesting under the Security tab it shows Wayne with only special 
permissions. No Read, Write, Read  Execute(!!).  Admin allows all but 
special. Users allows ReadExecute and Read. Same with Everyone


Under Details tab Name is IDLE(Python GUI) link. Folder Path: 
c:\ProgramData\Microsoft\Windows\Start... I can see nothing past Start...



Under ...\Python27\Lib\idlelib, I can find idle.py, idle.pyw and

IdleHistory.py.  Clicking on idle.pyw does nothing.

Does double clicking idle.pyw do anything?

Nothing but a momentary circular arrow icon.  Thinking I guess.


Normally double clicking
idle.pyw will start IDLE.  Does double clicking idle.bat do anything?
Normally clicking idle.bat will also start IDLE.  If you open a
command prompt and then enter
cd \Python27\Lib\idlelib
idle.bat

Does it output any error messages? If so, what?
A black command window comes up very briefly.  It looks empty, but it's 
really gone quickly.



A few months ago when I broached this install and IDLE problem, someone
mentioned idle.bat. It is in the same  idlelib. Is there something that
needs to be done here, to get IDLE active?  Is this where having Python27 in
the path causes a problem with IDLE?

Whether

Re: [Tutor] A few Python Mysteries

2011-12-22 Thread Wayne Watson



On 12/21/2011 4:10 PM, Alan Gauld wrote:

On 21/12/11 19:56, Wayne Watson wrote:


To clarify: Python on Windows does **not** put itself on the System
PATH when installed.

So, PythonNN, where NN is the version, should never appear in PATH?


Not from a standard Python installation.
But other programs whjich use Pythonn may install a version and modify 
the PATH for you, or you may, for your own benefit, add it manually.

I always add a new Python version to my PATH as a matter of course.


It's conceivable when I raised some of the questions a month of so ago,
someone suggested putting PythonNN on the path.


Very possible indeed.


likely the application that *did* put it there is the **same**
application that is now complaining about the fact that it can't find
the Python 2.5 DLL when you boot up...

See my mis-copy 26.dll in my other post to you.


OK, But the principle remains. If you have an app in your startup 
sequence that expects to find Python it will complain.
Per my new sub thread {Reset], Uniblue seems to the trouble maker with 
26.dll.


You can check your startup sequence using a Microsoft tool.
MSCONFIG or somesuch. Google Windows startup tool or similar...
You can disable individual programs and restart to find out
what is causing it.

I see msconfig.exe, but at the moment am hesitant to use it.



I have no idea why some remnant of why Python6 is hanging around. I
uninstalled it long ago too.


The problem is that it is not hanging around and some app expects
it to be there. The error message is about a missing file...

One thing that may be significant...
Are you installing your Windows Python versions from
python.org or from ActiveState? They are very similar
but not identical.

from Python Org.

--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries [Reset]

2011-12-22 Thread Wayne Watson
I just searched the registry for the dll. Nothing. I then searched for 
python. It found a a Python folder with a PythonCore folder. Under it 
are three folders: 2.5, 2.7 and 3.2.  I do recall installing 3.2, but 
I'm pretty sure I uninstalled it. Under each of the three folders is 
Module.  Looking at the contents shows only default (name) REG_SZ (type) 
for each. Nothing else.


OK,in scrolling around I see another Python folder and PythonCore 
under it, and subfolders 2.7 and 3.2.  Under 2.7 are the subfolders 
Help, InstallPath, Modules, PythonPath. For 3.2, just an empty Modules.  
All of these are under SOFTWARE. The first set of three is under 
WOW6432Node, which is under SOFTWARE.


Interesting, but it doesn't reveal much to me.

For more fun, I searched for idle. It's buried under Interface, and the 
entry is REG_SZ with value idlesettings.

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


Re: [Tutor] A few Python Mysteries [Reset]

2011-12-22 Thread Wayne Watson
More. I did some Googling on IDLE not appearing.  My case appears not to 
be unique.  One site offered this as a solution in 2.6, 
C:\Python27python.exe \Lib\idlelib\idle.py. It issued a complaint that  
no such file or directory exists. It however does.


A place to go that may clear this up might be 
http://bugs.python.org/.  I found the suggestion above there. There 
are other comments about this issue there, but I haven't sorted through 
all of them.



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


Re: [Tutor] A few Python Mysteries [Reset]

2011-12-22 Thread Wayne Watson

Ah, yes.Thanks. That is, I think, was the what I copied from some web page.
OK, I just tried it, and got several messages.

C:\Python27python.exe Lib\idlelib\idle.py
Traceback (most recent call last):
  File Lib\idlelib\idle.py, line 11, in module
idlelib.PyShell.main()
  File C:\Python27\Lib\idlelib\PyShell.py, line 1403, in main
shell = flist.open_shell()
  File C:\Python27\Lib\idlelib\PyShell.py, line 279, in open_shell
self.pyshell = PyShell(self)
  File C:\Python27\Lib\idlelib\PyShell.py, line 832, in __init__
OutputWindow.__init__(self, flist, None, None)
  File C:\Python27\Lib\idlelib\OutputWindow.py, line 16, in __init__
EditorWindow.__init__(self, *args)
  File C:\Python27\Lib\idlelib\EditorWindow.py, line 273, in __init__
self.update_recent_files_list()
  File C:\Python27\Lib\idlelib\EditorWindow.py, line 799, in 
update_recent_files_list

rf_file = open(self.recent_files_path, 'w')
IOError: [Errno 13] Permission denied: 
'C:\\Users\\Wayne\\.idlerc\\recent-files.lst'

  -
Maybe as I pointed out a few msgs ago here the permissions shown on 
Properties looked a bit odd.




On 12/22/2011 9:58 AM, Alan Gauld wrote:

On 22/12/11 16:37, Wayne Watson wrote:


C:\Python27python.exe \Lib\idlelib\idle.py. It issued a complaint that
no such file or directory exists. It however does.


It almost certainly doesn't. The \ in front of Lib says look in the 
root directory of the C drive.


You probably need:

C:\Python27 python.exe Lib\idlelib\idle.py.

HTH



--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries [Reset]

2011-12-22 Thread Wayne Watson
Hi, I found it, but not in a place I would expect. It's under my 
username, Wayne. It is a folder and has three files:

breakpoints.lst
recent-files.lst
ZZrecent-files.lst

The last one has the odd ZZ, but is empty. breakpoints.lst is empty too.

recent-files.lst contains about 21 files like:
C:\Users\Wayne\Sandia_Meteors\Trajectory_Estimation\radiant.py
C:\Users\Wayne\Sandia_Meteors\Trajectory_Estimation\cross_prod.py

ZZ... is the most recent file, 7/18/2011.

If I right-click .idlerc, I can see properties for SYSTEM, some very 
oddly named user, Wayne, Admin, and WMPNetwork.




On 12/22/2011 2:34 PM, Alan Gauld wrote:

On 22/12/11 19:08, Wayne Watson wrote:


IOError: [Errno 13] Permission denied:
'C:\\Users\\Wayne\\.idlerc\\recent-files.lst'
-
Maybe as I pointed out a few msgs ago here the permissions shown on
Properties looked a bit odd.


But the problem here is with .idlerc in your home directory.

Can you find that file and ensure that read/write permissions
are set? It may be a hidden file so you might have to tweak
the View settings.

.idelrc is presumably where Idle stores your local config settings.
Although I confess I never noticed it when I used Windows. But then I 
probably never had a need to notice it!




--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries

2011-12-21 Thread Wayne Watson
Python is long gone from my system.  I only have Python 27.  Somewhere a 
long the line, the uninstall of Python5 probably did not remove the 
Python5 from the PATH. I have no explanation as to why Python7 was not 
in the PATH.  I have no idea why some remnant of why Python6 is hanging 
around. I uninstalled it long ago too.


On 12/21/2011 2:43 AM, Steven D'Aprano wrote:

Wayne Watson wrote:
I changed Python25 to Python27, and rebooted.  I got the same two dll 
msgs again.


I suggest you find out what applications are trying to run using 
Python 2.5. This is a Windows problem -- you need to get the list of 
programs that run at start up and inspect them for something that uses 
Python.


Since I don't use Windows, I can't be more specific.





--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries

2011-12-21 Thread Wayne Watson

Howdy,


On 12/21/2011 2:08 AM, Walter Prins wrote:

Hi Wayne,

On 21 December 2011 02:32, Wayne Watsonsierra_mtnv...@sbcglobal.net  wrote:

I changed Python25 to Python27, and rebooted.  I got the same two dll msgs
again.

The PATH issue has nothing to do with your error messages.
True, but it should have a lot to do with Python27.  Some good news is 
that unlike previous attempts, I can actually see IDLE as a choice on a 
right-click of a py file. However, a spinner icon appears for about 5 
seconds and then disappears.

Python25.dll is normally installed in the C:\Windows\System32 folder,
not C:\Python25, so whether or not c:\Python25 is in your PATH is
irrelevant to whether it will be found (in C:\Windows\System32).
I have no Python of any kind in System32.  I uninstalled 25 months ago. 
As far as I can tell, there is not a scrap of it left.





The facts as far as I can tell are:
a) Some application in your startup is trying to link to/load
Python25.dll but failing as per the message you posted.
Hmm, I made have made a mistake about a 25 dll.  When I rebooted last 
night, I though I recalled 26. I'll reboot again in awhile and verify 
that. Yikes! No need. It's 26dll.  I wrote it down after my first boot. 
My second was last night.

b) You've uninstalled Python 2.5, so a) is not really surprising.
c) The application (whatever it is) will *NOT* automatically start
using the newer Python27.dll because you've installed Python 2.7.
These are considered seperate/distinct versions of Python.

Your options to get rid of the message is:
a) Reinstall Python 2.5
b) Remove the application that depends on Python 2.5 (that is
expecting it to be present.)

To add: I'd be careful of 32 bit/64 bit issues -- If the application
trying to run is in fact 32 bit then you should probably be installing
the 32-bit version of Python, otherwise it probably still won't find
Python25.dll.
Forgetting about 25 (32-bit), per above, I installed a 64-bit version of 
2.7.2. python-2.7.2.adm64.msi.



(32-bit applications won't be able to link to 64-bit
dll's, and in any case on 64-bit versions of Windows things get a bit
obscure -- C:\Windows\System32 actually contain 64-bit native dll's
while 32-bit compatility dll's reside in c:\Windows\SysWOW64 but is
presented as c:\Windows\System32 to 32-bit processes by the OS... )
If you don't know whether the application is 32-bit or 64-bit you'll
just have to find out by trial and error.  Install the one and if this
doesn't resolve the problem then remove it again and install the
other.

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



--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries

2011-12-21 Thread Wayne Watson



On 12/21/2011 9:57 AM, bod...@googlemail.com wrote:

I think your missing the point. Ignore the fact that your PATH doesn't contain 
the correct paths to python.
As I just wrote to Prins. I think I made a copy error on the dll. I'm 
looking at the sheet I wrote the msg on and it shows 26.dll

There is no 2.5 on my system. I removed it months ago.
True about the PATH, but having Python25 in it was wrong. It's now 27.  
Why 25 got put in there I do not know.




The problem is that on startup, a program (unknown) is looking for the dll file 
for python2.5 - it is looking for this in the system32 directory. To be rid of 
the startup errors, you need to replace the dll that was removed by the 
uninstallation of python2.5 - to do this, reinstall python2.5

See my post to Prins above.


Bodsda
Sent from my BlackBerry® wireless device

-Original Message-
From: Wayne Watsonsierra_mtnv...@sbcglobal.net
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Wed, 21 Dec 2011 07:15:31
To: Steven D'Apranost...@pearwood.info; tutor@python.orgtutor@python.org
Subject: Re: [Tutor] A few Python Mysteries

Python is long gone from my system.  I only have Python 27.  Somewhere a
long the line, the uninstall of Python5 probably did not remove the
Python5 from the PATH. I have no explanation as to why Python7 was not
in the PATH.  I have no idea why some remnant of why Python6 is hanging
around. I uninstalled it long ago too.

On 12/21/2011 2:43 AM, Steven D'Aprano wrote:

Wayne Watson wrote:

I changed Python25 to Python27, and rebooted.  I got the same two dll
msgs again.

I suggest you find out what applications are trying to run using
Python 2.5. This is a Windows problem -- you need to get the list of
programs that run at start up and inspect them for something that uses
Python.

Since I don't use Windows, I can't be more specific.





--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries

2011-12-21 Thread Wayne Watson

Hi,

On 12/21/2011 10:18 AM, Walter Prins wrote:

Hi Wayne,

On 21 December 2011 15:15, Wayne Watsonsierra_mtnv...@sbcglobal.net  wrote:

Python is long gone from my system.

I presume you mean Python **2.5** is long gone from your system (not
Python in general), but in any case, this much has been well
understood since several emails ago.

All but 2.7.2.



I only have Python 27.

OK, that's also been clear since several emails ago and is not an
issue (except that I have the impression that's not working properly
either?)


Somewhere along the line, the uninstall of Python5 probably did not remove the 
Python5
from the PATH. I have no explanation as to why Python7 was not in the PATH.

To clarify: Python on Windows does **not** put itself on the System
PATH when installed.  Consequently the reason Python 2.7 is not on the
PATH is in fact because no-one put it there (yet), since as I say,

So, PythonNN, where NN is the version, should never appear in PATH?

Python itself would not have done it.  This also explains why
C:\Python25 was not removed from the PATH when you uninstalled Python
2.5 -- Since Python's installation never put it there, it obviously
wasn't going to remove it when it was uninstalled.  Instead, the
implication is that something or somebody else put it there -- most
It's conceivable when I raised some of the questions a month of so ago, 
someone suggested putting PythonNN on the path. I recall the PATH idea 
surfaced back then.

likely the application that *did* put it there is the **same**
application that is now complaining about the fact that it can't find
the Python 2.5 DLL when you boot up...

See my mis-copy 26.dll in my other post to you.



  I have no idea why some remnant of why Python6 is hanging around. I
uninstalled it long ago too.

I presume by Python6 you mean Python 2.6.  Why do you think a remnant
of this is hanging around?

True. 2.6, and not 6.  See previous comments about 26.dll.
I think I'm going to pass on the 2.5 comments below in light of the 
26.dll typo.

Anyway, re the bootup messages, I've already suggested what your
options are, but in short:
a) Find and remove the application that's trying to use Python 2.5
b) Install Python 2.5 again, and hope that's enough to get the app
that wants to use it running again.

Re your other Python problems, I'd suggest doing the following:
1) Go into your Control Panel-Programs and Features, and remove all
copies of Python (if any.)

I'm leaving 2.7.2 there for now.

2) Go into your C:\ Drive, and delete any existing Python folders that
may still exist:
C:\Python25
C:\Python26

C:\Python25 and 26 are long gone. I'm holding onto 27.

3) Redownload your Python installer (MSI file) of the version of your
choice (2.7?)  from the Python dowload site and re-install that with
default options.

Let's hold off on this in light of the 26.dll discover. It may have some 
bearing on the current state of 27.

 4) IDLE should then be present in your Start-All Programs menu under
Python 2.7, and should be easily locatable also with the Start menu
quick search feature.

IDLE shows as normal when I right-click on py files. It just doesn't bring up 
IDLE.

 Note, at this point (after the initial installation), Python via the
command prompt won't be runnable from anywhere, since C:\Python27 will
not have been put on the system PATH yet.  A previous post in this
thread explains how to add it (and you should be familiar enough with
the system PATH by now to do this yourself anyway ;)  )

When the PythonNN point I made is answered, then I address the PATH again.

 Please try these suggestions and post back with specificity if you
have further problems.

HTH,

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



--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries [Reset]

2011-12-21 Thread Wayne Watson
If you read on past a few paragraphs, there is some reason for hope that 
2.7.2 is close to running. But first, the dll story.


As it turns out in the other part of this thread, the Python25.dll was 
a typo on my part.  It's really Python26.dll.  Upon re-booting to make 
sure of that I read the message fully, and discovered that it read:
C:\Program Files9x86)\Uniblue\DriverScanner\Python26.dll not installed. 
What is Uniblue you ask? I installed a new version of the video program 
Winamp back in early Nov, and it had some selections.  One of which was 
to include Uniblue Driver Checker.  I thought I'd give it a try.


After the install completed, I thought I'd give it a  try. It goes 
through all your drivers to find which ones are out of date. Surprise. 
You can buy the latest ones through them. I uninstalled Uniblue, but as 
it turns out, it was an incomplete uninstall.  I just spent the last 
30-45 minutes trying to get it uninstalled. Finally, I sent an e-mail on 
how to do it. I have no idea how it got entangled with Python 2.6. So 
for the time being it's out of the picture.


As a question asked by others, is Python27 under ...\System32. It is 
under C:\Python27.  Further, it is the 64-bit version associated with 
Python.


In reading some of the other posts, I was unsure of whether Python27 is 
put on the PATH or not by the install.  The question remains 
unanswered.  I just left it there, as I re-installed 2.7.2 minutes ago.  
Here's where matters stand.


The fact that when I right click on a py file, it begins with Open and 
then Edit with IDLE is very encouraging.  The downside is that IDLE does 
not come up.  However, the Start menu's Python27 entry shows Edit with 
IDLE, Manuals, ..., and Python Console.  The console works. The fact 
that IDLE actually appears in both places is again encouraging.


Under ...\Python27\Lib\idlelib, I can find idle.py, idle.pyw and 
IdleHistory.py.  Clicking on idle.pyw does nothing.


A few months ago when I broached this install and IDLE problem, someone 
mentioned idle.bat. It is in the same  idlelib. Is there something that 
needs to be done here, to get IDLE active?  Is this where having 
Python27 in the path causes a problem with IDLE?



--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries

2011-12-20 Thread Wayne Watson
I changed Python25 to Python27, and rebooted.  I got the same two dll 
msgs again.


On 12/19/2011 7:33 PM, Wayne Watson wrote:
It became apparent during the other part of this thread that I had not 
uninstalled Python 2.7, as I thought I had.  As pointed out in the 
PATH discussion (James R.), the last item in the system variable PATH 
was Python25. I would think then changing it to Python27 might Python 
rolling again.




--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


[Tutor] A few Python Mysteries

2011-12-19 Thread Wayne Watson

Win 7, 64-bit

I had Py 2.5 installed on my PC earlier this year, and it began failing 
around June. I finally uninstalled it, and tried 2.6.  Still had 
problems that centered around getting to IDLE. Uninstalled 2.6, and went 
to 2.7. Same problem. I completely uninstalled 2.7. I do have several 
folders of py programs. No Python.


After that episode, I began to notice the following messages when I 
signed on to my PC after a boot. I do not bring my PC down very often.


Specified module could not be found: Loadlib python.dll failed, and 
another of the same for Python25.dll failed (maybe not found).  I did a 
search for both, but neither were found.


I ignored this inconvenience for a few weeks, and had developed a need 
to copy a particular python program on Win 7 to another computer. Call 
it abc.py.  I copied it to a thumb drive, and plugged the drive into the 
other PC, which has Python on it.  abc.py was missing from the drive.  I 
tried this about three times, and even went to yet another PC. No abc.py.


 Finally, I pulled xyz.py from an XP PC on to the drive. When I put it 
on yet another PC, xyz.py was there, and I copied it on to the PC. Very 
strange.  Note again, I did not have Python installed on the Win 7 PC.  
I have no idea if any of this is relevant to the attempt to install Py 
on my Win 7 PC, but it and the sign-on msgs may indicate something is 
twisted in the registry.


Comments?

It would be nice to get rid of the two msgs upon sign-on.

--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries

2011-12-19 Thread Wayne Watson

  
  


On 12/19/2011 8:50 AM, James Reynolds wrote:

  
  On Mon, Dec 19, 2011 at 11:35 AM, Wayne
Watson sierra_mtnv...@sbcglobal.net
wrote:

  Win 7, 64-bit
  
  I had Py 2.5 installed on my PC earlier this year, and it
  began failing around June. I finally ...
CE 1955 October 20 07:53:32.6 UT
   -- "The Date" The mystery unfolds.
  
   Web Page:www.speckledwithstars.net/
  
  
  ___
  Tutor maillist - Tutor@python.org
  To unsubscribe or change subscription options:
  http://mail.python.org/mailman/listinfo/tutor

  
  
  
  
  
  
  
  
  Did you change the PATH to the right directory? It may still
be pointing to the old directory, or you may have never set it
to begin with.

Someone suggested this several months when I was having an install
problem.
===
That being said, it sounds an awful lot like the python.exe isn't in
your path. To get it there you can open windows explorer (WIN+E)
right click on computer  properties then click advanced system
settings. In the window that pops up, click the "environment
variables" button. In the "system variables" portion, find the path
variable and click the "Edit..." button. Assuming that your new
installation was placed in C:\Python25\ you will want to add
";C:\Python25\" (the semicolon is important!) to the end of your
path.
===
Is that what you are suggesting? I brought up WE and clicked on
properties, and got a six tab dialog. Pushed Advanced. Tabs are:
Sharing, Security, Prev versions, general, tools, h/w, quota. I
don't see anything about about a PATH, sys or env vars. 
-- 
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39 15' 7" N, 121 2' 32" W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT 
-- "The Date" The mystery unfolds.

Web Page: www.speckledwithstars.net/



  

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


Re: [Tutor] A few Python Mysteries

2011-12-19 Thread Wayne Watson

1. Go to start
2. Right click on Computer
3. Select Properties. This will bring up the System menu.
4. Select Advanced system Settings on the left hand side.
5. In this new window, select Environment variables... at the bottom
6. In the bottom window area, scroll down until you find PATH
7. Select Edit (do NOT delete anything contained in this or will 
screw some stuff up)
8. scroll to the very end and put a ; as a deliminator if there isn't 
one on the end already. Then put the direct path to you Python install 
you care about. (it should be something like this:(;C:\Python27)

I see at the end: Program Files\jEdit;C:\Python25\
There is no Python on my PC. Python 2.5 is what I started with, so I 
guess I should make this:

Program Files\jEdit


- this is mine in fact.
9. Hit OK. Then accept your way out. You will have to reboot.
10. To test, open a cmd prompt and and type simply python. if you 
get Python 2.7.2 (some more stuff) then python is now on your path.


--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries

2011-12-19 Thread Wayne Watson



On 12/19/2011 3:19 PM, Steven D'Aprano wrote:

Wayne Watson wrote:

Win 7, 64-bit

I had Py 2.5 installed on my PC earlier this year, and it began 
failing around June. I finally uninstalled it, and tried 2.6.  Still 
had problems that centered around getting to IDLE. Uninstalled 2.6, 
and went to 2.7. Same problem. I completely uninstalled 2.7. I do 
have several folders of py programs. No Python.



Programs should not just begin failing unless somebody (you?) or 
something (a virus, another program?) mess with them. Especially not 
something as simple and stable as Python.


Who installed Python 2.5 in the first place? If it was provided with 
your computer, then it was 

I did. It worked  for months.
provided for a reason. Python is not a standard part Windows, but a 
number of PC manufacturers provide Python 2.5 to run their tools, and 
by removing it, you have broken whatever it is that the manufacturer 
tools are supposed to be doing. Installing Python 2.6 or 2.7 will 
probably not work as a replacement.


If you installed Python 2.5 yourself, then it doesn't matter.

However, my guess is that Python 2.5 was installed by the 
manufacturer, and my evidence for this is the error messages that you 
now see at boot up:



After that episode, I began to notice the following messages when I 
signed on to my PC after a boot. I do not bring my PC down very often.


Specified module could not be found: Loadlib python.dll failed, and 
another of the same for Python25.dll failed (maybe not found).  I did 
a search for both, but neither were found.


Of course they're not found. You uninstalled them.
I would expect so, but why did it complain specifically about them and 
not others? See PATH comment below.


My first advice: re-install Python 2.5. If you have a recovery disk 
supplied by the manufacturer, try using that. Make sure you install a 
64-bit version of Python, not 32-bit.
I really no longer have a need for 2.5, so I thought I might as well go 
for something newer, which is basically what I'm doing, since 2.5 wasn't 
working.


Then do the same with Python 2.7. Make sure it is the 64-bit version. 
Then check that you still have BOTH Python 2.5 and 2.7 installed: look 
in the start menu, and you should see two entries for Python.


Whoops. Python 2.7.2 is on the menu and was installed 12/18. I thought I 
uninstalled it last night.  It is the 64-bit version. It's beginning to 
look like the PATH is the problem, since I found Python25 at the end of 
the PATH variable, as noted to James above.


I ignored this inconvenience for a few weeks, and had developed a 
need to copy a particular python program on Win 7 to another 
computer. Call it abc.py.  I copied it to a thumb drive, and plugged 
the drive into the other PC, which has Python on it.  abc.py was 
missing from the drive.  I tried this about three times, and even 
went to yet another PC. No abc.py.


This has *nothing* to do with Python. To Windows, abc.py is just 
another file, like abc.txt or abc.jpg or abc.doc. If copying files to 
a thumb drive is failing (other than by human error, or faulty thumb 
drive), then you have deeper problems with your Windows installation 
than just missing Python.


But I suspect either human error or a faulty thumb drive. Since I 
don't use Windows 7, and did not see how you tried to copy the file to 
the thumb drive, I can't be sure, but if something as fundamental as 
copying files was failing, then I would expect your Windows machine to 
be crashing constantly. So more likely the thumb drive is failing, or 
human error.


Can you copy *other* files from the Windows 7 machine onto the thumb 
drive, and then from there to the second computer?
No problem at all copying any other files to the thumb drive.  After I 
get out of this quandary with PATH, and get 2.7.2 working, I'll try to 
recreate the problem.





--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries

2011-12-19 Thread Wayne Watson

The PATH variable for me (user) has c:\Users\Wayne\g95\bin

On 12/19/2011 12:25 PM, Prasad, Ramit wrote:

James wrote:
In windows 7,

1. Go to start
2. Right click on Computer
3. Select Properties. This will bring up the System menu.
4. Select Advanced system Settings on the left hand side.
5. In this new window, select Environment variables... at the bottom
6. In the bottom window area, scroll down until you find PATH
7. Select Edit (do NOT delete anything contained in this or will screw some 
stuff up)
8. scroll to the very end and put a ; as a deliminator if there isn't one on 
the end already. Then put the direct path to you Python install you care about. 
(it should be something like this:(;C:\Python27) - this is mine in fact.
9. Hit OK. Then accept your way out. You will have to reboot.
10. To test, open a cmd prompt and and type simply python. if you get Python 
2.7.2 (some more stuff) then python is now on your path.
=
Modify User Variables and not System variables.
You will need to restart any open command prompt
but not the full machine.

PATH=%PATH%;c:\python27

That should pick up the system variables
and then append python's location to it.

http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx

If that does not work; then feel free to follow
James's advice and then restart.


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.



--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] A few Python Mysteries

2011-12-19 Thread Wayne Watson
It became apparent during the other part of this thread that I had not 
uninstalled Python 2.7, as I thought I had.  As pointed out in the PATH 
discussion (James R.), the last item in the system variable PATH was 
Python25. I would think then changing it to Python27 might Python 
rolling again.


--
   Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 CE 1955 October 20 07:53:32.6 UT
-- The Date The mystery unfolds.

Web Page:www.speckledwithstars.net/


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


Re: [Tutor] 'str' object has no attribute 'description'

2011-12-18 Thread Wayne Werner
On Sun, Dec 18, 2011 at 4:06 PM, Russell Shackleton rsh...@xtra.co.nzwrote:

 I am learning Python classes by writing an adventure game. I have
 extracted just the relevant code. The player can look, go, drop, take,
 inventory but not examine.

 Python produces the error message in the Player class, examine function,
 in the first print statement.


It's best to give the full traceback, because it provides an awful lot of
information.

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


Re: [Tutor] sqlite3: turning on foreign key support thru python

2011-12-18 Thread Wayne Werner
On Fri, Dec 16, 2011 at 1:43 PM, Modulok modu...@gmail.com wrote:

  How do I tell if it succeeded (short of trying an operation that should
 be
  blocked by foreign keys)?  How do I use that cursor object returned by
 the
  pragma query to tell if its a '1' (on) or a '0' (off) and verify the
 state?


 The cursor object contains the result set. It's a python generator object.
 (Or
 at least a generator interface.) You have to iterate over it in order to
 see
 the resulting rows which are stored as a tuple. Not all operations return a
 result row. (For example, conn.execute('pragma foreign_keys=ON' will
 return a
 cursor object, but it won't generate any result rows, as there were
 none returned by the database.)

 To see the result of your second command, do something like this::

rows = conn.execute('pragma foreign_keys')
for r in rows:
print r


If you're mucking about in the interactive prompt, and you just want to see
the results quickly you can just turn it into a tuple or a list (list would
be less typing):

print(list(rows))

or just

list(rows)

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


Re: [Tutor] reset password program

2011-12-18 Thread Wayne Werner
On Fri, Dec 16, 2011 at 7:17 PM, Robert Sjoblom robert.sjob...@gmail.comwrote:

  Some improvements to think about, in order of least secure (easiest) to
 most
  secure (hardest).
 
  (1) my secret password.txt is a crappy name. Is there a better name?

 I'm going to go with EULA.txt; the reasons should be obvious.


+1, because I laughed.

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


Re: [Tutor] 'str' object has no attribute 'description'

2011-12-18 Thread Wayne Werner
On Sun, Dec 18, 2011 at 4:49 PM, Russell Shackleton rsh...@xtra.co.nzwrote:

 I am learning Python classes by writing an adventure game. I have
 extracted just the relevant code. The player can look, go, drop, take,
 inventory but not examine.

 Python produces the error message in the Player class, examine function,
 in the first print statement.

 I have added the traceback following a suggestion from Wayne Werner.


That's much more useful. As a slight aside, it probably would have been
better to just reply-all to the original thread with the traceback.



 Traceback (most recent call last):
  File adv03.py, line 205, in module
main()
  File adv03.py, line 202, in main
game.play(adventurer)
  File adv03.py, line 147, in play
character.examine(cmdlist[1])
  File adv03.py, line 86, in examine
print Item Description:  + item.description + .\n
 AttributeError: 'str' object has no attribute 'description'
 [Note: actual line numbers appended in comments in this listing]


This is *much* more helpful - I don't even need to see your code to tell
you what went wrong. I don't know if you've worked with other programming
languages with nearly useless stack traces, but in Python you'll find that
they're (usually) very high quality. In this case it tells you a few
things. First, it tells you where it happened with this line:

  File adv03.py, line 86, in examine

It happened in the file adv03.py, on line 86, in a function (or method)
called examine.

The next two lines tell you what blew up, and why it did:

   print Item Description:  + item.description + .\n
 AttributeError: 'str' object has no attribute 'description'


'str' object has no attribute 'description'. Well if you look on the line
before that the only description attribute you try to look up is
item.description. So if 'str' doesn't have that attribute then item must be
a string.

With that in mind, let's take a look at that function:

   def examine(self, item):
Prints description of item.
if item in self.items:
# Error: 'str' object has no attribute 'description'
print Item Description:  + item.description + .\n # line 86
else:
print You are not holding the  + item +  to examine!\n


This looks pretty straightforward. You pass something in as item, and check
to see if it's contained in your list of items. If it is, then you print
out the description, otherwise you print out whatever you passed in.

And so if we rewind back to where you call the function:

  character.examine(cmdlist[1]) # line 147


What is cmdlist? A list of strings. What is contained in cmdlist[1]?

If you still have issues fixing this, please let us know.

HTH,
Wayne

How do I fix this code, please?

 class Player(object):
The player in the game.
def __init__(self, name, currentRoom=None):
self.name = name
self.currentRoom = currentRoom
self.items = [] # items taken by Player

def look(self):
Prints the room description, exits and items in the current
 room.
print self.currentRoom

def go(self, direction):
Go to another room through an exit.

def drop(self, item):
Drop an item you are carrying in the current room.

def take(self, item):
Take (pick up) an item from the current room.
if item == self.currentRoom.item:
self.items.append(item)
print self.currentRoom.item +  added to player's inventory.\n
# remove item from currentRoom
self.currentRoom.item = ''
else:
print There is no  + item +  here to take!\n

def inventory(self):
Prints list of items the player is carrying.

def examine(self, item):
Prints description of item.
if item in self.items:
# Error: 'str' object has no attribute 'description'
print Item Description:  + item.description + .\n # line 86
else:
print You are not holding the  + item +  to examine!\n

 class Item(object):
A useful item in the game.
def __init__(self, name, description, location):
self.name = name
self.description = description
self.location = location

def __str__(self):
Description of item.
return self.description

 class Game(object):
The adventure game.
def __init__(self, name, player):
self.name = name
self.player = player
print Welcome to  + self.name + \n
print player.currentRoom

def play(self, character):
Command loop for game.
while True: # loop forever
commands = raw_input(- ).lower()
if not commands:
print Huh?
else:
try:
cmdlist = commands.split()  # separate commands
action = cmdlist[0]
if action == quit:
print See you later!
break

Re: [Tutor] where I am going wrong?

2011-12-14 Thread Wayne Werner
On Wed, Dec 14, 2011 at 8:13 AM, surya k sur...@live.com wrote:


 This is a project Euler puzzle. http://projecteuler.net/problem=30
 I applied brute force way and here is my code
 k=0for p in range(1,10):for q in range(0,10):for r in
 range(0,10):for s in range(0,10):for t in
 range(0,10): n = (p*1)+ (q*1000) + (r*100) + (s*10) +
 (t*1) if n == \ p**5 + q**5 + r**5 +
 s**5 + t**5:print n
 k+=nprint k
 My answer: 240559
 But its showing the answer as wrong!!.
 I used the same method on the example puzzle and it worked.


Your email client broke the formatting - you should probably use plain-text
or a pastebin.

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


Re: [Tutor] return, why do I need it?

2011-12-11 Thread Wayne Werner
On Dec 11, 2011 8:41 AM, Pete Oapos;Connell pedrooconn...@gmail.com
wrote:

 Hi I have been writing python code for a while now and I never return
anything within any of my functions, I just (eg.) print stuff or make
directories or update a log or what have you. When I look at other people's
code they are always returning in their functions and I was wondering if
someone could give me an example of when I would absolutely have to return
something. The thing I don't like about returning is that when I unindent a
function and try to run the code to inspect parts of it for debugging I
always have to alter the code so as not to get the return not inside a
function error,  so I will change the word return to print and in many
cases that's the way I leave it. Anyone have any thoughts on this?


No one has mentioned it so far, but the interactive interpreter is what you
should use for debugging short code snippets.  I always program with two
windows open - one with my editor and one with the interpreter. This lets
me try out short bits of code without running my whole program.

Hth,
Wayne
 Thanks
 Pete


 ___
 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] Python Windows Vista Installation Question

2011-12-09 Thread Wayne Werner
On Fri, Dec 9, 2011 at 12:41 PM, Homme, James james.ho...@highmark.comwrote:

  Hi,

 Can Python easily be installed on a Windows Vista computer without needing
 administrative rights to that machine?



If you use portable python: http://www.portablepython.com/ that might work
for you.

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


Re: [Tutor] how to use int and split() simultaneously

2011-12-08 Thread Wayne Werner
On Thu, Dec 8, 2011 at 7:43 AM, Dario Lopez-Kästen cl2dl...@gmail.comwrote:

 snip

 In that case a for loop with a try-except would better:

 strNum = raw_input(enter numbers, separated by space: ).split()
 num_list = []

 for token in strNum:
 try:
 num_list.append(int(token))
 except ValueError:
 # Do nothing, fetch the next token
 continue

 print repr(num_list)
 snip
 Strictly speaking the continue in the except clause is not necessary in
 this simple example.


Though you do have to have *something* or you'll get a syntax error because
you can't have an empty block. The keyword `pass` works well in cases like
this.

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


Re: [Tutor] Python Saved the Day

2011-12-04 Thread Wayne Werner
On Sun, Dec 4, 2011 at 2:51 AM, wesley chun wes...@gmail.com wrote:


 Does anyone else have similar stories? (I think I may be biased as I use
 Python for everything, trouble or otherwise, so I can't tell the difference
 anymore!)


I work in a .NET shop, and the last project I worked on required us to
re-implement a report system that was doing a variety of complicated things
(due to the nature of the older tech used).

This required us to run and re-run our version to compare against the old,
many many times. My teammate started doing the comparisons by hand using a
merge tool... after watching that process for about 5 minutes, I went ahead
and wrote a quick Python script (30 lines) that would compare the two
reports. I ended out extending the script to a full blown text-program with
some nice menus and things, and all told probably spent less than an hour
or two writing scripts that saved... probably at least 10 man hours of
comparisons, probably much more than that when you factor in the exhaustion
from doing such a menial task.

The tools that I found extremely useful:

1) Modules - I used re and csv fairly heavily. One piece of the report was
textual and the re module allowed me to easily parse out the important
information from each report. The other one was a spreadsheet, so csv
readers were quite nice

2) List comprehensions/generator expressions - mutating the data from text
to something that I could really use took two or three passes. Being able
to express this in two or three lines was invaluable

3) Syntax (including dynamic binding) - the terse syntax allowed me to
express what I wanted to express, with no extra stuff (e.g. End With)

Personally I wish I was in your shoes (using it for everything), but I'm a
huge Pythonista so that should hardly be a surprise ;) (and definitely
wouldn't be a surprise for any of my former classmates. I was quite the
evangelist... and still am)
-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Prime Factorization Tool

2011-12-01 Thread Wayne Werner
On Thu, Dec 1, 2011 at 7:15 AM, Robert Sjoblom robert.sjob...@gmail.comwrote:

 So I've recently started poking at the Project Euler site, because I
 feel that I need to practice writing code. For those of you interested
 in solving the problems on your own I advice you to not read this, as
 it will spoil the solution.

 Problem 3 is this:
 The prime factors of 13195 are 5, 7, 13 and 29.

 What is the largest prime factor of the number 600851475143 ?

 I came up with this pseudocode:
 #pseudocode:
 #divide by x until non-prime is found:
 #if not remainder:
 #check if it's prime or not:
 #if not prime: exit loop
 #if not prime: store in variable
 #increment x by 1

 Here are the functions I came up with:

 def isprime(n):
if n == 1:
return False
for x in range(2, n):
if n % x == 0:
return False
else:
return True

 def factorization(n):
factor = 0
x = 2
while True:
if n % x == 0:
if isprime(x):
factor = x
else:
return factor
x += 1

 This, however, feels horribly inefficient. Is there a better way to do
 it? I think most of my problems stem from my weak mathematical skills,
 to be honest. This wasn't too bad, but even for problems 1 and 2 I've
 relied on brute forcing the answer instead of looking for a
 mathematical solution.


Well, there are really only a couple of optimizations that you could make.
That's the nice (bad?) thing about primes - you really only *can* brute
force a solution. That's why nice things like encryption exist.

The less obvious optimization is in reference to primes - you don't
actually have to check all the way up to N. Or even N/2. You only have to
check numbers up to the square root of N. This explanation may not be
mathematically sound, but basically the reason this works is the definition
of prime: N is divisible only by N and 1. If you divide a number by 2 then
then the result will be the largest factor (e.g. 100/2 = 50). But as you
start increasing the divisor then obviously the result has to decrease. The
point at which these numbers are equivalent? The square root, of course.

That will easily decrease the running time of your program because now
instead of dividing N numbers you're dividing sqrt(N) numbers.

The other optimization that you can do is in the factorization loop -
you're checking all factors from 2 to N. The easiest fix here is the fact
that you *know* that no even number can be a prime factor for the simple
reason that it's divisible by 2. So start your loop at 3 and increment by 2
and you've just cut out half the numbers. But wait, there's more! What is
the largest possible factor of a number?

I'll let you think about it for a moment...

Got it?

Hey, no peeking!

Well, I guess you can peek.

N/2 is the largest possible factor. Any number larger than N/2 is somewhere
between N/2 and N/1, and since there's no whole number between 2 and 1 you
know that the largest number you need to check for a factor is N/2, or in
the case of 100/2 = 50.

So for 100, instead of checking if 100 numbers are prime, now you're only
checking:

3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 49

*much* fewer numbers. And for each N in that list you're only checking up
to the sqrt(N). Now you've vastly improved your running time.

Now, I'm not sure what the time complexity of these two operations is, but
go ahead and put this line in your isprime:

if n == 11: print(Checked 11... again)

Can you think of a way to compute the primes you need to check only once?

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


Re: [Tutor] tkinter message button questions

2011-11-30 Thread Wayne Werner
On Wed, Nov 30, 2011 at 8:32 AM, Cranky Frankie cranky.fran...@gmail.comwrote:

 Peter Otten __pete...@web.de wrote:
 snipPeter thanks again. The msg_widget is still resizing vertically
 depending on the lenght of the quote, but at least now the horizontal
 sizing is staying the same. Ideally the msg_widget would be the *same
 size*, no matter what the quote length is, but since this program is
 really just a learning exercise and to show database adminstrators a
 simple Python GUI application I can live with it.


The whole purpose of the Message widget is that it *does* resize. If you
wanted something to be a static size, I think a Label would fit the bill -
though I haven't played around enough with that in recent time.



 The syntax you used, like root.geometry(400x100), I have not seen
 before, and I've done a lot of searching. Again, much of the tkinter
 stuff I see seems to be based on Python 2.6. If there is a definitive
 book or reference on using tkinter in Python 3.x I'd really like to
 know about it.


That's the great thing about Python - most of the syntax is identical, and
there should be only minor differences between Python 2.x and 3.x -
especially where Tkinter is concerned.

I would go ahead and look at 2.x tutorials/articles for Tkinter and just be
aware that you'll encounter some issues (probably mostly dealing with
Unicode strings, and occasionally something numeric - based on my
experience). With that preparation then you should be able to easily search
for answers to the problems you encounter.

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


Re: [Tutor] plotting in python

2011-11-30 Thread Wayne Werner
On Wed, Nov 30, 2011 at 3:08 PM, stm atoc stm.at...@googlemail.com wrote:

 Hi there,

 I have a question regarding plotting with Python.

 snip
 ValueError: x and y must have same first dimension


It looks like  something is wrong with the data that you're trying to plot.
Specifically, the data that you're trying to plot has the wrong dimensions
(like it says).

An example:

# 2d space:
x = [(1, 1), (2, 2), (3,3)]
y = [(1,1,1), (2,2,2), (3,3,3)]

x is a series of points in 2 dimensions, and y is a series in 3. If your
data really is supposed to look like that then you'll need to pad or trim
the data so you've got the correct dimensions.

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


Re: [Tutor] is there a better way to organise this code

2011-11-30 Thread Wayne Werner
On Wed, Nov 30, 2011 at 3:34 PM, Norman Khine nor...@khine.net wrote:

 hello,

 is there a better way to organise this code or optimise it.

 http://pastie.org/2944797


After glancing at it the only change that I would recommend (possibly)
making is lines 58 and 39 - you can wrap the dictionaries (line line 7) and
that will bring all your lines  80 characters. Other than that it looks
perfectly readable. You could add some docstrings for completeness.

As far as anything else - is this code too slow? If not, why bother trying
to optimise it? Obviously if you were doing something horribly inefficient
like a bubble sort (especially considering Python has a built-in sort),
then you would want to get rid of that, but I didn't really notice
anything. Though now that I took a few more seconds, it does look like
you're not using rows, aside from looping over it. If you only care about
the values and not the collection as a whole you could (and should) change
the list comprehension to a generator expression:

 [x for x in (1,2,3)]
[1, 2, 3]
 (x for x in (1,2,3))
generator object genexpr at 0x01BFB6C0

If you're not familiar with a generators, I highly recommend this set of
slides: http://www.dabeaz.com/generators/Generators.pdf

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


Re: [Tutor] problem with msg widget button

2011-11-29 Thread Wayne Werner
On Tue, Nov 29, 2011 at 9:54 AM, Cranky Frankie cranky.fran...@gmail.comwrote:

 Peter Otten __pete...@web.de wrote:

 snip

Isn't msg_widget an object, like everything else in Python. If so, why is
 it not

 def display_quote():
   msg_widget.text = choose_quote()

 That is one of the things I tried. I don't understand why the [test]
 pair works above.


Just because msg_widget is an object doesn't automatically give it a .text
attribute. Just like the following dictionary (which is an object):

 knights = {'Aurthur': 'King of the Britons', 'Robin':'The Brave'}
 knights['Robin']
'The Brave'
 knights['Robin'] = 'The Coward'
 knights.Robin
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'dict' object has no attribute 'Robin'

They simply made a design choice to allow access to the data via index (in
this case text is the index), rather than by object attribute.

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


Re: [Tutor] Making a function run every second.

2011-11-29 Thread Wayne Werner
On Tue, Nov 29, 2011 at 10:09 AM, Dave Angel d...@davea.name wrote:

 sniptkinter provides a couple of specific timer events, and I now see
 your reply to a message that said to use the after() method, which is a
 one-shot.  I believe there's another one that sets a periodic timer so you
 don't have to do an after() call each time it fires.


Not in Tkinter - you have to do what Peter Otten suggested:


 For a script that uses tkinter there's the after() method.
 Example:
 root = Tk()
 def hi():
print(ho)
 def hi_reschedule():
hi()
# make tkinter call it again after 1000 milliseconds
root.after(1000, hi_reschedule)
 hi_reschedule() # call it manually the first time



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


Re: [Tutor] list, tuple or dictionary

2011-11-29 Thread Wayne Werner
On Tue, Nov 29, 2011 at 2:31 PM, ADRIAN KELLY kellyadr...@hotmail.comwrote:

  i am trying to create a program that will allow users to enter items and
 their prices; should i be looking at a list, tuple or what?


The entering part isn't as important as how you want to display the data.
For instance, here's a program that allows the user to input an unlimited
amount of data (using Python 3.x):

while input(Enter q to quit, or an item: ).lower() not in ('q', 'quit',
'goodbye'):
 input(Enter the price: )

Of course it doesn't store the data, so it's pretty useless. But it does
allow the user to input whatever they want.

If you wanted to simply create a collection of items you could do it as a
list with alternating values:

inventory = ['Crunchy Frog', 4.13, 'Anthrax Ripple', 12.999,
'Spring Surprise', 0.00]
for x in range(0, len(inventory)-1, 2):
  print(inventory[x], inventory[x+1])

Or as a list of tuples:

inventory = [('Norwegian Blue', 500.00), ('Slug', 500.00), ('Cage',
50.00)]
for item in inventory:
print(item[0], item[1])

Or a dictionary:

inventory = {'Spam':5.00, 'Spam on eggs':10.00, 'Spam on Spam':7.50}
for item, price in inventory.items():
print(item, price)

Or if you wanted to get ridiculous, you could go with a list of classes:

class Item:
def __init__(self, desc='', price=0.00):
self.desc = desc
self.price = price
def __repr__(self):
return str(self)
def __str__(self):
return {0} - {1}.format(self.desc, self.price)

inventory = [Item('Lumberjack', 5.5), Item('Tree', 50), Item('Flapjack',
0.5)]
for item in inventory:
print(item)


It just depends on how complex you want to get!
HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] list, tuple or dictionary

2011-11-29 Thread Wayne Werner
On Tue, Nov 29, 2011 at 3:04 PM, ADRIAN KELLY kellyadr...@hotmail.comwrote:

  thanks guy, i was thinking of using a dictionary:-
  Stock_list = {White Bread: 1.24,
 Biscuits: 1.77,
 Banana : 0.23,
 Tea Bags : 2.37,
 Eggs : 1.23,
 Beans : 0.57}

 how would i go about *adding, *for example tea and eggs to get a subtotal?


Why, you would add tea and eggs, of course!

print(Subtotal: , Stock_list[Tea Bags] + Stock_list[Eggs])


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


Re: [Tutor] pass tuples to user defined function(beginner)

2011-11-29 Thread Wayne Werner
On Tue, Nov 29, 2011 at 3:40 PM, Mayo Adams mayoad...@gmail.com wrote:

  I cant immediately see how anything in a script is
 anything other than a representation of some kind, hence the
 distinction between representamen and object does no work for me.


That's exactly it - when you have something like this in a file named, say
data.txt:

(This, 'is', 'a', 'silly', 'tuple')

Then that's all it is - just text data. I happens to *look* like a tuple,
but it's not. If you rename that file to data.py... well, it's still text
data. If you add an assignment operation to the line:

data = (This, 'is', 'a', 'silly', 'tuple')

Then you could actually import it with `from data import data`. Once the
data is actually evaluated, then it's live - it really is a tuple, and it
can be used in tuple-ish ways.

I think the main reason to make a distinction like that is that if you
encounter a .py file with data like this:

 __import__('os').system('echo i got you now rm-rf')

You know it's probably going to do some bad things to your system if you
run it. If you open that in a text editor, on the other hand, it's unlikely
to do anything painful.

I think there's also some use in making the distinction between data and
code. Python provides you with /ridiculously/ easy ways to read in data. So
if you have a bunch of strings that you want in a tuple you should do
something like:

data = tuple(f.open('data.txt').readlines())

Which has the added advantage of *just* reading in strings. If you want to
convert that data into other types (integer, float, etc.) then you can
easily do it explicitly, and explicit is better than implicit.

In reality of course, all the data is just 1's and 0's floating out there,
but I think it's helpful to develop these abstractions.
HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing Game in python

2011-11-27 Thread Wayne Werner
On Sun, Nov 27, 2011 at 7:52 AM, surya k sur...@live.com wrote:

  Hi,


 Actually, I want to develop a multiplayer Bingo game. So, I would like to
 develop it in python  C. As I am not familiar with game development, could
 you please tell me what libraries I should use for development?... etc


You could easily develop the game entirely in Python. As for libraries...
well it depends on what you're trying to do.

If you want a GUI you'll want to look at one of the frameworks like
Tkinter, PyGTK+, wxPython, or QtPython. Alternatively you could look at the
PyGame library which is geared towards game development.

If you want to do internet communication, you'll want to investigate the
socket module, and possibly the threading module.

How familiar are you with Python? Have you written any programs before?

What would really help is if you gave us some psuedocode of your algorithm
or the steps you think each piece should need to accomplish. We like to see
that you've at least tried to do something.

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


Re: [Tutor] Python 3 dictionary questions

2011-11-23 Thread Wayne Werner
On Wed, Nov 23, 2011 at 7:04 AM, Cranky Frankie cranky.fran...@gmail.comwrote:

 In playing around with Pyton 3 dictionaries I've come up with 2 questions

 1) How are duplicate keys handled? For example:

 Qb_Dict = {Montana: [Joe, Montana, 415-123-4567,
 joe.mont...@gmail.com,Candlestick Park],
 Tarkington: [Fran, 651-321-7657, frank.tarking...@gmail.com,
 Metropolitan Stadidum],
 Namath: [Joe, 212-222-, joe.nam...@gmail.com, Shea Stadium],
 Elway: [John, 303-9876-333, john.el...@gmai.com, Mile High
 Stadium],
 Elway: [Ed, 303-9876-333, john.el...@gmai.com, Mile High
 Stadium],
 Manning: [Archie,504-888-1234, archie.mann...@gmail.com,
 Louisiana Superdome],
 Staubach: [Roger,214-765-8989, roger.staub...@gmail.com,
 Cowboy Stadium]}

 print(Qb_Dict[Elway],\n)# print a dictionary
 entry

 In the above the wrong Elway entry, the second one, where the first
 name is Ed, is getting printed. I just added that second Elway row to
 see how it would handle duplicates and the results are interesting, to
 say the least.

 2) Is there a way to print out the actual value of the key, like
 Montana would be 0, Tarkington would be 1, etc?


I'm not sure about #1, but I can tell you about #2.

Dictionaries are not ordered, so you have absolutely no guarantee which
order they'll appear in when you print them out, or if you iterate over the
dictionary. If you want to maintain some type of order you have a few
options. First, store the keys in a list, which does maintain order:

keys = ['Elway', 'Montana', ... ]

Then you would do something like:

Qb_Dict[keys[0]]

(As a slight aside, I'll direct you to PEP 8 which is the Python style
guide which contains things like naming conventions. If you want your code
to look Pythonic, you should take a look there.)

If you just want them to be sorted, you can run sorted on the keys()
collection from the dictionary:

for key in sorted(Qb_Dict.keys()):
print(Qb_Dict[key])

In Python 3 this will only work if your collection contains comparable
types - if you have {1:'Hello', 'Goodbye':2} then you'll get a TypeError
when it tries to compare 1 and 'Goodbye'

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


Re: [Tutor] sensing EOF in Python 3.1

2011-11-23 Thread Wayne Werner
On Wed, Nov 23, 2011 at 12:03 PM, Cranky Frankie
cranky.fran...@gmail.comwrote:

 [...]
 The reason why I'm pickling is I'm trying to include information on
 Python data structures in the presentaton I'm preparing. [...]


In your context why not just use modules?


 # data.py
Qb_dict = {Montana: [Joe, Montana, 415-123-4567,
joe.mont...@gmail.com,Candlestick Park],
Tarkington: [Fran, 651-321-7657, frank.tarking...@gmail.com,
Metropolitan Stadidum],
Namath: [Joe, 212-222-, joe.nam...@gmail.com, Shea Stadium],
Elway: [John, 303-9876-333, john.el...@gmai.com, Mile High
Stadium],
Elway: [Ed, 303-9876-333, john.el...@gmai.com, Mile High
Stadium],
Manning: [Archie,504-888-1234, archie.mann...@gmail.com,
Louisiana Superdome],
Staubach: [Roger,214-765-8989, roger.staub...@gmail.com,
Cowboy Stadium]}

# program.py
from data import Qb_dict
print(Qb_dict)

Then you can put whatever comments or data you want. Just make sure that
you don't name your data.py file the same as something built-in. It's
pretty horrible when you try to 'import random' and it doesn't randint() or
anything else that you're looking for.

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


Re: [Tutor] FW: urgent help!! THANKS EVERYONE!

2011-11-18 Thread Wayne Werner
On Fri, Nov 18, 2011 at 9:26 AM, Prasad, Ramit ramit.pra...@jpmorgan.comwrote:

 Forwarding to the list since I wasn't the only person who helped ;)

 From: ADRIAN KELLY [mailto:kellyadr...@hotmail.com]
 Sent: Thursday, November 17, 2011 6:08 PM
 To: Prasad, Ramit
 Subject: RE: [Tutor] urgent help!! THANKS EVERYONE!

 Thanks for your help i just got it going my way below - but your way looks
 easier and better!
 thanks for all your help everyone.  feel free to comment on my method -
 its awkward but it works.. snip
 def main():
 amount=0
 amount = float(raw_input('how much do you want to change:'))
 while amount50:
 print 'enter an amount over 50'
 amount = float(raw_input('how much do you want to change:'))
 else:
 total=exchange(amount)
 print 'Your exchange comes to: ',total


In these sorts of cases I actually prefer the recursive solution. And from
a usability standpoint it's much nicer to warn the user ahead of time:

def amount_over_50():
amount = float(raw_input(How much do you want to change (minimum $50)?
Amount: $))
if amount  50.0:
print 'Please enter an amount greater than $50'
return amount_over_50()
return amount


Then you can just do this:

def main():
print 'Your total comes to', exchange(amount_over_50())

The chances of hitting the maximum recursion depth is pretty slim, unless
your user manages to type in a wrong number about 1000 times ;)

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


Re: [Tutor] Saving read-only or encoded text files?

2011-11-18 Thread Wayne Werner
On Fri, Nov 18, 2011 at 11:17 AM, Max gmail maxskywalk...@gmail.com wrote:

 Thank you.  This will work perfectly.

 On Nov 18, 2011, at 11:58 AM, Prasad, Ramit wrote:
 snip
 
  Any file will eventually be able to be reverse engineered, but it
 matters how much effort you care to obfuscate it. The way you can do it
 will vary based on your OS.
 
  For Windows, you can change the file extension to something that is not
 read by most text editors '.zxy'. It will still be able to be read if they
 try and open it with a text editor, but double clicking  will not work by
 default. You can also try setting the file attribute directly:
 http://code.activestate.com/recipes/303343-changing-file-attributes-on-windows/
 
  For *nix/OS X, you can prepend the file with . as those files are
 hidden by default on most *nix systems I have used. You can also try to use
 os.chmod(0###, 'filename').
 
 
  Keep in mind that all of these solutions are probably user reversible
 since the application will have the permissions of the user account it is
 run as; in most cases this is the same as the logged in user.
 snip


As an addition, you can also create the file using the zipfile module (
http://docs.python.org/library/zipfile.html). This adds another layer of
obfuscation and has the added benefit of making your files smaller. Of
course, the savvy user won't have any issue getting past this (Office files
are just archive files). On Ubuntu at least, if you just remove the
extension then it will attempt to discover what the filetype, and can
usually guess archive types.

It's security through obscurity, of course, so it all depends on who you're
worried about accessing this data.

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


Re: [Tutor] Clock in tkinter?

2011-11-17 Thread Wayne Werner
On Thu, Nov 17, 2011 at 8:57 AM, Mic o0m...@hotmail.se wrote:

   snip

 Okay, to begin with, I hope I am replying correctly now.


Better, though there was quite a lot of my email that you could have
removed.



 I wonder, how do I add a background picture to my GUI window?

 So far, I thought I could make a label that is as large as the
 entire window, and then add a picture to it. The other widgets
 are supposed to be placed on top of the picture.

 But I am lost on how to accomplish this. Can you point me in the
 right direction to solve this?


If you want to do this, I would recommend using the place (as opposed to
pack or grid) manager inside of a frame widget. Use that to place your
image, and another frame that contains your other widgets - I would use the
pack or grid layout inside this other frame, though.

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


Re: [Tutor] Clock in tkinter?

2011-11-17 Thread Wayne Werner
On Thu, Nov 17, 2011 at 1:17 PM, Mic o0m...@hotmail.se wrote:

   I have now worked to stop using the global scope and instead put my
 prior global variable into
 the constructor in the class. I believe that I have managed to do that now.

 Do you believe that this is correctly done?


 #Trying putting the_time'' in constructor instead of
 #putting it in the global scope to shorten code.

 snip

   def update_time(self):

self.display_time.config(text=time.strftime('%H:%M:%S'), font='40')
self.after(20, self.update_time)


Since you're using the shorter version of the function you no longer need
self.the_time, so you can go ahead and remove that variable.



 I have another question.


It would have been fine (and even preferred) to create a new email here
with a title something like How do I shorten this code?



 Say that I have a class and I want to make 100 objects.
 Then it could look like this:
 snip
 class Chairs(object):
 snip code


 #Create the objects
 chair1=Chairs(10,20)
 chair2=Chairs(10,20)
 chair3=Chairs(10,20)


 How do I shorten this? I have thought of using a for sling. I have looked
 in my programming
 book and on the internet, but I don’t know how to make this shorter. The
 arguements (“10”, “20”)
 should be the same for every object, which should make it easier than if
 they were different each time?


If you ever write a line of code more than once, it's a good sign that you
have what's called a code smell. This example is very smelly code ;)

What you should do instead is have a collection of chairs:

chairs = []
for _ in range(100): # the underscore `_` indicates that you don't care
about the value
chairs.append(Chairs(10,20))

You can do that even shorter with a list comprehension, but I'll leave that
exercise up to you :)

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


  1   2   3   4   5   6   7   8   9   >