Re: [Tutor] Misunderstanding the Entry Widget

2009-03-07 Thread Alan Gauld


Wayne Watson sierra_mtnv...@sbcglobal.net wrote 

Can you easily construct a simple example where they are 
absolutely necessary, or at least provide a situation where 
they are necessary?


I don't think you can. They are a convenience feature 
not a necessity. But the same can be said of standard dialogs, 
message boxes etc. You could build all of those from basic 
widgets but it woulfd be a pain. Sometimes Control variables 
save you some pain.


Personally I don't bother with them much but others like them.

Alan G

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


Re: [Tutor] print problem python

2009-03-07 Thread Alan Gauld


mustafa akkoc mustafa.c...@gmail.com wrote

i start learning pyton language i want to print some thing but when i 
type :
print hello world  but it give an error like this  SyntaxError: 
invalid

syntax (pyshell#18, line 1)
i am using python shell version 3.0.1


If you are new to programming as well as Pyton I recommend
you get Python 2.6 rather than Python 3. Python 3 has a lot of
changes and most of the beginners material hasn't caught
up yet. It will be easier to get answers to your questions if
you stick with v2.6 and then when comfortable with that move
to v3 aand learn about the differences.

Sometimes newest isn't the best.

--
Alan G
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


Re: [Tutor] glob in order of the file numbers

2009-03-07 Thread عماد نوفل
On Fri, Mar 6, 2009 at 11:34 PM, Kent Johnson ken...@tds.net wrote:

 On Fri, Mar 6, 2009 at 9:52 PM, Emad Nawfal (عماد نوفل)
 emadnaw...@gmail.com wrote:
  Hi Tutors,
  suppose I have four files in the current directory: 1.temp, 2.temp,
 3.temp,
  and 4.temp. I want to use glob, or anything else, to print the contents
 of
  the files in their respective orders, where the content of 1.temp gets
  printed, then 2.temp, then 3.temp, then 4.temp.
  I write the following, but it does not get me what I want:
 
  import glob
  for path in glob.iglob(*.temp):
  infile = open(path)
  for line in infile:
  print line.strip()

 Since you know the file names, just build the names directly:

 for i in range(1, 5):
  path = '%s.temp' % i
  print open(path).read()

 Kent



Thank you all for the solutions. I had figured out Kent's solution before,
so thank you for letting me know that I did it right.
So, glob just creates a list of the file names.
Thank you all again.
-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.محمد
الغزالي
No victim has ever been more repressed and alienated than the truth

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com

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


Re: [Tutor] print problem python

2009-03-07 Thread W W
On Sat, Mar 7, 2009 at 3:11 AM, Alan Gauld alan.ga...@btinternet.com wrote:
snip Python 3 has a lot of
 changes and most of the beginners material hasn't caught
 up yet. It will be easier to get answers to your questions if
 you stick with v2.6 and then when comfortable with that move
 to v3 aand learn about the differences.

As far as I know, Snake Wrangling For Kids has been updated... that's
the only one I know about.

-Wayne

-- 
To be considered stupid and to be told so is more painful than being
called gluttonous, mendacious, violent, lascivious, lazy, cowardly:
every weakness, every vice, has found its defenders, its rhetoric, its
ennoblement and exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] print problem python

2009-03-07 Thread Kent Johnson
On Sat, Mar 7, 2009 at 7:51 AM, W W sri...@gmail.com wrote:
 On Sat, Mar 7, 2009 at 3:11 AM, Alan Gauld alan.ga...@btinternet.com wrote:
snip Python 3 has a lot of
 changes and most of the beginners material hasn't caught
 up yet. It will be easier to get answers to your questions if
 you stick with v2.6 and then when comfortable with that move
 to v3 aand learn about the differences.

 As far as I know, Snake Wrangling For Kids has been updated... that's
 the only one I know about.

I didn't know about that one! There is a list of Python 3.0 learning
resources here:
http://wiki.python.org/moin/Python3.0Tutorials

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


[Tutor] Pyusb: get data via USB sent from mouse

2009-03-07 Thread andré palma
Hi folks, I'm new on pyusb programming and to learn how to get data i'm 
trying  to get  data  sent  from  my mouse.
I've download a program called usbview( http://www.kroah.com/linux/usb/ 
) to display the device descriptors of any USB device  pluged  to my  
computer. 

I made a peace of code that was supposed to get the data sent from my 
mouse but when i try to run it there is an error saying that the device 
is busy  =S




Code:
===

import sys
import usb
import time
import struct
import array
import math


class DeviceDescriptor(object) :
   def __init__(self, vendor_id, product_id, interface_id) :
   self.vendor_id = vendor_id
   self.product_id = product_id
   self.interface_id = interface_id
  
  
   def getDevice(self) :


   busses = usb.busses()

   for bus in busses:   
   for device in bus.devices :

   if device.idVendor == self.vendor_id :
   if device.idProduct == self.product_id :
   return device
   return None






class PlugUSBDevice(object) :
  
   PLUG_VENDOR_ID = 0x1c4f # mouse vendor id

   PLUG_PRODUCT_ID = 0x0003# mouse product id
   PLUG_INTERFACE_ID = 0# mouse interface number
   PLUG_INTERRUPT_IN_EP = 0x81L# mouse end point address

   def __init__(self) :
   self.device_descriptor = 
DeviceDescriptor(PlugUSBDevice.PLUG_VENDOR_ID,
 
PlugUSBDevice.PLUG_PRODUCT_ID,
 
PlugUSBDevice.PLUG_INTERFACE_ID)

   self.device = self.device_descriptor.getDevice()
   self.handle = None

   def open(self) :
   self.device = self.device_descriptor.getDevice()
   self.handle = self.device.open()
   self.handle.claimInterface(self.device_descriptor.interface_id)

   def close(self) :
   self.handle.releaseInterface()

   def getDataPacket(self, bytesToGet) :
   return self.handle.interruptRead(PlugUSBDevice.PLUG_INTERRUPT_IN_EP, 
bytesToGet, 15)



if __name__ == __main__:
   device = PlugUSBDevice()
   device.open()
   print device.getDataPacket(4)
  




The error:

 File readusb.py, line 61, in module
   device.open()
 File readusb.py, line 50, in open
   self.handle.claimInterface(self.device_descriptor.interface_id)
usb.USBError: could not claim interface 0: Device or resource busy

==

What am i doing wrong? =S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] could someone explain why this happens to me.

2009-03-07 Thread sphennings W.
When I enter the following code into IDLE  do both lists have the same value?
How would I manipulate both lists separately?

 List1=[1,2,3]
 List2=List1
 List2.reverse()
 print(List2)
[3, 2, 1]
 print(List1)
[3, 2, 1]
 List2.append(0)
 print(List2)
[3, 2, 1, 0]
 print(List1)
[3, 2, 1, 0]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] could someone explain why this happens to me.

2009-03-07 Thread عماد نوفل
On Sat, Mar 7, 2009 at 2:09 PM, sphennings W. sphenni...@gmail.com wrote:

 When I enter the following code into IDLE  do both lists have the same
 value?
 How would I manipulate both lists separately?

  List1=[1,2,3]
  List2=List1
  List2.reverse()
  print(List2)
 [3, 2, 1]
  print(List1)
 [3, 2, 1]
  List2.append(0)
  print(List2)
 [3, 2, 1, 0]
  print(List1)
 [3, 2, 1, 0]
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor


When you assign list2 to list1, you are just referencing the old list.
Whatever you do either one, it will affect the other as well. The solution,
to my limited knowledge, is to deep-copy the list, as illustrated here:
 l1 = [1,2,3]
 import copy
 l2 = copy.deepcopy(l1)
 l2
[1, 2, 3]
 l1.reverse()
 l1
[3, 2, 1]
 l2
[1, 2, 3]



-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.محمد
الغزالي
No victim has ever been more repressed and alienated than the truth

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com

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


Re: [Tutor] could someone explain why this happens to me.

2009-03-07 Thread Kapsicum
On Sun, Mar 8, 2009 at 12:39 AM, sphennings W. sphenni...@gmail.com wrote:

 When I enter the following code into IDLE  do both lists have the same
 value?
 How would I manipulate both lists separately?

  List1=[1,2,3]
  List2=List1
  List2.reverse()
  print(List2)
 [3, 2, 1]
  print(List1)
 [3, 2, 1]
  List2.append(0)
  print(List2)
 [3, 2, 1, 0]
  print(List1)
 [3, 2, 1, 0]


When you create an object and assign it to a variable, the variable only
refers to the object
and does not represent the object itself.


If you want to make a copy of a list or such kinds of sequences , then you
have to use
the slicing operation to make a copy. If you just assign the variable name
to another name,
both of them will refer to the same object.

List2=List1[ : ]



Kapil Dua
Mobile: +919711311052
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] could someone explain why this happens to me.

2009-03-07 Thread عماد نوفل
On Sat, Mar 7, 2009 at 2:36 PM, Kapsicum duaka...@gmail.com wrote:



 On Sun, Mar 8, 2009 at 12:39 AM, sphennings W. sphenni...@gmail.comwrote:

 When I enter the following code into IDLE  do both lists have the same
 value?
 How would I manipulate both lists separately?

  List1=[1,2,3]
  List2=List1
  List2.reverse()
  print(List2)
 [3, 2, 1]
  print(List1)
 [3, 2, 1]
  List2.append(0)
  print(List2)
 [3, 2, 1, 0]
  print(List1)
 [3, 2, 1, 0]


 When you create an object and assign it to a variable, the variable only
 refers to the object
 and does not represent the object itself.


 If you want to make a copy of a list or such kinds of sequences , then you
 have to use
 the slicing operation to make a copy. If you just assign the variable name
 to another name,
 both of them will refer to the same object.

 List2=List1[ : ]



 Kapil Dua
 Mobile: +919711311052





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

 This made me search, and I found another solution: if you use the list
function as follows:
 s = [1,2,3]
 v = list(s)
 s.reverse()
 s
[3, 2, 1]
 v
[1, 2, 3]


As a linguist, I would love to know what the difference between  these
things are:
mycopy = original[:]
mycopy = copy.deepcopy(original)
mycopy = list(original)


-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.محمد
الغزالي
No victim has ever been more repressed and alienated than the truth

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com

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


Re: [Tutor] could someone explain why this happens to me.

2009-03-07 Thread Alan Gauld


Emad Nawfal (عماد نوفل) emadnaw...@gmail.com wrote

As a linguist, I would love to know what the difference between 
these

things are:


The differences are the same whether you are a linguist or not :-)
(and yes I know my reading is incorrect grammaticallly but I couldn't 
resist it!)



mycopy = original[:]

Returns a slice of the original list. In this case it so happens
the slice is the full list.


mycopy = copy.deepcopy(original)


calls the deepcopy function which traverses the original list
and all nested structures explicitly copying the elements.


mycopy = list(original)


Use the list type constructor to make a list out of its argument.
It just so happens the argument in this case is a list.

The end result is the same but the mechanisms (ie the code called)
are quite different. It would be interesting to compare speeds,
but I'm too lazy! I suspect deepcopy would be slowest but I'm
not sure about the other two.

Alan G.



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


Re: [Tutor] could someone explain why this happens to me.

2009-03-07 Thread عماد نوفل
2009/3/7 Alan Gauld alan.ga...@btinternet.com


 Emad Nawfal (عماد نوفل) emadnaw...@gmail.com wrote

  As a linguist, I would love to know what the difference between these
 things are:


 The differences are the same whether you are a linguist or not :-)
 (and yes I know my reading is incorrect grammaticallly but I couldn't
 resist it!)

  mycopy = original[:]

 Returns a slice of the original list. In this case it so happens
 the slice is the full list.

  mycopy = copy.deepcopy(original)


 calls the deepcopy function which traverses the original list
 and all nested structures explicitly copying the elements.

  mycopy = list(original)


 Use the list type constructor to make a list out of its argument.
 It just so happens the argument in this case is a list.

 The end result is the same but the mechanisms (ie the code called)
 are quite different. It would be interesting to compare speeds,
 but I'm too lazy! I suspect deepcopy would be slowest but I'm
 not sure about the other two.

 Alan G.




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



Thanks Alan,
As a linguist, I appreciate your disambiiguation mechanism.
Not all subscribers to this list are programmers, or know much about
computer science. I know lots about formal thinking, but not about
programming, and I always preface my questions with an expression that
means: please give me a simple answer without so much jargon.
Thanks for the explanation
-- 
لا أعرف مظلوما تواطأ الناس علي هضمه ولا زهدوا في إنصافه كالحقيقة.محمد
الغزالي
No victim has ever been more repressed and alienated than the truth

Emad Soliman Nawfal
Indiana University, Bloomington
http://emnawfal.googlepages.com

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


Re: [Tutor] could someone explain why this happens to me.

2009-03-07 Thread Sander Sweers
2009/3/7 Alan Gauld alan.ga...@btinternet.com:
 mycopy = original[:]

 Returns a slice of the original list. In this case it so happens
 the slice is the full list.

 mycopy = list(original)

 Use the list type constructor to make a list out of its argument.
 It just so happens the argument in this case is a list.

Both not give the desired result with nested lists and this is why you have..

 mycopy = copy.deepcopy(original)

 calls the deepcopy function which traverses the original list
 and all nested structures explicitly copying the elements.

copy.deepcopy :-)

 import copy
 list1 = [1,2]
 list2 = [3.4]
 list3 = [list1, list2]
 list4 = list(list3)
 list5 = list3[:]
 list6 = copy.deepcopy(list3)
 list1.append('a')
 list1
[1, 2, 'a']
 list3
[[1, 2, 'a'], [3.3999]]
 list4
[[1, 2, 'a'], [3.3999]]
 list5
[[1, 2, 'a'], [3.3999]]
 list6
[[1, 2], [3.3999]]

Notice that list6 is the only list which does not have the appended a.

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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-07 Thread Wayne Watson
Title: Signature.html




I have no idea of the history of these variables, but they have very
limited descriptions and examples. Maybe someone like Grayson goes into
detail on them. Looking at the program I'm concerned about, it almost
looks like the use is a learned response to dealing with the widgets
used. That's OK. I just wanted to make sure I wasn't overlooking
something. It provided a helpful interlude. :-)

Alan Gauld wrote:

"Wayne Watson" sierra_mtnv...@sbcglobal.net
wrote  
  
  Can you easily construct a simple example
where they are absolutely necessary, or at least provide a situation
where they are necessary? 
  
  
I don't think you can. They are a convenience feature not a necessity.
But the same can be said of standard dialogs, message boxes etc. You
could build all of those from basic widgets but it woulfd be a pain.
Sometimes Control variables save you some pain. 
  
Personally I don't bother with them much but others like them. 
  
Alan G 
  
___ 
Tutor maillist - Tutor@python.org 
  http://mail.python.org/mailman/listinfo/tutor
  
  


-- 


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

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


In mathematics you don't understand things. 
 You just get used to them. -- John Von Neumann
(P.S. The same is true in life.)




Web Page: www.speckledwithstars.net/



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


Re: [Tutor] Misunderstanding the Entry Widget

2009-03-07 Thread Wayne Watson
Title: Signature.html




Another thought occurred to me about this situation. Suppose I have a
dialog with two Entry objects in a dialog object called TwoEntries:
 entry1 = Entry(master, width=10).grid(row=4, column=1)
 entry2 = Entry(master, width=10).grid(row=5, column=1) 
and I do not use a StringVar to return the values entered. Is it
possible to reach inside TwoEntries, after returning from it, and grab
entry1 and 2? It would seem so if the call was dialog=TwoEntries(...).

Wayne Watson wrote:

  
I have no idea of the history of these variables, but they have very
limited descriptions and examples. Maybe someone like Grayson goes into
detail on them. Looking at the program I'm concerned about, it almost
looks like the use is a learned response to dealing with the widgets
used. That's OK. I just wanted to make sure I wasn't overlooking
something. It provided a helpful interlude. :-)
  
Alan Gauld wrote:
  
"Wayne Watson" sierra_mtnv...@sbcglobal.net
wrote  

Can you easily construct a simple example
where they are absolutely necessary, or at least provide a situation
where they are necessary? 


I don't think you can. They are a convenience feature not a necessity.
But the same can be said of standard dialogs, message boxes etc. You
could build all of those from basic widgets but it woulfd be a pain.
Sometimes Control variables save you some pain. 

Personally I don't bother with them much but others like them. 

Alan G 

___ 
Tutor maillist - Tutor@python.org

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


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

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


In mathematics you don't understand things. 
 You just get used to them. -- John Von Neumann
(P.S. The same is true in life.)

  
  
  
Web Page: www.speckledwithstars.net/
  
  

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


-- 

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

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


In mathematics you don't understand things. 
 You just get used to them. -- John Von Neumann
(P.S. The same is true in life.)




Web Page: www.speckledwithstars.net/




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