Re: [Tutor] Need some info

2010-04-21 Thread Alan Gauld


"Marco Rompré"  wrote


Hi! in my programming course at university, I need to create a python model
with 2 concepts in a one towards many relation  each of them  having 2-3
properties.


Are you allowed to use a relational database as part of the solution?
That would simplify things because managing relationships is pretty
much what they do... If you have to do it from scratch using Python
only then it a much more challenging task.

How much Python do you know?
How much of any programming language do you know?
How much about relational algebra do you know?


Also, I need to create an application with screens to add, modify, and
delete the data of the model.


This is the easy bit. Either using web or windows techniques.
Which OS are you using?


Can someone know where I can find the information that would help me to
successfully complete my assignment


For the theory asp[ect Wikipedia is a good start.
For Python try both python.org and Activestate.com

HTH,

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



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


[Tutor] Changing Default Install Path on Windows

2010-04-21 Thread Luke Paireepinart
Hi guys,
my first post to the list with a question rather than a response in a
few years, I think :)

(NOTE: I solved my question while writing this e-mail, I'm just
mailing this to the list for future users now)

I'm running Windows 7 64-bit.

I currently have 3 python installs.
First I installed the 64-bit version of Python 2.6 to C:\Python26,
then realized that it doesn't have as much lib support.
Then I installed the 32-bit version to C:\Python26x86
Everything worked fine after this (installs, etc. all went to the
proper site-packages.)

Then I installed Panda3D and normally it doesn't hijack your Python
install but I guess in this case I accidentally told it to become
default.

Now, when I try to run an installer, it finds the Panda3D Python first.

I'm getting really frustrated because I can't figure out why it's
finding the Panda3D Python.
I don't understand how the multiple version precedence works.


In my registry, HKLM / SOFTWARE / Python, all I have is PythonCore/2.6
and all references in here (PythonPath, InstallPath, etc. etc.) all
reference the FIRST python install (C:\Python26)

My PATH environment variable is:
C:\Users\rabidpoobear>echo %path%

C:\Program Files (x86)\PC Connectivity
Solution\;C:\Python26x86\Lib\site-packages\PyQt4\bin;C:\Program Files
(x86)\NVIDIA Corporation\PhysX\
Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program
Files\TortoiseSVN\bin;
C:\python26x86;C:\Program Files
(x86)\Graphviz2.26.3\bin;C:\jython2.5.1;C:\Panda3D-1.7.0\bin

the Panda3D bin directory does NOT contain a python.exe, it only
contains panda3d stuff.  The Panda3d python install is in
C:\Panda3D-1.7.0\python

I cannot find any references to the Panda3D python install ANYWHERE.

Yet anytime I try to run an installer, it tries to install there.  And
the stupid "helpful" python installers that auto-find the directory do
not let you change it.
They make the (faulty) assumption that they're correct.

-

I figured out the solution, I just did a Find on my entire registry
and found C:\Panda3D-1.7.0 in
HKLM\Software\Wow6432Node\Python\PythonCore\2.6\InstallPath .
After some investigation it seems that the special Wow6432Node has to
do with 64-bit versions of Windows running 32-bit versions of Python.

So the lesson we've learned today is that your 64-bit Python install
path should will be where it normally is
(HKLM\Software\Python\PythonCore\version\InstallPath)
but your 32-bit path will be in that special WowNode directory.

Hope that helps someone in the future,
-Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] the binary math "wall"

2010-04-21 Thread spir ☣
On Tue, 20 Apr 2010 19:11:24 -0700 (PDT)
Lowell Tackett  wrote:

> > >>> round(18.15*100) == 1815  
> > True  
> 
> Interestingly, this is the [above] result when I tried entered the same 
> snippet:
> 
> Python 2.5.1 (r251:54863, Oct 14 2007, 12:51:35)
> [GCC 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> round(18.15)*100 == 1815  
> False
> >>>  
> 
> But...I'm just offering that for its' curiosity value, not to contradict your 
> comments or the case you are making.

hum hum hum...

Denis


vit esse estrany ☣

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


Re: [Tutor] the binary math "wall"

2010-04-21 Thread Dave Angel



Lowell Tackett wrote:

--- On Tue, 4/20/10, Steven D'Aprano  wrote:

  

From: Steven D'Aprano 




The simplest, roughest way to fix these sorts of problems
(at the risk 
of creating *other* problems!) is to hit them with a

hammer:



round(18.15*100) == 1815
  

True



Interestingly, this is the [above] result when I tried entered the same snippet:

Python 2.5.1 (r251:54863, Oct 14 2007, 12:51:35)
[GCC 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
  

round(18.15)*100 == 1815


False
  



But you typed it differently than Steven.  He had   round(18.15*100), 
and you used round(18.15)*100


Very different.   His point boils down to comparing integers, and when 
you have dubious values, round them to an integer before comparing.  I 
have my doubts, since in this case it would lead to bigger sloppiness 
than necessary.


round(18.154 *100) == 1815

probably isn't what you'd want.

So let me ask again, are all angles a whole number of seconds?  Or can 
you make some assumption about how accurate they need to be when first 
input (like tenths of a second, or whatever)?  If so use an integer as 
follows:


val =  rounddegrees*60)+minutes)*60) + seconds)*10)

The 10 above is assuming that tenths of a second are your quantization.

HTH
DaveA

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


[Tutor] classes passing information

2010-04-21 Thread Stefan Lesicnik
Hi Guys,

I'm slowly starting to understand classes coming from basic non oo scripting. I 
guess the problem comes in that you think you understand, and then look at code 
and its totally different and confusing. 

My question is maybe more generic with functions as opposed to classes, but 
i've been trying some pyGtk and I am unsure how i get values back from other 
classes.
Its something like, i have a program.py which has a class and methods.  One of 
those methods would be create a new dialog which is a class in dialog.py. So i 
can call that and pass it parameters. The question is, how do i get the result 
of that dialog back to the calling method?

Im not even sure if this makes sense. I guess im still struggling to understand 
how to pass parameters around to other methods, methods in other files, and get 
answers back.

Hope this makes somewhat sense.

Thanks

Stefan

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


Re: [Tutor] Python Examples of processing MS Outlook

2010-04-21 Thread Emile van Sebille

On 4/16/2010 2:13 AM Peter Meagher said...

Does anyone have references to simple MS Outlook 2007
processing code that I could vulture for my purposes?  (The
code that I adapted was from an old Office 2000 vba text, so
the version 2007 may not be that essential to my purposes)


You may what to dig into the spambayes code -- see 
http://spambayes.sourceforge.net/


Emile

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


Re: [Tutor] the binary math "wall"

2010-04-21 Thread Lowell Tackett

>From the virtual desk of Lowell Tackett  



--- On Wed, 4/21/10, Dave Angel  wrote:

> From: Dave Angel 
> Subject: Re: [Tutor] the binary math "wall"
> To: "Lowell Tackett" 
> Cc: tutor@python.org, "Steven D'Aprano" 
> Date: Wednesday, April 21, 2010, 6:46 AM
> 
> 
> Lowell Tackett wrote:
> > --- On Tue, 4/20/10, Steven D'Aprano 
> wrote:
> > 
> >   
> >> From: Steven D'Aprano 
> >> 
> >> 
> >> The simplest, roughest way...hit them with a
> >> hammer:
> >> 
> > round(18.15*100) == 1815
> >   
>
> >> True
> >> 
> > 
> > ...when I tried...:
> > 
> > Python 2.5.1 (r251:54863, Oct 14 2007, 12:51:35)
> > [GCC 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk)] on linux2
> > Type "help", "copyright", "credits" or "license" for
> more information.
> >   
>  round(18.15)*100 == 1815
>  
> > False
> >   
> > 
> But you typed it differently than Steven.  He
> had   round(18.15*100), and you used
> round(18.15)*100

As soon as I'd posted my answer I realized this mistake.

> 
> Very different.   His point boils down to
> comparing integers, and when you have dubious values, round
> them to an integer before comparing.  I have my doubts,
> since in this case it would lead to bigger sloppiness than
> necessary.
> 
> round(18.154 *100) == 1815
> 
> probably isn't what you'd want.
> 
> So let me ask again, are all angles a whole number of
> seconds?  Or can you make some assumption about how
> accurate they need to be when first input (like tenths of a
> second, or whatever)?  If so use an integer as
> follows:
> 
> val =  rounddegrees*60)+minutes)*60) +
> seconds)*10)
> 
> The 10 above is assuming that tenths of a second are your
> quantization.
> 
> HTH
> DaveA
> 
> 

Recalling (from a brief foray into college Chem.) that a result could not be 
displayed with precision greater than the least precise component that bore 
[the result].  So, yes, I could accept my input as the arbitrator of accuracy.

A scenario:

Calculating the coordinates of a forward station from a given base station 
would require [perhaps] the bearing (an angle from north, say) and distance 
from hither to there.  Calculating the north coordinate would set up this 
relationship, e.g.:

cos(3° 22' 49.6") x 415.9207'(Hyp) = adjacent side(North)

My first requirement, and this is the struggle I (we) are now engaged in, is to 
convert my bearing angle (3° 22' 49.6") to decimal degrees, such that I can 
assign its' proper cosine value.  Now, I am multiplying these two very refined 
values (yes, the distance really is honed down to 10,000'ths of a foot-that's 
normal in surveying data); within the bowels of the computer's blackboard 
scratch-pad, I cannot allow errors to evolve and emerge.

Were I to accumulate many of these "legs" into perhaps a 15 mile 
traverse-accumulating little computer errors along the way-the end result could 
be catastrophically wrong.

(Recall that in the great India Survey in the 1800's, Waugh got the elevation 
of Mt. Everest wrong by almost 30' feet for just this exact same reason.)  In 
surveying, we have a saying, "Measure with a micrometer, mark with chalk, cut 
with an axe".  Accuracy [in math] is a sacred tenet.

So, I am setting my self very high standards of accuracy, simply because those 
are the standards imposed by the project I am adapting, and I can require 
nothing less of my finished project.


  

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


Re: [Tutor] the binary math "wall"

2010-04-21 Thread Emile van Sebille

On 4/21/2010 8:37 AM Lowell Tackett said...


So, I am setting my self very high standards of accuracy,
simply because those are the standards imposed by the project
I am adapting, and I can require nothing less of my finished project.


Then keep the source data in tenths (or 100ths or 1000ths) as whole 
numbers and only convert upon presentation and your calculations will 
always be accurate for the source measurements taken.


In accounting systems I've always keep dollar amounts in whole pennies 
for this same reason.


Emile



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


[Tutor] set and sets.Set

2010-04-21 Thread Bala subramanian
Friends,
Someone please write me the difference between creating set with set() and a
sets.Set().

>>> a=set([1,2,3])
>>> b=sets.Set([1,2,3])
>>> print a
set([1, 2, 3])
>>> print b
Set([1, 2, 3])

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


Re: [Tutor] the binary math "wall"

2010-04-21 Thread Dave Angel

Lowell Tackett wrote:
From the virtual desk of Lowell Tackett  




--- On Wed, 4/21/10, Dave Angel  wrote:

  

From: Dave Angel 
Subject: Re: [Tutor] the binary math "wall"
To: "Lowell Tackett" 
Cc: tutor@python.org, "Steven D'Aprano" 
Date: Wednesday, April 21, 2010, 6:46 AM


Lowell Tackett wrote:


--- On Tue, 4/20/10, Steven D'Aprano 
  

wrote:

  
  

From: Steven D'Aprano 


The simplest, roughest way...hit them with a
hammer:



round(18.15*100) == 1815
  
  
   


True



...when I tried...:

Python 2.5.1 (r251:54863, Oct 14 2007, 12:51:35)
[GCC 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk)] on linux2
Type "help", "copyright", "credits" or "license" for
  

more information.

  
  

round(18.15)*100 == 1815



False
  

  

But you typed it differently than Steven.  He
had   round(18.15*100), and you used
round(18.15)*100



As soon as I'd posted my answer I realized this mistake.

  

Very different.   His point boils down to
comparing integers, and when you have dubious values, round
them to an integer before comparing.  I have my doubts,
since in this case it would lead to bigger sloppiness than
necessary.

round(18.154 *100) == 1815

probably isn't what you'd want.

So let me ask again, are all angles a whole number of
seconds?  Or can you make some assumption about how
accurate they need to be when first input (like tenths of a
second, or whatever)?  If so use an integer as
follows:

val =  rounddegrees*60)+minutes)*60) +
seconds)*10)

The 10 above is assuming that tenths of a second are your
quantization.

HTH
DaveA





Recalling (from a brief foray into college Chem.) that a result could not be 
displayed with precision greater than the least precise component that bore 
[the result].  So, yes, I could accept my input as the arbitrator of accuracy.

A scenario:

Calculating the coordinates of a forward station from a given base station 
would require [perhaps] the bearing (an angle from north, say) and distance 
from hither to there.  Calculating the north coordinate would set up this 
relationship, e.g.:

cos(3° 22' 49.6") x 415.9207'(Hyp) = adjacent side(North)

My first requirement, and this is the struggle I (we) are now engaged in, is to 
convert my bearing angle (3° 22' 49.6") to decimal degrees, such that I can 
assign its' proper cosine value.  Now, I am multiplying these two very refined 
values (yes, the distance really is honed down to 10,000'ths of a foot-that's normal 
in surveying data); within the bowels of the computer's blackboard scratch-pad, I 
cannot allow errors to evolve and emerge.

Were I to accumulate many of these "legs" into perhaps a 15 mile 
traverse-accumulating little computer errors along the way-the end result could be 
catastrophically wrong.

(Recall that in the great India Survey in the 1800's, Waugh got the elevation of Mt. 
Everest wrong by almost 30' feet for just this exact same reason.)  In surveying, we have 
a saying, "Measure with a micrometer, mark with chalk, cut with an axe".  
Accuracy [in math] is a sacred tenet.

So, I am setting my self very high standards of accuracy, simply because those 
are the standards imposed by the project I am adapting, and I can require 
nothing less of my finished project.

  
If you're trying to be accurate when calling cos, why are you using 
degrees?  The cosine function takes an angle in radians.  So what you 
need is a method to convert from deg/min/sec to radians.  And once you 
have to call trig, you can throw out all the other nonsense about 
getting exact values.  Trig functions don't take arbitrary number 
units.  They don't take decimals, and they don't take fractions.  They 
take double-precision floats.


Perhaps you don't realize the amount of this quantization error we've 
been talking about.  The double type is 64bits in size, and contains the 
equivalent of about 18 decimal digits of precision.  (Assuming common 
modern architectures, of course)



Your angle is specified to about 5 digits of precision, and the distance 
to 7.  So it would take a VERY large number of typical calculations for 
errors in the 18th place to accumulate far enough to affect those.


The real problem, and one that we can't solve for you, and neither can 
Python, is that it's easy to do calculations starting with 8 digits of 
accuracy, and the result be only useful to 3 or 4.  For example, simply 
subtract two very close numbers, and use the result as though it were 
meaningful.


I once had a real customer send us a letter asking about the math 
precision of a calculation he was doing.  I had written the math 
microcode of the machine he was using (from add and subtract, up to 
trigs and logs, I wrote it all).  So I analyzed his problem, pointed out 
his errors, and sent him away happy.


He was trying to calculate the difference between a perfectly flat 
machine table, and one that was leval at all points, follow

Re: [Tutor] set and sets.Set

2010-04-21 Thread bob gailer

On 4/21/2010 12:28 PM, Bala subramanian wrote:

Friends,
Someone please write me the difference between creating set with set() 
and a sets.Set().


When sets were introduced to Python in version 2.3. they came as a 
separate "sets" module.


In version 2.6 built-in set/frozenset types replaced this module.

So either way is OK for now, but the sets module might go away in a 
newer version.


--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] the binary math "wall"

2010-04-21 Thread Lowell Tackett

>From the virtual desk of Lowell Tackett  



--- On Wed, 4/21/10, Dave Angel  wrote:

> From: Dave Angel 
> Subject: Re: [Tutor] the binary math "wall"
> To: "Lowell Tackett" 
> Cc: tutor@python.org, "Steven D'Aprano" 
> Date: Wednesday, April 21, 2010, 12:31 PM
> Lowell Tackett wrote:
> > From the virtual desk of Lowell Tackett  
> > 
> > 
*Whole buncha stuff snipped*
> 
> Anyway, in your case binary floating point is
> irrelevant.  You've got to do your own error analysis
> of every step in the calculation to understand how much you
> can trust the result.  And it's unlikely the "errors"
> in the math package will be the limiting factor.
> 
> DaveA
> 
> 

The sense of all this is beginning to emerge (perhaps).  Emile has just made a 
good point, simply convert all to whole values (using a subset algorithm that 
keeps track of the number of decimal "slips" that have accumulated-for later 
reconversion), crunch merrily away, and get good results.

Maybe that's valid, maybe not.  But I do know that this much is happening; I'm 
now beginning to quantify very novel and wide ranging ideas way outside "the 
box" I'd originally approached the challenge with.  That's the bigger value of 
this entire exercise, I think.  Naively thinking that the computer was benign 
and forgiving, I'd first opted for the most transparent and 'at hand' 
solutions...there was much to be learned.

I know a coupla things now...I'm gonna solve this dilemma, and largely with the 
help of all who've weighed in.   The solution may ultimately not be close to 
what has been suggested, but isn't that the fun of it all?

Secondly, there has accumulated [here] quite an array of novel (to me) thinking 
that I'm going to return to more and more as I tackle other, different 
projects, for the pedagogical value that will linger.


  

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


Re: [Tutor] classes passing information

2010-04-21 Thread Alan Gauld


"Stefan Lesicnik"  wrote

Caveat: I know zilch about pyGtk.


My question is maybe more generic with functions as opposed to classes,
but i've been trying some pyGtk and I am unsure how i get values back
from other classes.


They should be returned by the methods. So you just assign the method
result to a variable:

foo = someModule.SomeClass() # create an instance
bar = foo.someMethod()  # call a merthod and store the result.


Its something like, i have a program.py which has a class and methods.
One of those methods would be create a new dialog which is a class in
dialog.py. So i can call that and pass it parameters.


import dialog

d = dialog.Dialog(foo, bar)

The question is, how do i get the result of that dialog back to the calling 
method?


The result being what? A reference to the new dialog object?
Or the button pressed by the user of the dialog?
For that I would need to know more about Gtk than I do.

Im not even sure if this makes sense. I guess im still struggling to 
understand

how to pass parameters around to other methods, methods in other files,
and get answers back.


It sounds like its the functions and parameter/value passing that you need help
with. The classes aspect is just an extra layer of fog.

Try my tutorial topic on Methods and Functions, see if that helps.

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


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


Re: [Tutor] the binary math "wall"

2010-04-21 Thread Ricardo Aráoz
Lowell Tackett wrote:
> >From the virtual desk of Lowell Tackett  
>
>
>
> --- On Wed, 4/21/10, Dave Angel  wrote:
>
>   
>> From: Dave Angel 
>> Subject: Re: [Tutor] the binary math "wall"
>> To: "Lowell Tackett" 
>> Cc: tutor@python.org, "Steven D'Aprano" 
>> Date: Wednesday, April 21, 2010, 12:31 PM
>> Lowell Tackett wrote:
>> 
>>> From the virtual desk of Lowell Tackett  
>>>
>>>
>>>   
> *Whole buncha stuff snipped*
>   
>> Anyway, in your case binary floating point is
>> irrelevant.  You've got to do your own error analysis
>> of every step in the calculation to understand how much you
>> can trust the result.  And it's unlikely the "errors"
>> in the math package will be the limiting factor.
>>
>> DaveA
>>
>>
>> 
>
> The sense of all this is beginning to emerge (perhaps).  Emile has just made 
> a good point, simply convert all to whole values (using a subset algorithm 
> that keeps track of the number of decimal "slips" that have accumulated-for 
> later reconversion), crunch merrily away, and get good results.
>
> Maybe that's valid, maybe not.  But I do know that this much is happening; 
> I'm now beginning to quantify very novel and wide ranging ideas way outside 
> "the box" I'd originally approached the challenge with.  That's the bigger 
> value of this entire exercise, I think.  Naively thinking that the computer 
> was benign and forgiving, I'd first opted for the most transparent and 'at 
> hand' solutions...there was much to be learned.
>
> I know a coupla things now...I'm gonna solve this dilemma, and largely with 
> the help of all who've weighed in.   The solution may ultimately not be close 
> to what has been suggested, but isn't that the fun of it all?
>
> Secondly, there has accumulated [here] quite an array of novel (to me) 
> thinking that I'm going to return to more and more as I tackle other, 
> different projects, for the pedagogical value that will linger.
>   

Check python help docs for module decimal, there you have an example on
how to code a sin() and cos() functions with arbitrary precision
(depends on your context precision) using decimal values. Might be what
you are looking for (of course you would have to express your angles in
radians throughout all of your calculations and if needed convert at the
end.

HTH

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


Re: [Tutor] set and sets.Set

2010-04-21 Thread wesley chun
> When sets were introduced to Python in version 2.3. they came as a separate 
> "sets" module.
>
> In version 2.6 built-in set/frozenset types replaced this module.

2.4


> So either way is OK for now, but the sets module might go away in a newer 
> version.

agreed

cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Python Web Development with Django", Addison Wesley, (c) 2009
http://withdjango.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Remote access from Windows PC to a Linux box

2010-04-21 Thread Mike Baker
Thanks Tim,

Your subprocess examples got me started in the right direction.  I've moved
on to a slightly more advanced problem that I need help with.

I want to remotely start a Tshark packet capture session on one of our Linux
machines in the lab.  I want to start the session from my Windows machine
running Python 2.5.  The output capture file needs to be saved on the remote
Linux machine.

The example below nearly does what I want.  It starts Tshark via Putty, runs
for 10 seconds then writes the capture file (out.txt) to a remote Linux
machine.  The problem is that the putty session hangs open while Tshark is
running. So, I can't execute additional Python commands until the Tshark
capture finishes.

I've experimented with the Unix nohup command, but it does not seem to work
as expected with Tshark.  If you call my function below with
>>> test_subp(alt_cmd=1)
then the nohup command is added to the subprocess command list (along with a
trailing '&' to send the command to background).  This should work.  Using
this alternate command, out.txt gets created, but is always empty.


Here is my code:
**
def test_subp(alt_cmd=0):
'''Establish a Putty connection with one of our Linux machines in the
lab.
Send Tshark command to start a data collection session over Putty.
'''
PLINK = 'C:\\Progra~1\\putty\\plink'
sess_name='LabComp1'
if alt_cmd:
'''This command does not work as expected.  The tshark output file
(out.txt)is created,
but there is nothing in it '''
CMD_LIST=[PLINK,sess_name,'/usr/bin/nohup','/usr/bin/sudo
/usr/sbin/tshark', '-a', 'duration:10', '-i',  'wlan0', '-T', 'text',
'-V','>', 'out.txt','&'];
else:
'This command works great, writing tshark output to out.txt on the
remote machine.'
'Unfortunately, this command hangs the putty session until the
tshark capture ends'
CMD_LIST=[PLINK,sess_name,'/usr/bin/sudo /usr/sbin/tshark', '-a',
'duration:10', '-i',  'wlan0', '-T', 'text', '-V','>', 'out.txt'];
print "The command list you are sending to the subprocess is: \n", "\t",
CMD_LIST

PIPE = subprocess.PIPE
p = subprocess.Popen(CMD_LIST, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate ()
print 'stdout = ', stdout
print 'stderr = ', stderr
*

For both runs (atl_cmd=0 or alt_cmd=1), the stdout and stderr printouts at
the end of the script are empty.

Any suggestions would be appreciated.

Thanks,

Mike
***

On Wed, Mar 31, 2010 at 7:42 AM, Tim Golden  wrote:

> On 30/03/2010 17:29, Mike Baker wrote:
>
>> I'm trying to connect to a Linux box from my Windows machine and execute a
>> series of commands
>>
>> I want a script to always
>> execute the same series of commands without having to do so manually.   I
>> also have code that will execute a single command like cat a file and
>> write
>> the ouput to a new file. However, when I try to use the communicate object
>> in subprocess, my window hangs.
>>
>
>
> This works for me:
>
> 
> import os, sys
> import subprocess
>
> PLINK = "plink"
> REMOTE_USER = "tgol...@web30.webfaction.com"
> PIPE = subprocess.PIPE
>
> p = subprocess.Popen ([PLINK, REMOTE_USER, "ls"], stdout=PIPE)
> stdout, stderr = p.communicate ()
> print "#1:", stdout.splitlines ()[0]
>
> with open ("out.txt", "w") as f:
>  p = subprocess.Popen ([PLINK, REMOTE_USER, "cat .bashrc"], stdout=f)
>  p.communicate ()
> print "#2:", open ("out.txt").read ().splitlines ()[0]
>
> p = subprocess.Popen ([PLINK, REMOTE_USER], stdin=PIPE, stdout=PIPE)
> stdout, stderr = p.communicate ("ls\nexit\n")
> print "#3", stdout
>
> p = subprocess.Popen ([PLINK, REMOTE_USER], stdin=PIPE, stdout=PIPE)
> p.stdin.write ("ls\nexit\n")
> stdout, stderr = p.communicate ()
> print "#4", stdout
>
> 
>
> A few things to note, none of which I believe to be germane to the
> issues you're experiencing:
>
> * You almost never need to use shell=True on a Windows call to subprocess.
>  If in doubt, don't use it.
>
> * Definitely better to pass the list-of-params style as the first param
>  of subprocess.Popen; it sorts out issues with embedded spaces etc.
>
> * The open ("...", "w") in your second example *may* be closing the
>  file immediately. I doubt it, since you'd expect Popen to hold a
>  reference, but I haven't checked the implementation.
>
> TJG
>
> ___
> 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] Remote access from Windows PC to a Linux box

2010-04-21 Thread Yashwin Kanchan
Hi Mike

have you tried running the tshark process in the background...

*CMD_LIST=[PLINK,sess_name,'/usr/bin/sudo /usr/sbin/tshark &', '-a',
'duration:10', '-i', 'wlan0', '-T', 'text', '-V','>', 'out.txt'];*

Or if you are using NOHUP try redirecting this way...

*CMD_LIST=[PLINK,sess_name,'/usr/bin/nohup','/usr/bin/sudo /usr/sbin/tshark >
out.txt 2> out.err < /dev/null ', '-a', 'duration:10', '-i', 'wlan0', '-T',
'text','&'];*

Regards
Yashwin Kanchan


On 21 April 2010 19:15, Mike Baker  wrote:

> Thanks Tim,
>
> Your subprocess examples got me started in the right direction.  I've moved
> on to a slightly more advanced problem that I need help with.
>
> I want to remotely start a Tshark packet capture session on one of our
> Linux machines in the lab.  I want to start the session from my Windows
> machine running Python 2.5.  The output capture file needs to be saved on
> the remote Linux machine.
>
> The example below nearly does what I want.  It starts Tshark via Putty,
> runs for 10 seconds then writes the capture file (out.txt) to a remote Linux
> machine.  The problem is that the putty session hangs open while Tshark is
> running. So, I can't execute additional Python commands until the Tshark
> capture finishes.
>
> I've experimented with the Unix nohup command, but it does not seem to work
> as expected with Tshark.  If you call my function below with
> >>> test_subp(alt_cmd=1)
> then the nohup command is added to the subprocess command list (along
> with a trailing '&' to send the command to background).  This should work.
> Using this alternate command, out.txt gets created, but is always empty.
>
>
> Here is my code:
> **
> def test_subp(alt_cmd=0):
> '''Establish a Putty connection with one of our Linux machines in the
> lab.
> Send Tshark command to start a data collection session over Putty.
> '''
> PLINK = 'C:\\Progra~1\\putty\\plink'
> sess_name='LabComp1'
> if alt_cmd:
> '''This command does not work as expected.  The tshark output file
> (out.txt)is created,
> but there is nothing in it '''
> CMD_LIST=[PLINK,sess_name,'/usr/bin/nohup','/usr/bin/sudo
> /usr/sbin/tshark', '-a', 'duration:10', '-i',  'wlan0', '-T', 'text',
> '-V','>', 'out.txt','&'];
> else:
> 'This command works great, writing tshark output to out.txt on the
> remote machine.'
> 'Unfortunately, this command hangs the putty session until the
> tshark capture ends'
> CMD_LIST=[PLINK,sess_name,'/usr/bin/sudo /usr/sbin/tshark', '-a',
> 'duration:10', '-i',  'wlan0', '-T', 'text', '-V','>', 'out.txt'];
> print "The command list you are sending to the subprocess is: \n",
> "\t", CMD_LIST
>
> PIPE = subprocess.PIPE
> p = subprocess.Popen(CMD_LIST, stdout=PIPE, stderr=PIPE)
> stdout, stderr = p.communicate ()
> print 'stdout = ', stdout
> print 'stderr = ', stderr
> *
>
> For both runs (atl_cmd=0 or alt_cmd=1), the stdout and stderr printouts at
> the end of the script are empty.
>
> Any suggestions would be appreciated.
>
> Thanks,
>
> Mike
>
> ***
>
> On Wed, Mar 31, 2010 at 7:42 AM, Tim Golden  wrote:
>
>> On 30/03/2010 17:29, Mike Baker wrote:
>>
>>> I'm trying to connect to a Linux box from my Windows machine and execute
>>> a
>>> series of commands
>>>
>>> I want a script to always
>>> execute the same series of commands without having to do so manually.   I
>>> also have code that will execute a single command like cat a file and
>>> write
>>> the ouput to a new file. However, when I try to use the communicate
>>> object
>>> in subprocess, my window hangs.
>>>
>>
>>
>> This works for me:
>>
>> 
>> import os, sys
>> import subprocess
>>
>> PLINK = "plink"
>> REMOTE_USER = "tgol...@web30.webfaction.com"
>> PIPE = subprocess.PIPE
>>
>> p = subprocess.Popen ([PLINK, REMOTE_USER, "ls"], stdout=PIPE)
>> stdout, stderr = p.communicate ()
>> print "#1:", stdout.splitlines ()[0]
>>
>> with open ("out.txt", "w") as f:
>>  p = subprocess.Popen ([PLINK, REMOTE_USER, "cat .bashrc"], stdout=f)
>>  p.communicate ()
>> print "#2:", open ("out.txt").read ().splitlines ()[0]
>>
>> p = subprocess.Popen ([PLINK, REMOTE_USER], stdin=PIPE, stdout=PIPE)
>> stdout, stderr = p.communicate ("ls\nexit\n")
>> print "#3", stdout
>>
>> p = subprocess.Popen ([PLINK, REMOTE_USER], stdin=PIPE, stdout=PIPE)
>> p.stdin.write ("ls\nexit\n")
>> stdout, stderr = p.communicate ()
>> print "#4", stdout
>>
>> 
>>
>> A few things to note, none of which I believe to be germane to the
>> issues you're experiencing:
>>
>> * You almost never need to use shell=True on a Windows call to subprocess.
>>  If in doubt, don't use it.
>>
>> * Definitely better to pass the list-of-params style as the first param
>>  of subprocess.Popen; it sorts out issues with embe

Re: [Tutor] Remote access from Windows PC to a Linux box

2010-04-21 Thread Mike Baker
Yashwin,

Thanks!  Your nohup redirection worked great!

  - Mike

On Wed, Apr 21, 2010 at 2:45 PM, Yashwin Kanchan
wrote:

> Hi Mike
>
> have you tried running the tshark process in the background...
>
> *CMD_LIST=[PLINK,sess_name,'/usr/bin/sudo /usr/sbin/tshark &', '-a',
> 'duration:10', '-i', 'wlan0', '-T', 'text', '-V','>', 'out.txt'];*
>
> Or if you are using NOHUP try redirecting this way...
>
> *CMD_LIST=[PLINK,sess_name,'/usr/bin/nohup','/usr/bin/sudo
> /usr/sbin/tshark > out.txt 2> out.err < /dev/null ', '-a', 'duration:10',
> '-i', 'wlan0', '-T', 'text','&'];*
>
> Regards
> Yashwin Kanchan
>
>
> On 21 April 2010 19:15, Mike Baker  wrote:
>
>> Thanks Tim,
>>
>> Your subprocess examples got me started in the right direction.  I've
>> moved on to a slightly more advanced problem that I need help with.
>>
>> I want to remotely start a Tshark packet capture session on one of our
>> Linux machines in the lab.  I want to start the session from my Windows
>> machine running Python 2.5.  The output capture file needs to be saved on
>> the remote Linux machine.
>>
>> The example below nearly does what I want.  It starts Tshark via Putty,
>> runs for 10 seconds then writes the capture file (out.txt) to a remote Linux
>> machine.  The problem is that the putty session hangs open while Tshark is
>> running. So, I can't execute additional Python commands until the Tshark
>> capture finishes.
>>
>> I've experimented with the Unix nohup command, but it does not seem to
>> work as expected with Tshark.  If you call my function below with
>> >>> test_subp(alt_cmd=1)
>> then the nohup command is added to the subprocess command list (along
>> with a trailing '&' to send the command to background).  This should work.
>> Using this alternate command, out.txt gets created, but is always empty.
>>
>>
>> Here is my code:
>> **
>> def test_subp(alt_cmd=0):
>> '''Establish a Putty connection with one of our Linux machines in the
>> lab.
>> Send Tshark command to start a data collection session over Putty.
>> '''
>> PLINK = 'C:\\Progra~1\\putty\\plink'
>> sess_name='LabComp1'
>> if alt_cmd:
>> '''This command does not work as expected.  The tshark output file
>> (out.txt)is created,
>> but there is nothing in it '''
>> CMD_LIST=[PLINK,sess_name,'/usr/bin/nohup','/usr/bin/sudo
>> /usr/sbin/tshark', '-a', 'duration:10', '-i',  'wlan0', '-T', 'text',
>> '-V','>', 'out.txt','&'];
>> else:
>> 'This command works great, writing tshark output to out.txt on the
>> remote machine.'
>> 'Unfortunately, this command hangs the putty session until the
>> tshark capture ends'
>> CMD_LIST=[PLINK,sess_name,'/usr/bin/sudo /usr/sbin/tshark', '-a',
>> 'duration:10', '-i',  'wlan0', '-T', 'text', '-V','>', 'out.txt'];
>> print "The command list you are sending to the subprocess is: \n",
>> "\t", CMD_LIST
>>
>> PIPE = subprocess.PIPE
>> p = subprocess.Popen(CMD_LIST, stdout=PIPE, stderr=PIPE)
>> stdout, stderr = p.communicate ()
>> print 'stdout = ', stdout
>> print 'stderr = ', stderr
>> *
>>
>> For both runs (atl_cmd=0 or alt_cmd=1), the stdout and stderr printouts at
>> the end of the script are empty.
>>
>> Any suggestions would be appreciated.
>>
>> Thanks,
>>
>> Mike
>>
>> ***
>>
>>  On Wed, Mar 31, 2010 at 7:42 AM, Tim Golden wrote:
>>
>>> On 30/03/2010 17:29, Mike Baker wrote:
>>>
 I'm trying to connect to a Linux box from my Windows machine and execute
 a
 series of commands

 I want a script to always
 execute the same series of commands without having to do so manually.
 I
 also have code that will execute a single command like cat a file and
 write
 the ouput to a new file. However, when I try to use the communicate
 object
 in subprocess, my window hangs.

>>>
>>>
>>> This works for me:
>>>
>>> 
>>> import os, sys
>>> import subprocess
>>>
>>> PLINK = "plink"
>>> REMOTE_USER = "tgol...@web30.webfaction.com"
>>> PIPE = subprocess.PIPE
>>>
>>> p = subprocess.Popen ([PLINK, REMOTE_USER, "ls"], stdout=PIPE)
>>> stdout, stderr = p.communicate ()
>>> print "#1:", stdout.splitlines ()[0]
>>>
>>> with open ("out.txt", "w") as f:
>>>  p = subprocess.Popen ([PLINK, REMOTE_USER, "cat .bashrc"], stdout=f)
>>>  p.communicate ()
>>> print "#2:", open ("out.txt").read ().splitlines ()[0]
>>>
>>> p = subprocess.Popen ([PLINK, REMOTE_USER], stdin=PIPE, stdout=PIPE)
>>> stdout, stderr = p.communicate ("ls\nexit\n")
>>> print "#3", stdout
>>>
>>> p = subprocess.Popen ([PLINK, REMOTE_USER], stdin=PIPE, stdout=PIPE)
>>> p.stdin.write ("ls\nexit\n")
>>> stdout, stderr = p.communicate ()
>>> print "#4", stdout
>>>
>>> 
>>>
>>> A few things to note, none of which I believe to be germane to the
>

Re: [Tutor] set and sets.Set

2010-04-21 Thread Steven D'Aprano
On Thu, 22 Apr 2010 02:28:03 am Bala subramanian wrote:
> Friends,
> Someone please write me the difference between creating set with
> set() and a sets.Set().

The sets module, including sets.Set(), were first introduced in Python 
2.3 and is written in Python.

The built-in set object was introduced in Python 2.4 and is re-written 
in C for speed.

Functionally, they are identical. Speed-wise, the built-in version is 
much faster, so unless you need to support Python 2.3, always use the 
built-in set type.



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


Re: [Tutor] the binary math "wall"

2010-04-21 Thread Steven D'Aprano
On Thu, 22 Apr 2010 01:37:35 am Lowell Tackett wrote:

> Recalling (from a brief foray into college Chem.) that a result could
> not be displayed with precision greater than the least precise
> component that bore [the result].  So, yes, I could accept my input
> as the arbitrator of accuracy.

Unfortunately, you can't distinguish the number of supplied digits of 
accuracy from a float. Given as floats, all of the following are 
identical:

0.1
0.1
0.09
0.11

as are these two:

0.08
0.099985

Perhaps you should look at the Decimal class, not necessarily to use it, 
but to see what they do. For instance, you create a Decimal with a 
string, not a float:

>>> from decimal import Decimal
>>> Decimal('0.1')
Decimal("0.1")
>>> Decimal('0.1')
Decimal("0.1")

which allows you to distinguish the number of digits of precision.


> A scenario:
>
> Calculating the coordinates of a forward station from a given base
> station would require [perhaps] the bearing (an angle from north,
> say) and distance from hither to there.  Calculating the north
> coordinate would set up this relationship, e.g.:
>
> cos(3° 22' 49.6") x 415.9207'(Hyp) = adjacent side(North)
>
> My first requirement, and this is the struggle I (we) are now engaged
> in, is to convert my bearing angle (3° 22' 49.6") to decimal degrees,
> such that I can assign its' proper cosine value.

This is MUCH MUCH MUCH easier than trying to deal with DMS as a float. 
Your data already separates the parts for you, so it is just a matter 
of:

>>> d = 3 + 22/60.0 + 49.2/3600.0
>>> import math
>>> angle = math.radians(d)
>>> math.cos(angle)
0.9982601259166638

Then the only problem you have is whether or not the formula you are 
using is numerically stable, or whether it is subject to 
catastrophically growing errors.

I hope we're not frightening you off here. For nearly anything people 
are going to want to do, their input data will be in single-precision. 
One of the simplest things they can do to improve the accuracy of 
floating point calculations is to do their intermediate calculations in 
double-precision.

The good news is, Python floats are already in double-precision.

For most modern systems, single-precision floats have 24 binary digits 
of precision (approximately 6 decimal digits) and double-precision 
floats have 53 binary digits (15 decimal) of precision. More than 
sufficient for dealing with an angle measured to a tenth of a second.


Some resources for you to read:

http://en.wikipedia.org/wiki/Floating_point
http://www.cs.princeton.edu/introcs/91float/
http://www.cs.berkeley.edu/~wkahan/
http://docs.sun.com/source/806-3568/ncg_goldberg.html



> Were I to accumulate many of these "legs" into perhaps a 15 mile
> traverse-accumulating little computer errors along the way-the end
> result could be catastrophically wrong.

YES!!! 

And just by being aware of this potential problem, you are better off 
than 90% of programmers who are blithely unaware that floats are not 
real numbers.




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


[Tutor] Fwd: python tutor needed

2010-04-21 Thread Danny Yoo
Forwarding for Lumka:


-- Forwarded message --
From: Lumka Msibi 
Date: Tue, Apr 20, 2010 at 2:51 PM
Subject: Fwd: python tutor needed
To: Danny Yoo , "dany.yoo" 


This
communication is intended for the addressee only. It is confidential.
If you have received this communication in error, please notify us
immediately and destroy the original message. You may not copy or
disseminate this communication without the permission of the
University. Only authorized signatories are competent to enter into
agreements on behalf of the University and recipients are thus advised
that the content of this message may not be legally binding on the
University and may contain the personal views and opinions of the
author, which are not necessarily the views and opinions of The
University of the Witwatersrand, Johannesburg. All agreements between
the University and outsiders are subject to South African Law unless
the University agrees in writing to the contrary.

-- Forwarded message --
From: Lumka Msibi 
To: Danny Yoo , "dany.yoo" 
Date: Tue, 20 Apr 2010 20:51:41 +0200
Subject: Fwd: python tutor needed


-- Forwarded message --
From: Lumka Msibi 
To: Danny Yoo 
Date: Mon, 19 Apr 2010 16:25:19 +0200
Subject: python tutor needed
Hi

Are there any python tutors in Johannesburg, South Africa? i really
need some tution before my exam in 2 weeks. please help.

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


Re: [Tutor] the binary math "wall"

2010-04-21 Thread Dave Angel

Steven D'Aprano wrote:

On Thu, 22 Apr 2010 01:37:35 am Lowell Tackett wrote:



Were I to accumulate many of these "legs" into perhaps a 15 mile
traverse-accumulating little computer errors along the way-the end
result could be catastrophically wrong.



YES!!! 

And just by being aware of this potential problem, you are better off 
than 90% of programmers who are blithely unaware that floats are not 
real numbers.



  
Absolutely.  But "catastrophically wrong" has to be defined, and 
analyzed.  If each of these measurements is of 100 feet, measured to an 
accuracy of .0001 feet, and you add up the measurements in Python 
floats, you'll be adding 750 measurements, and your human error could 
accumulate to as much as .07 feet.


The same 750 floating point ads, each to 15 digits of quantization 
accuracy (thanks for the correction, it isn't 18) will give a maximum 
"computer error" of  maybe .1 feet.  The human error is much 
larger than the computer error.


No results can be counted on without some analysis of both sources of 
error.  Occasionally, the "computer error" will exceed the human, and 
that depends on the calculations you do on your measurements.


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