Re: [Tutor] Defining "bit" type

2009-01-25 Thread Vicent
On Sat, Jan 24, 2009 at 20:43, bob gailer  wrote:

>  Vicent wrote:
>
>
> It would be great if   "b.value = 0"   could be just written as "b = 0"
> without changing type as a result.
>
>
> Assignment in effect does a del b, then creates a new b based on the
> expression. There is no way in Python right now to do that. The closest I
> can come is to support the syntax b(0) and b(1) to emulate assignment. That
> would require that I add to the Bit class:
>
>   def __call__(self, value):
> self.value = value
>

OK, I think I understand...


>
>
> What happens if every time I want to update the value of "b", I use "b=
> Bit(0)" , "b=Bit(1)", and so on?? Is like "building" the object each time?
> It is less efficient, isn't it?
>
>
> Yes and yes.
>

Ok...


>
>
> You are going to kill me
>
>
> Are you saying that to prepare your self for a negative response from me,
> or in hopes that I would not have such? I view everything we do here as
> incremental improvement. I am glad you are thinking of alternatives.
>

Thank you...


>
>
>  , but... Maybe the solution is not to re-define what already exists
> —boolean data type, but just using it, as suggested at the beginning of the
> thread...
>
> b = bool(1)
> b = bool(0)
>
> After all, it's not so bad...
>
>
> It really depends on your goals for having this new type.
>


I was thinking about this during this night (sometimes, it is near to sleep
or when having a shower when new ideas come out!, isn't it?).

Maybe, all I need to do is this:

>>> bit = bool

And then, I can do this:

>>> b = bit(0)

I mean, just using "bit" as an "alias" for "bool" [, and forget about any
new class or whatever]. In fact, type for "b" is "bool":

>>> type(b)




On Sat, Jan 24, 2009 at 22:46, Kent Johnson  wrote:

>
>
> You have an incorrect idea about how variables and assignment work in
> Python. Type is associated with a value, not a name. You might want to
> read this:
> http://personalpages.tds.net/~kent37/kk/00012.html
>
> and this classic:
> http://effbot.org/zone/python-objects.htm
>
>

Yes, I was a bit confused, although I've already read those links you
provide (I think you gave them to me in another recent post). They are very
good explanations.

I think I hadn't get that "0" is always integer, but now I get it. If I want
to make it boolean (bit-like), it should be referred as "bool(0)".   [It is
like that, isn't it]

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


Re: [Tutor] Defining "bit" type

2009-01-25 Thread Kent Johnson
On Sun, Jan 25, 2009 at 5:13 AM, Vicent  wrote:

> I think I hadn't get that "0" is always integer, but now I get it. If I want
> to make it boolean (bit-like), it should be referred as "bool(0)".   [It is
> like that, isn't it]

Yes, though bool(0) is actually creating a new bool object with the
same true/false value as the integer 0. It's not the same as a cast in
C that just looks at the same value in a new way. You can also do
things like
In [1]: bool("hello")
Out[1]: True

In [2]: bool("")
Out[2]: False

In [3]: bool([1,2,3])
Out[3]: True

In [4]: bool([])
Out[4]: False

In each case it is creating a new bool value.

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


[Tutor] Creating a PDF from http://effbot.org/imagingbook/

2009-01-25 Thread Wayne Watson
Title: Signature.html




I have acrobat pro 8, but have only used it occasionally. I tried
creating a pdf from . It worked,
but I had hoped it would draw in all the links in the "TOC".  Not so. 
Maybe someone knows how to do this, or perhaps there's already a pdf
with everything in it? 
-- 


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

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)

 Copper and its alloys have been found effective in hospital
 sinks, hand rails, beds, ... in significantly reducing 
 bacteria. Estimates are 1/20 people admitted to a hospital
 become infected, and 1/20 die from the infection.
   -- NPR Science Friday, 01/16/2009 

Web Page: 



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


[Tutor] string problem

2009-01-25 Thread Manoj kumar
  
i was trying to write a script for a port scanner. i was able to get a working 
scanner which can scan a given host.

now i want to upgrade it to scan for a given range of ip address. 
for example:
starting ip:166.43.234.43
last ip:234.23.45.123

no problem i am facing is that i am really NOT able to split ip addresses into 
nodes like:
166.43.234.43 would be like '166','43','234','43'


help me please.

thanks in advance


MANOJ SHEOKAND

(+919728523528)

"some day there won't be a song in ur heart, sing anyway"___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] string problem

2009-01-25 Thread Eugene Perederey
What's a problem to split the string like
>>>'166.43.234.43'.split('.')
Maybe I misunderstand you problem...

2009/1/25 Manoj kumar :
>
> i was trying to write a script for a port scanner. i was able to get a
> working scanner which can scan a given host.
>
> now i want to upgrade it to scan for a given range of ip address.
> for example:
> starting ip:166.43.234.43
> last ip:234.23.45.123
>
> no problem i am facing is that i am really NOT able to split ip addresses
> into nodes like:
> 166.43.234.43 would be like '166','43','234','43'
>
>
> help me please.
>
> thanks in advance
>
> MANOJ SHEOKAND
>
> (+919728523528)
>
> "some day there won't be a song in ur heart, sing anyway"
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>



-- 
Sincerely yours, Eugene Perederey
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Find a Word in *.py (Win XP)

2009-01-25 Thread Wayne Watson
Title: Signature.html




If I open a folder in Win XP with a number of py files, and when I
search for *.py for the word angle, I get zippo. However, the word
exists in one of the py files. Probably the py files are scrambled in
some way. How nevertheless do I find the file. BTW, I know where it is,
but I'm wondering why this doesn't work. 
-- 


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

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)

 Copper and its alloys have been found effective in hospital
 sinks, hand rails, beds, ... in significantly reducing 
 bacteria. Estimates are 1/20 people admitted to a hospital
 become infected, and 1/20 die from the infection.
   -- NPR Science Friday, 01/16/2009 

Web Page: 



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


Re: [Tutor] Find a Word in *.py (Win XP)

2009-01-25 Thread Kent Johnson
On Sun, Jan 25, 2009 at 10:31 AM, Wayne Watson
 wrote:
> If I open a folder in Win XP with a number of py files, and when I search
> for *.py for the word angle, I get zippo. However, the word exists in one of
> the py files. Probably the py files are scrambled in some way. How
> nevertheless do I find the file. BTW, I know where it is, but I'm wondering
> why this doesn't work.

How are you searching? .py files are plain text.

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


[Tutor] No module named 'module name'

2009-01-25 Thread Robert Berman

In the following code:

import sys

from PyQt4 import QtCore, QtGui

from testwin import Ui_TestWindow

class StartQT4(QtGui.QMainWindow):
   def __init__(self, parent = None):
   QtGui.QWidget.__init__(self, parent)
   self.ui = Ui_TestWindow()
   self.ui.setupUi(self)
  
  
  
if __name__ == "__main__":

   app = QtGui.QApplication(sys.argv)
   myapp = StartQT4()
   myapp.show()
   sys.exit(app.exec_())

I receive the following error message: Import error: No module named 
testwin. If I use ipython and do the from statement, it works just fine. 
I think it may have something to do with a path value although I hate to 
even bring that up as I am using Linux Ubuntu 8.10 and cannot remember a 
"path" error since working under Windows XP.


The editor in use is Wing IDE Personal version. I am building my form(s) 
using QT4 and testwin.py is built with pyuic4.


I have sen some reference to something called "Python Path", but it 
seems to be referenced most often by Windows users so I am now totally 
confused. Would a few of you who understand these relationships far 
better than I please elaborate as to what I might be doing wrong.


Thanks for the assistance.

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


Re: [Tutor] No module named 'module name'

2009-01-25 Thread Alan Gauld

"Robert Berman"  wrote


from testwin import Ui_TestWindow

I receive the following error message: Import error: No module named 
testwin.


If I use ipython and do the from statement, it works just fine. I 
think it may have something to do with a path value


I think you are right!

Try putting

import sys
print sys.path

At the top of the file then run it from both IPython and Wing.

Also try running the file from an OS prompt rather than
from inside the IDE.

I have seen some reference to something called "Python Path", but it 
seems to be referenced most often by Windows users


Nope, PYTHONPATH applies to any OS.
You need to use it if you have any modules in folders other than
the default locations used by Python. I think the preferred place
to set PYTHONPATH is in your .login script but if I'm wrong I'm
sure a more regular *nix user will say so :-)

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



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


Re: [Tutor] No module named 'module name'

2009-01-25 Thread Robert Berman

Alan,

After you gave me the blatant hint to look at the system path; the 
problem became obvious. Wing assigns the path of the project file to one 
of the paths revealed by sys.path. I, of course, had put the project 
file in the folder above  my working folder.


Another learning experience.

Thank you for the key that unlocked the obvious.

Robert


Alan Gauld wrote:

"Robert Berman"  wrote


from testwin import Ui_TestWindow

I receive the following error message: Import error: No module named 
testwin.


If I use ipython and do the from statement, it works just fine. I 
think it may have something to do with a path value


I think you are right!

Try putting

import sys
print sys.path

At the top of the file then run it from both IPython and Wing.

Also try running the file from an OS prompt rather than
from inside the IDE.

I have seen some reference to something called "Python Path", but it 
seems to be referenced most often by Windows users


Nope, PYTHONPATH applies to any OS.
You need to use it if you have any modules in folders other than
the default locations used by Python. I think the preferred place
to set PYTHONPATH is in your .login script but if I'm wrong I'm
sure a more regular *nix user will say so :-)

HTH,


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


Re: [Tutor] No module named 'module name' -- sub-folders?

2009-01-25 Thread spir
Le Sun, 25 Jan 2009 18:04:00 -,
"Alan Gauld"  a écrit :


> Nope, PYTHONPATH applies to any OS.
> You need to use it if you have any modules in folders other than
> the default locations used by Python. I think the preferred place
> to set PYTHONPATH is in your .login script but if I'm wrong I'm
> sure a more regular *nix user will say so :-)
> 
> HTH,

I take the opportunity to ask a question about module lookup. I was *sure* 
that, when searching for a module, python automatically explores sub-folders 
(both of the current folder and of the pathes listed in PYTHONPATH). But this 
does not work by me (anymore):
from ospyp.py, located in /home/spir/prog/ospyp, I cannot simply import 
wikilang which is in /home/spir/prog/ospyp/samples

???

Denis

--
la vida e estranya
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] No module named 'module name' -- sub-folders?

2009-01-25 Thread Kent Johnson
On Sun, Jan 25, 2009 at 4:21 PM, spir  wrote:

> I take the opportunity to ask a question about module lookup. I was *sure* 
> that, when searching for a module, python automatically explores sub-folders 
> (both of the current folder and of the pathes listed in PYTHONPATH). But this 
> does not work by me (anymore):
> from ospyp.py, located in /home/spir/prog/ospyp, I cannot simply import 
> wikilang which is in /home/spir/prog/ospyp/samples

No, Python does not automatically search subfolders of directories in
PYTHONPATH. It will search package folders and subfolders if you ask
it to. For example if your samples folder includes a file __init__.py
(marking it  as a package) then you can import samples.wikilang.

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


[Tutor] To Arc (PIL) or Not to Arc (Tkinter)

2009-01-25 Thread Wayne Watson
Title: Signature.html




I'm working on making changes to a GUI program that I did not write. It
uses PIL and Tkinter. I'm pretty much making good progress, but my
question is what each class really does with respect to each other?
Here's my view.

When I noticed that both have an arc method that gave me pause.
Apparently, PIL provides IP (image processing:  blur, graphic format
conversion, color transforms, anti-aliasing, resizing,  etc.), while
Tkinter provides widgets. In PIL, arc allows one to draw on images but
doesn't allow one to display them. The display and presentation is the
function of Tkinter, and can draw on the widget canvas where an image,
from PIL, might be placed. Comments? I have some pretty fair web
material on this, which I'm still reading. New Mexico, Lundh, and
Tkinter Book. 

-- 


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

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)

 Copper and its alloys have been found effective in hospital
 sinks, hand rails, beds, ... in significantly reducing 
 bacteria. Estimates are 1/20 people admitted to a hospital
 become infected, and 1/20 die from the infection.
   -- NPR Science Friday, 01/16/2009 

Web Page: 



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


Re: [Tutor] To Arc (PIL) or Not to Arc (Tkinter)

2009-01-25 Thread Alan Gauld

"Wayne Watson"  wrote


When I noticed that both have an arc method that gave me pause.



Apparently, PIL provides IP (image processing:  ...while Tkinter
provides widgets. In PIL, arc allows one to draw on images but
doesn't allow one to display them. The display and presentation
is the function of Tkinter, and can draw on the widget canvas
where an image, from PIL, might be placed. Comments?


Yes you have understood pretty well. PIL provides more sophisticated
IP than Tkinter can do on its own. For simple images such as
charts/graphs you might decide to draw them direct in Tkinter
without using PIL. For that reason Tkinter canvas allows you to
draw shapes, such as arc, directly on the canvas.

For more sophisticated use (such as complex charts) you might
use a plotting library to create the image and then display the image
in Tkinter. Or to manipulate sophisticated graphics (like photos)
you would probably use PIL or ImageMagik or somesuch.

HTH,

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


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


[Tutor] Python Program: Newton's Method

2009-01-25 Thread Donna Ibarra
Hello,

I need to write a program that implements Newton's method ((guess + x/guess)
/ (2)). The program should prompt the user for the value to find the
squareroot of (x) and the number of times to improve the guess. Starting
with a guess value of x/2, your program should loop the specified number of
times applying newton's method and report the final value of guess. You
should also subtract your estimate from the value of math.sqrt() to show how
close it is.

So far.. I got:

 Help with Code
Tags
(Toggle Plain Text )

import math

def main():
value, guess = input("Please enter the value, and the number of
times to loop: ")

for i in range(guess):
top = guess + value / guess
final_value = float(top) / 2

close = final_value - math.sqrt(x)
close_two = math.sqrt(x)

print "The guess is", final_value, "which is", close, "away from", close_two

main()


Could you please help me out? Thanks

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


Re: [Tutor] Python Program: Newton's Method

2009-01-25 Thread John Fouhy
2009/1/26 Donna Ibarra :
> I need to write a program that implements Newton's method
[...]

What problems are you having?

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


Re: [Tutor] Python Program: Newton's Method

2009-01-25 Thread Kent Johnson
On Sun, Jan 25, 2009 at 6:11 PM, Donna Ibarra  wrote:
> Hello,
>
> I need to write a program that implements Newton's method ((guess + x/guess)
> / (2)). The program should prompt the user for the value to find the
> squareroot of (x) and the number of times to improve the guess. Starting
> with a guess value of x/2, your program should loop the specified number of
> times applying newton's method and report the final value of guess. You
> should also subtract your estimate from the value of math.sqrt() to show how
> close it is.
>
> So far.. I got:
>
> Help with Code Tags
> (Toggle Plain Text)
>
> import math
>
>
> def main():
> value, guess = input("Please enter the value, and the number of times to
> loop: ")
>
> for i in range(guess):
> top = guess + value / guess
> final_value = float(top) / 2
>
>
> close = final_value - math.sqrt(x)
> close_two = math.sqrt(x)
>
> print "The guess is", final_value, "which is", close, "away from",
> close_two
>
> main()
>
> Could you please help me out? Thanks

This looks like homework, so we are limited in how we can help. Some hints:
What does the variable guess represent in the input line? How about in
the for loop?
What does final_value represent? why do you divide it by 2?

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


[Tutor] import confusion

2009-01-25 Thread Eric Abrahamsen

Hi there,

I'm trying to understand how module imports work, and am seeing some  
behavior I don't understand:


>>> import django
>>> from django import forms
>>> from forms import DecimalField
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named forms
>>> import django.contrib
>>> from django.contrib import auth
>>> from auth import ImproperlyConfigured
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named auth


So what I'm seeing is that you can import X, then from X import Y, but  
only if Y is another module and not an object. The import chains above  
work until I try to import a class definition. Can someone explain  
what it is about module imports that makes it work this way? And why  
the unhelpful error message?


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


[Tutor] How Do I Put an Image on a Canvas and Display it?

2009-01-25 Thread Wayne Watson
Title: Signature.html




I've started with this, but it's not hacking it. Aside from not knowing
how to attach img to the canvas, it has a few problems. First it gives:
    AttributeError: class Image has no attribute 'open'

wagon.tif does exist in the same folder as the program.

Then draw.line() are a bit shaky after I meddle a bit. I get an
objection  that fill=None objects to multiple values. I've seen two
different formats for the coordinates: (0,0,10,100) and
((0,0),(10,100). 

# fun and games
import Image, ImageDraw
from Tkinter import *

root = Tk()
root.title('Simple Draw on Image')

canvas = Canvas(root, width=450, height=300, bg = 'white')
canvas.pack()

im = Image.open("wagon.tif")
draw = ImageDraw.Draw(im)
draw.line((0, 0,100,100, file=None)

canvas.new(draw)

root.mainloop()
-- 


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

 (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)

 Copper and its alloys have been found effective in hospital
 sinks, hand rails, beds, ... in significantly reducing 
 bacteria. Estimates are 1/20 people admitted to a hospital
 become infected, and 1/20 die from the infection.
   -- NPR Science Friday, 01/16/2009 

Web Page: 



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


Re: [Tutor] import confusion

2009-01-25 Thread Marc Tompkins
On Sun, Jan 25, 2009 at 8:23 PM, Eric Abrahamsen wrote:

> Hi there,
>
> I'm trying to understand how module imports work, and am seeing some
> behavior I don't understand:
>
> >>> import django
> >>> from django import forms
> >>> from forms import DecimalField
> Traceback (most recent call last):
>  File "", line 1, in 
> ImportError: No module named forms
> >>> import django.contrib
> >>> from django.contrib import auth
> >>> from auth import ImproperlyConfigured
> Traceback (most recent call last):
>  File "", line 1, in 
> ImportError: No module named auth
>
>
> So what I'm seeing is that you can import X, then from X import Y, but only
> if Y is another module and not an object. The import chains above work until
> I try to import a class definition. Can someone explain what it is about
> module imports that makes it work this way? And why the unhelpful error
> message?
>

Someone will no doubt phrase this better, but let's take a shot...

1)  You don't need to import django before you import forms; it's
redundant.
2)  You DO need to give Python enough information (i.e. the full name path)
to find the most-specific thing you're trying to import.
2)  "import django" makes the entire django package and all sub-modules
available.  You could then refer to django.forms.DecimalField and
django.contrib.auth.ImproperlyConfigured (for example) in your program, no
further imports needed.
3)  "from django import forms" ONLY imports django.forms, and makes it
available as "forms" (i.e. no need to refer to django.forms) - but not for
further imports; for those you still need to specify the full name.
4)  To import ONLY DecimalField or ImproperlyConfigured, you would do the
following:
from django.forms import DecimalField
from django.contrib.auth import ImproperlConfigured
5)  You can also create aliases:
from django.forms import DecimalField as decField
from django.contrib.auth import ImproperlyConfigured as Oopsie

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


Re: [Tutor] import confusion

2009-01-25 Thread Marc Tompkins
On Sun, Jan 25, 2009 at 9:45 PM, Eric Abrahamsen wrote:
>
> Thanks for the break-down! I've got a fairly good handle on how to make all
> this work correctly, I guess what I'm after is an understand of why the
> above produces an error. What's going on in the system's module accounting
> that makes one thing work and the other fail?
>

Don't know about the internals, but here's a passage from the 2.61 docs (
http://docs.python.org/tutorial/modules.html):

> Note that when using from package import item, the item can be either a
> submodule (or subpackage) of the package, or some other name defined in the
> package, like a function, class or variable. The import statement first
> tests whether the item is defined in the package; if not, it assumes it is a
> module and attempts to load it. If it fails to find it, an 
> ImportErrorexception
>  is raised.
>
> Contrarily, when using syntax like import item.subitem.subsubitem, each
> item except for the last must be a package; the last item can be a module or
> a package but can't be a class or function or variable defined in the
> previous item.
>
>
-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] clipboard questions

2009-01-25 Thread Che M

I'm curious about how to interact with the contents of the clipboard 
effectively and have a couple of questions...

1) Is there one cross-platform way to read the clipboard, or does one
have to have a different way to do it for Win, Mac, and Linux?  (I have
seen some ways with the win32clipboard module, and so thought maybe one
has to do a similar thing for each platform).

2) I would like to be able to copy formatting (bold, italics, bullets, 
hyperlinks, etc.) into the clipboard and then have Python have access 
to the text content and its formatting in such a way that it could be 
pasted somewhere within a Python app with formatting preserved.  How 
can that be done?

Thanks for any suggestions or thoughts.
Che


_
Windows Live™ Hotmail®…more than just e-mail. 
http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_012009
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor